1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_offline.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +let proxyPrefValue; 1.5 + 1.6 +// ---------------------------------------------------------------------------- 1.7 +// Tests that going offline cancels an in progress download. 1.8 +function test() { 1.9 + Harness.downloadProgressCallback = download_progress; 1.10 + Harness.installsCompletedCallback = finish_test; 1.11 + Harness.setup(); 1.12 + 1.13 + var pm = Services.perms; 1.14 + pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); 1.15 + 1.16 + var triggers = encodeURIComponent(JSON.stringify({ 1.17 + "Unsigned XPI": TESTROOT + "unsigned.xpi" 1.18 + })); 1.19 + gBrowser.selectedTab = gBrowser.addTab(); 1.20 + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); 1.21 +} 1.22 + 1.23 +function download_progress(addon, value, maxValue) { 1.24 + try { 1.25 + // Tests always connect to localhost, and per bug 87717, localhost is now 1.26 + // reachable in offline mode. To avoid this, disable any proxy. 1.27 + proxyPrefValue = Services.prefs.getIntPref("network.proxy.type"); 1.28 + Services.prefs.setIntPref("network.proxy.type", 0); 1.29 + Services.io.manageOfflineStatus = false; 1.30 + Services.io.offline = true; 1.31 + } catch (ex) { 1.32 + } 1.33 +} 1.34 + 1.35 +function finish_test(count) { 1.36 + function wait_for_online() { 1.37 + info("Checking if the browser is still offline..."); 1.38 + 1.39 + let tab = gBrowser.selectedTab; 1.40 + tab.linkedBrowser.addEventListener("DOMContentLoaded", function errorLoad() { 1.41 + tab.linkedBrowser.removeEventListener("DOMContentLoaded", errorLoad, true); 1.42 + let url = tab.linkedBrowser.contentDocument.documentURI; 1.43 + info("loaded: " + url); 1.44 + if (/^about:neterror\?e=netOffline/.test(url)) { 1.45 + wait_for_online(); 1.46 + } else { 1.47 + gBrowser.removeCurrentTab(); 1.48 + Harness.finish(); 1.49 + } 1.50 + }, true); 1.51 + tab.linkedBrowser.loadURI("http://example.com/"); 1.52 + } 1.53 + 1.54 + is(count, 0, "No add-ons should have been installed"); 1.55 + try { 1.56 + Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); 1.57 + Services.io.offline = false; 1.58 + } catch (ex) { 1.59 + } 1.60 + 1.61 + Services.perms.remove("example.com", "install"); 1.62 + 1.63 + wait_for_online(); 1.64 +}