tor-browser

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

window-serviceworker-failure.https.html (2235B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>SharedArrayBuffer cannot cross agent clusters, service worker edition</title>
      4 <link rel="help" href="https://html.spec.whatwg.org/multipage/#structuredserialize">
      5 <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
      9 
     10 <script>
     11 "use strict";
     12 promise_test(t => {
     13  const scope = "resources/blank.html";
     14  return service_worker_unregister_and_register(t, "resources/serviceworker-failure.js", scope)
     15  .then(reg => {
     16    t.add_cleanup(() => service_worker_unregister(t, scope));
     17    return wait_for_state(t, reg.installing, "activated");
     18  })
     19  .then(() =>  with_iframe(scope))
     20  .then(iframe => {
     21    t.add_cleanup(() => iframe.remove());
     22    const sw = iframe.contentWindow.navigator.serviceWorker;
     23    let state = "start in window";
     24 
     25    return new Promise(resolve => {
     26      sw.onmessage = t.step_func(e => {
     27        if (e.data === "start in worker") {
     28          assert_equals(state, "start in window");
     29          sw.controller.postMessage(new SharedArrayBuffer());
     30          state = "we are expecting confirmation of an onmessageerror in the worker";
     31        } else if (e.data === "onmessageerror was received in worker") {
     32          assert_equals(state, "we are expecting confirmation of an onmessageerror in the worker");
     33          state = "we are expecting a messageerror due to the worker sending us a SAB";
     34          sw.controller.postMessage(state);
     35        } else {
     36          assert_unreached("Got an unexpected message from the service worker: " + e.data);
     37        }
     38      });
     39 
     40      sw.onmessageerror = t.step_func(e => {
     41        assert_equals(state, "we are expecting a messageerror due to the worker sending us a SAB");
     42 
     43        assert_equals(e.data, null, "data");
     44        assert_equals(e.origin, self.origin, "origin");
     45        assert_not_equals(e.source, null, "source");
     46        assert_equals(e.ports.length, 0, "ports length");
     47 
     48        state = "done in window";
     49        resolve();
     50      });
     51 
     52      sw.controller.postMessage(state);
     53    });
     54  });
     55 });
     56 </script>