Bug 1288885: Migrate simple extension mochitests to xpcshell. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 22 Jul 2016 16:57:58 -0700
changeset 392204 ffa857bf7510a72bd4fd13b3a9fbf87ddfb78121
parent 392203 1dd5e678e1827c254012b4581f979df696ae277e
child 392205 2a8d8360e956113419ed6f2869411e45c77cbdbe
push id23963
push usermaglione.k@gmail.com
push dateSun, 24 Jul 2016 23:16:27 +0000
reviewersaswan
bugs1288885
milestone50.0a1
Bug 1288885: Migrate simple extension mochitests to xpcshell. r?aswan MozReview-Commit-ID: BiaTf6u43XP
toolkit/components/extensions/test/mochitest/mochitest.ini
toolkit/components/extensions/test/mochitest/test_ext_background_runtime_connect_params.html
toolkit/components/extensions/test/mochitest/test_ext_extension.html
toolkit/components/extensions/test/mochitest/test_ext_idle.html
toolkit/components/extensions/test/mochitest/test_ext_onmessage_removelistener.html
toolkit/components/extensions/test/mochitest/test_ext_runtime_getPlatformInfo.html
toolkit/components/extensions/test/mochitest/test_ext_runtime_sendMessage.html
toolkit/components/extensions/test/mochitest/test_ext_simple.html
toolkit/components/extensions/test/xpcshell/test_ext_background_runtime_connect_params.js
toolkit/components/extensions/test/xpcshell/test_ext_extension.js
toolkit/components/extensions/test/xpcshell/test_ext_idle.js
toolkit/components/extensions/test/xpcshell/test_ext_onmessage_removelistener.js
toolkit/components/extensions/test/xpcshell/test_ext_runtime_getPlatformInfo.js
toolkit/components/extensions/test/xpcshell/test_ext_runtime_sendMessage.js
toolkit/components/extensions/test/xpcshell/test_ext_simple.js
toolkit/components/extensions/test/xpcshell/xpcshell.ini
--- a/toolkit/components/extensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest.ini
@@ -31,61 +31,54 @@ support-files =
   file_script_xhr.js
   file_sample.html
   redirection.sjs
   file_privilege_escalation.html
   file_ext_test_api_injection.js
   file_permission_xhr.html
   file_download.txt
 
-[test_ext_extension.html]
 [test_ext_inIncognitoContext_window.html]
 skip-if = os == 'android' # Android does not currently support windows.
-[test_ext_simple.html]
 [test_ext_geturl.html]
 [test_ext_background_canvas.html]
 [test_ext_content_security_policy.html]
 [test_ext_contentscript.html]
 skip-if = buildapp == 'b2g' # runat != document_idle is not supported.
 [test_ext_contentscript_api_injection.html]
 [test_ext_contentscript_create_iframe.html]
 [test_ext_contentscript_devtools_metadata.html]
 [test_ext_contentscript_css.html]
 [test_ext_downloads.html]
 [test_ext_exclude_include_globs.html]
 [test_ext_i18n_css.html]
 [test_ext_generate.html]
-[test_ext_idle.html]
 [test_ext_localStorage.html]
