summaryrefslogtreecommitdiffstats
path: root/browser/components/preferences/tests/browser_experimental_features_resetall.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/components/preferences/tests/browser_experimental_features_resetall.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/preferences/tests/browser_experimental_features_resetall.js')
-rw-r--r--browser/components/preferences/tests/browser_experimental_features_resetall.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/browser/components/preferences/tests/browser_experimental_features_resetall.js b/browser/components/preferences/tests/browser_experimental_features_resetall.js
new file mode 100644
index 0000000000..636374c057
--- /dev/null
+++ b/browser/components/preferences/tests/browser_experimental_features_resetall.js
@@ -0,0 +1,112 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// It doesn't matter what two preferences are used here, as long as the first is a built-in
+// one that defaults to false and the second defaults to true.
+const KNOWN_PREF_1 = "browser.display.use_system_colors";
+const KNOWN_PREF_2 = "browser.underline_anchors";
+
+// This test verifies that pressing the reset all button for experimental features
+// resets all of the checkboxes to their default state.
+add_task(async function testResetAll() {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["browser.preferences.experimental", true],
+ ["test.featureA", false],
+ ["test.featureB", true],
+ [KNOWN_PREF_1, false],
+ [KNOWN_PREF_2, true],
+ ],
+ });
+
+ // Add a number of test features.
+ const server = new DefinitionServer();
+ let definitions = [
+ {
+ id: "test-featureA",
+ preference: "test.featureA",
+ defaultValue: false,
+ },
+ {
+ id: "test-featureB",
+ preference: "test.featureB",
+ defaultValue: true,
+ },
+ {
+ id: "test-featureC",
+ preference: KNOWN_PREF_1,
+ defaultValue: false,
+ },
+ {
+ id: "test-featureD",
+ preference: KNOWN_PREF_2,
+ defaultValue: true,
+ },
+ ];
+ for (let { id, preference, defaultValue } of definitions) {
+ server.addDefinition({ id, preference, defaultValue, isPublic: true });
+ }
+
+ await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ `about:preferences?definitionsUrl=${encodeURIComponent(
+ server.definitionsUrl
+ )}#paneExperimental`
+ );
+ let doc = gBrowser.contentDocument;
+
+ await TestUtils.waitForCondition(
+ () => doc.getElementById(definitions[definitions.length - 1].id),
+ "wait for the first public feature to get added to the DOM"
+ );
+
+ // Check the initial state of each feature.
+ ok(!Services.prefs.getBoolPref("test.featureA"), "initial state A");
+ ok(Services.prefs.getBoolPref("test.featureB"), "initial state B");
+ ok(!Services.prefs.getBoolPref(KNOWN_PREF_1), "initial state C");
+ ok(Services.prefs.getBoolPref(KNOWN_PREF_2), "initial state D");
+
+ // Modify the state of some of the features.
+ doc.getElementById("test-featureC").click();
+ doc.getElementById("test-featureD").click();
+ ok(!Services.prefs.getBoolPref("test.featureA"), "modified state A");
+ ok(Services.prefs.getBoolPref("test.featureB"), "modified state B");
+ ok(Services.prefs.getBoolPref(KNOWN_PREF_1), "modified state C");
+ ok(!Services.prefs.getBoolPref(KNOWN_PREF_2), "modified state D");
+
+ // State after reset.
+ let prefChangedPromise = new Promise(resolve => {
+ Services.prefs.addObserver(KNOWN_PREF_2, function observer() {
+ Services.prefs.removeObserver(KNOWN_PREF_2, observer);
+ resolve();
+ });
+ });
+ doc.getElementById("experimentalCategory-reset").click();
+ await prefChangedPromise;
+
+ // The preferences will be reset to the default value for the feature.
+ ok(!Services.prefs.getBoolPref("test.featureA"), "after reset state A");
+ ok(Services.prefs.getBoolPref("test.featureB"), "after reset state B");
+ ok(!Services.prefs.getBoolPref(KNOWN_PREF_1), "after reset state C");
+ ok(Services.prefs.getBoolPref(KNOWN_PREF_2), "after reset state D");
+ ok(
+ !doc.getElementById("test-featureA").checked,
+ "after reset checkbox state A"
+ );
+ ok(
+ doc.getElementById("test-featureB").checked,
+ "after reset checkbox state B"
+ );
+ ok(
+ !doc.getElementById("test-featureC").checked,
+ "after reset checkbox state C"
+ );
+ ok(
+ doc.getElementById("test-featureD").checked,
+ "after reset checkbox state D"
+ );
+
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});