tor-browser

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

document-base-url-initiated-grand-parent.https.window.js (2284B)


      1 // META: script=/common/get-host-info.sub.js
      2 // META: script=/common/utils.js
      3 // META: script=/common/dispatcher/dispatcher.js
      4 
      5 const testBaseUriAboutBlankFromGrandParent = (description, child_origin) => {
      6  promise_test(async test => {
      7    // Create a child in an iframe.
      8    const child_token = token();
      9    const child_url = child_origin +
     10      '/common/dispatcher/executor.html' +
     11      `?uuid=${child_token}`;
     12    const iframe = document.createElement("iframe");
     13    iframe.src = child_url;
     14    document.body.appendChild(iframe);
     15 
     16    // The child creates a grand child in an iframe.
     17    const reply_token = token();
     18    send(child_token, `
     19      const iframe = document.createElement("iframe");
     20      location.hash = "interesting-fragment";
     21      iframe.src = "/common/blank.html";
     22      iframe.onload = () => {
     23        send("${reply_token}", "grand child loaded");
     24      };
     25      document.body.appendChild(iframe);
     26    `);
     27    assert_equals(await receive(reply_token), "grand child loaded");
     28 
     29    const child = iframe.contentWindow;
     30    const grandchild = child[0];
     31 
     32    // Navigate the grand-child toward about:blank.
     33    // Navigation are always asynchronous. It doesn't exist a ways to know the
     34    // about:blank document committed. A timer is used instead:
     35    grandchild.location = "about:blank";
     36    await new Promise(r => test.step_timeout(r, /*ms=*/500));
     37 
     38    // The grandchild baseURI must correspond to its grand parent.
     39    //
     40    // Note: `child_token` is removed, to get a stable failure, in case the
     41    // about:blank's document.baseURI reports the parent's URL instead of its
     42    // grand-parent.
     43    assert_equals(
     44        grandchild.document.baseURI.replace(child_token, "child_token"),
     45        self.document.baseURI);
     46  }, description);
     47 }
     48 
     49 onload = () => {
     50  testBaseUriAboutBlankFromGrandParent(
     51    "Check the baseURL of an about:blank document same-origin with its parent",
     52    get_host_info().HTTPS_ORIGIN,
     53  );
     54  testBaseUriAboutBlankFromGrandParent(
     55    "Check the baseURL of an about:blank document cross-origin with its parent",
     56    get_host_info().HTTPS_REMOTE_ORIGIN,
     57  );
     58  testBaseUriAboutBlankFromGrandParent(
     59    "Check the baseURL of an about:blank document cross-site with its parent",
     60    get_host_info().HTTPS_NOTSAMESITE_ORIGIN,
     61  );
     62 }