Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test for triggering popup in microtask</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>
<div id="target" style="width: 50px; height: 50px; background: green"></div>
<script>
add_setup(async function() {
  await SpecialPowers.pushPrefEnv({"set": [
    // Enable popup blocker
    ["dom.disable_open_during_load", true],
  ]});
});
add_task(async function window_open_in_microtask() {
  let target = document.getElementById("target");
  let testPromise = new Promise(resolve => {
    target.addEventListener("click", () => {
      queueMicrotask(() => {
        let w = window.open("about:blank");
        ok(!!w, "Should allow popup");
        if (w) {
          w.close();
        }
        w = window.open("about:blank");
        ok(!w, "Should block popup");
        if (w) {
          w.close();
        }
        resolve();
      });
    }, { once: true });
  });
  SpecialPowers.wrap(document).notifyUserGestureActivation();
  // Dispatch an untrusted click event.
  SimpleTest.executeSoon(() => {
    target.dispatchEvent(new MouseEvent("click", {
      bubbles: true,
      cancelable: true,
      view: window,
    }));
  });
  await testPromise;
});
</script>
</body>
</html>