test_popup_blocker_microtask.html (1444B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test for triggering popup in microtask</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 <div id="target" style="width: 50px; height: 50px; background: green"></div> 12 <script> 13 14 add_setup(async function() { 15 await SpecialPowers.pushPrefEnv({"set": [ 16 // Enable popup blocker 17 ["dom.disable_open_during_load", true], 18 ]}); 19 }); 20 21 // Test for bug 1863217 22 add_task(async function window_open_in_microtask() { 23 let target = document.getElementById("target"); 24 let testPromise = new Promise(resolve => { 25 target.addEventListener("click", () => { 26 queueMicrotask(() => { 27 let w = window.open("about:blank"); 28 ok(!!w, "Should allow popup"); 29 if (w) { 30 w.close(); 31 } 32 w = window.open("about:blank"); 33 ok(!w, "Should block popup"); 34 if (w) { 35 w.close(); 36 } 37 resolve(); 38 }); 39 }, { once: true }); 40 }); 41 42 SpecialPowers.wrap(document).notifyUserGestureActivation(); 43 // Dispatch an untrusted click event. 44 SimpleTest.executeSoon(() => { 45 target.dispatchEvent(new MouseEvent("click", { 46 bubbles: true, 47 cancelable: true, 48 view: window, 49 })); 50 }); 51 await testPromise; 52 }); 53 54 </script> 55 </body> 56 </html>