tor-browser

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

onLine_worker_head.js (1766B)


      1 /*
      2 * Any copyright is dedicated to the Public Domain.
      3 * http://creativecommons.org/licenses/publicdomain/
      4 */
      5 
      6 /* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
      7 
      8 function info(text) {
      9  dump("Test for Bug 925437: worker: " + text + "\n");
     10 }
     11 
     12 function ok(test, message) {
     13  postMessage({ type: "ok", test, message });
     14 }
     15 
     16 /**
     17 * Returns a handler function for an online/offline event. The returned handler
     18 * ensures the passed event object has expected properties and that the handler
     19 * is called at the right moment (according to the gState variable).
     20 *
     21 * @param nameTemplate The string identifying the hanlder. '%1' in that
     22 *                     string will be replaced with the event name.
     23 * @param eventName 'online' or 'offline'
     24 * @param expectedState value of gState at the moment the handler is called.
     25 *                       The handler increases gState by one before checking
     26 *                       if it matches expectedState.
     27 */
     28 function makeHandler(nameTemplate, eventName, expectedState, prefix, custom) {
     29  prefix += ": ";
     30  return function (e) {
     31    var name = nameTemplate.replace(/%1/, eventName);
     32    ok(e.constructor == Event, prefix + "event should be an Event");
     33    ok(e.type == eventName, prefix + "event type should be " + eventName);
     34    ok(!e.bubbles, prefix + "event should not bubble");
     35    ok(!e.cancelable, prefix + "event should not be cancelable");
     36    ok(
     37      e.target == self,
     38      prefix + "the event target should be the worker scope"
     39    );
     40    ok(
     41      eventName == "online" ? navigator.onLine : !navigator.onLine,
     42      prefix +
     43        "navigator.onLine " +
     44        navigator.onLine +
     45        " should reflect event " +
     46        eventName
     47    );
     48 
     49    if (custom) {
     50      custom();
     51    }
     52  };
     53 }