tor-browser

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

browser_javascript_links.js (2521B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_PATH = getRootDirectory(gTestPath).replace(
      7  "chrome://mochitests/content/",
      8  "https://example.com/"
      9 );
     10 const IFRAME_PATH = TEST_PATH + "file_javascript_links_subframe.html";
     11 
     12 add_setup(async function () {
     13  await SpecialPowers.pushPrefEnv({
     14    set: [
     15      ["browser.link.alternative_click.block_javascript", true],
     16      ["browser.tabs.opentabfor.middleclick", true],
     17      ["middlemouse.paste", false],
     18      ["middlemouse.contentLoadURL", false],
     19      ["general.autoScroll", false],
     20    ],
     21  });
     22 });
     23 
     24 add_task(async function () {
     25  await BrowserTestUtils.withNewTab(
     26    `data:text/html,<a href="javascript:alert(1);">click me`,
     27    async browser => {
     28      await BrowserTestUtils.synthesizeMouseAtCenter(
     29        "a",
     30        { button: 0, ctrlKey: true, metaKey: true },
     31        browser
     32      );
     33      is(
     34        gBrowser.tabs.length,
     35        2,
     36        "Accel+click on javascript: link shouldn't open a new tab"
     37      );
     38 
     39      await BrowserTestUtils.synthesizeMouseAtCenter(
     40        "a",
     41        { button: 1 },
     42        browser
     43      );
     44      is(
     45        gBrowser.tabs.length,
     46        2,
     47        "Middle click on javascript: link shouldn't open a new tab"
     48      );
     49 
     50      await BrowserTestUtils.synthesizeMouseAtCenter(
     51        "a",
     52        { button: 0, shiftKey: true },
     53        browser
     54      );
     55      // This is fragile and might miss the new window, but the test will fail
     56      // anyway when finishing with an extra window left behind.
     57      // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     58      await new Promise(resolve => setTimeout(resolve, 200));
     59      is(
     60        BrowserWindowTracker.windowCount,
     61        1,
     62        "Shift+click on javascript: link shouldn't open a new window"
     63      );
     64    }
     65  );
     66 });
     67 
     68 add_task(async function iframe_link() {
     69  await BrowserTestUtils.withNewTab(
     70    `data:text/html,<iframe src="${IFRAME_PATH}"></iframe>`,
     71    async browser => {
     72      // ctrl/cmd-click the link in the subframe.
     73      await BrowserTestUtils.synthesizeMouseAtCenter(
     74        "a",
     75        { ctrlKey: true, metaKey: true },
     76        browser.browsingContext.children[0]
     77      );
     78 
     79      // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     80      await new Promise(resolve => setTimeout(resolve, 200));
     81      is(
     82        gBrowser.tabs.length,
     83        2,
     84        "Click on javascript: link in iframe shouldn't open a new tab"
     85      );
     86    }
     87  );
     88 });