tor-browser

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

deep-copy-config.https.html (3958B)


      1 <!DOCTYPE html>
      2 <title>Test deep copying FencedFrameConfig objects</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/utils.js"></script>
      6 <script src="/common/dispatcher/dispatcher.js"></script>
      7 <script src="resources/utils.js"></script>
      8 <script src="/common/get-host-info.sub.js"></script>
      9 
     10 <body>
     11 <script>
     12 promise_test(async(t) => {
     13  const key = token();
     14 
     15  // Create a FencedFrameConfig from a FLEDGE auction, then deep copy it.
     16  let old_config = await generateURNFromFledge(
     17      "resources/embeddee.html", [key], [], true);
     18  assert_true(old_config instanceof FencedFrameConfig);
     19  let new_config = structuredClone(old_config);
     20 
     21  const fencedframe = attachFencedFrame(new_config);
     22  const response = await nextValueFromServer(key);
     23  assert_equals(response, "PASS",
     24      "The page should have loaded from the cloned config.");
     25 }, 'A cloned config with a URN will navigate.');
     26 
     27 promise_test(async(t) => {
     28  const key = token();
     29 
     30  // Create a FencedFrameConfig from a FLEDGE auction, then deep copy it.
     31  let old_config = new FencedFrameConfig(generateURL(
     32      "resources/embeddee.html", [key]));
     33  assert_true(old_config instanceof FencedFrameConfig);
     34  let new_config = structuredClone(old_config);
     35 
     36  const fencedframe = attachFencedFrame(new_config);
     37  const response = await nextValueFromServer(key);
     38  assert_equals(response, "PASS",
     39      "The page should have loaded from the cloned config.");
     40 }, 'A cloned config with a URL will navigate.');
     41 
     42 promise_test(async(t) => {
     43  const key = token();
     44  const fenced_url = generateURL("resources/embeddee.html", [key]);
     45 
     46  // Create a fenced frame once the config comes in through postMessage.
     47  window.addEventListener(
     48    "message",
     49    (event) => {
     50      attachFencedFrame(event.data);
     51    },
     52    false,
     53  );
     54 
     55  // Create an iframe that creates a FencedFrameConfig
     56  const frame = await attachIFrameContext(
     57      {origin: get_host_info().HTTPS_REMOTE_ORIGIN});
     58  await frame.execute(async (fenced_url) => {
     59    const config = await generateURNFromFledge(fenced_url, [], [], true);
     60    window.parent.postMessage(config, "*");
     61  }, [fenced_url]);
     62 
     63  const response = await nextValueFromServer(key);
     64  assert_equals(response, "PASS",
     65      "The page should have loaded from the postMessage'd config.");
     66 }, 'A config received through window.postMessage will navigate.');
     67 
     68 promise_test(async(t) => {
     69  // Create a FencedFrameConfig from a FLEDGE auction.
     70  let config = await generateURNFromFledge(
     71      "resources/embeddee.html", [], [], true);
     72  assert_true(config instanceof FencedFrameConfig);
     73 
     74  assert_throws_dom("DataCloneError", () => {
     75    history.pushState(config, "", location.href);
     76  }, "The write should fail for a FencedFrameConfig.");
     77 }, 'A FencedFrameConfig cannot be written to storage.');
     78 
     79 promise_test(async(t) => {
     80  const key = token();
     81 
     82  // Create a fenced frame once the config comes in through postMessage.
     83  window.addEventListener(
     84    "message",
     85    (event) => {
     86      attachFencedFrame(event.data);
     87    },
     88    false,
     89  );
     90 
     91  // The pop-up will generate a FencedFrameConfig from a FLEDGE auction, and
     92  // then pass it back into this page through postMessage(). Since config
     93  // mappings are only valid within the same frame tree, this page will not be
     94  // able to navigate a fenced frame to the config.
     95  window.open(generateURL("resources/postmessage-config.html", [key]), "foo");
     96 
     97  // Set up a timeout to ensure that there's enough time for any messages to be
     98  // sent from a fenced frame if it loads.
     99  const timeout = new Promise(resolve => t.step_timeout(resolve, 1000));
    100  const result = await Promise.race([nextValueFromServer(key), timeout]);
    101  assert_true(typeof result === "undefined",
    102      "The fenced frame should not have loaded.");
    103 }, 'A FencedFrameConfig sent to a context that does not support it gracefully' +
    104   ' fails to load.');
    105 
    106 </script>
    107 </body>
    108 </html>