diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/components/preferences/tests/browser_privacy_relayIntegration.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/preferences/tests/browser_privacy_relayIntegration.js')
-rw-r--r-- | browser/components/preferences/tests/browser_privacy_relayIntegration.js | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/browser/components/preferences/tests/browser_privacy_relayIntegration.js b/browser/components/preferences/tests/browser_privacy_relayIntegration.js new file mode 100644 index 0000000000..23d62f38bd --- /dev/null +++ b/browser/components/preferences/tests/browser_privacy_relayIntegration.js @@ -0,0 +1,251 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(async function initialState() { + // check pref permutations to verify the UI opens in the correct state + const prefTests = [ + { + initialPrefs: [ + ["signon.firefoxRelay.feature", undefined], + ["signon.rememberSignons", true], + ], + expected: "hidden", + }, + { + initialPrefs: [ + ["signon.firefoxRelay.feature", "available"], + ["signon.rememberSignons", true], + ], + expected: "checked", + }, + { + initialPrefs: [ + ["signon.firefoxRelay.feature", "enabled"], + ["signon.rememberSignons", true], + ], + expected: "checked", + }, + { + initialPrefs: [ + ["signon.firefoxRelay.feature", "disabled"], + ["signon.rememberSignons", true], + ], + expected: "unchecked", + }, + { + initialPrefs: [ + ["signon.firefoxRelay.feature", undefined], + ["signon.rememberSignons", false], + ], + expected: "hidden", + }, + { + initialPrefs: [ + ["signon.firefoxRelay.feature", "available"], + ["signon.rememberSignons", false], + ], + expected: "checked", + }, + { + initialPrefs: [ + ["signon.firefoxRelay.feature", "enabled"], + ["signon.rememberSignons", false], + ], + expected: "checked", + }, + { + initialPrefs: [ + ["signon.firefoxRelay.feature", "disabled"], + ["signon.rememberSignons", false], + ], + expected: "unchecked", + }, + ]; + for (let test of prefTests) { + // set initial pref values + info("initialState, testing with: " + JSON.stringify(test)); + await SpecialPowers.pushPrefEnv({ set: test.initialPrefs }); + + // open about:privacy in a tab + // verify expected conditions + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: "about:preferences#privacy", + }, + async function (browser) { + const doc = browser.contentDocument; + const relayGroup = doc.getElementById("relayIntegrationBox"); + const checkbox = doc.getElementById("relayIntegration"); + const savePasswords = doc.getElementById("savePasswords"); + doc.getElementById("passwordSettings").scrollIntoView(); + + Assert.equal( + checkbox.disabled, + !savePasswords.checked, + "#relayIntegration checkbox disabled when #passwordAutofillCheckbox is unchecked" + ); + + switch (test.expected) { + case "hidden": + is_element_hidden(relayGroup, "#relayIntegrationBox is hidden"); + break; + case "checked": + is_element_visible(relayGroup, "#relayIntegrationBox is visible"); + Assert.ok( + checkbox.checked, + "#relayIntegration checkbox is checked" + ); + break; + case "unchecked": + is_element_visible(relayGroup, "#relayIntegrationBox is visible"); + Assert.ok( + !checkbox.checked, + "#relayIntegration checkbox is un-checked" + ); + break; + default: + Assert.ok(false, "Unknown expected state: " + test.expected); + break; + } + } + ); + await SpecialPowers.popPrefEnv(); + } +}); + +add_task(async function toggleRelayIntegration() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["signon.firefoxRelay.feature", "enabled"], + ["signon.rememberSignons", true], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: "about:preferences#privacy", + }, + async browser => { + await SimpleTest.promiseFocus(browser); + + // the preferences "Search" bar obscures the checkbox if we scrollIntoView and try to click on it + // so use keyboard events instead + const doc = browser.contentDocument; + const relayCheckbox = doc.getElementById("relayIntegration"); + relayCheckbox.focus(); + Assert.equal(doc.activeElement, relayCheckbox, "checkbox is focused"); + Assert.equal( + relayCheckbox.checked, + true, + "#relayIntegration checkbox is not checked" + ); + + async function clickOnFeatureCheckbox( + expectedPrefValue, + expectedCheckValue, + message + ) { + const prefChanged = TestUtils.waitForPrefChange( + "signon.firefoxRelay.feature" + ); + EventUtils.synthesizeKey(" "); + await prefChanged; + Assert.equal( + Services.prefs.getStringPref("signon.firefoxRelay.feature"), + expectedPrefValue, + message + ); + Assert.equal( + relayCheckbox.checked, + expectedCheckValue, + `#relayIntegration checkbox is ${ + expectedCheckValue ? "checked" : "unchecked" + }` + ); + } + + await clickOnFeatureCheckbox( + "disabled", + false, + 'Turn integration off from "enabled" feature state' + ); + await clickOnFeatureCheckbox( + "available", + true, + 'Turn integration on from "enabled" feature state' + ); + await clickOnFeatureCheckbox( + "disabled", + false, + 'Turn integration off from "enabled" feature state' + ); + } + ); + await SpecialPowers.popPrefEnv(); +}); + +add_task(async function toggleRememberSignon() { + // toggling rememberSignons checkbox should make generation checkbox disabled + SpecialPowers.pushPrefEnv({ + set: [ + ["signon.firefoxRelay.feature", "available"], + ["signon.rememberSignons", true], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: "about:preferences#privacy", + }, + async function (browser) { + const doc = browser.contentDocument; + const checkbox = doc.getElementById("savePasswords"); + const relayCheckbox = doc.getElementById("relayIntegration"); + + Assert.ok( + !relayCheckbox.disabled, + "generation checkbox is not initially disabled" + ); + + await SimpleTest.promiseFocus(browser); + const prefChanged = TestUtils.waitForPrefChange("signon.rememberSignons"); + + // the preferences "Search" bar obscures the checkbox if we scrollIntoView and try to click on it + // so use keyboard events instead + checkbox.focus(); + Assert.equal(doc.activeElement, checkbox, "checkbox is focused"); + EventUtils.synthesizeKey(" "); + + await prefChanged; + Assert.ok(!checkbox.checked, "#savePasswords checkbox is un-checked"); + Assert.ok( + relayCheckbox.disabled, + "Relay integration checkbox becomes disabled" + ); + } + ); + await SpecialPowers.popPrefEnv(); +}); + +add_task(async function testLockedRelayPreference() { + // Locking relay preference should disable checkbox + Services.prefs.lockPref("signon.firefoxRelay.feature"); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: "about:preferences#privacy", + }, + async function (browser) { + const doc = browser.contentDocument; + const relayCheckbox = doc.getElementById("relayIntegration"); + + Assert.ok(relayCheckbox.disabled, "Relay checkbox should be disabled"); + } + ); + + Services.prefs.unlockPref("signon.firefoxRelay.feature"); +}); |