Bug 1295324 Test for content scripts with mozAddonManager r=kmag
authorAndrew Swan <aswan@mozilla.com>
Fri, 07 Oct 2016 12:54:03 -0700
changeset 452495 ab439ec85d1556fdeaf5aafb5261bfa452a69f4e
parent 452494 c3861ac69c78994cf478e07ce467880f881d7a45
child 452496 ae0c5117b7b0254f9f0aa969b46836ebe570b960
child 452614 b6fc4e878493f949125b6adae8a7b0ed1628d44f
child 453494 6ca89ce8ef77252189a98facce2941c328dcf159
child 453510 3475a52bbcd358c8f8c2177e162fa50795d5b821
child 453616 2d6f0aa2c2c7df6b7999a1aee7d1aae2428b0f35
child 453617 b5ab6471f0c8cdf067ea9480429be9242e2f16dc
push id39415
push usermozilla@noorenberghe.ca
push dateWed, 21 Dec 2016 20:49:14 +0000
reviewerskmag
bugs1295324
milestone53.0a1
Bug 1295324 Test for content scripts with mozAddonManager r=kmag MozReview-Commit-ID: BN9HKaHkbuC
toolkit/components/extensions/test/mochitest/mochitest-common.ini
toolkit/components/extensions/test/mochitest/test_ext_contentscript_permission.html
--- a/toolkit/components/extensions/test/mochitest/mochitest-common.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest-common.ini
@@ -50,16 +50,17 @@ skip-if = os == 'android' # Android does
 [test_ext_contentscript_context.html]
 [test_ext_contentscript_create_iframe.html]
 [test_ext_contentscript_devtools_metadata.html]
 [test_ext_contentscript_exporthelpers.html]
 [test_ext_contentscript_incognito.html]
 skip-if = os == 'android' # Android does not multiple windows.
 [test_ext_contentscript_css.html]
 [test_ext_contentscript_about_blank.html]
+[test_ext_contentscript_permission.html]
 [test_ext_contentscript_teardown.html]
 skip-if = (os == 'android') # Android does not support tabs API. Bug 1260250
 [test_ext_exclude_include_globs.html]
 [test_ext_i18n_css.html]
 [test_ext_generate.html]
 [test_ext_notifications.html]
 [test_ext_permission_xhr.html]
 [test_ext_runtime_connect.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_ext_contentscript_permission.html
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for content script</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">
+"use strict";
+
+add_task(function* test_contentscript() {
+  function background() {
+    browser.test.onMessage.addListener(url => {
+      browser.tabs.create({url}).then(tab => {
+        return browser.tabs.executeScript(tab.id, {code: "true;"})
+                      .then(() => {
+                        browser.test.sendMessage("executed", true);
+                        browser.tabs.remove([tab.id]);
+                      }, err => {
+                        browser.test.sendMessage("executed", false);
+                        browser.tabs.remove([tab.id]);
+                      });
+      });
+    });
+  }
+
+  let extensionData = {
+    manifest: {
+      permissions: ["<all_urls>"],
+    },
+    background,
+  };
+
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+  yield extension.startup();
+
+  extension.sendMessage("https://example.com");
+  let result = yield extension.awaitMessage("executed");
+  is(result, true, "Content script can be run in a page without mozAddonManager");
+
+  yield SpecialPowers.pushPrefEnv({
+    set: [["extensions.webapi.testing", true]],
+  });
+
+  extension.sendMessage("https://example.com");
+  result = yield extension.awaitMessage("executed");
+  is(result, false, "Content script cannot be run in a page with mozAddonManager");
+
+  yield extension.unload();
+});
+</script>
+
+</body>
+</html>