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 makes the browser go online. See bug 435325. */ michael@0: michael@0: let proxyPrefValue; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let tab = gBrowser.selectedTab = gBrowser.addTab(); michael@0: michael@0: // Go offline and disable the proxy and cache, then try to load the test URL. michael@0: Services.io.offline = true; 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: Services.prefs.setBoolPref("browser.cache.disk.enable", false); michael@0: Services.prefs.setBoolPref("browser.cache.memory.enable", false); michael@0: content.location = "http://example.com/"; michael@0: michael@0: window.addEventListener("DOMContentLoaded", function load() { 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: window.removeEventListener("DOMContentLoaded", load, false); michael@0: michael@0: let observer = new MutationObserver(function (mutations) { michael@0: for (let mutation of mutations) { michael@0: if (mutation.attributeName == "hasBrowserHandlers") { michael@0: observer.disconnect(); michael@0: checkPage(); michael@0: return; michael@0: } michael@0: } michael@0: }); michael@0: let docElt = tab.linkedBrowser.contentDocument.documentElement; michael@0: observer.observe(docElt, { attributes: true }); michael@0: }, false); michael@0: } michael@0: michael@0: function checkPage() { michael@0: ok(Services.io.offline, "Setting Services.io.offline to true."); michael@0: is(gBrowser.contentDocument.documentURI.substring(0,27), michael@0: "about:neterror?e=netOffline", "Loading the Offline mode neterror page."); michael@0: michael@0: // Now press the "Try Again" button michael@0: ok(gBrowser.contentDocument.getElementById("errorTryAgain"), michael@0: "The error page has got a #errorTryAgain element"); michael@0: michael@0: // Re-enable the proxy so example.com is resolved to localhost, rather than michael@0: // the actual example.com. michael@0: Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); michael@0: michael@0: gBrowser.contentDocument.getElementById("errorTryAgain").click(); michael@0: michael@0: ok(!Services.io.offline, "After clicking the Try Again button, we're back " + michael@0: "online."); michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: Services.prefs.setBoolPref("browser.cache.disk.enable", true); michael@0: Services.prefs.setBoolPref("browser.cache.memory.enable", true); michael@0: Services.io.offline = false; michael@0: gBrowser.removeCurrentTab(); michael@0: });