tor-browser

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

browser_protectionsUI_open_preferences.js (4768B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TP_PREF = "privacy.trackingprotection.enabled";
      7 const TPC_PREF = "network.cookie.cookieBehavior";
      8 const TRACKING_PAGE =
      9  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     10  "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/trackingPage.html";
     11 const COOKIE_PAGE =
     12  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     13  "http://tracking.example.com/browser/browser/base/content/test/protectionsUI/cookiePage.html";
     14 
     15 async function waitAndAssertPreferencesShown(_spotlight) {
     16  await BrowserTestUtils.waitForEvent(
     17    gProtectionsHandler._protectionsPopup,
     18    "popuphidden"
     19  );
     20  await TestUtils.waitForCondition(
     21    () => gBrowser.currentURI.spec == "about:preferences#privacy",
     22    "Should open about:preferences."
     23  );
     24 
     25  await SpecialPowers.spawn(
     26    gBrowser.selectedBrowser,
     27    [_spotlight],
     28    async spotlight => {
     29      let doc = content.document;
     30      let section = await ContentTaskUtils.waitForCondition(
     31        () => doc.querySelector(".spotlight"),
     32        "The spotlight should appear."
     33      );
     34      Assert.equal(
     35        section.getAttribute("data-subcategory"),
     36        spotlight,
     37        "The correct section is spotlighted."
     38      );
     39    }
     40  );
     41 
     42  BrowserTestUtils.removeTab(gBrowser.selectedTab);
     43 }
     44 
     45 add_setup(async function () {
     46  await UrlClassifierTestUtils.addTestTrackers();
     47  let oldCanRecord = Services.telemetry.canRecordExtended;
     48  Services.telemetry.canRecordExtended = true;
     49 
     50  registerCleanupFunction(() => {
     51    Services.telemetry.canRecordExtended = oldCanRecord;
     52    UrlClassifierTestUtils.cleanupTestTrackers();
     53  });
     54 });
     55 
     56 // Tests that pressing the preferences button in the trackers subview
     57 // links to about:preferences
     58 add_task(async function testOpenPreferencesFromTrackersSubview() {
     59  Services.prefs.setBoolPref(TP_PREF, true);
     60 
     61  let promise = BrowserTestUtils.openNewForegroundTab({
     62    url: TRACKING_PAGE,
     63    gBrowser,
     64  });
     65 
     66  // Wait for 2 content blocking events - one for the load and one for the tracker.
     67  let [tab] = await Promise.all([promise, waitForContentBlockingEvent(2)]);
     68 
     69  await openProtectionsPanel();
     70 
     71  let categoryItem = document.getElementById(
     72    "protections-popup-category-trackers"
     73  );
     74 
     75  // Explicitly waiting for the category item becoming visible.
     76  await TestUtils.waitForCondition(() => {
     77    return BrowserTestUtils.isVisible(categoryItem);
     78  });
     79 
     80  ok(BrowserTestUtils.isVisible(categoryItem), "TP category item is visible");
     81  let trackersView = document.getElementById("protections-popup-trackersView");
     82  let viewShown = BrowserTestUtils.waitForEvent(trackersView, "ViewShown");
     83  categoryItem.click();
     84  await viewShown;
     85 
     86  ok(true, "Trackers view was shown");
     87 
     88  let preferencesButton = document.getElementById(
     89    "protections-popup-trackersView-settings-button"
     90  );
     91 
     92  ok(
     93    BrowserTestUtils.isVisible(preferencesButton),
     94    "The preferences button is shown."
     95  );
     96 
     97  let shown = waitAndAssertPreferencesShown("trackingprotection");
     98  preferencesButton.click();
     99  await shown;
    100  BrowserTestUtils.removeTab(tab);
    101 
    102  Services.prefs.clearUserPref(TP_PREF);
    103 });
    104 
    105 // Tests that pressing the preferences button in the cookies subview
    106 // links to about:preferences
    107 add_task(async function testOpenPreferencesFromCookiesSubview() {
    108  Services.prefs.setIntPref(
    109    TPC_PREF,
    110    Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER
    111  );
    112 
    113  let promise = BrowserTestUtils.openNewForegroundTab({
    114    url: COOKIE_PAGE,
    115    gBrowser,
    116  });
    117 
    118  // Wait for 2 content blocking events - one for the load and one for the tracker.
    119  let [tab] = await Promise.all([promise, waitForContentBlockingEvent(2)]);
    120 
    121  await openProtectionsPanel();
    122 
    123  let categoryItem = document.getElementById(
    124    "protections-popup-category-cookies"
    125  );
    126 
    127  // Explicitly waiting for the category item becoming visible.
    128  await TestUtils.waitForCondition(() => {
    129    return BrowserTestUtils.isVisible(categoryItem);
    130  });
    131 
    132  ok(BrowserTestUtils.isVisible(categoryItem), "TP category item is visible");
    133  let cookiesView = document.getElementById("protections-popup-cookiesView");
    134  let viewShown = BrowserTestUtils.waitForEvent(cookiesView, "ViewShown");
    135  categoryItem.click();
    136  await viewShown;
    137 
    138  ok(true, "Cookies view was shown");
    139 
    140  let preferencesButton = document.getElementById(
    141    "protections-popup-cookiesView-settings-button"
    142  );
    143 
    144  ok(
    145    BrowserTestUtils.isVisible(preferencesButton),
    146    "The preferences button is shown."
    147  );
    148 
    149  let shown = waitAndAssertPreferencesShown("trackingprotection");
    150  preferencesButton.click();
    151  await shown;
    152  BrowserTestUtils.removeTab(tab);
    153 
    154  Services.prefs.clearUserPref(TPC_PREF);
    155 });