|
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 updates |
|
5 global history. See bug 680727. */ |
|
6 /* TEST_PATH=toolkit/components/places/tests/browser/browser_bug680727.js make -C $(OBJDIR) mochitest-browser-chrome */ |
|
7 |
|
8 |
|
9 const kUniqueURI = Services.io.newURI("http://mochi.test:8888/#bug_680727", |
|
10 null, null); |
|
11 var gAsyncHistory = |
|
12 Cc["@mozilla.org/browser/history;1"].getService(Ci.mozIAsyncHistory); |
|
13 |
|
14 let proxyPrefValue; |
|
15 |
|
16 function test() { |
|
17 waitForExplicitFinish(); |
|
18 |
|
19 gBrowser.selectedTab = gBrowser.addTab(); |
|
20 |
|
21 // Tests always connect to localhost, and per bug 87717, localhost is now |
|
22 // reachable in offline mode. To avoid this, disable any proxy. |
|
23 proxyPrefValue = Services.prefs.getIntPref("network.proxy.type"); |
|
24 Services.prefs.setIntPref("network.proxy.type", 0); |
|
25 |
|
26 // Clear network cache. |
|
27 Components.classes["@mozilla.org/netwerk/cache-storage-service;1"] |
|
28 .getService(Components.interfaces.nsICacheStorageService) |
|
29 .clear(); |
|
30 |
|
31 // Go offline, expecting the error page. |
|
32 Services.io.offline = true; |
|
33 window.addEventListener("DOMContentLoaded", errorListener, false); |
|
34 content.location = kUniqueURI.spec; |
|
35 } |
|
36 |
|
37 //------------------------------------------------------------------------------ |
|
38 // listen to loading the neterror page. (offline mode) |
|
39 function errorListener() { |
|
40 if(content.location == "about:blank") { |
|
41 info("got about:blank, which is expected once, so return"); |
|
42 return; |
|
43 } |
|
44 |
|
45 window.removeEventListener("DOMContentLoaded", errorListener, false); |
|
46 ok(Services.io.offline, "Services.io.offline is true."); |
|
47 |
|
48 // This is an error page. |
|
49 is(gBrowser.contentDocument.documentURI.substring(0, 27), |
|
50 "about:neterror?e=netOffline", |
|
51 "Document URI is the error page."); |
|
52 |
|
53 // But location bar should show the original request. |
|
54 is(content.location.href, kUniqueURI.spec, |
|
55 "Docshell URI is the original URI."); |
|
56 |
|
57 // Global history does not record URI of a failed request. |
|
58 promiseAsyncUpdates().then(function() { |
|
59 gAsyncHistory.isURIVisited(kUniqueURI, errorAsyncListener); |
|
60 }); |
|
61 } |
|
62 |
|
63 function errorAsyncListener(aURI, aIsVisited) { |
|
64 ok(kUniqueURI.equals(aURI) && !aIsVisited, |
|
65 "The neterror page is not listed in global history."); |
|
66 |
|
67 Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); |
|
68 |
|
69 // Now press the "Try Again" button, with offline mode off. |
|
70 Services.io.offline = false; |
|
71 |
|
72 window.addEventListener("DOMContentLoaded", reloadListener, false); |
|
73 |
|
74 ok(gBrowser.contentDocument.getElementById("errorTryAgain"), |
|
75 "The error page has got a #errorTryAgain element"); |
|
76 gBrowser.contentDocument.getElementById("errorTryAgain").click(); |
|
77 } |
|
78 |
|
79 //------------------------------------------------------------------------------ |
|
80 // listen to reload of neterror. |
|
81 function reloadListener() { |
|
82 window.removeEventListener("DOMContentLoaded", reloadListener, false); |
|
83 |
|
84 // This listener catches "DOMContentLoaded" on being called |
|
85 // nsIWPL::onLocationChange(...). That is right *AFTER* |
|
86 // IHistory::VisitURI(...) is called. |
|
87 ok(!Services.io.offline, "Services.io.offline is false."); |
|
88 |
|
89 // This is not an error page. |
|
90 is(gBrowser.contentDocument.documentURI, kUniqueURI.spec, |
|
91 "Document URI is not the offline-error page, but the original URI."); |
|
92 |
|
93 // Check if global history remembers the successfully-requested URI. |
|
94 promiseAsyncUpdates().then(function() { |
|
95 gAsyncHistory.isURIVisited(kUniqueURI, reloadAsyncListener); |
|
96 }); |
|
97 } |
|
98 |
|
99 function reloadAsyncListener(aURI, aIsVisited) { |
|
100 ok(kUniqueURI.equals(aURI) && aIsVisited, "We have visited the URI."); |
|
101 promiseClearHistory().then(finish); |
|
102 } |
|
103 |
|
104 registerCleanupFunction(function() { |
|
105 Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); |
|
106 Services.io.offline = false; |
|
107 window.removeEventListener("DOMContentLoaded", errorListener, false); |
|
108 window.removeEventListener("DOMContentLoaded", reloadListener, false); |
|
109 gBrowser.removeCurrentTab(); |
|
110 }); |