tor-browser

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

document-base-url-changes-about-srcdoc-2.https.html (2685B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="/common/get-host-info.sub.js"></script>
      5 
      6 <iframe src='about:blank'></iframe>
      7 
      8 <script>
      9 // If document.open's behavior is modified to remove the url-rewriting behavior,
     10 // then this test can be deleted (https://github.com/whatwg/html/issues/3989).
     11 setup({ explicit_done: true });
     12 
     13 // This function is called by directly by the child iframe (above), with the
     14 // child iframe's document. The child iframe's document contains an about:srcdoc iframe.
     15 window.start = childDocument => {
     16  const grandchildDocument =
     17    childDocument.getElementById('foo').contentDocument;
     18 
     19  test(() => {
     20    assert_equals(childDocument.URL, 'about:blank',
     21      'Child document starting URL');
     22    assert_equals(grandchildDocument.URL, 'about:srcdoc',
     23      'Grandchild document starting URL');
     24    const originalChildBaseURL = childDocument.baseURI;
     25 
     26    grandchildDocument.open("", "");
     27    // Verify that the document.open() trick worked: the grandchild should now
     28    // have the same url as the child, and have inherited the child's base url.
     29    assert_equals(grandchildDocument.URL, 'about:blank',
     30      'Grandchild document after document.open() trick');
     31    assert_equals(grandchildDocument.baseURI, originalChildBaseURL,
     32      'Grandchild base URL must match child base URL');
     33 
     34    // Give child a new base URL.
     35    const baseElement = childDocument.createElement('base');
     36    baseElement.href = get_host_info().REMOTE_ORIGIN;
     37    childDocument.head.append(baseElement);
     38 
     39    // Verify that changing the child's base url succeeded and did not affect
     40    // the grandchild's base url.
     41    const newChildBaseURL = childDocument.baseURI;
     42    assert_equals(grandchildDocument.URL, 'about:blank',
     43      'Grandchild document after child gets new base URL');
     44    assert_not_equals(newChildBaseURL, originalChildBaseURL,
     45      'Child base URL must change');
     46    assert_equals(grandchildDocument.baseURI, originalChildBaseURL,
     47      'Grandchild base URL must not change');
     48  });
     49 
     50  done();
     51 };
     52 
     53 let subframe_doc = document.querySelector('iframe').contentDocument;
     54 subframe_doc.body.innerHTML = '<iframe srcdoc="foo" id="foo"></iframe>';
     55 promise_test(async t => {
     56  const grandchildIframe = subframe_doc.querySelector('iframe');
     57  await new Promise(resolve => {
     58    grandchildIframe.onload = resolve;
     59  });
     60 
     61  assert_equals(grandchildIframe.contentDocument.URL, 'about:srcdoc');
     62 
     63  let script = subframe_doc.createElement('script');
     64  script.innerHTML = 'parent.start(document);';
     65  subframe_doc.body.appendChild(script);
     66 }, "wrapper promise test for timeout.");
     67 </script>