tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_warning_permanent_private_browsing_srd.js (2126B)


      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        ["browser.settings-redesign.history2.enabled", true],
     13      ],
     14    });
     15 
     16    await openPreferencesViaOpenPreferencesAPI("paneHistory", {
     17      leaveOpen: true,
     18    });
     19    let doc = gBrowser.contentDocument;
     20 
     21    // Stub out the prompt method as an easy way to check it was shown. We throw away
     22    // the tab straight after so don't need to bother restoring it.
     23    let promptFired = false;
     24    doc.defaultView.confirmRestartPrompt = () => {
     25      promptFired = true;
     26      return doc.defaultView.CONFIRM_RESTART_PROMPT_RESTART_NOW;
     27    };
     28    // Tick the checkbox and pretend the user did it:
     29    let checkbox = gBrowser.contentWindow.document.querySelector(
     30      "setting-group[groupid='historyAdvanced'] #privateBrowsingAutoStart"
     31    );
     32 
     33    ok(checkbox, "the privateBrowsingAutoStart checkbox should exist");
     34    is_element_visible(
     35      checkbox,
     36      "the privateBrowsingAutoStart checkbox should be visible"
     37    );
     38 
     39    // No need to click if we're already in the desired state.
     40    if (checkbox.checked === prefVal) {
     41      return;
     42    }
     43 
     44    // Scroll into view for click to succeed.
     45    checkbox.scrollIntoView();
     46 
     47    // Toggle the state.
     48    await EventUtils.synthesizeMouseAtCenter(
     49      checkbox,
     50      {},
     51      checkbox.ownerGlobal
     52    );
     53 
     54    // Now the prompt should have shown.
     55    ok(
     56      promptFired,
     57      `Expect a prompt when turning permanent private browsing ${
     58        prefVal ? "on" : "off"
     59      }!`
     60    );
     61    BrowserTestUtils.removeTab(gBrowser.selectedTab);
     62    await SpecialPowers.popPrefEnv();
     63  };
     64 }
     65 
     66 /**
     67 * Check we show the prompt if the permanent private browsing pref is false
     68 * and we flip the checkbox to true.
     69 */
     70 add_task(checkForPrompt(true));
     71 
     72 /**
     73 * Check it works in the other direction:
     74 */
     75 add_task(checkForPrompt(false));