1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/workers/test/onLine_worker_head.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,43 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + */ 1.8 + 1.9 +function info(text) { 1.10 + dump("Test for Bug 925437: worker: " + text + "\n"); 1.11 +} 1.12 + 1.13 +function ok(test, message) { 1.14 + postMessage({ type: 'ok', test: test, message: message }); 1.15 +} 1.16 + 1.17 +/** 1.18 + * Returns a handler function for an online/offline event. The returned handler 1.19 + * ensures the passed event object has expected properties and that the handler 1.20 + * is called at the right moment (according to the gState variable). 1.21 + * @param nameTemplate The string identifying the hanlder. '%1' in that 1.22 + * string will be replaced with the event name. 1.23 + * @param eventName 'online' or 'offline' 1.24 + * @param expectedState value of gState at the moment the handler is called. 1.25 + * The handler increases gState by one before checking 1.26 + * if it matches expectedState. 1.27 + */ 1.28 +function makeHandler(nameTemplate, eventName, expectedState, prefix, custom) { 1.29 + prefix += ": "; 1.30 + return function(e) { 1.31 + var name = nameTemplate.replace(/%1/, eventName); 1.32 + ok(e.constructor == Event, prefix + "event should be an Event"); 1.33 + ok(e.type == eventName, prefix + "event type should be " + eventName); 1.34 + ok(!e.bubbles, prefix + "event should not bubble"); 1.35 + ok(!e.cancelable, prefix + "event should not be cancelable"); 1.36 + ok(e.target == self, prefix + "the event target should be the worker scope"); 1.37 + ok(eventName == 'online' ? navigator.onLine : !navigator.onLine, prefix + "navigator.onLine " + navigator.onLine + " should reflect event " + eventName); 1.38 + 1.39 + if (custom) { 1.40 + custom(); 1.41 + } 1.42 + } 1.43 +} 1.44 + 1.45 + 1.46 +