michael@0: let proxyPrefValue; michael@0: michael@0: // ---------------------------------------------------------------------------- michael@0: // Tests that going offline cancels an in progress download. michael@0: function test() { michael@0: Harness.downloadProgressCallback = download_progress; michael@0: Harness.installsCompletedCallback = finish_test; michael@0: Harness.setup(); michael@0: michael@0: var pm = Services.perms; michael@0: pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); michael@0: michael@0: var triggers = encodeURIComponent(JSON.stringify({ michael@0: "Unsigned XPI": TESTROOT + "unsigned.xpi" michael@0: })); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); michael@0: } michael@0: michael@0: function download_progress(addon, value, maxValue) { michael@0: try { michael@0: // Tests always connect to localhost, and per bug 87717, localhost is now michael@0: // reachable in offline mode. To avoid this, disable any proxy. michael@0: proxyPrefValue = Services.prefs.getIntPref("network.proxy.type"); michael@0: Services.prefs.setIntPref("network.proxy.type", 0); michael@0: Services.io.manageOfflineStatus = false; michael@0: Services.io.offline = true; michael@0: } catch (ex) { michael@0: } michael@0: } michael@0: michael@0: function finish_test(count) { michael@0: function wait_for_online() { michael@0: info("Checking if the browser is still offline..."); michael@0: michael@0: let tab = gBrowser.selectedTab; michael@0: tab.linkedBrowser.addEventListener("DOMContentLoaded", function errorLoad() { michael@0: tab.linkedBrowser.removeEventListener("DOMContentLoaded", errorLoad, true); michael@0: let url = tab.linkedBrowser.contentDocument.documentURI; michael@0: info("loaded: " + url); michael@0: if (/^about:neterror\?e=netOffline/.test(url)) { michael@0: wait_for_online(); michael@0: } else { michael@0: gBrowser.removeCurrentTab(); michael@0: Harness.finish(); michael@0: } michael@0: }, true); michael@0: tab.linkedBrowser.loadURI("http://example.com/"); michael@0: } michael@0: michael@0: is(count, 0, "No add-ons should have been installed"); michael@0: try { michael@0: Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); michael@0: Services.io.offline = false; michael@0: } catch (ex) { michael@0: } michael@0: michael@0: Services.perms.remove("example.com", "install"); michael@0: michael@0: wait_for_online(); michael@0: }