Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test for triggering the popup blocker by clicking a target=_blank link</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a id="target" href="file_self_close.html" target="_blank">Click me</a>
<script>
let { ContentTaskUtils } = SpecialPowers.ChromeUtils.importESModule(
);
function testTargetBlankLink(aClickFun, aMsg) {
  add_task(async () => {
    info(aMsg);
    let popupBlockedPromise = ContentTaskUtils.waitForEvent(document, "DOMPopupBlocked", false, () => {
      ok(true, "received DOMPopupBlocked event");
      return true;
    });
    let link = document.getElementById("target");
    link.addEventListener("click", () => {
      // Consume the user activation to ensure the popup is blocked.
      SpecialPowers.wrap(document).clearUserGestureActivation();
    });
    aClickFun(link);
    await popupBlockedPromise;
  });
}
add_setup(async function() {
  await SpecialPowers.pushPrefEnv({"set": [
    // Enbale popup blocker
    ["dom.disable_open_during_load", true],
  ]});
});
testTargetBlankLink((aLink) => {
  synthesizeMouseAtCenter(aLink, {});
}, "Open link by mouse click");
testTargetBlankLink((aLink) => {
  aLink.click();
}, "Open link by click()");
</script>
</body>
</html>