test_onLine.html (2110B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Bug 925437: online/offline events tests. 5 6 Any copyright is dedicated to the Public Domain. 7 http://creativecommons.org/licenses/publicdomain/ 8 --> 9 <head> 10 <title>Test for Bug 925437 (worker online/offline events)</title> 11 <script src="/tests/SimpleTest/SimpleTest.js"></script> 12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 13 </head> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=925437">Mozilla Bug 925437</a> 15 <p id="display"></p> 16 <div id="content" style="display: none"> 17 18 </div> 19 <pre id="test"> 20 </pre> 21 22 <script class="testbody" type="text/javascript"> 23 24 addLoadEvent(function() { 25 var w = new Worker("onLine_worker.js"); 26 27 w.onmessage = function(e) { 28 if (e.data.type === 'ready') { 29 // XXX Important trick here. 30 // 31 // Setting iosvc.offline would trigger a sync notifyObservers call, and if 32 // there exists a preloaded about:newtab (see tabbrowser._handleNewTab), 33 // that tab will be notified. 34 // 35 // This implies a sync call across different tabGroups, and will hit the 36 // assertion in SchedulerGroup::ValidateAccess(). So use executeSoon to 37 // re-dispatch an unlabeled runnable to the event queue. 38 SpecialPowers.executeSoon(doTest); 39 } else if (e.data.type === 'ok') { 40 ok(e.data.test, e.data.message); 41 } else if (e.data.type === 'finished') { 42 SimpleTest.finish(); 43 } 44 } 45 46 function doTest() { 47 var iosvc = SpecialPowers.Cc["@mozilla.org/network/io-service;1"] 48 .getService(SpecialPowers.Ci.nsIIOService); 49 iosvc.manageOfflineStatus = false; 50 51 info("setting iosvc.offline = true"); 52 iosvc.offline = true; 53 54 info("setting iosvc.offline = false"); 55 iosvc.offline = false; 56 57 info("setting iosvc.offline = true"); 58 iosvc.offline = true; 59 60 for (var i = 0; i < 10; ++i) { 61 iosvc.offline = !iosvc.offline; 62 } 63 64 info("setting iosvc.offline = false"); 65 w.postMessage('lastTest'); 66 iosvc.offline = false; 67 } 68 }); 69 70 SimpleTest.waitForExplicitFinish(); 71 </script> 72 </body> 73 </html>