toolkit/components/places/tests/browser/browser_bug680727.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 updates
     5    global history. See bug 680727. */
     6 /* TEST_PATH=toolkit/components/places/tests/browser/browser_bug680727.js make -C $(OBJDIR) mochitest-browser-chrome */
     9 const kUniqueURI = Services.io.newURI("http://mochi.test:8888/#bug_680727",
    10                                       null, null);
    11 var gAsyncHistory = 
    12   Cc["@mozilla.org/browser/history;1"].getService(Ci.mozIAsyncHistory);
    14 let proxyPrefValue;
    16 function test() {
    17   waitForExplicitFinish();
    19   gBrowser.selectedTab = gBrowser.addTab();
    21   // Tests always connect to localhost, and per bug 87717, localhost is now
    22   // reachable in offline mode.  To avoid this, disable any proxy.
    23   proxyPrefValue = Services.prefs.getIntPref("network.proxy.type");
    24   Services.prefs.setIntPref("network.proxy.type", 0);
    26   // Clear network cache.
    27   Components.classes["@mozilla.org/netwerk/cache-storage-service;1"]
    28             .getService(Components.interfaces.nsICacheStorageService)
    29             .clear();
    31   // Go offline, expecting the error page.
    32   Services.io.offline = true;
    33   window.addEventListener("DOMContentLoaded", errorListener, false);
    34   content.location = kUniqueURI.spec;
    35 }
    37 //------------------------------------------------------------------------------
    38 // listen to loading the neterror page. (offline mode)
    39 function errorListener() {
    40   if(content.location == "about:blank") {
    41     info("got about:blank, which is expected once, so return");
    42     return;
    43   }
    45   window.removeEventListener("DOMContentLoaded", errorListener, false);
    46   ok(Services.io.offline, "Services.io.offline is true.");
    48   // This is an error page.
    49   is(gBrowser.contentDocument.documentURI.substring(0, 27),
    50      "about:neterror?e=netOffline",
    51      "Document URI is the error page.");
    53   // But location bar should show the original request.
    54   is(content.location.href, kUniqueURI.spec,
    55      "Docshell URI is the original URI.");
    57   // Global history does not record URI of a failed request.
    58   promiseAsyncUpdates().then(function() {
    59     gAsyncHistory.isURIVisited(kUniqueURI, errorAsyncListener);
    60   });
    61 }
    63 function errorAsyncListener(aURI, aIsVisited) {
    64   ok(kUniqueURI.equals(aURI) && !aIsVisited,
    65      "The neterror page is not listed in global history.");
    67   Services.prefs.setIntPref("network.proxy.type", proxyPrefValue);
    69   // Now press the "Try Again" button, with offline mode off.
    70   Services.io.offline = false;
    72   window.addEventListener("DOMContentLoaded", reloadListener, false);
    74   ok(gBrowser.contentDocument.getElementById("errorTryAgain"),
    75      "The error page has got a #errorTryAgain element");
    76   gBrowser.contentDocument.getElementById("errorTryAgain").click();
    77 }
    79 //------------------------------------------------------------------------------
    80 // listen to reload of neterror.
    81 function reloadListener() {
    82   window.removeEventListener("DOMContentLoaded", reloadListener, false);
    84   // This listener catches "DOMContentLoaded" on being called
    85   // nsIWPL::onLocationChange(...). That is right *AFTER*
    86   // IHistory::VisitURI(...) is called.
    87   ok(!Services.io.offline, "Services.io.offline is false.");
    89   // This is not an error page.
    90   is(gBrowser.contentDocument.documentURI, kUniqueURI.spec, 
    91      "Document URI is not the offline-error page, but the original URI.");
    93   // Check if global history remembers the successfully-requested URI.
    94   promiseAsyncUpdates().then(function() {
    95     gAsyncHistory.isURIVisited(kUniqueURI, reloadAsyncListener);
    96   });
    97 }
    99 function reloadAsyncListener(aURI, aIsVisited) {
   100   ok(kUniqueURI.equals(aURI) && aIsVisited, "We have visited the URI.");
   101   promiseClearHistory().then(finish);
   102 }
   104 registerCleanupFunction(function() {
   105   Services.prefs.setIntPref("network.proxy.type", proxyPrefValue);
   106   Services.io.offline = false;
   107   window.removeEventListener("DOMContentLoaded", errorListener, false);
   108   window.removeEventListener("DOMContentLoaded", reloadListener, false);
   109   gBrowser.removeCurrentTab();
   110 });

mercurial