browser_privacy_allowListPreference_reload.js (4778B)
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( 42 async function test_reload_does_not_show_after_baseline_checkbox_dialog_cancel() { 43 await SpecialPowers.pushPrefEnv({ 44 set: [[CB_CATEGORY_PREF, "strict"]], 45 }); 46 Assert.ok( 47 Services.prefs.getBoolPref(BASELINE_PREF), 48 "The baseline preference should be initially true." 49 ); 50 Assert.ok( 51 !Services.prefs.getBoolPref(CONVENIENCE_PREF), 52 "The convenience preference should be initially false." 53 ); 54 await openPreferencesViaOpenPreferencesAPI("privacy", { 55 leaveOpen: true, 56 }); 57 let doc = gBrowser.contentDocument; 58 59 let reloadButton = doc.querySelector( 60 "#contentBlockingOptionStrict .content-blocking-warning.reload-tabs .reload-tabs-button" 61 ); 62 is_element_hidden( 63 reloadButton, 64 "The reload button should be hidden initially in Strict mode." 65 ); 66 67 await clickCheckboxWithConfirmDialog( 68 doc, 69 STRICT_BASELINE_CHECKBOX_ID, 70 BASELINE_PREF, 71 true, 72 0 73 ); 74 75 Assert.ok( 76 Services.prefs.getBoolPref(BASELINE_PREF), 77 "The baseline pref should remain true after canceling dialog." 78 ); 79 80 is_element_hidden( 81 reloadButton, 82 "The reload button should be hidden after canceling the checkbox dialog." 83 ); 84 85 await cleanUp(); 86 } 87 ); 88 89 add_task(async function test_reload_button_shows_after_prefs_changed_strict() { 90 await setup(); 91 await openPreferencesViaOpenPreferencesAPI("privacy", { 92 leaveOpen: true, 93 }); 94 let tab = BrowserTestUtils.addTab(gBrowser, "about:blank"); 95 let doc = gBrowser.contentDocument; 96 97 doc.getElementById(ETP_STRICT_ID).click(); 98 99 let strictReloadButton = doc.querySelector( 100 "#contentBlockingOptionStrict .content-blocking-warning.reload-tabs .reload-tabs-button" 101 ); 102 103 is_element_visible( 104 strictReloadButton, 105 "The strict reload button must be visible" 106 ); 107 108 strictReloadButton.click(); 109 110 is_element_hidden( 111 strictReloadButton, 112 "The strict reload button must be hidden after clicking it" 113 ); 114 115 await clickCheckboxWithConfirmDialog( 116 doc, 117 STRICT_BASELINE_CHECKBOX_ID, 118 BASELINE_PREF, 119 false, 120 1 121 ); 122 123 is_element_visible( 124 strictReloadButton, 125 "The strict reload button must be visible after baseline pref changes" 126 ); 127 128 strictReloadButton.click(); 129 130 is_element_hidden( 131 strictReloadButton, 132 "The strict reload button must be hidden after clicking it" 133 ); 134 135 BrowserTestUtils.removeTab(tab); 136 await cleanUp(); 137 }); 138 139 add_task(async function test_reload_button_shows_after_prefs_changed_custom() { 140 await setup(); 141 await openPreferencesViaOpenPreferencesAPI("privacy", { 142 leaveOpen: true, 143 }); 144 let tab = BrowserTestUtils.addTab(gBrowser, "about:blank"); 145 let doc = gBrowser.contentDocument; 146 147 doc.getElementById(ETP_CUSTOM_ID).click(); 148 149 let customReloadButton = doc.querySelector( 150 "#contentBlockingOptionCustom .content-blocking-warning.reload-tabs .reload-tabs-button" 151 ); 152 153 is_element_hidden( 154 customReloadButton, 155 "The custom reload button must be hidden when switching from strict" 156 ); 157 158 await clickCheckboxWithConfirmDialog( 159 doc, 160 CUSTOM_BASELINE_CHECKBOX_ID, 161 BASELINE_PREF, 162 false, 163 1 164 ); 165 166 is_element_visible( 167 customReloadButton, 168 "The custom reload button must be visible after baseline checkbox changes" 169 ); 170 171 customReloadButton.click(); 172 173 is_element_hidden( 174 customReloadButton, 175 "The custom reload button must be hidden after clicking it" 176 ); 177 178 BrowserTestUtils.removeTab(tab); 179 await cleanUp(); 180 });