test_windowProxyDeadWrapper.html (2587B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1223372 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1223372</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://global/skin"/> 11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 12 <script type="application/javascript"> 13 14 /** Test for Bug 1223372 */ 15 const {TestUtils} = ChromeUtils.importESModule( 16 "resource://testing-common/TestUtils.sys.mjs" 17 ); 18 19 async function go() { 20 SimpleTest.waitForExplicitFinish(); 21 await SpecialPowers.pushPrefEnv({"set": [["security.allow_eval_with_system_principal", 22 true]]}); 23 24 var frame = $('subframe'); 25 frame.onload = null; 26 27 var w = frame.contentWindow; 28 29 w.eval("checkDead = function() { return Components.utils.isDeadWrapper(this); };"); 30 var checkDead = w.checkDead; 31 32 w.eval("getObject = function() { return {}; }"); 33 var getObject = w.getObject; 34 35 ok(!checkDead(), "WindowProxy shouldn't be dead yet"); 36 37 // Load a content page in the chrome frame. 38 w.location = "https://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"; 39 tryWindow(); 40 41 function tryWindow() { 42 if (w.document.title != 'empty test page') { 43 info("Document not loaded yet - retrying"); 44 SimpleTest.executeSoon(tryWindow); 45 return; 46 } 47 48 let winID = w.docShell.outerWindowID; 49 // Remove the frame. This will nuke the WindowProxy wrapper from our chrome 50 // document's global, so evaluating 'this' in it will return a dead wrapper 51 // once the window is destroyed. 52 frame.remove(); 53 54 TestUtils.topicObserved("outer-window-nuked", (subject) => { 55 let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data; 56 return id == winID; 57 }).then(() => { 58 ok(checkDead(), "Expected a dead object wrapper"); 59 60 // Wrapping the Window should return a dead wrapper now. 61 var global = Cu.getGlobalForObject(getObject()); 62 ok(Cu.isDeadWrapper(global), 63 "Expected a dead wrapper when requesting the window's global"); 64 65 SimpleTest.finish(); 66 }); 67 } 68 } 69 70 </script> 71 </head> 72 <body> 73 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1223372">Mozilla Bug 1223372</a> 74 75 <iframe id="subframe" src="./file_empty.html" onload="go()"></iframe> 76 77 </body> 78 </html>