toolkit/components/places/tests/browser/browser_bug680727.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.

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

mercurial