Transferred_objects_unusable.sub.htm (1679B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> Transferred objects are no longer usable on the sending side </title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 </head> 8 <body> 9 <div id=log></div> 10 11 <div style="display:none"> 12 <iframe width="70%" onload="PostMessageTest()" src="{{location[scheme]}}://{{domains[www1]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe> 13 </div> 14 15 <script> 16 17 18 var description = "Test Description: " + 19 "Objects listed in transfer are transferred, not just cloned, meaning that they are " + 20 "no longer usable on the sending side."; 21 22 var t = async_test(description); 23 24 var DATA = {test: "e.ports[0].postMessage('TRANSFERRED')"}; 25 var TARGET = document.querySelector("iframe"); 26 var ExpectedResult = ["PING", "TRANSFERRED"]; 27 var ActualResult = []; 28 29 function PostMessageTest() 30 { 31 test(function() 32 { 33 assert_own_property(window, "MessageChannel", "window"); 34 35 var channel = new MessageChannel(); 36 37 channel.port2.onmessage = t.step_func(VerifyResult); 38 39 channel.port1.postMessage("PING"); 40 41 TARGET.contentWindow.postMessage(DATA, "*", [channel.port1]); 42 43 channel.port1.postMessage("PONG"); 44 45 }, "MessageChannel is supported."); 46 } 47 48 function VerifyResult(e) 49 { 50 ActualResult.push(e.data) 51 52 if (ActualResult.length >= ExpectedResult.length) 53 { 54 assert_array_equals(ActualResult, ExpectedResult, "ActualResult"); 55 t.done(); 56 } 57 } 58 </script> 59 </body> 60 </html>