tor-browser

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

browser_protectionsUI_shield_visibility.js (3032B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /* This test checks pages of different URL variants (mostly differing in scheme)
      5 * and verifies that the shield is only shown when content blocking can deal
      6 * with the specific variant. */
      7 
      8 const TEST_CASES = [
      9  {
     10    type: "http",
     11    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     12    testURL: "http://example.com",
     13    hidden: false,
     14  },
     15  {
     16    type: "https",
     17    testURL: "https://example.com",
     18    hidden: false,
     19  },
     20  {
     21    type: "chrome page",
     22    testURL: "chrome://global/content/mozilla.html",
     23    hidden: true,
     24  },
     25  {
     26    type: "content-privileged about page",
     27    testURL: "about:robots",
     28    hidden: true,
     29  },
     30  {
     31    type: "non-chrome about page",
     32    testURL: "about:about",
     33    hidden: true,
     34  },
     35  {
     36    type: "chrome about page",
     37    testURL: "about:preferences",
     38    hidden: true,
     39  },
     40  {
     41    type: "file",
     42    testURL: "benignPage.html",
     43    hidden: true,
     44  },
     45  {
     46    type: "certificateError",
     47    testURL: "https://self-signed.example.com",
     48    hidden: true,
     49  },
     50  {
     51    type: "localhost",
     52    testURL: "http://127.0.0.1",
     53    hidden: false,
     54  },
     55  {
     56    type: "data URI",
     57    testURL: "data:text/html,<div>",
     58    hidden: true,
     59  },
     60  {
     61    type: "view-source HTTP",
     62    testURL: "view-source:http://example.com/",
     63    hidden: true,
     64  },
     65  {
     66    type: "view-source HTTPS",
     67    testURL: "view-source:https://example.com/",
     68    hidden: true,
     69  },
     70  {
     71    type: "top level sandbox",
     72    testURL:
     73      "https://example.com/browser/browser/base/content/test/protectionsUI/sandboxed.html",
     74    hidden: false,
     75  },
     76 ];
     77 
     78 add_task(async function () {
     79  await SpecialPowers.pushPrefEnv({
     80    set: [
     81      // By default, proxies don't apply to 127.0.0.1. We need them to for this test, though:
     82      ["network.proxy.allow_hijacking_localhost", true],
     83    ],
     84  });
     85 
     86  for (let testData of TEST_CASES) {
     87    info(`Testing for ${testData.type}`);
     88    let testURL = testData.testURL;
     89 
     90    // Overwrite the url if it is testing the file url.
     91    if (testData.type === "file") {
     92      let dir = getChromeDir(getResolvedURI(gTestPath));
     93      dir.append(testURL);
     94      dir.normalize();
     95      testURL = Services.io.newFileURI(dir).spec;
     96    }
     97 
     98    let pageLoaded;
     99    let tab = await BrowserTestUtils.openNewForegroundTab(
    100      gBrowser,
    101      () => {
    102        gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, testURL);
    103        let browser = gBrowser.selectedBrowser;
    104        if (testData.type === "certificateError") {
    105          pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
    106        } else {
    107          pageLoaded = BrowserTestUtils.browserLoaded(browser, true);
    108        }
    109      },
    110      false
    111    );
    112    await pageLoaded;
    113 
    114    is(
    115      BrowserTestUtils.isHidden(
    116        gProtectionsHandler._trackingProtectionIconContainer
    117      ),
    118      testData.hidden,
    119      "tracking protection icon container is correctly displayed"
    120    );
    121 
    122    BrowserTestUtils.removeTab(tab);
    123  }
    124 });