tor-browser

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

nontraditional-about-srcdoc.html (4469B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Non-traditional about:srcdoc documents</title>
      4 <link rel="help" href="https://github.com/whatwg/html/issues/9514">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <body>
      8 <script>
      9 promise_test(async t => {
     10  const iframe = document.createElement('iframe');
     11 
     12  const srcdocOpenPromise = new Promise(resolve => {
     13    window.srcdocOpenResolve = resolve;
     14  });
     15 
     16  iframe.srcdoc = `
     17    <body onload="document.open();window.parent.srcdocOpenResolve();"></body>`;
     18  document.body.append(iframe);
     19 
     20  await srcdocOpenPromise;
     21  assert_equals(iframe.contentDocument.URL, 'about:srcdoc');
     22 
     23  // Calling the `about:srcdoc` Window's `fetch()` like this uses that Window's
     24  // environment settings object as the request's client, which is where the
     25  // request's referrer comes from, per
     26  // https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer.
     27  //
     28  // If this `document.open()`d srcdoc document is considered a proper
     29  // `about:srcdoc` document, the referrer will not be `about:srcdoc`, but will
     30  // instead come from the parent document.
     31  let referrer = await iframe.contentWindow.fetch('resources/echo-referrer-text.py');
     32  referrer = await referrer.text();
     33  assert_equals(referrer, location.href,
     34      'The request referrer is retrieved from the parent document for ' +
     35      'about:srcdoc documents');
     36 
     37  // Observe that the "about base URL" is retrieved [1] for `document.baseURI`
     38  // as well, indicating that the document is treated like a normal srcdoc
     39  // document.
     40  // [1]: https://html.spec.whatwg.org/#fallback-base-url
     41  assert_equals(iframe.contentDocument.baseURI, location.href,
     42      'The about base URL is retrieved as the base URL for srcdoc documents');
     43 }, 'about:srcdoc with document.open() is treated like a normal about:srcdoc document');
     44 
     45 promise_test(async t => {
     46  const iframe = document.createElement('iframe');
     47 
     48  const javascriptURLPromise = new Promise(resolve => {
     49    window.javascriptURLResolve = resolve;
     50  });
     51 
     52  iframe.srcdoc = `
     53  <script>
     54    location.href = "javascript:'<body onload=window.parent.javascriptURLResolve();>Document contents here</body>'";
     55  </scr`+`ipt>`;
     56  document.body.append(iframe);
     57 
     58  // This promise will resolve as a result of script running in the *new*
     59  // document that gets created by the `javascript:` URL.
     60  await javascriptURLPromise;
     61  assert_equals(iframe.contentDocument.URL, 'about:srcdoc');
     62 
     63  // See the first assertion in the first test in this file.
     64  let referrer = await iframe.contentWindow.fetch('resources/echo-referrer-text.py');
     65  referrer = await referrer.text();
     66  assert_equals(referrer, location.href,
     67      'The request referrer is retrieved from the parent document for ' +
     68      'about:srcdoc documents');
     69 
     70  // See the second assertion in the first test in this file.
     71  assert_equals(iframe.contentDocument.baseURI, location.href,
     72      'The about base URL is retrieved as the base URL for srcdoc documents');
     73 }, 'about:srcdoc navigated via a `javascript:` URL is treated like a normal about:srcdoc document');
     74 
     75 promise_test(async t => {
     76  const iframe = document.createElement('iframe');
     77 
     78  const srcdocLoadPromise = new Promise(resolve => {
     79    iframe.onload = resolve;
     80  });
     81  iframe.srcdoc = `Document contents here`;
     82  document.body.append(iframe);
     83 
     84  await srcdocLoadPromise;
     85  assert_equals(iframe.contentDocument.URL, 'about:srcdoc');
     86 
     87  // Change the document's URL to `about:srcdoc#foo` and ensure that the
     88  // observable behavior in that document is consistent with treating it as a
     89  // normal `about:srcdoc` document.
     90  iframe.contentWindow.history.replaceState(null, '', 'about:srcdoc#foo');
     91  assert_equals(iframe.contentDocument.URL, 'about:srcdoc#foo');
     92 
     93  // See the first assertion in the first test in this file.
     94  let referrer = await iframe.contentWindow.fetch('resources/echo-referrer-text.py');
     95  referrer = await referrer.text();
     96  assert_equals(referrer, location.href,
     97      'The request referrer is retrieved from the parent document for ' +
     98      'about:srcdoc documents');
     99 
    100  // See the second assertion in the first test in this file.
    101  assert_equals(iframe.contentDocument.baseURI, location.href,
    102      'The about base URL is retrieved as the base URL for srcdoc documents');
    103 }, 'about:srcdoc with URL changed by history.replaceState() is treated like ' +
    104   'a normal about:srcdoc document');
    105 </script>
    106 </body>