storage/test/unit/test_storage_fulltextindex.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 // This file tests support for the fts3 (full-text index) module.
     7 // Example statements in these tests are taken from the Full Text Index page
     8 // on the SQLite wiki: http://www.sqlite.org/cvstrac/wiki?p=FullTextIndex
    10 function test_table_creation()
    11 {
    12   var msc = getOpenedUnsharedDatabase();
    14   msc.executeSimpleSQL(
    15     "CREATE VIRTUAL TABLE recipe USING fts3(name, ingredients)");
    17   do_check_true(msc.tableExists("recipe"));
    18 }
    20 function test_insertion()
    21 {
    22   var msc = getOpenedUnsharedDatabase();
    24   msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " +
    25                        "('broccoli stew', 'broccoli peppers cheese tomatoes')");
    26   msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " +
    27                        "('pumpkin stew', 'pumpkin onions garlic celery')");
    28   msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " +
    29                        "('broccoli pie', 'broccoli cheese onions flour')");
    30   msc.executeSimpleSQL("INSERT INTO recipe (name, ingredients) VALUES " +
    31                        "('pumpkin pie', 'pumpkin sugar flour butter')");
    33   var stmt = msc.createStatement("SELECT COUNT(*) FROM recipe");
    34   stmt.executeStep();
    36   do_check_eq(stmt.getInt32(0), 4);
    38   stmt.reset();
    39   stmt.finalize();
    40 }
    42 function test_selection()
    43 {
    44   var msc = getOpenedUnsharedDatabase();
    46   var stmt = msc.createStatement(
    47     "SELECT rowid, name, ingredients FROM recipe WHERE name MATCH 'pie'");
    49   do_check_true(stmt.executeStep());
    50   do_check_eq(stmt.getInt32(0), 3);
    51   do_check_eq(stmt.getString(1), "broccoli pie");
    52   do_check_eq(stmt.getString(2), "broccoli cheese onions flour");
    54   do_check_true(stmt.executeStep());
    55   do_check_eq(stmt.getInt32(0), 4);
    56   do_check_eq(stmt.getString(1), "pumpkin pie");
    57   do_check_eq(stmt.getString(2), "pumpkin sugar flour butter");
    59   do_check_false(stmt.executeStep());
    61   stmt.reset();
    62   stmt.finalize();
    63 }
    65 var tests = [test_table_creation, test_insertion, test_selection];
    67 function run_test()
    68 {
    69   // It's extra important to start from scratch, since these tests won't work
    70   // with an existing shared cache connection, so we do it even though the last
    71   // test probably did it already.
    72   cleanup();
    74   try {
    75     for (var i = 0; i < tests.length; i++) {
    76       tests[i]();
    77     }
    78   }
    79   // It's extra important to clean up afterwards, since later tests that use
    80   // a shared cache connection will not be able to read the database we create,
    81   // so we do this in a finally block to ensure it happens even if some of our
    82   // tests fail.
    83   finally {
    84     cleanup();
    85   }
    86 }

mercurial