dom/workers/test/onLine_worker_head.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial