browser_privacy_allowListPreference.js (11240B)
1 /* Any copyright is dedicated to the Public Domain. 2 * https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const BASELINE_PREF = "privacy.trackingprotection.allow_list.baseline.enabled"; 7 const CONVENIENCE_PREF = 8 "privacy.trackingprotection.allow_list.convenience.enabled"; 9 const CB_CATEGORY_PREF = "browser.contentblocking.category"; 10 11 const ETP_STANDARD_ID = "standardRadio"; 12 const ETP_STRICT_ID = "strictRadio"; 13 const ETP_CUSTOM_ID = "customRadio"; 14 15 const STRICT_BASELINE_CHECKBOX_ID = "contentBlockingBaselineExceptionsStrict"; 16 const STRICT_CONVENIENCE_CHECKBOX_ID = 17 "contentBlockingConvenienceExceptionsStrict"; 18 const CUSTOM_BASELINE_CHECKBOX_ID = "contentBlockingBaselineExceptionsCustom"; 19 const CUSTOM_CONVENIENCE_CHECKBOX_ID = 20 "contentBlockingConvenienceExceptionsCustom"; 21 22 async function cleanUp() { 23 await SpecialPowers.popPrefEnv(); 24 gBrowser.removeCurrentTab(); 25 } 26 27 async function setup() { 28 await SpecialPowers.pushPrefEnv({ 29 set: [[CB_CATEGORY_PREF, "standard"]], 30 }); 31 Assert.ok( 32 Services.prefs.getBoolPref(BASELINE_PREF), 33 "The baseline preference should be initially true." 34 ); 35 Assert.ok( 36 Services.prefs.getBoolPref(CONVENIENCE_PREF), 37 "The convenience preference should be initially true." 38 ); 39 } 40 41 add_task(async function test_standard_mode_no_checkboxes_and_prefs_true() { 42 await setup(); 43 await openPreferencesViaOpenPreferencesAPI("privacy", { 44 leaveOpen: true, 45 }); 46 let doc = gBrowser.contentDocument; 47 doc.getElementById(ETP_STANDARD_ID).click(); 48 is_element_hidden( 49 doc.getElementById(STRICT_BASELINE_CHECKBOX_ID), 50 "Strict mode's baseline checkbox should be hidden when ETP Standard is selected." 51 ); 52 is_element_hidden( 53 doc.getElementById(STRICT_CONVENIENCE_CHECKBOX_ID), 54 "Strict mode's convenience checkbox should be hidden when ETP Standard is selected." 55 ); 56 is_element_hidden( 57 doc.getElementById(CUSTOM_BASELINE_CHECKBOX_ID), 58 "Custom mode's baseline checkbox should be hidden when ETP Standard is selected." 59 ); 60 is_element_hidden( 61 doc.getElementById(CUSTOM_CONVENIENCE_CHECKBOX_ID), 62 "Custom mode's convenience checkbox should be hidden when ETP Standard is selected." 63 ); 64 Assert.ok( 65 Services.prefs.getBoolPref(BASELINE_PREF), 66 "The baseline preference should be true in ETP Standard mode." 67 ); 68 Assert.ok( 69 Services.prefs.getBoolPref(CONVENIENCE_PREF), 70 "The convenience preference should be true in ETP Standard mode." 71 ); 72 await cleanUp(); 73 }); 74 75 add_task(async function test_strict_mode_checkboxes_and_default_prefs() { 76 await setup(); 77 await openPreferencesViaOpenPreferencesAPI("privacy", { 78 leaveOpen: true, 79 }); 80 let doc = gBrowser.contentDocument; 81 doc.getElementById(ETP_STRICT_ID).click(); 82 let baselineCheckbox = doc.getElementById(STRICT_BASELINE_CHECKBOX_ID); 83 let convenienceCheckbox = doc.getElementById(STRICT_CONVENIENCE_CHECKBOX_ID); 84 is_element_visible( 85 baselineCheckbox, 86 "The baseline checkbox should be visible in ETP Strict mode." 87 ); 88 is_element_visible( 89 convenienceCheckbox, 90 "The convenience checkbox should be visible in ETP Strict mode." 91 ); 92 is( 93 baselineCheckbox.checked, 94 true, 95 "The baseline checkbox should be checked by default in ETP Strict mode." 96 ); 97 is( 98 convenienceCheckbox.checked, 99 false, 100 "The convenience checkbox should be unchecked by default in ETP Strict mode." 101 ); 102 Assert.ok( 103 Services.prefs.getBoolPref(BASELINE_PREF), 104 "The baseline preference should be true by default in ETP Strict mode." 105 ); 106 Assert.ok( 107 !Services.prefs.getBoolPref(CONVENIENCE_PREF), 108 "The convenience preference should be false by default in ETP Strict mode." 109 ); 110 await cleanUp(); 111 }); 112 113 add_task( 114 async function test_strict_mode_convenience_false_when_baseline_false() { 115 await setup(); 116 await openPreferencesViaOpenPreferencesAPI("privacy", { 117 leaveOpen: true, 118 }); 119 let doc = gBrowser.contentDocument; 120 doc.getElementById(ETP_STRICT_ID).click(); 121 122 await clickCheckboxWithConfirmDialog( 123 doc, 124 STRICT_BASELINE_CHECKBOX_ID, 125 BASELINE_PREF, 126 false, 127 1 128 ); 129 130 Assert.ok( 131 !Services.prefs.getBoolPref(BASELINE_PREF), 132 "The baseline pref should be false after unchecking its checkbox in ETP Strict mode." 133 ); 134 Assert.ok( 135 !Services.prefs.getBoolPref(CONVENIENCE_PREF), 136 "The convenience pref should remain false when the baseline checkbox is unchecked in ETP Strict mode." 137 ); 138 await cleanUp(); 139 } 140 ); 141 142 add_task(async function test_custom_mode_checkboxes_and_ids() { 143 await setup(); 144 await openPreferencesViaOpenPreferencesAPI("privacy", { 145 leaveOpen: true, 146 }); 147 let doc = gBrowser.contentDocument; 148 await doc.getElementById(ETP_CUSTOM_ID).click(); 149 let baselineCheckbox = doc.getElementById(CUSTOM_BASELINE_CHECKBOX_ID); 150 let convenienceCheckbox = doc.getElementById(CUSTOM_CONVENIENCE_CHECKBOX_ID); 151 is_element_visible( 152 baselineCheckbox, 153 "The baseline checkbox should be visible in ETP Custom mode." 154 ); 155 is_element_visible( 156 convenienceCheckbox, 157 "The convenience checkbox should be visible in ETP Custom mode." 158 ); 159 await cleanUp(); 160 }); 161 162 add_task(async function test_custom_mode_inherits_last_mode() { 163 await setup(); 164 // Test switching from Standard to Custom 165 await openPreferencesViaOpenPreferencesAPI("privacy", { 166 leaveOpen: true, 167 }); 168 let doc = gBrowser.contentDocument; 169 doc.getElementById(ETP_STANDARD_ID).click(); 170 doc.getElementById(ETP_CUSTOM_ID).click(); 171 let baselineCheckbox = doc.getElementById(CUSTOM_BASELINE_CHECKBOX_ID); 172 let convenienceCheckbox = doc.getElementById(CUSTOM_CONVENIENCE_CHECKBOX_ID); 173 is( 174 baselineCheckbox.checked, 175 true, 176 "Custom's baseline checkbox should be checked, inheriting state from Standard mode." 177 ); 178 is( 179 convenienceCheckbox.checked, 180 true, 181 "Custom's convenience checkbox should be checked, inheriting state from Standard mode." 182 ); 183 gBrowser.removeCurrentTab(); 184 185 // Test switching from Strict (with baseline unchecked) to Custom 186 await openPreferencesViaOpenPreferencesAPI("privacy", { 187 leaveOpen: true, 188 }); 189 doc = gBrowser.contentDocument; 190 doc.getElementById(ETP_STRICT_ID).click(); 191 let convenienceCheckboxStrict = doc.getElementById( 192 STRICT_CONVENIENCE_CHECKBOX_ID 193 ); 194 is_element_visible( 195 convenienceCheckboxStrict, 196 "The convenience checkbox in Strict mode must be visible for this test." 197 ); 198 await clickCheckboxWithConfirmDialog( 199 doc, 200 STRICT_BASELINE_CHECKBOX_ID, 201 BASELINE_PREF, 202 false, 203 1 204 ); 205 doc.getElementById(ETP_CUSTOM_ID).click(); 206 let baselineCheckboxCustom = doc.getElementById(CUSTOM_BASELINE_CHECKBOX_ID); 207 let convenienceCheckboxCustom = doc.getElementById( 208 CUSTOM_CONVENIENCE_CHECKBOX_ID 209 ); 210 is( 211 baselineCheckboxCustom.checked, 212 false, 213 "Custom's baseline checkbox should be unchecked, inheriting state from a modified Strict mode." 214 ); 215 is( 216 convenienceCheckboxCustom.checked, 217 false, 218 "Custom's convenience checkbox should be unchecked, inheriting state from a modified Strict mode." 219 ); 220 await cleanUp(); 221 }); 222 223 add_task(async function test_checkbox_state_persists_after_reload() { 224 await setup(); 225 await openPreferencesViaOpenPreferencesAPI("privacy", { 226 leaveOpen: true, 227 }); 228 let doc = gBrowser.contentDocument; 229 doc.getElementById(ETP_STRICT_ID).click(); 230 await clickCheckboxWithConfirmDialog( 231 doc, 232 STRICT_BASELINE_CHECKBOX_ID, 233 BASELINE_PREF, 234 false, 235 1 236 ); 237 is( 238 doc.getElementById(STRICT_BASELINE_CHECKBOX_ID).checked, 239 false, 240 "The Strict mode baseline checkbox should be unchecked before reload." 241 ); 242 doc.defaultView.location.reload(); 243 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); 244 doc = gBrowser.contentDocument; 245 let baselineCheckboxAfter = doc.getElementById(STRICT_BASELINE_CHECKBOX_ID); 246 is( 247 baselineCheckboxAfter.checked, 248 false, 249 "The Strict mode baseline checkbox should remain unchecked after page reload." 250 ); 251 await cleanUp(); 252 }); 253 254 add_task(async function test_switching_modes_resets_checkboxes() { 255 await setup(); 256 await openPreferencesViaOpenPreferencesAPI("privacy", { 257 leaveOpen: true, 258 }); 259 let doc = gBrowser.contentDocument; 260 let standardRadio = doc.getElementById(ETP_STANDARD_ID); 261 standardRadio.click(); 262 doc.getElementById(ETP_STRICT_ID).click(); 263 await clickCheckboxWithConfirmDialog( 264 doc, 265 STRICT_BASELINE_CHECKBOX_ID, 266 BASELINE_PREF, 267 false, 268 1 269 ); 270 is( 271 doc.getElementById(STRICT_BASELINE_CHECKBOX_ID).checked, 272 false, 273 "The Strict mode baseline checkbox should be in its modified, unchecked state." 274 ); 275 standardRadio.click(); 276 doc.getElementById(ETP_STRICT_ID).click(); 277 let baselineCheckbox = doc.getElementById(STRICT_BASELINE_CHECKBOX_ID); 278 let convenienceCheckbox = doc.getElementById(STRICT_CONVENIENCE_CHECKBOX_ID); 279 is( 280 baselineCheckbox.checked, 281 true, 282 "The baseline checkbox should reset to its default checked state after toggling ETP modes." 283 ); 284 is( 285 convenienceCheckbox.checked, 286 false, 287 "The convenience checkbox should reset to its default unchecked state after toggling ETP modes." 288 ); 289 await cleanUp(); 290 }); 291 292 add_task(async function test_convenience_cannot_be_enabled_if_baseline_false() { 293 await setup(); 294 await openPreferencesViaOpenPreferencesAPI("privacy", { 295 leaveOpen: true, 296 }); 297 let doc = gBrowser.contentDocument; 298 doc.getElementById(ETP_STRICT_ID).click(); 299 let convenienceCheckbox = doc.getElementById(STRICT_CONVENIENCE_CHECKBOX_ID); 300 301 is( 302 convenienceCheckbox.parentDisabled, 303 false, 304 "The convenience checkbox should be enabled when the baseline checkbox is checked." 305 ); 306 307 await clickCheckboxWithConfirmDialog( 308 doc, 309 STRICT_BASELINE_CHECKBOX_ID, 310 BASELINE_PREF, 311 false, 312 1 313 ); 314 315 is( 316 convenienceCheckbox.parentDisabled, 317 true, 318 "The convenience checkbox should be disabled when the baseline checkbox is unchecked." 319 ); 320 321 convenienceCheckbox.click(); 322 323 is( 324 convenienceCheckbox.checked, 325 false, 326 "Clicking the disabled convenience checkbox should not change its state." 327 ); 328 await cleanUp(); 329 }); 330 331 add_task(async function test_prefs_update_when_toggling_checkboxes_in_custom() { 332 await setup(); 333 await openPreferencesViaOpenPreferencesAPI("privacy", { 334 leaveOpen: true, 335 }); 336 let doc = gBrowser.contentDocument; 337 doc.getElementById(ETP_CUSTOM_ID).click(); 338 339 await clickCheckboxWithConfirmDialog( 340 doc, 341 CUSTOM_BASELINE_CHECKBOX_ID, 342 BASELINE_PREF, 343 false, 344 1 345 ); 346 347 Assert.ok( 348 !Services.prefs.getBoolPref(BASELINE_PREF), 349 "The baseline pref should be false after being unchecked in Custom mode." 350 ); 351 Assert.ok( 352 Services.prefs.getBoolPref(CONVENIENCE_PREF), 353 "The convenience pref should be unchanged after baseline unchecked in Custom mode." 354 ); 355 356 // Check both boxes and verify the preferences are updated. 357 await clickCheckboxAndWaitForPrefChange( 358 doc, 359 CUSTOM_BASELINE_CHECKBOX_ID, 360 BASELINE_PREF, 361 true 362 ); 363 Assert.ok( 364 Services.prefs.getBoolPref(BASELINE_PREF), 365 "The baseline pref should be true after being checked in Custom mode." 366 ); 367 await cleanUp(); 368 });