Bug 1184186 - Convert robocop testWebChannel to mochitest-chrome; r=nalexander
authorGeoff Brown <gbrown@mozilla.com>
Thu, 06 Aug 2015 07:27:48 -0600
changeset 288193 dd0af7b479aedb59abe176dd4b460e4c5040a77b
parent 288192 514b2733ac8fe25ff933ca53f7abed755911f719
child 288194 8317a91e32542106471bd5cb611da06b631cc418
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)
reviewersnalexander
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 testWebChannel to mochitest-chrome; r=nalexander
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_web_channel.html
mobile/android/tests/browser/chrome/web_channel.html
mobile/android/tests/browser/robocop/robocop.ini
mobile/android/tests/browser/robocop/testWebChannel.html
mobile/android/tests/browser/robocop/testWebChannel.java
mobile/android/tests/browser/robocop/testWebChannel.js
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -3,16 +3,17 @@ skip-if = os != 'android'
 support-files =
   basic_article.html
   desktopmode_user_agent.sjs
   devicesearch.xml
   session_formdata_sample.html
   simpleservice.xml
   video_controls.html
   video_discovery.html
+  web_channel.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]
@@ -24,8 +25,9 @@ support-files =
 [test_offline_page.html]
 [test_reader_view.html]
 [test_resource_substitutions.html]
 [test_restricted_profiles.html]
 [test_session_form_data.html]
 [test_shared_preferences.html]
 [test_simple_discovery.html]
 [test_video_discovery.html]
