tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

event.origin.sub.htm (2164B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title> event.origin returns the origin of the message </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[天気の良い日]}}:{{location[port]}}/webmessaging/support/ChildWindowPostMessage.htm"></iframe>
     13    <iframe width="70%" onload="PostMessageTest()" src="./support/ChildWindowPostMessage.htm"></iframe>
     14 </div>
     15 
     16 <script>
     17 
     18 
     19    var description = "Test Description: event.origin returns the origin of the message.";
     20 
     21    var t = async_test(description);
     22 
     23    var PORT = location.port !== "" ? ":" + location.port : "";
     24    var TARGET1 = document.querySelectorAll("iframe")[0];
     25    var TARGET2 = document.querySelectorAll("iframe")[1];
     26    var XORIGIN = "{{location[scheme]}}://{{domains[天気の良い日]}}" + PORT;
     27    var SORIGIN = "{{location[scheme]}}://{{host}}" + PORT;
     28    var ExpectedResult = ["#1", XORIGIN, "#2", SORIGIN];
     29    var ActualResult = [];
     30    var loaded = 0;
     31 
     32    function PostMessageTest()
     33    {
     34        loaded++;
     35 
     36        if (loaded == 2)
     37        {
     38            TARGET1.contentWindow.postMessage("#1", XORIGIN);
     39            TARGET2.contentWindow.postMessage("#2", SORIGIN);
     40        }
     41    }
     42 
     43    window.onmessage = t.step_func(function(e)
     44    {
     45        // Messages from TARGET1 and TARGET2 can come in any order
     46        // (since one of them is cross-origin and can run in parallel).
     47        // To make the tests immune to message reordering, always
     48        // put the response from TARGET1 at the start of the list.
     49        if (e.data.toString() === "#1")
     50        {
     51            ActualResult = [e.data, e.origin].concat(ActualResult);
     52        }
     53        else if (e.data.toString() === "#2")
     54        {
     55            ActualResult = ActualResult.concat([e.data, e.origin]);
     56        }
     57 
     58        if (ActualResult.length >= ExpectedResult.length)
     59        {
     60            assert_array_equals(ActualResult, ExpectedResult, "ActualResult");
     61            t.done();
     62        }
     63    });
     64 </script>
     65 </body>
     66 </html>