tor-browser

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

window-parent-inner.html (2238B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="utils.js"></script>
      4 <title>Fenced frame content to report the value of window.parent</title>
      5 
      6 <body>
      7 <script>
      8 async function init() { // Needed in order to use top-level await.
      9  // This file is meant to run in a <fencedframe>. It reports back to the
     10  // outermost page whether or not the value of `window.parent` was correct for:
     11  //   1.) Top-level fenced frames
     12  //   2.) Nested iframes inside a fenced frame
     13  //   3.) Nested fenced frames
     14  const url = new URL(location.href);
     15 
     16  const [window_parent_key, window_parent_ack_key, nested] = parseKeylist();
     17  const is_nested_fenced_frame = (nested == "nested");
     18 
     19  // Report whether or not `window.parent` was correct.
     20  let pass_string = "";
     21  if (is_nested_fenced_frame)
     22    pass_string = "pass: fenced frame > fenced frame";
     23  else
     24    pass_string = "pass: fenced frame";
     25 
     26  let result = (window.parent == window) ? pass_string : "fail";
     27  writeValueToServer(window_parent_key, result);
     28 
     29  // If this page is a nested fenced frame, all we need to do is report the
     30  // top-level value.
     31  if (is_nested_fenced_frame)
     32    return;
     33 
     34  // Wait for ACK, so we know that the outer page has read the last value from
     35  // the `window_parent_key` stash and we can write to it again.
     36  await nextValueFromServer(window_parent_ack_key);
     37 
     38  // Now test `window.parent` inside an iframe.
     39  const iframe = document.createElement('iframe');
     40  iframe.src = "dummy.html";
     41  const load_promise = new Promise((resolve, reject) => {
     42    iframe.onload = resolve;
     43    iframe.onerror = reject;
     44  });
     45  document.body.append(iframe);
     46 
     47  await load_promise;
     48 
     49  // Report whether or not the subframe's `window.parent` was correct.
     50  result = (iframe.contentWindow.parent == window) ?
     51      "pass: fenced frame > iframe" : "fail";
     52  writeValueToServer(window_parent_key, result);
     53 
     54  // Wait for ACK, so we know that the outer page has read the last value from
     55  // the `window_parent_key` stash and we can write to it again.
     56  await nextValueFromServer(window_parent_ack_key);
     57 
     58  attachFencedFrame(generateURL("window-parent-inner.html",
     59      [window_parent_key, window_parent_ack_key, "nested"]));
     60 }
     61 
     62 init();
     63 </script>
     64 </body>