+[test_web_channel.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_web_channel.html
@@ -0,0 +1,121 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1174458
+Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1174458</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">
+
+  const { classes: Cc, interfaces: Ci, utils: Cu } = Components; /*global Components */
+
+  Cu.import("resource://gre/modules/Promise.jsm"); /*global Promise */
+  Cu.import("resource://gre/modules/Services.jsm"); /*global Services */
+  Cu.import("resource://gre/modules/XPCOMUtils.jsm"); /*global XPCOMUtils */
+  Cu.import("resource://gre/modules/Task.jsm"); /*global Task */
+  XPCOMUtils.defineLazyModuleGetter(this, "WebChannel",
+    "resource://gre/modules/WebChannel.jsm"); /*global WebChannel */
+
+  const HTTP_PATH = "http://mochi.test:8888";
+  const HTTP_ENDPOINT = "/chrome/mobile/android/tests/browser/chrome/web_channel.html";
+
+  const gChromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  let BrowserApp = gChromeWin.BrowserApp;
+
+  // TODO: consider if we want to run the original test in browser-chrome instead
+
+  // Keep this synced with /browser/base/content/test/general/browser_web_channel.js
+  // as much as possible.  (We only have this since we can't run browser chrome
+  // tests on Android.  Yet?)
+  let gTests = [
+    {
+      desc: "WebChannel generic message",
+      run: function* () {
+        return new Promise(function(resolve, reject) {
+          let tab;
+          let channel = new WebChannel("generic", Services.io.newURI(HTTP_PATH, null, null));
+          channel.listen(function (id, message, target) {
+            is(id, "generic");
+            is(message.something.nested, "hello");
+            channel.stopListening();
+            BrowserApp.closeTab(tab);
+            resolve();
+          });
+
+          tab = BrowserApp.addTab(HTTP_PATH + HTTP_ENDPOINT + "?generic");
+        });
+      }
+    },
+    {
+      desc: "WebChannel two way communication",
+      run: function* () {
+        return new Promise(function(resolve, reject) {
+          let tab;
+          let channel = new WebChannel("twoway", Services.io.newURI(HTTP_PATH, null, null));
+
+          channel.listen(function (id, message, sender) {
+            is(id, "twoway");
+            ok(message.command);
+
+            if (message.command === "one") {
+              channel.send({ data: { nested: true } }, sender);
+            }
+
+            if (message.command === "two") {
+              is(message.detail.data.nested, true);
+              channel.stopListening();
+              BrowserApp.closeTab(tab);
+              resolve();
+            }
+          });
+
+          tab = BrowserApp.addTab(HTTP_PATH + HTTP_ENDPOINT + "?twoway");
+        });
+      }
+    },
+    {
+      desc: "WebChannel multichannel",
+      run: function* () {
+        return new Promise(function(resolve, reject) {
+          let tab;
+          let channel = new WebChannel("multichannel", Services.io.newURI(HTTP_PATH, null, null));
+
+          channel.listen(function (id, message, sender) {
+            is(id, "multichannel");
+            BrowserApp.closeTab(tab);
+            resolve();
+          });
+
+          tab = BrowserApp.addTab(HTTP_PATH + HTTP_ENDPOINT + "?multichannel");
+        });
+      }
+    }
+  ]; // gTests
+
+  add_task(function* test() {
+    for (let test of gTests) {
+      info("Running: " + test.desc);
+      yield test.run();
+    }
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1174458">Mozilla Bug 1174458</a>
+<br>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1184186">Migrated from Robocop testWebChannel</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/web_channel.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>web_channel_test</title>
+</head>
+<body>
+<script>
+  window.onload = function() {
+    var testName = window.location.search.replace(/^\?/, "");
+
+    switch(testName) {
+      case "generic":
+        test_generic();
+        break;
+      case "twoway":
+        test_twoWay();
+        break;
+      case "multichannel":
+        test_multichannel();
+        break;
+    }
+  };
+
+  function test_generic() {
+    var event = new window.CustomEvent("WebChannelMessageToChrome", {
+      detail: {
+        id: "generic",
+        message: {
+          something: {
+            nested: "hello",
+          },
+        }
+      }
+    });
+
+    window.dispatchEvent(event);
+  }
+
+  function test_twoWay() {
+    var firstMessage = new window.CustomEvent("WebChannelMessageToChrome", {
+      detail: {
+        id: "twoway",
+        message: {
+          command: "one",
+        },
+      }
+    });
+
+    window.addEventListener("WebChannelMessageToContent", function(e) {
+      var secondMessage = new window.CustomEvent("WebChannelMessageToChrome", {
+        detail: {
+          id: "twoway",
+          message: {
+            command: "two",
+            detail: e.detail.message,
+          },
+        },
+      });
+
+      if (!e.detail.message.error) {
+        window.dispatchEvent(secondMessage);
+      }
+    }, true);
+
+    window.dispatchEvent(firstMessage);
+  }
+
+  function test_multichannel() {
+    var event1 = new window.CustomEvent("WebChannelMessageToChrome", {
+      detail: {
+        id: "wrongchannel",
+        message: {},
+      }
+    });
+
+    var event2 = new window.CustomEvent("WebChannelMessageToChrome", {
+      detail: {
+        id: "multichannel",
+        message: {},
+      }
+    });
+
+    window.dispatchEvent(event1);
+    window.dispatchEvent(event2);
+  }
+</script>
+</body>
+</html>
--- a/mobile/android/tests/browser/robocop/robocop.ini
+++ b/mobile/android/tests/browser/robocop/robocop.ini
@@ -104,16 +104,18 @@ skip-if = android_version == "10" || and
 skip-if = android_version == "10" || android_version == "18"
 # [testThumbnails.java] # see bug 813107
 [testTitleBar.java]
 # disabled on Android 2.3, bug 979552; on 4.3, bug 1145881
 skip-if = android_version == "10" || android_version == "18"
 # [testVkbOverlap.java] # see bug 907274
 
 # Using JavascriptTest
+# (If your test can be written entirely in Javascript, consider writing
+# it as a chrome test instead. See mobile/android/tests/browser/chrome.)
 [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
@@ -125,17 +127,16 @@ skip-if = android_version == "10" || and
 [testRestrictions.java]
 [testTrackingProtection.java]
 # disabled on 4.3, bug 1158363
 skip-if = android_version == "18"
 [testUITelemetry.java]
 [testVideoControls.java]
 # disabled on Android 2.3 due to video playback issues, bug 1088038; on 4.3, bug 1098532
 skip-if = android_version == "10" || android_version == "18"
-[testWebChannel.java]
 
 # Used for Talos, please don't use in mochitest
 #[testCheck2.java]
 #[testCheck3.java] # and the autophone version
 
 # Using UITest
 #[testAboutHomePageNavigation.java] # see bug 947550, bug 979038 and bug 977952
 [testAboutHomeVisibility.java]
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testWebChannel.html
+++ /dev/null
@@ -1,89 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <meta charset="utf-8">
-  <title>web_channel_test</title>
-</head>
-<body>
-<script>
-  window.onload = function() {
-    var testName = window.location.search.replace(/^\?/, "");
-
-    switch(testName) {
-      case "generic":
-        test_generic();
-        break;
-      case "twoway":
-        test_twoWay();
-        break;
-      case "multichannel":
-        test_multichannel();
-        break;
-    }
-  };
-
-  function test_generic() {
-    var event = new window.CustomEvent("WebChannelMessageToChrome", {
-      detail: {
-        id: "generic",
-        message: {
-          something: {
-            nested: "hello",
-          },
-        }
-      }
-    });
-
-    window.dispatchEvent(event);
-  }
-
-  function test_twoWay() {
-    var firstMessage = new window.CustomEvent("WebChannelMessageToChrome", {
-      detail: {
-        id: "twoway",
-        message: {
-          command: "one",
-        },
-      }
-    });
-
-    window.addEventListener("WebChannelMessageToContent", function(e) {
-      var secondMessage = new window.CustomEvent("WebChannelMessageToChrome", {
-        detail: {
-          id: "twoway",
-          message: {
-            command: "two",
-            detail: e.detail.message,
-          },
-        },
-      });
-
-      if (!e.detail.message.error) {
-        window.dispatchEvent(secondMessage);
-      }
-    }, true);
-
-    window.dispatchEvent(firstMessage);
-  }
-
-  function test_multichannel() {
-    var event1 = new window.CustomEvent("WebChannelMessageToChrome", {
-      detail: {
-        id: "wrongchannel",
-        message: {},
-      }
-    });
-
-    var event2 = new window.CustomEvent("WebChannelMessageToChrome", {
-      detail: {
-        id: "multichannel",
-        message: {},
-      }
-    });
-
-    window.dispatchEvent(event1);
-    window.dispatchEvent(event2);
-  }
-</script>
-</body>
-</html>
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testWebChannel.java
+++ /dev/null
@@ -1,13 +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 testWebChannel extends JavascriptTest {
-    public testWebChannel() {
-        super("testWebChannel.js");
-    }
-}
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/testWebChannel.js
+++ /dev/null
@@ -1,95 +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/. */
-
-const { classes: Cc, interfaces: Ci, utils: Cu } = Components; /*global Components */
-
-Cu.import("resource://gre/modules/Promise.jsm"); /*global Promise */
-Cu.import("resource://gre/modules/Services.jsm"); /*global Services */
-Cu.import("resource://gre/modules/XPCOMUtils.jsm"); /*global XPCOMUtils */
-XPCOMUtils.defineLazyModuleGetter(this, "WebChannel",
-  "resource://gre/modules/WebChannel.jsm"); /*global WebChannel */
-
-const HTTP_PATH = "http://mochi.test:8888";
-const HTTP_ENDPOINT = "/tests/robocop/testWebChannel.html";
-
-const gChromeWin = Services.wm.getMostRecentWindow("navigator:browser");
-let BrowserApp = gChromeWin.BrowserApp;
-
-// Keep this synced with /browser/base/content/test/general/browser_web_channel.js
-// as much as possible.  (We only have this since we can't run browser chrome
-// tests on Android.  Yet?)
-let gTests = [
-  {
-    desc: "WebChannel generic message",
-    run: function* () {
-      return new Promise(function(resolve, reject) {
-        let tab;
-        let channel = new WebChannel("generic", Services.io.newURI(HTTP_PATH, null, null));
-        channel.listen(function (id, message, target) {
-          is(id, "generic");
-          is(message.something.nested, "hello");
-          channel.stopListening();
-          BrowserApp.closeTab(tab);
-          resolve();
-        });
-
-        tab = BrowserApp.addTab(HTTP_PATH + HTTP_ENDPOINT + "?generic");
-      });
-    }
-  },
-  {
-    desc: "WebChannel two way communication",
-    run: function* () {
-      return new Promise(function(resolve, reject) {
-        let tab;
-        let channel = new WebChannel("twoway", Services.io.newURI(HTTP_PATH, null, null));
-
-        channel.listen(function (id, message, sender) {
-          is(id, "twoway");
-          ok(message.command);
-
-          if (message.command === "one") {
-            channel.send({ data: { nested: true } }, sender);
-          }
-
-          if (message.command === "two") {
-            is(message.detail.data.nested, true);
-            channel.stopListening();
-            BrowserApp.closeTab(tab);
-            resolve();
-          }
-        });
-
-        tab = BrowserApp.addTab(HTTP_PATH + HTTP_ENDPOINT + "?twoway");
-      });
-    }
-  },
-  {
-    desc: "WebChannel multichannel",
-    run: function* () {
-      return new Promise(function(resolve, reject) {
-        let tab;
-        let channel = new WebChannel("multichannel", Services.io.newURI(HTTP_PATH, null, null));
-
-        channel.listen(function (id, message, sender) {
-          is(id, "multichannel");
-          BrowserApp.closeTab(tab);
-          resolve();
-        });
-
-        tab = BrowserApp.addTab(HTTP_PATH + HTTP_ENDPOINT + "?multichannel");
-      });
-    }
-  }
-]; // gTests
-
-add_task(function test() {
-  for (let test of gTests) {
-    do_print("Running: " + test.desc);
-    yield test.run();
-  }
-});
-
-run_next_test();