dom/base/test/test_postMessage_solidus.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/base/test/test_postMessage_solidus.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +
     1.5 +<!DOCTYPE HTML>
     1.6 +<html>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=949488
     1.9 +-->
    1.10 +<head>
    1.11 +  <meta charset="utf-8">
    1.12 +  <title>Test for Bug 949488 - basic support</title>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949488">Mozilla Bug 949488</a>
    1.18 +  <div id="content"></div>
    1.19 +  <script type="application/javascript">
    1.20 +
    1.21 +  function selfMessage() {
    1.22 +    addEventListener('message', receiveMessage);
    1.23 +    function receiveMessage(evt) {
    1.24 +      is(evt.data, 1, "Message received");
    1.25 +      removeEventListener('message', receiveMessage);
    1.26 +      runTest();
    1.27 +    }
    1.28 +
    1.29 +    postMessage(1, '/');
    1.30 +  }
    1.31 +
    1.32 +  function frameOk() {
    1.33 +    var ifr = document.createElement("iframe");
    1.34 +    ifr.addEventListener("load", iframeLoaded, false);
    1.35 +    ifr.setAttribute('src', "iframe_postMessage_solidus.html");
    1.36 +
    1.37 +    var div = document.getElementById("content");
    1.38 +    div.appendChild(ifr);
    1.39 +
    1.40 +    function iframeLoaded() {
    1.41 +      addEventListener('message', receiveMessage);
    1.42 +      function receiveMessage(evt) {
    1.43 +        is(evt.data, 2, "Message received");
    1.44 +        removeEventListener('message', receiveMessage);
    1.45 +        runTest();
    1.46 +      }
    1.47 +
    1.48 +      ifr.contentWindow.postMessage(2, '/');
    1.49 +    }
    1.50 +  }
    1.51 +
    1.52 +  function frameWrong() {
    1.53 +    var ifr = document.createElement("iframe");
    1.54 +    ifr.addEventListener("load", iframeLoaded, false);
    1.55 +    ifr.setAttribute('src', "http://www.example.com/tests/dom/base/test/iframe_postMessage_solidus.html");
    1.56 +
    1.57 +    var div = document.getElementById("content");
    1.58 +    div.appendChild(ifr);
    1.59 +
    1.60 +    function iframeLoaded() {
    1.61 +      addEventListener('message', receiveMessage);
    1.62 +      function receiveMessage(evt) {
    1.63 +        ok(evt.data, 3, "Message received");
    1.64 +        removeEventListener('message', receiveMessage);
    1.65 +        runTest();
    1.66 +      }
    1.67 +
    1.68 +      ifr.contentWindow.postMessage(4, '/');
    1.69 +      SimpleTest.executeSoon(function() {
    1.70 +        ifr.contentWindow.postMessage(3, '*');
    1.71 +      });
    1.72 +    }
    1.73 +  }
    1.74 +
    1.75 +  var tests = [
    1.76 +    selfMessage,
    1.77 +    frameOk,
    1.78 +    frameWrong
    1.79 +  ];
    1.80 +
    1.81 +  function runTest() {
    1.82 +    if (!tests.length) {
    1.83 +      SimpleTest.finish();
    1.84 +      return;
    1.85 +    }
    1.86 +
    1.87 +    var test = tests.shift();
    1.88 +    test();
    1.89 +  }
    1.90 +
    1.91 +  SimpleTest.waitForExplicitFinish();
    1.92 +  runTest();
    1.93 +
    1.94 +  </script>
    1.95 +</body>
    1.96 +</html>

mercurial