test_open_and_immediately_close_opener.html (1509B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Test for Bug 1702678</title> 5 <meta charset="utf-8"> 6 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 8 </head> 9 <body> 10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1702678">Mozilla Bug 1702678</a> 11 12 <script type="application/javascript"> 13 "use strict"; 14 15 const HTML = ` 16 <!DOCTYPE html> 17 <html> 18 <head> 19 <meta charset="utf-8"> 20 <script> 21 // We need to queue a promise reaction job whilch will close the window 22 // during the nested event loop spun up by the window opening code. 23 Promise.resolve().then(() => { 24 window.close(); 25 }); 26 window.open("data:text/html,Hello"); 27 <\/script> 28 </head> 29 </html> 30 `; 31 32 add_task(async function() { 33 // This bug only manifests when opening tabs in new windows. 34 await SpecialPowers.pushPrefEnv({ 35 set: [["browser.link.open_newwindow", 2]], 36 }); 37 38 // Create a window in a new BrowsingContextGroup so that it will be the last 39 // window in the group when it closes, and the group will be destroyed. 40 window.open(`data:text/html,${encodeURIComponent(HTML)}`, "", "noopener"); 41 42 // Make a few trips through the event loop to ensure we've had a chance to 43 // open and close the relevant windows. 44 for (let i = 0; i < 10; i++) { 45 await new Promise(resolve => setTimeout(resolve, 0)); 46 } 47 48 ok(true, "We didn't crash"); 49 }); 50 </script> 51 52 </body> 53 </html>