browser/base/content/test/general/browser_bug435325.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial