tor-browser

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

browser_protectionsUI_state_reset.js (4034B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const TP_PREF = "privacy.trackingprotection.enabled";
      5 const TRACKING_PAGE =
      6  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      7  "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/trackingPage.html";
      8 const BENIGN_PAGE =
      9  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     10  "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/benignPage.html";
     11 const ABOUT_PAGE = "about:preferences";
     12 
     13 /* This asserts that the content blocking event state is correctly reset
     14 * when navigating to a new location, and that the user is correctly
     15 * reset when switching between tabs. */
     16 
     17 add_task(async function testResetOnLocationChange() {
     18  Services.prefs.setBoolPref(TP_PREF, true);
     19 
     20  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, BENIGN_PAGE);
     21  let browser = tab.linkedBrowser;
     22 
     23  is(
     24    browser.getContentBlockingEvents(),
     25    0,
     26    "Benign page has no content blocking event"
     27  );
     28  ok(
     29    !gProtectionsHandler.iconBox.hasAttribute("active"),
     30    "shield is not active"
     31  );
     32 
     33  await Promise.all([
     34    BrowserTestUtils.loadURIString({
     35      browser: tab.linkedBrowser,
     36      uriString: TRACKING_PAGE,
     37    }),
     38    waitForContentBlockingEvent(2),
     39  ]);
     40 
     41  is(
     42    browser.getContentBlockingEvents(),
     43    Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
     44    "Tracking page has a content blocking event"
     45  );
     46  ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
     47 
     48  await BrowserTestUtils.loadURIString({
     49    browser: tab.linkedBrowser,
     50    uriString: BENIGN_PAGE,
     51  });
     52 
     53  is(
     54    browser.getContentBlockingEvents(),
     55    0,
     56    "Benign page has no content blocking event"
     57  );
     58  ok(
     59    !gProtectionsHandler.iconBox.hasAttribute("active"),
     60    "shield is not active"
     61  );
     62 
     63  let contentBlockingEvent = waitForContentBlockingEvent(3);
     64  let trackingTab = await BrowserTestUtils.openNewForegroundTab(
     65    gBrowser,
     66    TRACKING_PAGE
     67  );
     68  await contentBlockingEvent;
     69 
     70  is(
     71    trackingTab.linkedBrowser.getContentBlockingEvents(),
     72    Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT,
     73    "Tracking page has a content blocking event"
     74  );
     75  ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
     76 
     77  gBrowser.selectedTab = tab;
     78  is(
     79    browser.getContentBlockingEvents(),
     80    0,
     81    "Benign page has no content blocking event"
     82  );
     83  ok(
     84    !gProtectionsHandler.iconBox.hasAttribute("active"),
     85    "shield is not active"
     86  );
     87 
     88  gBrowser.removeTab(trackingTab);
     89  gBrowser.removeTab(tab);
     90 
     91  Services.prefs.clearUserPref(TP_PREF);
     92 });
     93 
     94 /* Test that the content blocking icon is correctly reset
     95 * when changing tabs or navigating to an about: page */
     96 add_task(async function testResetOnTabChange() {
     97  Services.prefs.setBoolPref(TP_PREF, true);
     98 
     99  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, ABOUT_PAGE);
    100  ok(
    101    !gProtectionsHandler.iconBox.hasAttribute("active"),
    102    "shield is not active"
    103  );
    104 
    105  await Promise.all([
    106    BrowserTestUtils.loadURIString({
    107      browser: tab.linkedBrowser,
    108      uriString: TRACKING_PAGE,
    109    }),
    110    waitForContentBlockingEvent(3),
    111  ]);
    112  ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
    113 
    114  await BrowserTestUtils.loadURIString({
    115    browser: tab.linkedBrowser,
    116    uriString: ABOUT_PAGE,
    117  });
    118  ok(
    119    !gProtectionsHandler.iconBox.hasAttribute("active"),
    120    "shield is not active"
    121  );
    122 
    123  let contentBlockingEvent = waitForContentBlockingEvent(3);
    124  let trackingTab = await BrowserTestUtils.openNewForegroundTab(
    125    gBrowser,
    126    TRACKING_PAGE
    127  );
    128  await contentBlockingEvent;
    129  ok(gProtectionsHandler.iconBox.hasAttribute("active"), "shield is active");
    130 
    131  gBrowser.selectedTab = tab;
    132  ok(
    133    !gProtectionsHandler.iconBox.hasAttribute("active"),
    134    "shield is not active"
    135  );
    136 
    137  gBrowser.removeTab(trackingTab);
    138  gBrowser.removeTab(tab);
    139 
    140  Services.prefs.clearUserPref(TP_PREF);
    141 });