-[test_ext_onmessage_removelistener.html]
 [test_ext_notifications.html]
 [test_ext_permission_xhr.html]
 skip-if = buildapp == 'b2g' # JavaScript error: jar:remoteopenfile:///data/local/tmp/generated-extension.xpi!/content.js, line 46: NS_ERROR_ILLEGAL_VALUE:
 [test_ext_runtime_connect.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # port.sender.tab is undefined on b2g. Bug 1258975 on android.
 [test_ext_runtime_connect_twoway.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # port.sender.tab is undefined on b2g. Bug 1258975 on android.
 [test_ext_runtime_connect2.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # port.sender.tab is undefined on b2g. Bug 1258975 on android.
 [test_ext_runtime_disconnect.html]
-[test_ext_runtime_getPlatformInfo.html]
 [test_ext_runtime_id.html]
-[test_ext_runtime_sendMessage.html]
 [test_ext_sandbox_var.html]
 [test_ext_sendmessage_reply.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # sender.tab is undefined on b2g. Bug 1258975 on android.
 [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.html]
 [test_ext_storage_content.html]
 [test_ext_storage_tab.html]
 skip-if = os == 'android' # Android does not currently support tabs.
-[test_ext_background_runtime_connect_params.html]
 [test_ext_cookies.html]
 [test_ext_bookmarks.html]
 skip-if = (os == 'android' || buildapp == 'b2g') # unimplemented api. Bug 1258975 on android.
 [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]
rename from toolkit/components/extensions/test/mochitest/test_ext_background_runtime_connect_params.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_background_runtime_connect_params.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_background_runtime_connect_params.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_runtime_connect_params.js
@@ -1,21 +1,10 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>WebExtension test</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";
 
 function backgroundScript() {
   let detected_invalid_connect_params = 0;
   let received_ports_number = 0;
 
   const invalid_connect_params = [
     // too many params
@@ -55,27 +44,21 @@ function backgroundScript() {
   for (let params of invalid_connect_params) {
     assertInvalidConnectParamsException(params);
   }
 
   browser.runtime.connect(browser.runtime.id, {name: "check-results"});
 }
 
 let extensionData = {
-  background: "(" + backgroundScript.toString() + ")()",
+  background: backgroundScript,
   manifest: {},
   files: {},
 };
 
 add_task(function* test_backgroundRuntimeConnectParams() {
   let extension = ExtensionTestUtils.loadExtension(extensionData);
   yield extension.startup();
-  info("extension loaded");
 
   yield extension.awaitFinish("runtime.connect invalid params");
 
   yield extension.unload();
-  info("extension unloaded");
 });
-</script>
-
-</body>
-</html>
rename from toolkit/components/extensions/test/mochitest/test_ext_extension.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_extension.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_extension.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_extension.js
@@ -1,73 +1,55 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>WebExtension test</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* test_is_allowed_incognito_access() {
   function background() {
     browser.extension.isAllowedIncognitoAccess().then(isAllowedIncognitoAccess => {
       browser.test.assertEq(true, isAllowedIncognitoAccess, "isAllowedIncognitoAccess is true");
       browser.test.notifyPass("isAllowedIncognitoAccess");
     });
   }
 
   let extension = ExtensionTestUtils.loadExtension({
-    background: `(${background})()`,
+    background,
     manifest: {},
   });
 
   yield extension.startup();
   yield extension.awaitFinish("isAllowedIncognitoAccess");
   yield extension.unload();
 });
 
 add_task(function* test_in_incognito_context_false() {
   function background() {
     browser.test.assertEq(false, browser.extension.inIncognitoContext, "inIncognitoContext returned false");
     browser.test.notifyPass("inIncognitoContext");
   }
 
   let extension = ExtensionTestUtils.loadExtension({
-    background: `(${background})()`,
+    background,
     manifest: {},
   });
 
   yield extension.startup();
   yield extension.awaitFinish("inIncognitoContext");
   yield extension.unload();
 });
 
 add_task(function* test_is_allowed_file_scheme_access() {
-  function backgroundScript() {
+  function background() {
     browser.extension.isAllowedFileSchemeAccess().then(isAllowedFileSchemeAccess => {
       browser.test.assertEq(false, isAllowedFileSchemeAccess, "isAllowedFileSchemeAccess is false");
       browser.test.notifyPass("isAllowedFileSchemeAccess");
     });
   }
 
   let extension = ExtensionTestUtils.loadExtension({
-    background: `(${backgroundScript})()`,
+    background,
     manifest: {},
   });
 
   yield extension.startup();
-  info("extension loaded");
   yield extension.awaitFinish("isAllowedFileSchemeAccess");
   yield extension.unload();
-  info("extension unloaded");
 });
-
-</script>
-
-</body>
-</html>
rename from toolkit/components/extensions/test/mochitest/test_ext_idle.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_idle.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_idle.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_idle.js
@@ -1,43 +1,30 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>WebExtension idle API test</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* testIdle() {
   function background() {
     browser.idle.queryState(15).then(status => {
       browser.test.assertEq("active", status, "Expected status");
       browser.test.notifyPass("idle");
     },
     e => {
       browser.test.fail(`Error: ${e} :: ${e.stack}`);
       browser.test.notifyFail("idle");
     });
   }
 
   let extension = ExtensionTestUtils.loadExtension({
-    background: `(${background})()`,
+    background,
 
     manifest: {
       permissions: ["idle"],
     },
   });
 
   yield extension.startup();
 
   yield extension.awaitFinish("idle");
 
   yield extension.unload();
 });
-</script>
-</body>
rename from toolkit/components/extensions/test/mochitest/test_ext_onmessage_removelistener.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_onmessage_removelistener.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_onmessage_removelistener.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_onmessage_removelistener.js
@@ -1,21 +1,10 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>WebExtension test</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";
 
 function backgroundScript() {
   function listener() {
     browser.test.notifyFail("listener should not be invoked");
   }
 
   browser.runtime.onMessage.addListener(listener);
@@ -25,23 +14,17 @@ function backgroundScript() {
   // Make sure that, if we somehow fail to remove the listener, then we'll run
   // the listener before the test is marked as passing.
   setTimeout(function() {
     browser.test.notifyPass("onmessage_removelistener");
   }, 0);
 }
 
 let extensionData = {
-  background: "(" + backgroundScript.toString() + ")()",
+  background: backgroundScript,
 };
 
 add_task(function* test_contentscript() {
   let extension = ExtensionTestUtils.loadExtension(extensionData);
   yield extension.startup();
-  info("extension loaded");
   yield extension.awaitFinish("onmessage_removelistener");
   yield extension.unload();
-  info("extension unloaded");
 });
-</script>
-
-</body>
-</html>
rename from toolkit/components/extensions/test/mochitest/test_ext_runtime_getPlatformInfo.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_runtime_getPlatformInfo.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_runtime_getPlatformInfo.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_runtime_getPlatformInfo.js
@@ -1,40 +1,25 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>WebExtension test</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";
 
 function backgroundScript() {
   browser.runtime.getPlatformInfo(info => {
     let validOSs = ["mac", "win", "android", "cros", "linux", "openbsd", "gonk"];
     let validArchs = ["arm", "x86-32", "x86-64"];
 
     browser.test.assertTrue(validOSs.indexOf(info.os) != -1, "OS is valid");
     browser.test.assertTrue(validArchs.indexOf(info.arch) != -1, "Architecture is valid");
     browser.test.notifyPass("runtime.getPlatformInfo");
   });
 }
 
 let extensionData = {
-  background: "(" + backgroundScript.toString() + ")()",
+  background: backgroundScript,
 };
 
 add_task(function* test_contentscript() {
   let extension = ExtensionTestUtils.loadExtension(extensionData);
   yield extension.startup();
   yield extension.awaitFinish("runtime.getPlatformInfo");
   yield extension.unload();
 });
-</script>
-
-</body>
-</html>
rename from toolkit/components/extensions/test/mochitest/test_ext_runtime_sendMessage.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_runtime_sendMessage.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_runtime_sendMessage.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_runtime_sendMessage.js
@@ -1,21 +1,10 @@
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>WebExtension test</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* tabsSendMessageReply() {
   function background() {
     browser.runtime.onMessage.addListener((msg, sender, respond) => {
       if (msg == "respond-now") {
         respond(msg);
       } else if (msg == "respond-soon") {
@@ -67,19 +56,15 @@ add_task(function* tabsSendMessageReply(
       browser.test.notifyPass("sendMessage");
     }).catch(e => {
       browser.test.fail(`Error: ${e} :: ${e.stack}`);
       browser.test.notifyFail("sendMessage");
     });
   }
 
   let extension = ExtensionTestUtils.loadExtension({
-    background: `(${background})()`,
+    background,
   });
 
   yield extension.startup();
   yield extension.awaitFinish("sendMessage");
   yield extension.unload();
 });
-</script>
-
-</body>
-</html>
rename from toolkit/components/extensions/test/mochitest/test_ext_simple.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_simple.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_simple.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_simple.js
@@ -1,73 +1,52 @@
-<!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* test_simple() {
   let extensionData = {
     manifest: {
       "name": "Simple extension test",
       "version": "1.0",
       "manifest_version": 2,
       "description": "",
     },
   };
 
   let extension = ExtensionTestUtils.loadExtension(extensionData);
-  info("load complete");
   yield extension.startup();
-  info("startup complete");
   yield extension.unload();
-  info("extension unloaded successfully");
 });
 
 add_task(function* test_background() {
-  function backgroundScript() {
+  function background() {
     browser.test.log("running background script");
 
     browser.test.onMessage.addListener((x, y) => {
       browser.test.assertEq(x, 10, "x is 10");
       browser.test.assertEq(y, 20, "y is 20");
 
       browser.test.notifyPass("background test passed");
     });
 
     browser.test.sendMessage("running", 1);
   }
 
   let extensionData = {
-    background: "(" + backgroundScript.toString() + ")()",
+    background,
     manifest: {
       "name": "Simple extension test",
       "version": "1.0",
       "manifest_version": 2,
       "description": "",
     },
   };
 
   let extension = ExtensionTestUtils.loadExtension(extensionData);
-  info("load complete");
+
   let [, x] = yield Promise.all([extension.startup(), extension.awaitMessage("running")]);
-  is(x, 1, "got correct value from extension");
-  info("startup complete");
+  equal(x, 1, "got correct value from extension");
+
   extension.sendMessage(10, 20);
   yield extension.awaitFinish();
-  info("test complete");
   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
@@ -1,19 +1,26 @@
 [DEFAULT]
 head = head.js
 tail =
 firefox-appdir = browser
 skip-if = toolkit == 'gonk' || appname == "thunderbird"
 
-[test_ext_alarms.js]
 [test_csp_custom_policies.js]
 [test_csp_validator.js]
-[test_locale_data.js]
-[test_locale_converter.js]
+[test_ext_alarms.js]
+[test_ext_background_runtime_connect_params.js]
 [test_ext_contexts.js]
+[test_ext_extension.js]
+[test_ext_idle.js]
 [test_ext_json_parser.js]
 [test_ext_manifest_content_security_policy.js]
 [test_ext_manifest_incognito.js]
+[test_ext_onmessage_removelistener.js]
+[test_ext_runtime_getPlatformInfo.js]
+[test_ext_runtime_sendMessage.js]
 [test_ext_schemas.js]
+[test_ext_simple.js]
 [test_getAPILevelForWindow.js]
+[test_locale_converter.js]
+[test_locale_data.js]
 [test_native_messaging.js]
 skip-if = os == "android"