tor-browser

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

postMessage_joined_helper2.html (1990B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 http://example.org/tests/dom/tests/mochitest/whatwg/postMessage_joined_helper2.html
      5 -->
      6 <head>
      7  <title>postMessage joined domains, innermost frame</title>
      8  <script type="application/javascript">
      9    function receiveMessage(evt)
     10    {
     11      var response = "subframe-test-finished";
     12 
     13      if (evt.origin !== "http://sub1.test1.example.org")
     14      {
     15        response += " wrong-origin(" + evt.origin + ")";
     16        response += " location(" + window.location.href + ")";
     17      }
     18 
     19      if (evt.data !== "start-test")
     20        response += " incorrect-subframe-data(" + evt.data + ")";
     21      if (evt.type !== "message")
     22        response += " wrong-type(" + evt.type + ")";
     23      if (evt.target !== window)
     24      {
     25        response += " wrong-target(" + evt.target + ")";
     26        response += " location(" + window.location.href + ")";
     27      }
     28 
     29      if (evt.source !== window.parent)
     30      {
     31        response += " unexpected-source(" + evt.source + ")";
     32        response += " window-parent-is(" + window.parent + ")";
     33        response += " location(" + window.location.href + ")";
     34      }
     35 
     36      // verify that document.domain was actually joined with this domain
     37      try
     38      {
     39        var passed = evt.source.document.domain === document.domain;
     40      }
     41      catch (e)
     42      {
     43      }
     44 
     45      if (!passed)
     46        response += " expected-joined-domains";
     47 
     48      window.parent.postMessage(response, "http://sub1.test1.example.org");
     49    }
     50    
     51    function setup()
     52    {
     53      var oldDomain = document.domain;
     54      var newDomain = "example.org"; // join with parent
     55 
     56      document.domain = newDomain;
     57 
     58      var target = document.getElementById("location");
     59      target.textContent = "Location: " + oldDomain +
     60                           ", effective domain: " + newDomain;
     61 
     62      window.addEventListener("message", receiveMessage);
     63    }
     64 
     65    window.addEventListener("load", setup);
     66  </script>
     67 </head>
     68 <body>
     69 <p id="location">No location!</p>
     70 </body>
     71 </html>