tor-browser

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

blob-data.https.html (4102B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <div id=log></div>
      6 <script>
      7 const url = new URL("./", self.location);
      8 
      9 function httpWorkerIncrementerTest(name) {
     10  return `
     11 promise_test(t => {
     12  const worker = new Worker("${url.href}resources/incrementer-worker.js");
     13 
     14  return testSharingViaIncrementerScript(t, worker, "parent worker", worker, "sub-worker");
     15 }, "${name}: postMessaging to a dedicated HTTP sub-worker allows them to see each others' modifications");
     16 `;
     17 }
     18 
     19 function blobWorkerIncrementerTest(name, origin = "null") {
     20  return `
     21 promise_test(t => {
     22  const worker = new Worker(URL.createObjectURL(new Blob([\`
     23 const view = new Uint8Array(new SharedArrayBuffer(1));
     24 self.onmessage = () => {
     25  const succeeded = (view[0] === 1);
     26  self.postMessage({ succeeded });
     27 };
     28 self.postMessage({ origin: self.origin, view });
     29 \`], { type: "text/javascript" })));
     30 
     31  return new Promise((resolve, reject) => {
     32    /* Initially the sub-worker gives us an object containing an origin and a view on a shared
     33    // buffer. We then modify the shared buffer through the buffer and tell the sub-worker to
     34    // "continue". The sub-worker verifies the modification and relays whether it succeeded.
     35    */
     36    worker.onmessage = t.step_func(({ data }) => {
     37      if ("succeeded" in data) {
     38        assert_true(data.succeeded);
     39        resolve();
     40      } else {
     41        assert_equals(data.origin, "${origin}");
     42        assert_equals(data.view[0], 0);
     43        data.view[0] = 1;
     44        worker.postMessage("continue");
     45      }
     46    });
     47    worker.onmessageerror = reject;
     48  });
     49 }, "${name}: postMessaging to a dedicated blob sub-worker allows them to see each others' modifications");
     50 `;
     51 }
     52 
     53 function propertyTests(name, crossOriginIsolated) {
     54  return `
     55 test(() => {
     56  assert_equals(self.origin, self.location.origin);
     57 }, "${name}: self.origin");
     58 
     59 test(() => {
     60  assert_equals(self.crossOriginIsolated, ${crossOriginIsolated});
     61 }, "${name}: self.crossOriginIsolated");
     62 
     63 test(() => {
     64  assert_true(self.isSecureContext);
     65 }, "${name}: self.isSecureContext");
     66 `;
     67 }
     68 
     69 const workerScript = `
     70 importScripts("${url.origin}/resources/testharness.js");
     71 importScripts("${url.href}resources/test-incrementer.js");
     72 
     73 ${httpWorkerIncrementerTest("blob worker")}
     74 
     75 ${blobWorkerIncrementerTest("blob worker", self.location.origin)}
     76 
     77 ${propertyTests("blob worker", true)}
     78 
     79 done();
     80 `;
     81 
     82 fetch_tests_from_worker(new Worker(URL.createObjectURL(new Blob([workerScript], { type: "text/javascript" }))));
     83 
     84 const frameScript = `
     85 <!doctype html>
     86 <script src=${url.origin}/resources/testharness.js><\/script>
     87 <script src=${url.href}resources/test-incrementer.js><\/script>
     88 <script>
     89 ${httpWorkerIncrementerTest("blob frame")}
     90 
     91 ${blobWorkerIncrementerTest("blob frame", self.location.origin)}
     92 
     93 ${propertyTests("blob frame", true)}
     94 <\/script>
     95 `;
     96 
     97 const frame = document.body.appendChild(document.createElement("iframe"));
     98 frame.src = URL.createObjectURL(new Blob([frameScript], { type: "text/html" }));
     99 frame.style = "display:none";
    100 fetch_tests_from_window(frame.contentWindow);
    101 
    102 const dataWorkerScript = `
    103 importScripts("${url.origin}/resources/testharness.js?pipe=header(Cross-Origin-Resource-Policy,cross-origin)");
    104 
    105 /* Cannot use httpWorkerIncrementerTest() here as the HTTP URL is not same origin. */
    106 
    107 ${blobWorkerIncrementerTest("data worker")}
    108 
    109 ${propertyTests("data worker", false)}
    110 
    111 done();
    112 `;
    113 
    114 fetch_tests_from_worker(new Worker(`data:,${dataWorkerScript}`));
    115 
    116 const dataFrameScript = `
    117 <!doctype html>
    118 <script src=${url.origin}/resources/testharness.js?pipe=header(Cross-Origin-Resource-Policy,cross-origin)><\/script>
    119 <script>
    120 /* Cannot use httpWorkerIncrementerTest() here as the HTTP URL is not same origin. */
    121 
    122 ${blobWorkerIncrementerTest("data frame")}
    123 
    124 ${propertyTests("data frame", true)}
    125 <\/script>
    126 `;
    127 
    128 const dataFrame = document.body.appendChild(document.createElement("iframe"));
    129 dataFrame.src = `data:text/html,${dataFrameScript}`;
    130 dataFrame.style = "display:none";
    131 fetch_tests_from_window(dataFrame.contentWindow);
    132 </script>