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.

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

mercurial