tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

about-blank.https.sub.html (2018B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>The initial about:blank respects origin isolation</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 
      7 <div id="log"></div>
      8 
      9 <script type="module">
     10 import {
     11  insertIframe,
     12  setBothDocumentDomains,
     13  testSameAgentCluster,
     14  testDifferentAgentClusters,
     15  testGetter
     16 } from "./resources/helpers.mjs";
     17 
     18 promise_setup(async () => {
     19  await insertAboutBlankIframe();
     20  await insertIframe("{{hosts[][www]}}");
     21 });
     22 
     23 // Since the initial about:blank inherits its origin from its parent, it is
     24 // same-origin with the parent, and thus cross-origin with child2.
     25 testSameAgentCluster([self, 0], "parent to about:blank");
     26 testDifferentAgentClusters([0, 1], "about:blank to child2");
     27 testDifferentAgentClusters([1, 0], "child2 to about:blank");
     28 
     29 testGetter(self, true, "parent");
     30 testGetter(0, true, "about:blank");
     31 testGetter(1, false, "child2");
     32 
     33 async function insertAboutBlankIframe() {
     34  const iframe = await createBlankIframe();
     35 
     36  // Now create and add the script, but don't navigate anywhere (since we want
     37  // to stay on the initial about:blank).
     38  // We need to absolutize the URL to since about:blank doesn't have a base URL.
     39  const scriptURL = (new URL("./resources/send-header-page-script.mjs", import.meta.url)).href;
     40  const script = iframe.contentDocument.createElement("script");
     41  script.type = "module";
     42  script.src = scriptURL;
     43 
     44  await new Promise((resolve, reject) => {
     45    script.onload = resolve;
     46    script.onerror = () => reject(
     47      new Error("Could not load the child frame script into the about:blank page")
     48    );
     49    iframe.contentDocument.body.append(script);
     50  });
     51 
     52  await setBothDocumentDomains(iframe.contentWindow);
     53 }
     54 
     55 async function createBlankIframe() {
     56  const iframe = document.createElement("iframe");
     57  const promise = new Promise(resolve => {
     58    iframe.addEventListener("load", resolve);
     59  });
     60  document.body.append(iframe);
     61  await promise;
     62  return iframe;
     63 }
     64 </script>