|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /* Ensure that clicking the button in the Offline mode neterror page makes the browser go online. See bug 435325. */ |
|
5 |
|
6 let proxyPrefValue; |
|
7 |
|
8 function test() { |
|
9 waitForExplicitFinish(); |
|
10 |
|
11 let tab = gBrowser.selectedTab = gBrowser.addTab(); |
|
12 |
|
13 // Go offline and disable the proxy and cache, then try to load the test URL. |
|
14 Services.io.offline = true; |
|
15 |
|
16 // Tests always connect to localhost, and per bug 87717, localhost is now |
|
17 // reachable in offline mode. To avoid this, disable any proxy. |
|
18 proxyPrefValue = Services.prefs.getIntPref("network.proxy.type"); |
|
19 Services.prefs.setIntPref("network.proxy.type", 0); |
|
20 |
|
21 Services.prefs.setBoolPref("browser.cache.disk.enable", false); |
|
22 Services.prefs.setBoolPref("browser.cache.memory.enable", false); |
|
23 content.location = "http://example.com/"; |
|
24 |
|
25 window.addEventListener("DOMContentLoaded", function load() { |
|
26 if (content.location == "about:blank") { |
|
27 info("got about:blank, which is expected once, so return"); |
|
28 return; |
|
29 } |
|
30 window.removeEventListener("DOMContentLoaded", load, false); |
|
31 |
|
32 let observer = new MutationObserver(function (mutations) { |
|
33 for (let mutation of mutations) { |
|
34 if (mutation.attributeName == "hasBrowserHandlers") { |
|
35 observer.disconnect(); |
|
36 checkPage(); |
|
37 return; |
|
38 } |
|
39 } |
|
40 }); |
|
41 let docElt = tab.linkedBrowser.contentDocument.documentElement; |
|
42 observer.observe(docElt, { attributes: true }); |
|
43 }, false); |
|
44 } |
|
45 |
|
46 function checkPage() { |
|
47 ok(Services.io.offline, "Setting Services.io.offline to true."); |
|
48 is(gBrowser.contentDocument.documentURI.substring(0,27), |
|
49 "about:neterror?e=netOffline", "Loading the Offline mode neterror page."); |
|
50 |
|
51 // Now press the "Try Again" button |
|
52 ok(gBrowser.contentDocument.getElementById("errorTryAgain"), |
|
53 "The error page has got a #errorTryAgain element"); |
|
54 |
|
55 // Re-enable the proxy so example.com is resolved to localhost, rather than |
|
56 // the actual example.com. |
|
57 Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); |
|
58 |
|
59 gBrowser.contentDocument.getElementById("errorTryAgain").click(); |
|
60 |
|
61 ok(!Services.io.offline, "After clicking the Try Again button, we're back " + |
|
62 "online."); |
|
63 |
|
64 finish(); |
|
65 } |
|
66 |
|
67 registerCleanupFunction(function() { |
|
68 Services.prefs.setBoolPref("browser.cache.disk.enable", true); |
|
69 Services.prefs.setBoolPref("browser.cache.memory.enable", true); |
|
70 Services.io.offline = false; |
|
71 gBrowser.removeCurrentTab(); |
|
72 }); |