Bug 1089190 - Add testing for offline network pages r=bnicholson
authorMark Finkle <mfinkle@mozilla.com>
Mon, 27 Oct 2014 14:59:02 -0400
changeset 236825 0dce9d625fb5032ef67eeb6445edfd3df8e32f0f
parent 236824 7b93cd7127a570e1a6fb54ba50be5ac4c2d12fad
child 236826 b547004f9c098db854b38c7b71ef4ebe518e64e3
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs1089190
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1089190 - Add testing for offline network pages r=bnicholson
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/testOfflinePage.java
mobile/android/base/tests/testOfflinePage.js
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -99,16 +99,17 @@ skip-if = android_version == "10"
 [testAccounts]
 [testAndroidLog]
 [testBrowserDiscovery]
 [testDebuggerServer]
 [testDeviceSearchEngine]
 [testJNI]
 # [testMozPay] # see bug 945675
 [testNetworkManager]
+[testOfflinePage]
 [testOrderedBroadcast]
 [testOSLocale]
 [testResourceSubstitutions]
 [testRestrictedProfiles]
 [testSharedPreferences]
 [testSimpleDiscovery]
 [testUITelemetry]
 [testVideoControls]
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testOfflinePage.java
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.tests;
+
+public class testOfflinePage extends JavascriptTest {
+    public testOfflinePage() {
+        super("testOfflinePage.js");
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testOfflinePage.js
@@ -0,0 +1,107 @@
+// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Messaging.jsm");
+
+function ok(passed, text) {
+  do_report_result(passed, text, Components.stack.caller, false);
+}
+
+function is(lhs, rhs, text) {
+  do_report_result(lhs === rhs, text, Components.stack.caller, false);
+}
+
+// The chrome window
+let chromeWin;
+
+// Track the <browser> where the tests are happening
+let browser;
+
+// The proxy setting
+let proxyPrefValue;
+
+const kUniqueURI = Services.io.newURI("http://mochi.test:8888/tests/robocop/video_controls.html", null, null);
+
+add_test(function setup_browser() {
+  // Tests always connect to localhost, and per bug 87717, localhost is now
+  // reachable in offline mode.  To avoid this, disable any proxy.
+  proxyPrefValue = Services.prefs.getIntPref("network.proxy.type");
+  Services.prefs.setIntPref("network.proxy.type", 0);
+
+  // Clear network cache.
+  Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService).clear();
+
+  chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  let BrowserApp = chromeWin.BrowserApp;
+
+  do_register_cleanup(function cleanup() {
+    BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+    Services.prefs.setIntPref("network.proxy.type", proxyPrefValue);
+    Services.io.offline = false;
+  });
+
+  do_test_pending();
+
+  // Add a new tab with a blank page so we can better control the real page load and the offline state
+  browser = BrowserApp.addTab("about:blank", { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
+
+  // Go offline, expecting the error page.
+  Services.io.offline = true;
+
+  // Load our test web page
+  browser.addEventListener("DOMContentLoaded", errorListener, true);
+  browser.loadURI(kUniqueURI.spec, null, null)
+});
+
+//------------------------------------------------------------------------------
+// listen to loading the neterror page. (offline mode)
+function errorListener() {
+  if (browser.contentWindow.location == "about:blank") {
+    do_print("got about:blank, which is expected once, so return");
+    return;
+  }
+
+  browser.removeEventListener("DOMContentLoaded", errorListener, true);
+  ok(Services.io.offline, "Services.io.offline is true.");
+
+  // This is an error page.
+  is(browser.contentDocument.documentURI.substring(0, 27), "about:neterror?e=netOffline", "Document URI is the error page.");
+
+  // But location bar should show the original request.
+  is(browser.contentWindow.location.href, kUniqueURI.spec, "Docshell URI is the original URI.");
+
+  Services.prefs.setIntPref("network.proxy.type", proxyPrefValue);
+
+  // Now press the "Try Again" button, with offline mode off.
+  Services.io.offline = false;
+
+  browser.addEventListener("DOMContentLoaded", reloadListener, true);
+
+  ok(browser.contentDocument.getElementById("errorTryAgain"), "The error page has got a #errorTryAgain element");
+  browser.contentDocument.getElementById("errorTryAgain").click();
+}
+
+
+//------------------------------------------------------------------------------
+// listen to reload of neterror.
+function reloadListener() {
+  browser.removeEventListener("DOMContentLoaded", reloadListener, true);
+
+  ok(!Services.io.offline, "Services.io.offline is false.");
+
+  // This is not an error page.
+  is(browser.contentDocument.documentURI, kUniqueURI.spec, "Document URI is not the offline-error page, but the original URI.");
+
+  do_test_finished();
+
+  run_next_test();
+}
+
+run_next_test();