diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /storage/test/unit/test_readonly-immutable-nolock_vfs.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/test/unit/test_readonly-immutable-nolock_vfs.js')
-rw-r--r-- | storage/test/unit/test_readonly-immutable-nolock_vfs.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/storage/test/unit/test_readonly-immutable-nolock_vfs.js b/storage/test/unit/test_readonly-immutable-nolock_vfs.js new file mode 100644 index 0000000000..5c11150b0a --- /dev/null +++ b/storage/test/unit/test_readonly-immutable-nolock_vfs.js @@ -0,0 +1,47 @@ +/* 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 readonly-immutable-nolock VFS. + +add_task(async function test() { + const path = PathUtils.join(PathUtils.profileDir, "ro"); + await IOUtils.makeDirectory(path); + const dbpath = PathUtils.join(path, "test-immutable.sqlite"); + + let conn = await Sqlite.openConnection({ path: dbpath }); + await conn.execute("PRAGMA journal_mode = WAL"); + await conn.execute("CREATE TABLE test (id INTEGER PRIMARY KEY)"); + Assert.ok(await IOUtils.exists(dbpath + "-wal"), "wal journal exists"); + await conn.close(); + + // The wal should have been merged at this point, but just in case... + info("Remove auxiliary files and set the folder as readonly"); + await IOUtils.remove(dbpath + "-wal", { ignoreAbsent: true }); + await IOUtils.setPermissions(path, 0o555); + registerCleanupFunction(async () => { + await IOUtils.setPermissions(path, 0o777); + await IOUtils.remove(path, { recursive: true }); + }); + + // Windows doesn't disallow creating files in read only folders. + if (AppConstants.platform == "macosx" || AppConstants.platform == "linux") { + await Assert.rejects( + Sqlite.openConnection({ path: dbpath, readOnly: true }), + /NS_ERROR_FILE/, + "Should not be able to open the db because it can't create a wal journal" + ); + } + + // Open the database with ignoreLockingMode. + let conn2 = await Sqlite.openConnection({ + path: dbpath, + ignoreLockingMode: true, + }); + await conn2.execute("SELECT * FROM sqlite_master"); + Assert.ok( + !(await IOUtils.exists(dbpath + "-wal")), + "wal journal was not created" + ); + await conn2.close(); +}); |