diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:50 +0000 |
commit | def92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch) | |
tree | 2ef34b9ad8bb9a9220e05d60352558b15f513894 /modules/libpref/test | |
parent | Adding debian version 125.0.3-1. (diff) | |
download | firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'modules/libpref/test')
-rw-r--r-- | modules/libpref/test/unit/test_backupPrefFile.js | 46 | ||||
-rw-r--r-- | modules/libpref/test/unit/xpcshell.toml | 2 |
2 files changed, 48 insertions, 0 deletions
diff --git a/modules/libpref/test/unit/test_backupPrefFile.js b/modules/libpref/test/unit/test_backupPrefFile.js new file mode 100644 index 0000000000..6624443e7c --- /dev/null +++ b/modules/libpref/test/unit/test_backupPrefFile.js @@ -0,0 +1,46 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Tests that we can create a backup of the preferences state to + * a file asynchronously. + */ +add_task(async function test_backupPrefFile() { + // Create a backup of the preferences state to a file. + Services.prefs.setBoolPref("test.backup", true); + + let backupFilePath = PathUtils.join(PathUtils.tempDir, "prefs-backup.js"); + let backupFile = await IOUtils.getFile(backupFilePath); + await Services.prefs.backupPrefFile(backupFile); + + // Verify that the backup file was created and contains the expected content. + let backupContent = await IOUtils.read(backupFilePath, { encoding: "utf-8" }); + + let sawTestValue = false; + + // Now parse the backup file and verify that it contains the expected + // preference value. We'll not worry about any of the other preferences. + let observer = { + onStringPref() {}, + onIntPref() {}, + onBoolPref(kind, name, value, _isSticky, _isLocked) { + if (name == "test.backup" && value) { + sawTestValue = true; + } + }, + onError(message) { + Assert.ok(false, "Error while parsing backup file: " + message); + }, + }; + Services.prefs.parsePrefsFromBuffer(backupContent, observer); + + Assert.ok( + sawTestValue, + "The backup file contains the expected preference value." + ); + + // Clean up the backup file. + await IOUtils.remove(backupFilePath); +}); diff --git a/modules/libpref/test/unit/xpcshell.toml b/modules/libpref/test/unit/xpcshell.toml index 6f9440d609..03cf56d21a 100644 --- a/modules/libpref/test/unit/xpcshell.toml +++ b/modules/libpref/test/unit/xpcshell.toml @@ -5,6 +5,8 @@ support-files = [ "extdata/testExt.js", ] +["test_backupPrefFile.js"] + ["test_bug345529.js"] ["test_bug506224.js"] |