browser_warning_permanent_private_browsing.js (2132B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 function checkForPrompt(prefVal) { 7 return async function () { 8 await SpecialPowers.pushPrefEnv({ 9 set: [ 10 ["privacy.history.custom", true], 11 ["browser.privatebrowsing.autostart", !prefVal], 12 ], 13 }); 14 15 await openPreferencesViaOpenPreferencesAPI("panePrivacy", { 16 leaveOpen: true, 17 }); 18 let doc = gBrowser.contentDocument; 19 is( 20 doc.getElementById("historyMode").value, 21 "custom", 22 "Expect custom history mode" 23 ); 24 25 // Stub out the prompt method as an easy way to check it was shown. We throw away 26 // the tab straight after so don't need to bother restoring it. 27 let promptFired = false; 28 doc.defaultView.confirmRestartPrompt = () => { 29 promptFired = true; 30 return doc.defaultView.CONFIRM_RESTART_PROMPT_RESTART_NOW; 31 }; 32 33 // Tick the checkbox and pretend the user did it: 34 let checkbox = gBrowser.contentWindow.document.querySelector( 35 "setting-group[groupid='history'] #privateBrowsingAutoStart" 36 ); 37 38 ok(checkbox, "the privateBrowsingAutoStart checkbox should exist"); 39 is_element_visible( 40 checkbox, 41 "the privateBrowsingAutoStart checkbox should be visible" 42 ); 43 44 // No need to click if we're already in the desired state. 45 if (checkbox.checked === prefVal) { 46 return; 47 } 48 49 // Scroll into view for click to succeed. 50 checkbox.scrollIntoView(); 51 52 // Toggle the state. 53 await EventUtils.synthesizeMouseAtCenter( 54 checkbox, 55 {}, 56 checkbox.ownerGlobal 57 ); 58 59 // Now the prompt should have shown. 60 ok( 61 promptFired, 62 `Expect a prompt when turning permanent private browsing ${ 63 prefVal ? "on" : "off" 64 }!` 65 ); 66 BrowserTestUtils.removeTab(gBrowser.selectedTab); 67 }; 68 } 69 70 /** 71 * Check we show the prompt if the permanent private browsing pref is false 72 * and we flip the checkbox to true. 73 */ 74 add_task(checkForPrompt(true)); 75 76 /** 77 * Check it works in the other direction: 78 */ 79 add_task(checkForPrompt(false));