Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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 }