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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=2 sts=2 et : */
3 /**
4 * Any copyright is dedicated to the Public Domain.
5 * http://creativecommons.org/publicdomain/zero/1.0/
6 */
8 /**
9 * This file tests that the JS language helpers in various ways.
10 */
12 ////////////////////////////////////////////////////////////////////////////////
13 //// Test Functions
15 function test_params_enumerate()
16 {
17 let stmt = createStatement(
18 "SELECT * FROM test WHERE id IN (:a, :b, :c)"
19 );
21 // Make sure they are right.
22 let expected = ["a", "b", "c"];
23 let index = 0;
24 for (let name in stmt.params)
25 do_check_eq(name, expected[index++]);
26 }
28 function test_params_prototype()
29 {
30 let stmt = createStatement(
31 "SELECT * FROM sqlite_master"
32 );
34 // Set a property on the prototype and make sure it exist (will not be a
35 // bindable parameter, however).
36 Object.getPrototypeOf(stmt.params).test = 2;
37 do_check_eq(stmt.params.test, 2);
38 stmt.finalize();
39 }
41 function test_row_prototype()
42 {
43 let stmt = createStatement(
44 "SELECT * FROM sqlite_master"
45 );
47 do_check_true(stmt.executeStep());
49 // Set a property on the prototype and make sure it exists (will not be in the
50 // results, however).
51 Object.getPrototypeOf(stmt.row).test = 2;
52 do_check_eq(stmt.row.test, 2);
54 // Clean up after ourselves.
55 delete Object.getPrototypeOf(stmt.row).test;
56 stmt.finalize();
57 }
59 function test_params_gets_sync()
60 {
61 // Added for bug 562866.
62 /*
63 let stmt = createStatement(
64 "SELECT * FROM test WHERE id IN (:a, :b, :c)"
65 );
67 // Make sure we do not assert in getting the value.
68 let originalCount = Object.getOwnPropertyNames(stmt.params).length;
69 let expected = ["a", "b", "c"];
70 for each (let name in expected) {
71 stmt.params[name];
72 }
74 // Now make sure we didn't magically get any additional properties.
75 let finalCount = Object.getOwnPropertyNames(stmt.params).length;
76 do_check_eq(originalCount + expected.length, finalCount);
77 */
78 }
80 function test_params_gets_async()
81 {
82 // Added for bug 562866.
83 /*
84 let stmt = createAsyncStatement(
85 "SELECT * FROM test WHERE id IN (:a, :b, :c)"
86 );
88 // Make sure we do not assert in getting the value.
89 let originalCount = Object.getOwnPropertyNames(stmt.params).length;
90 let expected = ["a", "b", "c"];
91 for each (let name in expected) {
92 stmt.params[name];
93 }
95 // Now make sure we didn't magically get any additional properties.
96 let finalCount = Object.getOwnPropertyNames(stmt.params).length;
97 do_check_eq(originalCount + expected.length, finalCount);
98 */
99 }
101 ////////////////////////////////////////////////////////////////////////////////
102 //// Test Runner
104 let tests = [
105 test_params_enumerate,
106 test_params_prototype,
107 test_row_prototype,
108 test_params_gets_sync,
109 test_params_gets_async,
110 ];
111 function run_test()
112 {
113 cleanup();
115 // Create our database.
116 getOpenedDatabase().executeSimpleSQL(
117 "CREATE TABLE test (" +
118 "id INTEGER PRIMARY KEY " +
119 ")"
120 );
122 // Run the tests.
123 tests.forEach(function(test) test());
124 }