tor-browser

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

serviceworker-failure.js (1483B)


      1 // Based on similar tests in html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/.
      2 "use strict";
      3 self.importScripts("/resources/testharness.js");
      4 self.importScripts("./create-empty-wasm-module.js");
      5 
      6 let state = "start in worker";
      7 
      8 self.onmessage = e => {
      9  if (e.data === "start in window") {
     10    assert_equals(state, "start in worker");
     11    e.source.postMessage(state);
     12    state = "we are expecting a messageerror due to the window sending us a WebAssembly.Module";
     13  } else if (e.data === "we are expecting a messageerror due to the worker sending us a WebAssembly.Module") {
     14    assert_equals(state, "onmessageerror was received in worker");
     15    e.source.postMessage(createEmptyWasmModule());
     16    state = "done in worker";
     17  } else {
     18    e.source.postMessage(`worker onmessage was reached when in state "${state}" and data ${e.data}`);
     19  }
     20 };
     21 
     22 self.onmessageerror = e => {
     23  if (state === "we are expecting a messageerror due to the window sending us a WebAssembly.Module") {
     24    assert_equals(e.constructor.name, "ExtendableMessageEvent", "type");
     25    assert_equals(e.data, null, "data");
     26    assert_equals(e.origin, self.origin, "origin");
     27    assert_not_equals(e.source, null, "source");
     28    assert_equals(e.ports.length, 0, "ports length");
     29 
     30    state = "onmessageerror was received in worker";
     31    e.source.postMessage(state);
     32  } else {
     33    e.source.postMessage(`worker onmessageerror was reached when in state "${state}" and data ${e.data}`);
     34  }
     35 };