dom/indexedDB/test/test_third_party.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/test/test_third_party.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +<!--
     1.5 +  Any copyright is dedicated to the Public Domain.
     1.6 +  http://creativecommons.org/publicdomain/zero/1.0/
     1.7 +-->
     1.8 +<html>
     1.9 +<head>
    1.10 +  <title>Indexed Database Test</title>
    1.11 +
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +
    1.15 +  <script type="text/javascript;version=1.7">
    1.16 +    const testData = [
    1.17 +      { host: "http://" + window.location.host, expectedResult: true },
    1.18 +      { host: "http://example.com", expectedResult: false },
    1.19 +      { host: "http://sub1.test2.example.org:8000", expectedResult: false },
    1.20 +      { host: "http://" + window.location.host, expectedResult: true }
    1.21 +    ];
    1.22 +
    1.23 +    const iframe1Path =
    1.24 +      window.location.pathname.replace("test_third_party.html",
    1.25 +                                       "third_party_iframe1.html");
    1.26 +    const iframe2URL =
    1.27 +      "http://" + window.location.host +
    1.28 +      window.location.pathname.replace("test_third_party.html",
    1.29 +                                       "third_party_iframe2.html");
    1.30 +
    1.31 +    let testIndex = 0;
    1.32 +    let testRunning = false;
    1.33 +
    1.34 +    function iframeLoaded() {
    1.35 +      let message = { source: "parent", href: iframe2URL };
    1.36 +      let iframe = document.getElementById("iframe1");
    1.37 +      iframe.contentWindow.postMessage(message.toSource(), "*");
    1.38 +    }
    1.39 +
    1.40 +    function setiframe() {
    1.41 +      let iframe = document.getElementById("iframe1");
    1.42 +
    1.43 +      if (!testRunning) {
    1.44 +        testRunning = true;
    1.45 +        iframe.addEventListener("load", iframeLoaded, false);
    1.46 +      }
    1.47 +
    1.48 +      iframe.src = testData[testIndex].host + iframe1Path;
    1.49 +    }
    1.50 +
    1.51 +    function messageListener(event) {
    1.52 +      let message = eval(event.data);
    1.53 +
    1.54 +      is(message.source, "iframe", "Good source");
    1.55 +      is(message.result, testData[testIndex].expectedResult, "Good result");
    1.56 +
    1.57 +      if (testIndex < testData.length - 1) {
    1.58 +        testIndex++;
    1.59 +        setiframe();
    1.60 +        return;
    1.61 +      }
    1.62 +
    1.63 +      SimpleTest.finish();
    1.64 +    }
    1.65 +
    1.66 +    function runTest() {
    1.67 +      SimpleTest.waitForExplicitFinish();
    1.68 +      window.addEventListener("message", messageListener, false);
    1.69 +      setiframe();
    1.70 +    }
    1.71 +  </script>
    1.72 +
    1.73 +</head>
    1.74 +
    1.75 +<body onload="runTest();">
    1.76 +  <iframe id="iframe1"></iframe>
    1.77 +</body>
    1.78 +
    1.79 +</html>

mercurial