browser_privacy_relayIntegration.js (7286B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 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 }); 68 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(); 82 83 Assert.equal( 84 checkbox.disabled, 85 !savePasswords.checked, 86 "#relayIntegration checkbox disabled when #passwordAutofillCheckbox is unchecked" 87 ); 88 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 } 115 }); 116 117 add_task(async function toggleRelayIntegration() { 118 await SpecialPowers.pushPrefEnv({ 119 set: [ 120 ["signon.firefoxRelay.feature", "enabled"], 121 ["signon.rememberSignons", true], 122 ], 123 }); 124 125 await BrowserTestUtils.withNewTab( 126 { 127 gBrowser, 128 url: "about:preferences#privacy", 129 }, 130 async browser => { 131 await SimpleTest.promiseFocus(browser); 132 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 ); 144 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 } 168 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(); 187 }); 188 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 }); 197 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"); 207 208 Assert.ok( 209 !relayCheckbox.disabled, 210 "generation checkbox is not initially disabled" 211 ); 212 213 await SimpleTest.promiseFocus(browser); 214 const prefChanged = TestUtils.waitForPrefChange("signon.rememberSignons"); 215 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(" "); 221 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(); 231 }); 232 233 add_task(async function testLockedRelayPreference() { 234 // Locking relay preference should disable checkbox 235 Services.prefs.lockPref("signon.firefoxRelay.feature"); 236 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"); 245 246 Assert.ok(relayCheckbox.disabled, "Relay checkbox should be disabled"); 247 } 248 ); 249 250 Services.prefs.unlockPref("signon.firefoxRelay.feature"); 251 });