test_removedWindow.html (1288B)
1 <!DOCTYPE html> 2 <title>MessagePort should not work when created from a disconnected window</title> 3 <script src="/tests/SimpleTest/SimpleTest.js"></script> 4 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 5 6 <body> 7 <script> 8 "use strict"; 9 10 SimpleTest.waitForExplicitFinish(); 11 runTest(); 12 13 async function runTest() { 14 let ifr = document.createElement('iframe'); 15 await new Promise(resolve => { 16 ifr.onload = resolve; 17 ifr.src = 'support/empty.html'; 18 document.body.appendChild(ifr); 19 }); 20 21 let w = ifr.contentWindow; 22 23 let pre = new w.MessageChannel(); 24 ok(!!pre, "We have a channel"); 25 26 ifr.remove(); 27 28 let post = new w.MessageChannel(); 29 ok(!!post, "We have a channel"); 30 31 // This should silently fail. 32 pre.port1.postMessage(42); 33 pre.port2.onmessage = () => { 34 ok(false, "No messages should be received!"); 35 } 36 37 // This should silently fail. 38 post.port1.postMessage(42); 39 post.port2.onmessage = () => { 40 ok(false, "No messages should be received!"); 41 } 42 43 // Let's use another MessagePort just to be sure no messages are received by 44 // port2. 45 46 let mc = new MessageChannel(); 47 mc.port1.postMessage(42); 48 mc.port2.onmessage = () => { 49 ok(true, "Ready to complete the test"); 50 SimpleTest.finish(); 51 } 52 } 53 54 </script> 55 </body>