tor-browser

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

browser_test_toplevel_data_navigations.js (2399B)


      1 /* eslint-disable mozilla/no-arbitrary-setTimeout */
      2 
      3 "use strict";
      4 
      5 const kDataBody = "toplevel navigation to data: URI allowed";
      6 const kDataURI = "data:text/html,<body>" + kDataBody + "</body>";
      7 const kTestPath = getRootDirectory(gTestPath).replace(
      8  "chrome://mochitests/content",
      9  "http://example.com"
     10 );
     11 const kRedirectURI = kTestPath + "file_toplevel_data_navigations.sjs";
     12 const kMetaRedirectURI = kTestPath + "file_toplevel_data_meta_redirect.html";
     13 
     14 add_task(async function test_nav_data_uri() {
     15  await SpecialPowers.pushPrefEnv({
     16    set: [["security.data_uri.block_toplevel_data_uri_navigations", true]],
     17  });
     18  await BrowserTestUtils.withNewTab(kDataURI, async function () {
     19    await SpecialPowers.spawn(
     20      gBrowser.selectedBrowser,
     21      [{ kDataBody }],
     22      async function ({ kDataBody }) {
     23        // eslint-disable-line
     24        is(
     25          content.document.body.innerHTML,
     26          kDataBody,
     27          "data: URI navigation from system should be allowed"
     28        );
     29      }
     30    );
     31  });
     32 });
     33 
     34 add_task(async function test_nav_data_uri_redirect() {
     35  await SpecialPowers.pushPrefEnv({
     36    set: [["security.data_uri.block_toplevel_data_uri_navigations", true]],
     37  });
     38  let tab = BrowserTestUtils.addTab(gBrowser, kRedirectURI);
     39  registerCleanupFunction(async function () {
     40    BrowserTestUtils.removeTab(tab);
     41  });
     42  // wait to make sure data: URI did not load before checking that it got blocked
     43  await new Promise(resolve => setTimeout(resolve, 500));
     44  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
     45    is(
     46      content.document.body.innerHTML,
     47      "",
     48      "data: URI navigation after server redirect should be blocked"
     49    );
     50  });
     51 });
     52 
     53 add_task(async function test_nav_data_uri_meta_redirect() {
     54  await SpecialPowers.pushPrefEnv({
     55    set: [["security.data_uri.block_toplevel_data_uri_navigations", true]],
     56  });
     57  let tab = BrowserTestUtils.addTab(gBrowser, kMetaRedirectURI);
     58  registerCleanupFunction(async function () {
     59    BrowserTestUtils.removeTab(tab);
     60  });
     61  // wait to make sure data: URI did not load before checking that it got blocked
     62  await new Promise(resolve => setTimeout(resolve, 500));
     63  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
     64    is(
     65      content.document.body.innerHTML,
     66      "",
     67      "data: URI navigation after meta redirect should be blocked"
     68    );
     69  });
     70 });