Bug 1288885: Migrate background page mochitests to xpcshell. r=aswan
☠☠ backed out by 6254ca383718 ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Fri, 22 Jul 2016 18:44:27 -0700
changeset 332060 fca55647234643b6fde3b62b3337e491432ab0dc
parent 332059 abd51b3d2b52da0669680153e5321b9b843d6cd2
child 332061 eeb6bc8a42e69e989bb70cc6daf56296936f60b0
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1288885
milestone50.0a1
Bug 1288885: Migrate background page mochitests to xpcshell. r=aswan MozReview-Commit-ID: Fiv7sArlWDw
toolkit/components/extensions/test/mochitest/mochitest.ini
toolkit/components/extensions/test/mochitest/test_ext_background_generated_load_events.html
toolkit/components/extensions/test/mochitest/test_ext_background_generated_reload.html
toolkit/components/extensions/test/mochitest/test_ext_background_sub_windows.html
toolkit/components/extensions/test/mochitest/test_ext_background_window_properties.html
toolkit/components/extensions/test/xpcshell/test_ext_background_generated_load_events.js
toolkit/components/extensions/test/xpcshell/test_ext_background_generated_reload.js
toolkit/components/extensions/test/xpcshell/test_ext_background_sub_windows.js
toolkit/components/extensions/test/xpcshell/test_ext_background_window_properties.js
toolkit/components/extensions/test/xpcshell/xpcshell.ini
--- a/toolkit/components/extensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest.ini
@@ -66,22 +66,18 @@ skip-if = (os == 'android' || buildapp =
 [test_ext_sendmessage_reply2.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # sender.tab is undefined on b2g. Bug 1258975 on android.
 [test_ext_sendmessage_doublereply.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # sender.tab is undefined on b2g. Bug 1258975 on android.
 [test_ext_storage_content.html]
 [test_ext_storage_tab.html]
 skip-if = os == 'android' # Android does not currently support tabs.
 [test_ext_cookies.html]
-[test_ext_background_window_properties.html]
-[test_ext_background_sub_windows.html]
 [test_ext_background_api_injection.html]
 [test_ext_background_generated_url.html]
-[test_ext_background_generated_reload.html]
-[test_ext_background_generated_load_events.html]
 [test_ext_i18n.html]
 skip-if = (os == 'android') # Bug 1258975 on android.
 [test_ext_web_accessible_resources.html]
 skip-if = (os == 'android') # Bug 1258975 on android.
 [test_ext_webrequest.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # webrequest api uninplemented (bug 1199504). Bug 1258975 on android.
 [test_ext_webnavigation.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # needs TabManager which is not yet implemented. Bug 1258975 on android.
rename from toolkit/components/extensions/test/mochitest/test_ext_background_generated_load_events.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_background_generated_load_events.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_background_generated_load_events.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_generated_load_events.js
@@ -1,47 +1,23 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Test load events in _generated_background_page.html</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
-  <script type="text/javascript" src="head.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
-</head>
-<body>
-
-<script>
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 /* eslint-disable mozilla/balanced-listeners */
 
 add_task(function* test_DOMContentLoaded_in_generated_background_page() {
-  function backgroundScript() {
-    function reportListener(event) {
-      browser.test.sendMessage("eventname", event.type);
-    }
-    document.addEventListener("DOMContentLoaded", reportListener);
-    window.addEventListener("load", reportListener);
-  }
   let extension = ExtensionTestUtils.loadExtension({
-    manifest: {
-      background: {
-        scripts: ["bg.js"],
-      },
-      web_accessible_resources: ["_generated_background_page.html"],
-    },
-    files: {
-      "bg.js": `(${backgroundScript})();`,
+    background() {
+      function reportListener(event) {
+        browser.test.sendMessage("eventname", event.type);
+      }
+      document.addEventListener("DOMContentLoaded", reportListener);
+      window.addEventListener("load", reportListener);
     },
   });
 
   yield extension.startup();
-  is("DOMContentLoaded", yield extension.awaitMessage("eventname"));
-  is("load", yield extension.awaitMessage("eventname"));
+  equal("DOMContentLoaded", yield extension.awaitMessage("eventname"));
+  equal("load", yield extension.awaitMessage("eventname"));
 
   yield extension.unload();
 });
-
-</script>
-</body>
-</html>
rename from toolkit/components/extensions/test/mochitest/test_ext_background_generated_reload.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_background_generated_reload.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_background_generated_reload.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_generated_reload.js
@@ -1,50 +1,24 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Test reload of _generated_background_page.html</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
-  <script type="text/javascript" src="head.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
-</head>
-<body>
-
-<script>
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 add_task(function* test_reload_generated_background_page() {
-  function backgroundScript() {
-    if (location.hash !== "#firstrun") {
-      browser.test.sendMessage("first run");
-      location.hash = "#firstrun";
-      browser.test.assertEq("#firstrun", location.hash);
-      location.reload();
-    } else {
-      browser.test.notifyPass("second run");
-    }
-  }
   let extension = ExtensionTestUtils.loadExtension({
-    manifest: {
-      background: {
-        scripts: ["bg.js"],
-      },
-    },
-    files: {
-      "bg.js": `(${backgroundScript})();`,
+    background() {
+      if (location.hash !== "#firstrun") {
+        browser.test.sendMessage("first run");
+        location.hash = "#firstrun";
+        browser.test.assertEq("#firstrun", location.hash);
+        location.reload();
+      } else {
+        browser.test.notifyPass("second run");
+      }
     },
   });
 
   yield extension.startup();
-  info("Waiting for first message");
   yield extension.awaitMessage("first run");
-  info("Waiting for second message");
   yield extension.awaitFinish("second run");
-  info("Received both messages");
 
   yield extension.unload();
 });
-
-</script>
-</body>
-</html>
rename from toolkit/components/extensions/test/mochitest/test_ext_background_sub_windows.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_background_sub_windows.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_background_sub_windows.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_sub_windows.js
@@ -1,26 +1,15 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Test for sub-frames of WebExtension background pages</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
-  <script type="text/javascript" src="head.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-
-<script type="text/javascript">
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 add_task(function* testBackgroundWindow() {
   let extension = ExtensionTestUtils.loadExtension({
-    background: "new " + function() {
+    background() {
       browser.test.log("background script executed");
 
       browser.test.sendMessage("background-script-load");
 
       let img = document.createElement("img");
       img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
       document.body.appendChild(img);
 
@@ -36,30 +25,21 @@ add_task(function* testBackgroundWindow(
             browser.test.notifyPass("background sub-window test done");
           }, 0);
         };
         document.body.appendChild(iframe);
       };
     },
   });
 
-  info("extension loaded");
-
   let loadCount = 0;
   extension.onMessage("background-script-load", () => {
     loadCount++;
   });
 
   yield extension.startup();
 
-  info("startup complete loaded");
-
   yield extension.awaitFinish("background sub-window test done");
 
-  is(loadCount, 1, "background script loaded only once");
+  equal(loadCount, 1, "background script loaded only once");
 
   yield extension.unload();
 });
-
-</script>
-
-</body>
-</html>
rename from toolkit/components/extensions/test/mochitest/test_ext_background_window_properties.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_background_window_properties.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_background_window_properties.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_window_properties.js
@@ -1,26 +1,15 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Test for simple WebExtension</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
-  <script type="text/javascript" src="head.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-
-<script type="text/javascript">
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 add_task(function* testBackgroundWindowProperties() {
   let extension = ExtensionTestUtils.loadExtension({
-    background: "(" + function() {
+    background() {
       let expectedValues = {
         screenX: 0,
         screenY: 0,
         outerWidth: 0,
         outerHeight: 0,
       };
 
       for (let k in window) {
@@ -32,22 +21,14 @@ add_task(function* testBackgroundWindowP
             void window[k];
           }
         } catch (e) {
           browser.test.assertEq(null, e, `unexpected exception accessing window property: ${k}`);
         }
       }
 
       browser.test.notifyPass("background.testWindowProperties.done");
-    } + ")();",
+    },
   });
-  info("load complete");
   yield extension.startup();
-  info("startup complete");
   yield extension.awaitFinish("background.testWindowProperties.done");
   yield extension.unload();
-  info("extension unloaded successfully");
 });
-
-</script>
-
-</body>
-</html>
--- a/toolkit/components/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell.ini
@@ -4,17 +4,21 @@ tail =
 firefox-appdir = browser
 skip-if = toolkit == 'gonk' || appname == "thunderbird"
 support-files =
   data/**
 
 [test_csp_custom_policies.js]
 [test_csp_validator.js]
 [test_ext_alarms.js]
+[test_ext_background_generated_load_events.js]
+[test_ext_background_generated_reload.js]
 [test_ext_background_runtime_connect_params.js]
+[test_ext_background_sub_windows.js]
+[test_ext_background_window_properties.js]
 [test_ext_contexts.js]
 [test_ext_downloads.js]
 [test_ext_downloads_download.js]
 [test_ext_downloads_misc.js]
 [test_ext_downloads_search.js]
 [test_ext_extension.js]
 [test_ext_idle.js]
 [test_ext_json_parser.js]