postMessage_asterisk_xorigin.sub.htm (1855B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> Cross-origin postMessage with targetOrigin == "*" </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 <script> 12 13 14 var description = "Test Description: To send the message to the target regardless of origin, set the target origin to '*'."; 15 16 var t = async_test(description); 17 18 var PORT = location.port !== "" ? ":" + location.port : ""; 19 var XORIGIN = "{{location[scheme]}}://{{domains[www]}}" + PORT; 20 var SORIGIN = "{{location[scheme]}}://{{host}}" + PORT; 21 var ExpectedResult = ["#1", XORIGIN, "#2", SORIGIN]; 22 var ActualResult = []; 23 24 window.onmessage = t.step_func(function(e) 25 { 26 // Messages from TARGET1 and TARGET2 can come in any order 27 // (since one of them is cross-origin and can run in parallel). 28 // To make the tests immune to message reordering, always 29 // put the response from TARGET1 at the start of the list. 30 if (e.data.toString() === "#1") 31 { 32 ActualResult = [e.data, e.origin].concat(ActualResult); 33 } 34 else if (e.data.toString() === "#2") 35 { 36 ActualResult = ActualResult.concat([e.data, e.origin]); 37 } 38 39 if (ActualResult.length >= ExpectedResult.length) 40 { 41 assert_array_equals(ActualResult, ExpectedResult, "ActualResult"); 42 t.done(); 43 } 44 }); 45 </script> 46 47 <div style="display:none"> 48 <iframe width="70%" onload="this.contentWindow.postMessage('#1', '*')" src="{{location[scheme]}}://{{domains[www]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe> 49 <iframe width="70%" onload="this.contentWindow.postMessage('#2', '*')" src="./support/ChildWindowPostMessage.htm"></iframe> 50 </div> 51 </body> 52 </html>