test_window_open_discarded_bc.html (1297B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Discard a new BrowsingContext during window.open nested event loop</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <script> 10 add_task(async function() { 11 const TOPIC = "dangerous:test-only:new-browser-child-ready"; 12 13 let found = false; 14 function observer(subject) { 15 let win = SpecialPowers.wrap(subject); 16 if (SpecialPowers.compare(win.opener, window)) { 17 found = true; 18 SpecialPowers.removeObserver(observer, TOPIC); 19 20 win.close(); 21 // window.close() is not synchronous, so we need to wait for the 22 // BrowsingContext to actually become discarded after we call it, to 23 // make sure that the window provider actually has a discarded BC at the 24 // end of its own nested event loop. 25 SpecialPowers.Services.tm.spinEventLoopUntil( 26 "Test(test_window_open_discarded_bc.html:add_task)", 27 () => !win.opener 28 ); 29 } 30 } 31 SpecialPowers.addObserver(observer, TOPIC); 32 33 let win = window.open(); 34 35 is(found, true, "Our observer should have fired for the new window"); 36 is(win, null, "window.open() should return null when new window is already closed"); 37 }); 38 </script> 39 </body> 40 </html>