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 /* 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 the functions of mozIStorageService except for
6 // openUnsharedDatabase, which is tested by test_storage_service_unshared.js.
8 const BACKUP_FILE_NAME = "test_storage.sqlite.backup";
10 function test_openSpecialDatabase_invalid_arg()
11 {
12 try {
13 getService().openSpecialDatabase("abcd");
14 do_throw("We should not get here!");
15 } catch (e) {
16 print(e);
17 print("e.result is " + e.result);
18 do_check_eq(Cr.NS_ERROR_INVALID_ARG, e.result);
19 }
20 }
22 function test_openDatabase_null_file()
23 {
24 try {
25 getService().openDatabase(null);
26 do_throw("We should not get here!");
27 } catch (e) {
28 print(e);
29 print("e.result is " + e.result);
30 do_check_eq(Cr.NS_ERROR_INVALID_ARG, e.result);
31 }
32 }
34 function test_openUnsharedDatabase_null_file()
35 {
36 try {
37 getService().openUnsharedDatabase(null);
38 do_throw("We should not get here!");
39 } catch (e) {
40 print(e);
41 print("e.result is " + e.result);
42 do_check_eq(Cr.NS_ERROR_INVALID_ARG, e.result);
43 }
44 }
46 function test_openDatabase_file_DNE()
47 {
48 // the file should be created after calling
49 var db = getTestDB();
50 do_check_false(db.exists());
51 getService().openDatabase(db);
52 do_check_true(db.exists());
53 }
55 function test_openDatabase_file_exists()
56 {
57 // it should already exist from our last test
58 var db = getTestDB();
59 do_check_true(db.exists());
60 getService().openDatabase(db);
61 do_check_true(db.exists());
62 }
64 function test_corrupt_db_throws_with_openDatabase()
65 {
66 try {
67 getDatabase(getCorruptDB());
68 do_throw("should not be here");
69 }
70 catch (e) {
71 do_check_eq(Cr.NS_ERROR_FILE_CORRUPTED, e.result);
72 }
73 }
75 function test_fake_db_throws_with_openDatabase()
76 {
77 try {
78 getDatabase(getFakeDB());
79 do_throw("should not be here");
80 }
81 catch (e) {
82 do_check_eq(Cr.NS_ERROR_FILE_CORRUPTED, e.result);
83 }
84 }
86 function test_backup_not_new_filename()
87 {
88 const fname = getTestDB().leafName;
90 var backup = getService().backupDatabaseFile(getTestDB(), fname);
91 do_check_neq(fname, backup.leafName);
93 backup.remove(false);
94 }
96 function test_backup_new_filename()
97 {
98 var backup = getService().backupDatabaseFile(getTestDB(), BACKUP_FILE_NAME);
99 do_check_eq(BACKUP_FILE_NAME, backup.leafName);
101 backup.remove(false);
102 }
104 function test_backup_new_folder()
105 {
106 var parentDir = getTestDB().parent;
107 parentDir.append("test_storage_temp");
108 if (parentDir.exists())
109 parentDir.remove(true);
110 parentDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
111 do_check_true(parentDir.exists());
113 var backup = getService().backupDatabaseFile(getTestDB(), BACKUP_FILE_NAME,
114 parentDir);
115 do_check_eq(BACKUP_FILE_NAME, backup.leafName);
116 do_check_true(parentDir.equals(backup.parent));
118 parentDir.remove(true);
119 }
121 var tests = [
122 test_openSpecialDatabase_invalid_arg,
123 test_openDatabase_null_file,
124 test_openUnsharedDatabase_null_file,
125 test_openDatabase_file_DNE,
126 test_openDatabase_file_exists,
127 test_corrupt_db_throws_with_openDatabase,
128 test_fake_db_throws_with_openDatabase,
129 test_backup_not_new_filename,
130 test_backup_new_filename,
131 test_backup_new_folder,
132 ];
134 function run_test()
135 {
136 for (var i = 0; i < tests.length; i++)
137 tests[i]();
139 cleanup();
140 }