dom/tests/mochitest/whatwg/postMessage_onOther.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/whatwg/postMessage_onOther.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>postMessage called through another frame</title>
     1.8 +  <script type="application/javascript">
     1.9 +    var PATH = "/tests/dom/tests/mochitest/whatwg/postMessage_onOther.html";
    1.10 +
    1.11 +    function receiveMessage(evt)
    1.12 +    {
    1.13 +      if (evt.lastEventId !== "")
    1.14 +      {
    1.15 +        fail("unexpected non-empty lastEventId");
    1.16 +        return;
    1.17 +      }
    1.18 +
    1.19 +      switch (window.location.href)
    1.20 +      {
    1.21 +        case "http://example.com" + PATH:
    1.22 +          receiveTopDomain(evt);
    1.23 +          break;
    1.24 +
    1.25 +        case "http://test1.example.com" + PATH:
    1.26 +          receiveSubDomain(evt);
    1.27 +          break;
    1.28 +
    1.29 +        default:
    1.30 +          fail("unexpected location");
    1.31 +      }
    1.32 +    }
    1.33 +
    1.34 +    function fail(msg)
    1.35 +    {
    1.36 +      window.parent.postMessage("FAIL " + msg, "*");
    1.37 +    }
    1.38 +
    1.39 +    // The parent frame sends "start-test" to the subdomain frame to start.
    1.40 +    // The subdomain frame then sets document.domain to the top domain so that
    1.41 +    // the top domain frame can access it.  It then sends a message to the top
    1.42 +    // domain frame to tell it to do likewise; once that happens, the top domain
    1.43 +    // frame can then call a method on the subdomain frame window, which will
    1.44 +    // call a method *on the top domain window* to send a message to the parent
    1.45 +    // window.  We thus expect to see an event whose source is the subdomain
    1.46 +    // window -- *not* the top domain window.  Therefore, its .origin should be:
    1.47 +    //
    1.48 +    //   http://test1.example.com
    1.49 +    //
    1.50 +    // and not
    1.51 +    //
    1.52 +    //   http://example.com
    1.53 +
    1.54 +    function receiveSubDomain(evt)
    1.55 +    {
    1.56 +      if (evt.origin !== "http://mochi.test:8888")
    1.57 +      {
    1.58 +        fail("wrong top-domain origin: " + evt.origin);
    1.59 +        return;
    1.60 +      }
    1.61 +      if (evt.data !== "start-test")
    1.62 +      {
    1.63 +        fail("wrong top-domain message: " + evt.origin);
    1.64 +        return;
    1.65 +      }
    1.66 +
    1.67 +      document.domain = "example.com";
    1.68 +      window.parent.topDomainFrame.postMessage("domain-switch",
    1.69 +                                               "http://example.com");
    1.70 +    }
    1.71 +    
    1.72 +    function receiveTopDomain(evt)
    1.73 +    {
    1.74 +      if (evt.origin !== "http://test1.example.com")
    1.75 +      {
    1.76 +        fail("wrong subdomain origin: " + evt.origin);
    1.77 +        return;
    1.78 +      }
    1.79 +      if (evt.data !== "domain-switch")
    1.80 +      {
    1.81 +        fail("wrong subdomain message: " + evt.origin);
    1.82 +        return;
    1.83 +      }
    1.84 +      if (evt.source !== window.parent.subDomainFrame)
    1.85 +      {
    1.86 +        fail("wrong source on message from subdomain");
    1.87 +        return;
    1.88 +      }
    1.89 +
    1.90 +      document.domain = "example.com";
    1.91 +      window.parent.subDomainFrame.testSiblingPostMessage();
    1.92 +    }
    1.93 +
    1.94 +    function testSiblingPostMessage()
    1.95 +    {
    1.96 +      window.parent.postMessage("test-finished", "http://mochi.test:8888");
    1.97 +    }
    1.98 +
    1.99 +    function setup()
   1.100 +    {
   1.101 +      var target = document.getElementById("location");
   1.102 +      target.textContent = location.hostname + ":" + (location.port || 80);
   1.103 +    }
   1.104 +
   1.105 +    window.addEventListener("message", receiveMessage, false);
   1.106 +    window.addEventListener("load", setup, false);
   1.107 +  </script>
   1.108 +</head>
   1.109 +<body>
   1.110 +<h1 id="location">No location!</h1>
   1.111 +</body>
   1.112 +</html>

mercurial