1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 add_task(async function initialState() {
5 // check pref permutations to verify the UI opens in the correct state
9 ["signon.firefoxRelay.feature", undefined],
10 ["signon.rememberSignons", true],
16 ["signon.firefoxRelay.feature", "available"],
17 ["signon.rememberSignons", true],
23 ["signon.firefoxRelay.feature", "enabled"],
24 ["signon.rememberSignons", true],
30 ["signon.firefoxRelay.feature", "disabled"],
31 ["signon.rememberSignons", true],
33 expected: "unchecked",
37 ["signon.firefoxRelay.feature", undefined],
38 ["signon.rememberSignons", false],
44 ["signon.firefoxRelay.feature", "available"],
45 ["signon.rememberSignons", false],
51 ["signon.firefoxRelay.feature", "enabled"],
52 ["signon.rememberSignons", false],
58 ["signon.firefoxRelay.feature", "disabled"],
59 ["signon.rememberSignons", false],
61 expected: "unchecked",
64 for (let test of prefTests) {
65 // set initial pref values
66 info("initialState, testing with: " + JSON.stringify(test));
67 await SpecialPowers.pushPrefEnv({ set: test.initialPrefs });
69 // open about:privacy in a tab
70 // verify expected conditions
71 await BrowserTestUtils.withNewTab(
74 url: "about:preferences#privacy",
76 async function (browser) {
77 const doc = browser.contentDocument;
78 const relayGroup = doc.getElementById("relayIntegrationBox");
79 const checkbox = doc.getElementById("relayIntegration");
80 const savePasswords = doc.getElementById("savePasswords");
81 doc.getElementById("passwordSettings").scrollIntoView();
85 !savePasswords.checked,
86 "#relayIntegration checkbox disabled when #passwordAutofillCheckbox is unchecked"
89 switch (test.expected) {
91 is_element_hidden(relayGroup, "#relayIntegrationBox is hidden");
94 is_element_visible(relayGroup, "#relayIntegrationBox is visible");
97 "#relayIntegration checkbox is checked"
101 is_element_visible(relayGroup, "#relayIntegrationBox is visible");
104 "#relayIntegration checkbox is un-checked"
108 Assert.ok(false, "Unknown expected state: " + test.expected);
113 await SpecialPowers.popPrefEnv();
117 add_task(async function toggleRelayIntegration() {
118 await SpecialPowers.pushPrefEnv({
120 ["signon.firefoxRelay.feature", "enabled"],
121 ["signon.rememberSignons", true],
125 await BrowserTestUtils.withNewTab(
128 url: "about:preferences#privacy",
131 await SimpleTest.promiseFocus(browser);
133 // the preferences "Search" bar obscures the checkbox if we scrollIntoView and try to click on it
134 // so use keyboard events instead
135 const doc = browser.contentDocument;
136 const relayCheckbox = doc.getElementById("relayIntegration");
137 relayCheckbox.focus();
138 Assert.equal(doc.activeElement, relayCheckbox, "checkbox is focused");
140 relayCheckbox.checked,
142 "#relayIntegration checkbox is not checked"
145 async function clickOnFeatureCheckbox(
150 const prefChanged = TestUtils.waitForPrefChange(
151 "signon.firefoxRelay.feature"
153 EventUtils.synthesizeKey(" ");
156 Services.prefs.getStringPref("signon.firefoxRelay.feature"),
161 relayCheckbox.checked,
163 `#relayIntegration checkbox is ${
164 expectedCheckValue ? "checked" : "unchecked"
169 await clickOnFeatureCheckbox(
172 'Turn integration off from "enabled" feature state'
174 await clickOnFeatureCheckbox(
177 'Turn integration on from "enabled" feature state'
179 await clickOnFeatureCheckbox(
182 'Turn integration off from "enabled" feature state'
186 await SpecialPowers.popPrefEnv();
189 add_task(async function toggleRememberSignon() {
190 // toggling rememberSignons checkbox should make generation checkbox disabled
191 SpecialPowers.pushPrefEnv({
193 ["signon.firefoxRelay.feature", "available"],
194 ["signon.rememberSignons", true],
198 await BrowserTestUtils.withNewTab(
201 url: "about:preferences#privacy",
203 async function (browser) {
204 const doc = browser.contentDocument;
205 const checkbox = doc.getElementById("savePasswords");
206 const relayCheckbox = doc.getElementById("relayIntegration");
209 !relayCheckbox.disabled,
210 "generation checkbox is not initially disabled"
213 await SimpleTest.promiseFocus(browser);
214 const prefChanged = TestUtils.waitForPrefChange("signon.rememberSignons");
216 // the preferences "Search" bar obscures the checkbox if we scrollIntoView and try to click on it
217 // so use keyboard events instead
219 Assert.equal(doc.activeElement, checkbox, "checkbox is focused");
220 EventUtils.synthesizeKey(" ");
223 Assert.ok(!checkbox.checked, "#savePasswords checkbox is un-checked");
225 relayCheckbox.disabled,
226 "Relay integration checkbox becomes disabled"
230 await SpecialPowers.popPrefEnv();
233 add_task(async function testLockedRelayPreference() {
234 // Locking relay preference should disable checkbox
235 Services.prefs.lockPref("signon.firefoxRelay.feature");
237 await BrowserTestUtils.withNewTab(
240 url: "about:preferences#privacy",
242 async function (browser) {
243 const doc = browser.contentDocument;
244 const relayCheckbox = doc.getElementById("relayIntegration");
246 Assert.ok(relayCheckbox.disabled, "Relay checkbox should be disabled");
250 Services.prefs.unlockPref("signon.firefoxRelay.feature");