Source code
Revision control
Copy as Markdown
Other Tools
<!--
  Any copyright is dedicated to the Public Domain.
-->
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="timeout" content="long" />
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="testHelpers.js"></script>
    <iframe id="write-frame-window"></iframe>
    <iframe id="write-frame-worker"></iframe>
    <script>
      const messageHub = createMotherListener();
      async function runTests() {
        const params = new URL(window.location.href).searchParams;
        const api = params.get("api");
        assert_true(!!api);
        console.log("Tested API " + api);
        const testIdWindow = "WriteIFrameReadDifferentOriginWindowWith" + api;
        const testIdWorker = "Worker" + testIdWindow;
        const writeWindows = new Map();
        const writeFrameWindow = document.getElementById("write-frame-window");
        writeWindows.set(testIdWindow, writeFrameWindow.contentWindow);
        const writeFrameWorker = document.getElementById("write-frame-worker");
        writeWindows.set(testIdWorker, writeFrameWorker.contentWindow);
        const readWindowURL =
        const readWindows = new Map();
        messageHub.registerReadWindow(testIdWindow);
        readWindows.set(
          testIdWindow,
          window.open(readWindowURL + "?id=" + testIdWindow)
        );
        messageHub.registerReadWindow(testIdWorker);
        readWindows.set(
          testIdWorker,
          window.open(readWindowURL + "?id=" + testIdWorker)
        );
        const setup = { readWindows, writeWindows };
        await messageHub.getReadWindow(testIdWindow);
        async_test(t => {
          messageHub.registerWindow(t, testIdWindow, api, "allow", setup);
          writeFrameWindow.src =
            testIdWindow;
        }, "iframe of origin A in the parent window can read data written by iframe of origin A in a child window of origin B " + api);
        await messageHub.getReadWindow(testIdWorker);
        async_test(t => {
          messageHub.registerWorker(t, testIdWorker, api, "allow", setup);
          writeFrameWorker.src =
            testIdWorker;
        }, "worker in an iframe of origin A in the parent window can read data written by iframe of origin A in a child window of origin B " + api);
      }
    </script>
  </head>
  <body onload="runTests();"></body>
</html>