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.

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

mercurial