tor-browser

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

browser_bug575561.js (3979B)


      1 requestLongerTimeout(2);
      2 
      3 const TEST_URL =
      4  // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      5  "http://example.com/browser/browser/base/content/test/general/app_bug575561.html";
      6 
      7 add_task(async function () {
      8  SimpleTest.requestCompleteLog();
      9 
     10  // allow top level data: URI navigations, otherwise clicking data: link fails
     11  await SpecialPowers.pushPrefEnv({
     12    set: [["security.data_uri.block_toplevel_data_uri_navigations", false]],
     13  });
     14 
     15  // Pinned: Link to the same domain should not open a new tab
     16  // Tests link to http://example.com/browser/browser/base/content/test/general/dummy_page.html
     17  await testLink(0, true, false);
     18  // Pinned: Link to a different subdomain should open a new tab
     19  // Tests link to http://test1.example.com/browser/browser/base/content/test/general/dummy_page.html
     20  await testLink(1, true, true);
     21 
     22  // Pinned: Link to a different domain should open a new tab
     23  // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html
     24  await testLink(2, true, true);
     25 
     26  // Not Pinned: Link to a different domain should not open a new tab
     27  // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html
     28  await testLink(2, false, false);
     29 
     30  // Pinned: Targetted link should open a new tab
     31  // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html with target="foo"
     32  await testLink(3, true, true);
     33 
     34  // Pinned: Link in a subframe should not open a new tab
     35  // Tests link to http://example.org/browser/browser/base/content/test/general/dummy_page.html in subframe
     36  await testLink(0, true, false, true);
     37 
     38  // Pinned: Link to the same domain (with www prefix) should not open a new tab
     39  // Tests link to http://www.example.com/browser/browser/base/content/test/general/dummy_page.html
     40  await testLink(4, true, false);
     41 
     42  // Pinned: Link to a data: URI should not open a new tab
     43  // Tests link to data:text/html,<!DOCTYPE html><html><body>Another Page</body></html>
     44  await testLink(5, true, false);
     45 
     46  // Pinned: Link to an about: URI should not open a new tab
     47  // Tests link to about:logo
     48  await testLink(
     49    function (doc) {
     50      let link = doc.createElement("a");
     51      link.textContent = "Link to Mozilla";
     52      link.href = "about:logo";
     53      doc.body.appendChild(link);
     54      return link;
     55    },
     56    true,
     57    false,
     58    false,
     59    "about:robots"
     60  );
     61 });
     62 
     63 async function testLink(
     64  aLinkIndexOrFunction,
     65  pinTab,
     66  expectNewTab,
     67  testSubFrame,
     68  aURL = TEST_URL
     69 ) {
     70  let appTab = BrowserTestUtils.addTab(gBrowser, aURL, { skipAnimation: true });
     71  if (pinTab) {
     72    gBrowser.pinTab(appTab);
     73  }
     74  gBrowser.selectedTab = appTab;
     75 
     76  let browser = appTab.linkedBrowser;
     77  await BrowserTestUtils.browserLoaded(browser);
     78 
     79  let promise;
     80  if (expectNewTab) {
     81    promise = BrowserTestUtils.waitForNewTab(gBrowser).then(tab => {
     82      let loaded = tab.linkedBrowser.documentURI.spec;
     83      BrowserTestUtils.removeTab(tab);
     84      return loaded;
     85    });
     86  } else {
     87    promise = BrowserTestUtils.browserLoaded(browser, testSubFrame);
     88  }
     89 
     90  let href;
     91  if (typeof aLinkIndexOrFunction === "function") {
     92    ok(!browser.isRemoteBrowser, "don't pass a function for a remote browser");
     93    let link = aLinkIndexOrFunction(browser.contentDocument);
     94    info("Clicking " + link.textContent);
     95    link.click();
     96    href = link.href;
     97  } else {
     98    href = await SpecialPowers.spawn(
     99      browser,
    100      [[testSubFrame, aLinkIndexOrFunction]],
    101      function ([subFrame, index]) {
    102        let doc = subFrame
    103          ? content.document.querySelector("iframe").contentDocument
    104          : content.document;
    105        let link = doc.querySelectorAll("a")[index];
    106 
    107        info("Clicking " + link.textContent);
    108        link.click();
    109        return link.href;
    110      }
    111    );
    112  }
    113 
    114  info(`Waiting on load of ${href}`);
    115  let loaded = await promise;
    116  is(loaded, href, "loaded the right document");
    117  BrowserTestUtils.removeTab(appTab);
    118 }