Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | let proxyPrefValue; |
michael@0 | 2 | |
michael@0 | 3 | // ---------------------------------------------------------------------------- |
michael@0 | 4 | // Tests that going offline cancels an in progress download. |
michael@0 | 5 | function test() { |
michael@0 | 6 | Harness.downloadProgressCallback = download_progress; |
michael@0 | 7 | Harness.installsCompletedCallback = finish_test; |
michael@0 | 8 | Harness.setup(); |
michael@0 | 9 | |
michael@0 | 10 | var pm = Services.perms; |
michael@0 | 11 | pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
michael@0 | 12 | |
michael@0 | 13 | var triggers = encodeURIComponent(JSON.stringify({ |
michael@0 | 14 | "Unsigned XPI": TESTROOT + "unsigned.xpi" |
michael@0 | 15 | })); |
michael@0 | 16 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 17 | gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function download_progress(addon, value, maxValue) { |
michael@0 | 21 | try { |
michael@0 | 22 | // Tests always connect to localhost, and per bug 87717, localhost is now |
michael@0 | 23 | // reachable in offline mode. To avoid this, disable any proxy. |
michael@0 | 24 | proxyPrefValue = Services.prefs.getIntPref("network.proxy.type"); |
michael@0 | 25 | Services.prefs.setIntPref("network.proxy.type", 0); |
michael@0 | 26 | Services.io.manageOfflineStatus = false; |
michael@0 | 27 | Services.io.offline = true; |
michael@0 | 28 | } catch (ex) { |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function finish_test(count) { |
michael@0 | 33 | function wait_for_online() { |
michael@0 | 34 | info("Checking if the browser is still offline..."); |
michael@0 | 35 | |
michael@0 | 36 | let tab = gBrowser.selectedTab; |
michael@0 | 37 | tab.linkedBrowser.addEventListener("DOMContentLoaded", function errorLoad() { |
michael@0 | 38 | tab.linkedBrowser.removeEventListener("DOMContentLoaded", errorLoad, true); |
michael@0 | 39 | let url = tab.linkedBrowser.contentDocument.documentURI; |
michael@0 | 40 | info("loaded: " + url); |
michael@0 | 41 | if (/^about:neterror\?e=netOffline/.test(url)) { |
michael@0 | 42 | wait_for_online(); |
michael@0 | 43 | } else { |
michael@0 | 44 | gBrowser.removeCurrentTab(); |
michael@0 | 45 | Harness.finish(); |
michael@0 | 46 | } |
michael@0 | 47 | }, true); |
michael@0 | 48 | tab.linkedBrowser.loadURI("http://example.com/"); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | is(count, 0, "No add-ons should have been installed"); |
michael@0 | 52 | try { |
michael@0 | 53 | Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); |
michael@0 | 54 | Services.io.offline = false; |
michael@0 | 55 | } catch (ex) { |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | Services.perms.remove("example.com", "install"); |
michael@0 | 59 | |
michael@0 | 60 | wait_for_online(); |
michael@0 | 61 | } |