michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /* Ensure that clicking the button in the Offline mode neterror page updates michael@0: global history. See bug 680727. */ michael@0: /* TEST_PATH=toolkit/components/places/tests/browser/browser_bug680727.js make -C $(OBJDIR) mochitest-browser-chrome */ michael@0: michael@0: michael@0: const kUniqueURI = Services.io.newURI("http://mochi.test:8888/#bug_680727", michael@0: null, null); michael@0: var gAsyncHistory = michael@0: Cc["@mozilla.org/browser/history;1"].getService(Ci.mozIAsyncHistory); michael@0: michael@0: let proxyPrefValue; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: 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: michael@0: // Clear network cache. michael@0: Components.classes["@mozilla.org/netwerk/cache-storage-service;1"] michael@0: .getService(Components.interfaces.nsICacheStorageService) michael@0: .clear(); michael@0: michael@0: // Go offline, expecting the error page. michael@0: Services.io.offline = true; michael@0: window.addEventListener("DOMContentLoaded", errorListener, false); michael@0: content.location = kUniqueURI.spec; michael@0: } michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // listen to loading the neterror page. (offline mode) michael@0: function errorListener() { michael@0: if(content.location == "about:blank") { michael@0: info("got about:blank, which is expected once, so return"); michael@0: return; michael@0: } michael@0: michael@0: window.removeEventListener("DOMContentLoaded", errorListener, false); michael@0: ok(Services.io.offline, "Services.io.offline is true."); michael@0: michael@0: // This is an error page. michael@0: is(gBrowser.contentDocument.documentURI.substring(0, 27), michael@0: "about:neterror?e=netOffline", michael@0: "Document URI is the error page."); michael@0: michael@0: // But location bar should show the original request. michael@0: is(content.location.href, kUniqueURI.spec, michael@0: "Docshell URI is the original URI."); michael@0: michael@0: // Global history does not record URI of a failed request. michael@0: promiseAsyncUpdates().then(function() { michael@0: gAsyncHistory.isURIVisited(kUniqueURI, errorAsyncListener); michael@0: }); michael@0: } michael@0: michael@0: function errorAsyncListener(aURI, aIsVisited) { michael@0: ok(kUniqueURI.equals(aURI) && !aIsVisited, michael@0: "The neterror page is not listed in global history."); michael@0: michael@0: Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); michael@0: michael@0: // Now press the "Try Again" button, with offline mode off. michael@0: Services.io.offline = false; michael@0: michael@0: window.addEventListener("DOMContentLoaded", reloadListener, false); michael@0: michael@0: ok(gBrowser.contentDocument.getElementById("errorTryAgain"), michael@0: "The error page has got a #errorTryAgain element"); michael@0: gBrowser.contentDocument.getElementById("errorTryAgain").click(); michael@0: } michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: // listen to reload of neterror. michael@0: function reloadListener() { michael@0: window.removeEventListener("DOMContentLoaded", reloadListener, false); michael@0: michael@0: // This listener catches "DOMContentLoaded" on being called michael@0: // nsIWPL::onLocationChange(...). That is right *AFTER* michael@0: // IHistory::VisitURI(...) is called. michael@0: ok(!Services.io.offline, "Services.io.offline is false."); michael@0: michael@0: // This is not an error page. michael@0: is(gBrowser.contentDocument.documentURI, kUniqueURI.spec, michael@0: "Document URI is not the offline-error page, but the original URI."); michael@0: michael@0: // Check if global history remembers the successfully-requested URI. michael@0: promiseAsyncUpdates().then(function() { michael@0: gAsyncHistory.isURIVisited(kUniqueURI, reloadAsyncListener); michael@0: }); michael@0: } michael@0: michael@0: function reloadAsyncListener(aURI, aIsVisited) { michael@0: ok(kUniqueURI.equals(aURI) && aIsVisited, "We have visited the URI."); michael@0: promiseClearHistory().then(finish); michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); michael@0: Services.io.offline = false; michael@0: window.removeEventListener("DOMContentLoaded", errorListener, false); michael@0: window.removeEventListener("DOMContentLoaded", reloadListener, false); michael@0: gBrowser.removeCurrentTab(); michael@0: });