1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug435325.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/* Ensure that clicking the button in the Offline mode neterror page makes the browser go online. See bug 435325. */ 1.8 + 1.9 +let proxyPrefValue; 1.10 + 1.11 +function test() { 1.12 + waitForExplicitFinish(); 1.13 + 1.14 + let tab = gBrowser.selectedTab = gBrowser.addTab(); 1.15 + 1.16 + // Go offline and disable the proxy and cache, then try to load the test URL. 1.17 + Services.io.offline = true; 1.18 + 1.19 + // Tests always connect to localhost, and per bug 87717, localhost is now 1.20 + // reachable in offline mode. To avoid this, disable any proxy. 1.21 + proxyPrefValue = Services.prefs.getIntPref("network.proxy.type"); 1.22 + Services.prefs.setIntPref("network.proxy.type", 0); 1.23 + 1.24 + Services.prefs.setBoolPref("browser.cache.disk.enable", false); 1.25 + Services.prefs.setBoolPref("browser.cache.memory.enable", false); 1.26 + content.location = "http://example.com/"; 1.27 + 1.28 + window.addEventListener("DOMContentLoaded", function load() { 1.29 + if (content.location == "about:blank") { 1.30 + info("got about:blank, which is expected once, so return"); 1.31 + return; 1.32 + } 1.33 + window.removeEventListener("DOMContentLoaded", load, false); 1.34 + 1.35 + let observer = new MutationObserver(function (mutations) { 1.36 + for (let mutation of mutations) { 1.37 + if (mutation.attributeName == "hasBrowserHandlers") { 1.38 + observer.disconnect(); 1.39 + checkPage(); 1.40 + return; 1.41 + } 1.42 + } 1.43 + }); 1.44 + let docElt = tab.linkedBrowser.contentDocument.documentElement; 1.45 + observer.observe(docElt, { attributes: true }); 1.46 + }, false); 1.47 +} 1.48 + 1.49 +function checkPage() { 1.50 + ok(Services.io.offline, "Setting Services.io.offline to true."); 1.51 + is(gBrowser.contentDocument.documentURI.substring(0,27), 1.52 + "about:neterror?e=netOffline", "Loading the Offline mode neterror page."); 1.53 + 1.54 + // Now press the "Try Again" button 1.55 + ok(gBrowser.contentDocument.getElementById("errorTryAgain"), 1.56 + "The error page has got a #errorTryAgain element"); 1.57 + 1.58 + // Re-enable the proxy so example.com is resolved to localhost, rather than 1.59 + // the actual example.com. 1.60 + Services.prefs.setIntPref("network.proxy.type", proxyPrefValue); 1.61 + 1.62 + gBrowser.contentDocument.getElementById("errorTryAgain").click(); 1.63 + 1.64 + ok(!Services.io.offline, "After clicking the Try Again button, we're back " + 1.65 + "online."); 1.66 + 1.67 + finish(); 1.68 +} 1.69 + 1.70 +registerCleanupFunction(function() { 1.71 + Services.prefs.setBoolPref("browser.cache.disk.enable", true); 1.72 + Services.prefs.setBoolPref("browser.cache.memory.enable", true); 1.73 + Services.io.offline = false; 1.74 + gBrowser.removeCurrentTab(); 1.75 +});