Backed out 2 changesets (bug 1908320) for causing wr failures on align-items-baseline...
[gecko.git] / browser / components / preferences / tests / browser_privacy_relayIntegration.js
blob23d62f38bd52af46b6dc09ca7d1a34ed809b9031
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
6   const prefTests = [
7     {
8       initialPrefs: [
9         ["signon.firefoxRelay.feature", undefined],
10         ["signon.rememberSignons", true],
11       ],
12       expected: "hidden",
13     },
14     {
15       initialPrefs: [
16         ["signon.firefoxRelay.feature", "available"],
17         ["signon.rememberSignons", true],
18       ],
19       expected: "checked",
20     },
21     {
22       initialPrefs: [
23         ["signon.firefoxRelay.feature", "enabled"],
24         ["signon.rememberSignons", true],
25       ],
26       expected: "checked",
27     },
28     {
29       initialPrefs: [
30         ["signon.firefoxRelay.feature", "disabled"],
31         ["signon.rememberSignons", true],
32       ],
33       expected: "unchecked",
34     },
35     {
36       initialPrefs: [
37         ["signon.firefoxRelay.feature", undefined],
38         ["signon.rememberSignons", false],
39       ],
40       expected: "hidden",
41     },
42     {
43       initialPrefs: [
44         ["signon.firefoxRelay.feature", "available"],
45         ["signon.rememberSignons", false],
46       ],
47       expected: "checked",
48     },
49     {
50       initialPrefs: [
51         ["signon.firefoxRelay.feature", "enabled"],
52         ["signon.rememberSignons", false],
53       ],
54       expected: "checked",
55     },
56     {
57       initialPrefs: [
58         ["signon.firefoxRelay.feature", "disabled"],
59         ["signon.rememberSignons", false],
60       ],
61       expected: "unchecked",
62     },
63   ];
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(
72       {
73         gBrowser,
74         url: "about:preferences#privacy",
75       },
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();
83         Assert.equal(
84           checkbox.disabled,
85           !savePasswords.checked,
86           "#relayIntegration checkbox disabled when #passwordAutofillCheckbox is unchecked"
87         );
89         switch (test.expected) {
90           case "hidden":
91             is_element_hidden(relayGroup, "#relayIntegrationBox is hidden");
92             break;
93           case "checked":
94             is_element_visible(relayGroup, "#relayIntegrationBox is visible");
95             Assert.ok(
96               checkbox.checked,
97               "#relayIntegration checkbox is checked"
98             );
99             break;
100           case "unchecked":
101             is_element_visible(relayGroup, "#relayIntegrationBox is visible");
102             Assert.ok(
103               !checkbox.checked,
104               "#relayIntegration checkbox is un-checked"
105             );
106             break;
107           default:
108             Assert.ok(false, "Unknown expected state: " + test.expected);
109             break;
110         }
111       }
112     );
113     await SpecialPowers.popPrefEnv();
114   }
117 add_task(async function toggleRelayIntegration() {
118   await SpecialPowers.pushPrefEnv({
119     set: [
120       ["signon.firefoxRelay.feature", "enabled"],
121       ["signon.rememberSignons", true],
122     ],
123   });
125   await BrowserTestUtils.withNewTab(
126     {
127       gBrowser,
128       url: "about:preferences#privacy",
129     },
130     async browser => {
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");
139       Assert.equal(
140         relayCheckbox.checked,
141         true,
142         "#relayIntegration checkbox is not checked"
143       );
145       async function clickOnFeatureCheckbox(
146         expectedPrefValue,
147         expectedCheckValue,
148         message
149       ) {
150         const prefChanged = TestUtils.waitForPrefChange(
151           "signon.firefoxRelay.feature"
152         );
153         EventUtils.synthesizeKey(" ");
154         await prefChanged;
155         Assert.equal(
156           Services.prefs.getStringPref("signon.firefoxRelay.feature"),
157           expectedPrefValue,
158           message
159         );
160         Assert.equal(
161           relayCheckbox.checked,
162           expectedCheckValue,
163           `#relayIntegration checkbox is ${
164             expectedCheckValue ? "checked" : "unchecked"
165           }`
166         );
167       }
169       await clickOnFeatureCheckbox(
170         "disabled",
171         false,
172         'Turn integration off from "enabled" feature state'
173       );
174       await clickOnFeatureCheckbox(
175         "available",
176         true,
177         'Turn integration on from "enabled" feature state'
178       );
179       await clickOnFeatureCheckbox(
180         "disabled",
181         false,
182         'Turn integration off from "enabled" feature state'
183       );
184     }
185   );
186   await SpecialPowers.popPrefEnv();
189 add_task(async function toggleRememberSignon() {
190   // toggling rememberSignons checkbox should make generation checkbox disabled
191   SpecialPowers.pushPrefEnv({
192     set: [
193       ["signon.firefoxRelay.feature", "available"],
194       ["signon.rememberSignons", true],
195     ],
196   });
198   await BrowserTestUtils.withNewTab(
199     {
200       gBrowser,
201       url: "about:preferences#privacy",
202     },
203     async function (browser) {
204       const doc = browser.contentDocument;
205       const checkbox = doc.getElementById("savePasswords");
206       const relayCheckbox = doc.getElementById("relayIntegration");
208       Assert.ok(
209         !relayCheckbox.disabled,
210         "generation checkbox is not initially disabled"
211       );
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
218       checkbox.focus();
219       Assert.equal(doc.activeElement, checkbox, "checkbox is focused");
220       EventUtils.synthesizeKey(" ");
222       await prefChanged;
223       Assert.ok(!checkbox.checked, "#savePasswords checkbox is un-checked");
224       Assert.ok(
225         relayCheckbox.disabled,
226         "Relay integration checkbox becomes disabled"
227       );
228     }
229   );
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(
238     {
239       gBrowser,
240       url: "about:preferences#privacy",
241     },
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");
247     }
248   );
250   Services.prefs.unlockPref("signon.firefoxRelay.feature");