dom/tests/mochitest/whatwg/postMessage_helper.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/whatwg/postMessage_helper.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,110 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>postMessage message receiver</title>
     1.8 +  <script type="application/javascript" src="browserFu.js"></script>
     1.9 +  <script type="application/javascript">
    1.10 +    function $(id) { return document.getElementById(id); }
    1.11 +
    1.12 +    function setup()
    1.13 +    {
    1.14 +      var target = $("domain");
    1.15 +      target.textContent = location.hostname + ":" + (location.port || 80);
    1.16 +    }
    1.17 +
    1.18 +    function receiveMessage(evt)
    1.19 +    {
    1.20 +      var response = evt.data + "-response";
    1.21 +
    1.22 +      if (evt.lastEventId !== "")
    1.23 +        response += " wrong-lastEventId(" + evt.lastEventId + ")";
    1.24 +
    1.25 +      if (evt.source !== window.parent)
    1.26 +      {
    1.27 +        response += " unexpected-source(" + evt.source + ")";
    1.28 +        response += " window-parent-is(" + window.parent + ")";
    1.29 +        response += " location(" + window.location.href + ")";
    1.30 +      }
    1.31 +
    1.32 +      if (isMozilla)
    1.33 +      {
    1.34 +        if (evt.isTrusted !== false)
    1.35 +          response += " unexpected-trusted";
    1.36 +      }
    1.37 +
    1.38 +      if (evt.type != "message")
    1.39 +        response += " wrong-type(" + evt.type + ")";
    1.40 +
    1.41 +      var data = evt.data;
    1.42 +      if (data == "post-to-other-same-domain")
    1.43 +      {
    1.44 +        receiveSame(evt, response);
    1.45 +      }
    1.46 +      else if (data == "post-to-other-cross-domain")
    1.47 +      {
    1.48 +        receiveCross(evt, response);
    1.49 +      }
    1.50 +      else
    1.51 +      {
    1.52 +        response += " unexpected-message-to(" + window.location.href + ")";
    1.53 +        window.parent.postMessage(response, "http://mochi.test:8888");
    1.54 +        return;
    1.55 +      }
    1.56 +    }
    1.57 +
    1.58 +    function receiveSame(evt, response)
    1.59 +    {
    1.60 +      var source = evt.source;
    1.61 +      try
    1.62 +      {
    1.63 +        if (evt.origin != "http://mochi.test:8888")
    1.64 +          response += " unexpected-origin(" + evt.origin + ")";
    1.65 +          
    1.66 +        try
    1.67 +        {
    1.68 +          var threw = false;
    1.69 +          var privateVariable = source.privateVariable;
    1.70 +        }
    1.71 +        catch (e)
    1.72 +        {
    1.73 +          threw = true;
    1.74 +        }
    1.75 +        if (threw || privateVariable !== window.parent.privateVariable)
    1.76 +          response += " accessed-source!!!";
    1.77 +  
    1.78 +      }
    1.79 +      finally
    1.80 +      {
    1.81 +        source.postMessage(response, evt.origin);
    1.82 +      }
    1.83 +    }
    1.84 +
    1.85 +    function receiveCross(evt, response)
    1.86 +    {
    1.87 +      var source = evt.source;
    1.88 +      if (evt.origin != "http://mochi.test:8888")
    1.89 +        response += " unexpected-origin(" + evt.origin + ")";
    1.90 +        
    1.91 +      try
    1.92 +      {
    1.93 +        var threw = false;
    1.94 +        var privateVariable = source.privateVariable;
    1.95 +      }
    1.96 +      catch (e)
    1.97 +      {
    1.98 +        threw = true;
    1.99 +      }
   1.100 +      if (!threw || privateVariable !== undefined)
   1.101 +        response += " accessed-source!!!";
   1.102 +
   1.103 +      source.postMessage(response, evt.origin);
   1.104 +    }
   1.105 +
   1.106 +    window.addEventListener("load", setup, false);
   1.107 +    window.addEventListener("message", receiveMessage, false);
   1.108 +  </script>
   1.109 +</head>
   1.110 +<body>
   1.111 +<h1 id="domain"></h1>
   1.112 +</body>
   1.113 +</html>

mercurial