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