tor-browser

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

dynamic-adding-preload-nonce.html (1436B)


      1 <!DOCTYPE html>
      2 <script nonce="abc" src="/resources/testharness.js"></script>
      3 <script nonce="abc" src="/resources/testharnessreport.js"></script>
      4 <script nonce="abc" src="/common/utils.js"></script>
      5 <script nonce="abc" src="/preload/resources/preload_helper.js"></script>
      6 <body>
      7 <script nonce="abc">
      8 
      9 promise_test(async (t) => {
     10  verifyPreloadAndRTSupport();
     11  const id = token();
     12  const link = document.createElement("link");
     13  link.as = "script";
     14  link.rel = "preload";
     15  link.href = stashPutUrl(id);
     16  link.nonce = "abc";
     17 
     18  const load = new Promise((resolve) => {
     19    link.onload = resolve;
     20  });
     21  link.onerror = t.unreached_func("link.onerror");
     22 
     23  document.body.appendChild(link);
     24  await load;
     25 
     26  const arrived = await hasArrivedAtServer(id);
     27  assert_true(arrived, "The preload should've arrived at the server.");
     28 }, "link preload with nonce attribute");
     29 
     30 promise_test(async (t) => {
     31  verifyPreloadAndRTSupport();
     32  const id = token();
     33  const link = document.createElement("link");
     34  link.as = "script";
     35  link.rel = "preload";
     36  link.href = stashPutUrl(id);
     37 
     38  const error = new Promise((resolve) => {
     39    link.onerror = resolve;
     40  });
     41  link.onload = t.unreached_func("link.onload");
     42 
     43  document.body.appendChild(link);
     44  await error;
     45 
     46  const arrived = await hasArrivedAtServer(id);
     47  assert_false(arrived, "The preload should've arrived at the server.");
     48 }, "link preload without nonce attribute");
     49 
     50 </script>
     51 </body>