tor-browser

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

browser_click_link_within_view_source.js (2595B)


      1 "use strict";
      2 
      3 /**
      4 * Test for Bug 1359204
      5 *
      6 * Loading a local file, then view-source on that file. Make sure that
      7 * clicking a link within that view-source page is not blocked by security checks.
      8 */
      9 
     10 add_task(async function test_click_link_within_view_source() {
     11  let TEST_FILE = "file_click_link_within_view_source.html";
     12  let TEST_FILE_URI = getChromeDir(getResolvedURI(gTestPath));
     13  TEST_FILE_URI.append(TEST_FILE);
     14  TEST_FILE_URI = Services.io.newFileURI(TEST_FILE_URI).spec;
     15 
     16  let DUMMY_FILE = "dummy_page.html";
     17  let DUMMY_FILE_URI = getChromeDir(getResolvedURI(gTestPath));
     18  DUMMY_FILE_URI.append(DUMMY_FILE);
     19  DUMMY_FILE_URI = Services.io.newFileURI(DUMMY_FILE_URI).spec;
     20 
     21  await BrowserTestUtils.withNewTab(TEST_FILE_URI, async function () {
     22    let tabSpec = gBrowser.selectedBrowser.currentURI.spec;
     23    info("loading: " + tabSpec);
     24    ok(
     25      tabSpec.startsWith("file://") && tabSpec.endsWith(TEST_FILE),
     26      "sanity check to make sure html loaded"
     27    );
     28 
     29    info("click view-source of html");
     30    let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser);
     31    document.getElementById("View:PageSource").doCommand();
     32 
     33    let tab = await tabPromise;
     34    tabSpec = gBrowser.selectedBrowser.currentURI.spec;
     35    info("loading: " + tabSpec);
     36    ok(
     37      tabSpec.startsWith("view-source:file://") && tabSpec.endsWith(TEST_FILE),
     38      "loading view-source of html succeeded"
     39    );
     40 
     41    info("click testlink within view-source page");
     42    let loadPromise = BrowserTestUtils.browserLoaded(
     43      tab.linkedBrowser,
     44      false,
     45      url => url.endsWith("dummy_page.html")
     46    );
     47    await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
     48      if (content.document.readyState != "complete") {
     49        await ContentTaskUtils.waitForEvent(
     50          content.document,
     51          "readystatechange",
     52          false,
     53          () => content.document.readyState == "complete"
     54        );
     55      }
     56      // document.getElementById() does not work on a view-source page, hence we use document.links
     57      let linksOnPage = content.document.links;
     58      is(
     59        linksOnPage.length,
     60        1,
     61        "sanity check: make sure only one link is present on page"
     62      );
     63      let myLink = content.document.links[0];
     64      myLink.click();
     65    });
     66 
     67    await loadPromise;
     68 
     69    tabSpec = gBrowser.selectedBrowser.currentURI.spec;
     70    info("loading: " + tabSpec);
     71    ok(
     72      tabSpec.startsWith("view-source:file://") && tabSpec.endsWith(DUMMY_FILE),
     73      "loading view-source of html succeeded"
     74    );
     75 
     76    BrowserTestUtils.removeTab(tab);
     77  });
     78 });