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 /browser/components/extensions/test/xpcshell/test_ext_browsingData_settings.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/extensions/test/xpcshell/test_ext_browsingData_settings.js')
-rw-r--r-- | browser/components/extensions/test/xpcshell/test_ext_browsingData_settings.js | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/browser/components/extensions/test/xpcshell/test_ext_browsingData_settings.js b/browser/components/extensions/test/xpcshell/test_ext_browsingData_settings.js new file mode 100644 index 0000000000..a065c26c82 --- /dev/null +++ b/browser/components/extensions/test/xpcshell/test_ext_browsingData_settings.js @@ -0,0 +1,146 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +ChromeUtils.defineESModuleGetters(this, { + Preferences: "resource://gre/modules/Preferences.sys.mjs", + Sanitizer: "resource:///modules/Sanitizer.sys.mjs", +}); + +const PREF_DOMAIN = "privacy.cpd."; +const SETTINGS_LIST = [ + "cache", + "cookies", + "history", + "formData", + "downloads", +].sort(); + +add_task(async function testSettingsProperties() { + function background() { + browser.test.onMessage.addListener(msg => { + browser.browsingData.settings().then(settings => { + browser.test.sendMessage("settings", settings); + }); + }); + } + + let extension = ExtensionTestUtils.loadExtension({ + background, + manifest: { + permissions: ["browsingData"], + }, + }); + + await extension.startup(); + + extension.sendMessage("settings"); + let settings = await extension.awaitMessage("settings"); + + // Verify that we get the keys back we expect. + deepEqual( + Object.keys(settings.dataToRemove).sort(), + SETTINGS_LIST, + "dataToRemove contains expected properties." + ); + deepEqual( + Object.keys(settings.dataRemovalPermitted).sort(), + SETTINGS_LIST, + "dataToRemove contains expected properties." + ); + + let dataTypeSet = settings.dataToRemove; + for (let key of Object.keys(dataTypeSet)) { + equal( + Preferences.get(`${PREF_DOMAIN}${key.toLowerCase()}`), + dataTypeSet[key], + `${key} property of dataToRemove matches the expected pref.` + ); + } + + dataTypeSet = settings.dataRemovalPermitted; + for (let key of Object.keys(dataTypeSet)) { + equal( + true, + dataTypeSet[key], + `${key} property of dataRemovalPermitted is true.` + ); + } + + // Explicitly set a pref to both true and false and then check. + const SINGLE_OPTION = "cache"; + const SINGLE_PREF = "privacy.cpd.cache"; + + registerCleanupFunction(() => { + Preferences.reset(SINGLE_PREF); + }); + + Preferences.set(SINGLE_PREF, true); + + extension.sendMessage("settings"); + settings = await extension.awaitMessage("settings"); + equal( + settings.dataToRemove[SINGLE_OPTION], + true, + "Preference that was set to true returns true." + ); + + Preferences.set(SINGLE_PREF, false); + + extension.sendMessage("settings"); + settings = await extension.awaitMessage("settings"); + equal( + settings.dataToRemove[SINGLE_OPTION], + false, + "Preference that was set to false returns false." + ); + + await extension.unload(); +}); + +add_task(async function testSettingsSince() { + const TIMESPAN_PREF = "privacy.sanitize.timeSpan"; + const TEST_DATA = { + TIMESPAN_5MIN: Date.now() - 5 * 60 * 1000, + TIMESPAN_HOUR: Date.now() - 60 * 60 * 1000, + TIMESPAN_2HOURS: Date.now() - 2 * 60 * 60 * 1000, + TIMESPAN_EVERYTHING: 0, + }; + + function background() { + browser.test.onMessage.addListener(msg => { + browser.browsingData.settings().then(settings => { + browser.test.sendMessage("settings", settings); + }); + }); + } + + let extension = ExtensionTestUtils.loadExtension({ + background, + manifest: { + permissions: ["browsingData"], + }, + }); + + await extension.startup(); + + registerCleanupFunction(() => { + Preferences.reset(TIMESPAN_PREF); + }); + + for (let timespan in TEST_DATA) { + Preferences.set(TIMESPAN_PREF, Sanitizer[timespan]); + + extension.sendMessage("settings"); + let settings = await extension.awaitMessage("settings"); + + // Because it is based on the current timestamp, we cannot know the exact + // value to expect for since, so allow a 10s variance. + ok( + Math.abs(settings.options.since - TEST_DATA[timespan]) < 10000, + "settings.options contains the expected since value." + ); + } + + await extension.unload(); +}); |