tor-browser

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

test_popup_blocker_link_target_blank.html (1483B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>Test for triggering the popup blocker by clicking a target=_blank link</title>
      6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7 <script src="/tests/SimpleTest/EventUtils.js"></script>
      8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      9 </head>
     10 <body>
     11 <a id="target" href="file_self_close.html" target="_blank">Click me</a>
     12 <script>
     13 
     14 let { ContentTaskUtils } = SpecialPowers.ChromeUtils.importESModule(
     15  "resource://testing-common/ContentTaskUtils.sys.mjs"
     16 );
     17 
     18 function testTargetBlankLink(aClickFun, aMsg) {
     19  add_task(async () => {
     20    info(aMsg);
     21    let popupBlockedPromise = ContentTaskUtils.waitForEvent(document, "DOMPopupBlocked", false, () => {
     22      ok(true, "received DOMPopupBlocked event");
     23      return true;
     24    });
     25    let link = document.getElementById("target");
     26    link.addEventListener("click", () => {
     27      // Consume the user activation to ensure the popup is blocked.
     28      SpecialPowers.wrap(document).clearUserGestureActivation();
     29    });
     30    aClickFun(link);
     31    await popupBlockedPromise;
     32  });
     33 }
     34 
     35 add_setup(async function() {
     36  await SpecialPowers.pushPrefEnv({"set": [
     37    // Enbale popup blocker
     38    ["dom.disable_open_during_load", true],
     39  ]});
     40 });
     41 
     42 testTargetBlankLink((aLink) => {
     43  synthesizeMouseAtCenter(aLink, {});
     44 }, "Open link by mouse click");
     45 
     46 testTargetBlankLink((aLink) => {
     47  aLink.click();
     48 }, "Open link by click()");
     49 
     50 </script>
     51 </body>
     52 </html>