From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- storage/test/unit/test_storage_service_special.js | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 storage/test/unit/test_storage_service_special.js (limited to 'storage/test/unit/test_storage_service_special.js') diff --git a/storage/test/unit/test_storage_service_special.js b/storage/test/unit/test_storage_service_special.js new file mode 100644 index 0000000000..50cde042af --- /dev/null +++ b/storage/test/unit/test_storage_service_special.js @@ -0,0 +1,48 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This file tests the openSpecialDatabase function of mozIStorageService. + +add_task(async function test_invalid_storage_key() { + try { + Services.storage.openSpecialDatabase("abcd"); + do_throw("We should not get here!"); + } catch (e) { + print(e); + print("e.result is " + e.result); + Assert.equal(Cr.NS_ERROR_INVALID_ARG, e.result); + } +}); + +add_task(async function test_memdb_close_clone_fails() { + for (const name of [null, "foo"]) { + const db = Services.storage.openSpecialDatabase("memory", name); + db.close(); + expectError(Cr.NS_ERROR_NOT_INITIALIZED, () => db.clone()); + } +}); + +add_task(async function test_memdb_no_file_on_disk() { + for (const name of [null, "foo"]) { + const db = Services.storage.openSpecialDatabase("memory", name); + db.close(); + for (const dirKey of ["CurWorkD", "ProfD"]) { + const dir = Services.dirsvc.get(dirKey, Ci.nsIFile); + const file = dir.clone(); + file.append(!name ? ":memory:" : "file:foo?mode=memory&cache=shared"); + Assert.ok(!file.exists()); + } + } +}); + +add_task(async function test_memdb_sharing() { + for (const name of [null, "foo"]) { + const db = Services.storage.openSpecialDatabase("memory", name); + db.executeSimpleSQL("CREATE TABLE test(name TEXT)"); + const db2 = Services.storage.openSpecialDatabase("memory", name); + Assert.ok(!!name == db2.tableExists("test")); + db.close(); + db2.close(); + } +}); -- cgit v1.2.3