summaryrefslogtreecommitdiffstats
path: root/toolkit/components/kvstore/test/xpcshell
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /toolkit/components/kvstore/test/xpcshell
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/kvstore/test/xpcshell')
-rw-r--r--toolkit/components/kvstore/test/xpcshell/test_kvstore.js74
1 files changed, 73 insertions, 1 deletions
diff --git a/toolkit/components/kvstore/test/xpcshell/test_kvstore.js b/toolkit/components/kvstore/test/xpcshell/test_kvstore.js
index 363feaa43a..4c591622e1 100644
--- a/toolkit/components/kvstore/test/xpcshell/test_kvstore.js
+++ b/toolkit/components/kvstore/test/xpcshell/test_kvstore.js
@@ -12,9 +12,16 @@ function run_test() {
run_next_test();
}
-async function makeDatabaseDir(name) {
+async function makeDatabaseDir(name, { mockCorrupted = false } = {}) {
const databaseDir = PathUtils.join(PathUtils.profileDir, name);
await IOUtils.makeDirectory(databaseDir);
+ if (mockCorrupted) {
+ // Mock a corrupted db.
+ await IOUtils.write(
+ PathUtils.join(databaseDir, "data.safe.bin"),
+ new Uint8Array([0x00, 0x00, 0x00, 0x00])
+ );
+ }
return databaseDir;
}
@@ -26,6 +33,71 @@ add_task(async function getService() {
Assert.ok(gKeyValueService);
});
+add_task(async function getOrCreate_defaultRecoveryStrategyError() {
+ const databaseDir = await makeDatabaseDir("getOrCreate_Error", {
+ mockCorrupted: true,
+ });
+
+ await Assert.rejects(
+ KeyValueService.getOrCreate(databaseDir, "db"),
+ /FileInvalid/
+ );
+});
+
+add_task(async function getOrCreateWithOptions_RecoveryStrategyError() {
+ const databaseDir = await makeDatabaseDir("getOrCreateWithOptions_Error", {
+ mockCorrupted: true,
+ });
+
+ await Assert.rejects(
+ KeyValueService.getOrCreateWithOptions(databaseDir, "db", {
+ strategy: KeyValueService.RecoveryStrategy.ERROR,
+ }),
+ /FileInvalid/
+ );
+});
+
+add_task(async function getOrCreateWithOptions_RecoveryStrategyRename() {
+ const databaseDir = await makeDatabaseDir("getOrCreateWithOptions_Rename", {
+ mockCorrupted: true,
+ });
+
+ const database = await KeyValueService.getOrCreateWithOptions(
+ databaseDir,
+ "db",
+ {
+ strategy: KeyValueService.RecoveryStrategy.RENAME,
+ }
+ );
+ Assert.ok(database);
+
+ Assert.ok(
+ await IOUtils.exists(PathUtils.join(databaseDir, "data.safe.bin.corrupt")),
+ "Expect corrupt file to be found"
+ );
+});
+
+add_task(async function getOrCreateWithOptions_RecoveryStrategyDiscard() {
+ const databaseDir = await makeDatabaseDir("getOrCreateWithOptions_Discard", {
+ mockCorrupted: true,
+ });
+
+ const database = await KeyValueService.getOrCreateWithOptions(
+ databaseDir,
+ "db",
+ {
+ strategy: KeyValueService.RecoveryStrategy.DISCARD,
+ }
+ );
+ Assert.ok(database);
+
+ Assert.equal(
+ await IOUtils.exists(PathUtils.join(databaseDir, "data.safe.bin.corrupt")),
+ false,
+ "Expect corrupt file to not exist"
+ );
+});
+
add_task(async function getOrCreate() {
const databaseDir = await makeDatabaseDir("getOrCreate");
const database = await KeyValueService.getOrCreate(databaseDir, "db");