test_storage_service_special.js (1634B)
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/. */ 4 5 // This file tests the openSpecialDatabase function of mozIStorageService. 6 7 add_task(async function test_invalid_storage_key() { 8 try { 9 Services.storage.openSpecialDatabase("abcd"); 10 do_throw("We should not get here!"); 11 } catch (e) { 12 print(e); 13 print("e.result is " + e.result); 14 Assert.equal(Cr.NS_ERROR_INVALID_ARG, e.result); 15 } 16 }); 17 18 add_task(async function test_memdb_close_clone_fails() { 19 for (const name of [null, "foo"]) { 20 const db = Services.storage.openSpecialDatabase("memory", name); 21 db.close(); 22 expectError(Cr.NS_ERROR_NOT_INITIALIZED, () => db.clone()); 23 } 24 }); 25 26 add_task(async function test_memdb_no_file_on_disk() { 27 for (const name of [null, "foo"]) { 28 const db = Services.storage.openSpecialDatabase("memory", name); 29 db.close(); 30 for (const dirKey of ["CurWorkD", "ProfD"]) { 31 const dir = Services.dirsvc.get(dirKey, Ci.nsIFile); 32 const file = dir.clone(); 33 file.append(!name ? ":memory:" : "file:foo?mode=memory&cache=shared"); 34 Assert.ok(!file.exists()); 35 } 36 } 37 }); 38 39 add_task(async function test_memdb_sharing() { 40 for (const name of [null, "foo"]) { 41 const db = Services.storage.openSpecialDatabase("memory", name); 42 db.executeSimpleSQL("CREATE TABLE test(name TEXT)"); 43 const db2 = Services.storage.openSpecialDatabase("memory", name); 44 Assert.equal(!!name, db2.tableExists("test")); 45 db.close(); 46 db2.close(); 47 } 48 });