Bug 1184186 - Convert robocop testOfflinePage to mochitest-chrome; r=mfinkle
authorGeoff Brown <gbrown@mozilla.com>
Thu, 06 Aug 2015 07:27:47 -0600
changeset 288186 81ed032662fac244762293cfb805439d7217b287
parent 288185 5a057086c77d3aaf28dafe8f4f4696abdba1fce4
child 288187 07097d4a43b69c0c0a882c9ee797bc57849cced3
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1184186
milestone42.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 1184186 - Convert robocop testOfflinePage to mochitest-chrome; r=mfinkle
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_offline_page.html
mobile/android/tests/browser/chrome/video_controls.html
mobile/android/tests/browser/robocop/robocop.ini
mobile/android/tests/browser/robocop/testOfflinePage.java
mobile/android/tests/browser/robocop/testOfflinePage.js
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -1,19 +1,21 @@
 [DEFAULT]
 skip-if = os != 'android'
 support-files =
   desktopmode_user_agent.sjs
   devicesearch.xml
+  video_controls.html
 
 [test_about_logins.html]
 [test_accounts.html]
 [test_android_log.html]
 [test_app_constants.html]
 [test_debugger_server.html]
 [test_desktop_useragent.html]
 [test_device_search_engine.html]
 [test_home_provider.html]
 [test_java_addons.html]
 [test_jni.html]
 [test_migrate_ui.html]
 [test_network_manager.html]
+[test_offline_page.html]
 [test_resource_substitutions.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_offline_page.html
@@ -0,0 +1,128 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1089190
+Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1089190</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript;version=1.7">
+
+  "use strict";
+
+  const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/Messaging.jsm");
+  Cu.import("resource://gre/modules/Task.jsm");
+
+  function promiseBrowserEvent(browser, eventType) {
+    return new Promise((resolve) => {
+      function handle(event) {
+        // Since we'll be redirecting, don't make assumptions about the given URL and the loaded URL
+        if (event.target != browser.contentDocument || event.target.location.href == "about:blank") {
+          info("Skipping spurious '" + eventType + "' event" + " for " + event.target.location.href);
+          return;
+        }
+        info("Received event " + eventType + " from browser");
+        browser.removeEventListener(eventType, handle, true);
+        resolve(event);
+      }
+
+      browser.addEventListener(eventType, handle, true);
+      info("Now waiting for " + eventType + " event from browser");
+    });
+  }
+
+  // Provide a helper to yield until we are sure the offline state has changed
+  function promiseOffline(isOffline) {
+    return new Promise((resolve, reject) => {
+      function observe(subject, topic, data) {
+        info("Received topic: " + topic);
+        Services.obs.removeObserver(observe, "network:offline-status-changed");
+        resolve();
+      }
+      Services.obs.addObserver(observe, "network:offline-status-changed", false);
+      Services.io.offline = isOffline;
+    });
+  }
+
+  // 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/chrome/mobile/android/tests/browser/chrome/video_controls.html", null, null);
+
+  add_task(function* test_offline() {
+    // 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;
+
+    // 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;
+
+    SimpleTest.registerCleanupFunction(function() {
+      BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+      Services.prefs.setIntPref("network.proxy.type", proxyPrefValue);
+      Services.io.offline = false;
+    });
+
+    // Go offline, expecting the error page.
+    yield promiseOffline(true);
+
+    // Load our test web page
+    browser.loadURI(kUniqueURI.spec, null, null)
+    yield promiseBrowserEvent(browser, "DOMContentLoaded");
+
+    // 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);
+
+    // Go online and try to load the page again
+    yield promiseOffline(false);
+
+    ok(browser.contentDocument.getElementById("errorTryAgain"), "The error page has got a #errorTryAgain element");
+
+    // Click "Try Again" button to start the page load
+    browser.contentDocument.getElementById("errorTryAgain").click();
+    yield promiseBrowserEvent(browser, "DOMContentLoaded");
+
+    // This is not an error page.
+    is(browser.contentDocument.documentURI, kUniqueURI.spec, "Document URI is not the offline-error page, but the original URI.");
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1089190">Mozilla Bug 1089190</a>
+<br>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1184186">Migrated from Robocop testOfflinePage</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/video_controls.html
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <title>Video Controls Test</title>
+  </head>
+  <body>
+    <video id="video" style="height: 480px; width: 640px" controls mozNoDynamicControls></video>
+    <canvas id="canvas" style="height: 480px; width: 640px"></canvas>
+  </body>
+</html>
--- a/mobile/android/tests/browser/robocop/robocop.ini
+++ b/mobile/android/tests/browser/robocop/robocop.ini
@@ -112,17 +112,16 @@ skip-if = android_version == "10" || and
 [testBrowserDiscovery.java]
 # disabled on 4.3, bug 1158384
 skip-if = android_version == "18"
 [testFilePicker.java]
 [testHistoryService.java]
 # disabled on 4.3, bug 1116036
 skip-if = android_version == "18"
 # [testMozPay.java] # see bug 945675
-[testOfflinePage.java]
 [testOrderedBroadcast.java]
 [testOSLocale.java]
 # disabled on 2.3 and 4.3: Bug 1124494
 skip-if = android_version == "10" || android_version == "18"
 [testReaderView.java]
 [testReadingListCache.java]
 [testRestrictedProfiles.java]
 [testRestrictions.java]
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testOfflinePage.java
+++ /dev/null
@@ -1,11 +0,0 @@
-/* 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");
-    }
-}
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testOfflinePage.js
+++ /dev/null
@@ -1,104 +0,0 @@
-// -*- 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 promiseBrowserEvent(browser, eventType) {
-  return new Promise((resolve) => {
-    function handle(event) {
-      // Since we'll be redirecting, don't make assumptions about the given URL and the loaded URL
-      if (event.target != browser.contentDocument || event.target.location.href == "about:blank") {
-        do_print("Skipping spurious '" + eventType + "' event" + " for " + event.target.location.href);
-        return;
-      }
-      do_print("Received event " + eventType + " from browser");
-      browser.removeEventListener(eventType, handle, true);
-      resolve(event);
-    }
-
-    browser.addEventListener(eventType, handle, true);
-    do_print("Now waiting for " + eventType + " event from browser");
-  });
-}
-
-// Provide a helper to yield until we are sure the offline state has changed
-function promiseOffline(isOffline) {
-  return new Promise((resolve, reject) => {
-    function observe(subject, topic, data) {
-      do_print("Received topic: " + topic);
-      Services.obs.removeObserver(observe, "network:offline-status-changed");
-      resolve();
-    }
-    Services.obs.addObserver(observe, "network:offline-status-changed", false);
-    Services.io.offline = isOffline;
-  });
-}
-
-// 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_task(function* test_offline() {
-  // 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;
-  });
-
-  // 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.
-  yield promiseOffline(true);
-
-  // Load our test web page
-  browser.loadURI(kUniqueURI.spec, null, null)
-  yield promiseBrowserEvent(browser, "DOMContentLoaded");
-
-  // 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);
-
-  // Go online and try to load the page again
-  yield promiseOffline(false);
-
-  ok(browser.contentDocument.getElementById("errorTryAgain"), "The error page has got a #errorTryAgain element");
-
-  // Click "Try Again" button to start the page load
-  browser.contentDocument.getElementById("errorTryAgain").click();
-  yield promiseBrowserEvent(browser, "DOMContentLoaded");
-
-  // This is not an error page.
-  is(browser.contentDocument.documentURI, kUniqueURI.spec, "Document URI is not the offline-error page, but the original URI.");
-});
-
-run_next_test();