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