Tue, 06 Jan 2015 21:39:09 +0100
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 the unicode functions that we have added |
michael@0 | 6 | |
michael@0 | 7 | const LATIN1_AE = "\xc6"; // "Æ" |
michael@0 | 8 | const LATIN1_ae = "\xe6"; // "æ" |
michael@0 | 9 | |
michael@0 | 10 | function setup() |
michael@0 | 11 | { |
michael@0 | 12 | getOpenedDatabase().createTable("test", "id INTEGER PRIMARY KEY, name TEXT"); |
michael@0 | 13 | |
michael@0 | 14 | var stmt = createStatement("INSERT INTO test (name, id) VALUES (?1, ?2)"); |
michael@0 | 15 | stmt.bindByIndex(0, LATIN1_AE); |
michael@0 | 16 | stmt.bindByIndex(1, 1); |
michael@0 | 17 | stmt.execute(); |
michael@0 | 18 | stmt.bindByIndex(0, "A"); |
michael@0 | 19 | stmt.bindByIndex(1, 2); |
michael@0 | 20 | stmt.execute(); |
michael@0 | 21 | stmt.bindByIndex(0, "b"); |
michael@0 | 22 | stmt.bindByIndex(1, 3); |
michael@0 | 23 | stmt.execute(); |
michael@0 | 24 | stmt.bindByIndex(0, LATIN1_ae); |
michael@0 | 25 | stmt.bindByIndex(1, 4); |
michael@0 | 26 | stmt.execute(); |
michael@0 | 27 | stmt.finalize(); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function test_upper_ascii() |
michael@0 | 31 | { |
michael@0 | 32 | var stmt = createStatement("SELECT name, id FROM test WHERE name = upper('a')"); |
michael@0 | 33 | do_check_true(stmt.executeStep()); |
michael@0 | 34 | do_check_eq("A", stmt.getString(0)); |
michael@0 | 35 | do_check_eq(2, stmt.getInt32(1)); |
michael@0 | 36 | stmt.reset(); |
michael@0 | 37 | stmt.finalize(); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function test_upper_non_ascii() |
michael@0 | 41 | { |
michael@0 | 42 | var stmt = createStatement("SELECT name, id FROM test WHERE name = upper(?1)"); |
michael@0 | 43 | stmt.bindByIndex(0, LATIN1_ae); |
michael@0 | 44 | do_check_true(stmt.executeStep()); |
michael@0 | 45 | do_check_eq(LATIN1_AE, stmt.getString(0)); |
michael@0 | 46 | do_check_eq(1, stmt.getInt32(1)); |
michael@0 | 47 | stmt.reset(); |
michael@0 | 48 | stmt.finalize(); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function test_lower_ascii() |
michael@0 | 52 | { |
michael@0 | 53 | var stmt = createStatement("SELECT name, id FROM test WHERE name = lower('B')"); |
michael@0 | 54 | do_check_true(stmt.executeStep()); |
michael@0 | 55 | do_check_eq("b", stmt.getString(0)); |
michael@0 | 56 | do_check_eq(3, stmt.getInt32(1)); |
michael@0 | 57 | stmt.reset(); |
michael@0 | 58 | stmt.finalize(); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function test_lower_non_ascii() |
michael@0 | 62 | { |
michael@0 | 63 | var stmt = createStatement("SELECT name, id FROM test WHERE name = lower(?1)"); |
michael@0 | 64 | stmt.bindByIndex(0, LATIN1_AE); |
michael@0 | 65 | do_check_true(stmt.executeStep()); |
michael@0 | 66 | do_check_eq(LATIN1_ae, stmt.getString(0)); |
michael@0 | 67 | do_check_eq(4, stmt.getInt32(1)); |
michael@0 | 68 | stmt.reset(); |
michael@0 | 69 | stmt.finalize(); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | function test_like_search_different() |
michael@0 | 73 | { |
michael@0 | 74 | var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1"); |
michael@0 | 75 | stmt.bindByIndex(0, LATIN1_AE); |
michael@0 | 76 | do_check_true(stmt.executeStep()); |
michael@0 | 77 | do_check_eq(2, stmt.getInt32(0)); |
michael@0 | 78 | stmt.finalize(); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function test_like_search_same() |
michael@0 | 82 | { |
michael@0 | 83 | var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1"); |
michael@0 | 84 | stmt.bindByIndex(0, LATIN1_ae); |
michael@0 | 85 | do_check_true(stmt.executeStep()); |
michael@0 | 86 | do_check_eq(2, stmt.getInt32(0)); |
michael@0 | 87 | stmt.finalize(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | var tests = [test_upper_ascii, test_upper_non_ascii, test_lower_ascii, |
michael@0 | 91 | test_lower_non_ascii, test_like_search_different, |
michael@0 | 92 | test_like_search_same]; |
michael@0 | 93 | |
michael@0 | 94 | function run_test() |
michael@0 | 95 | { |
michael@0 | 96 | setup(); |
michael@0 | 97 | |
michael@0 | 98 | for (var i = 0; i < tests.length; i++) |
michael@0 | 99 | tests[i](); |
michael@0 | 100 | |
michael@0 | 101 | cleanup(); |
michael@0 | 102 | } |
michael@0 | 103 |