Bug 1295324 Test for content scripts with mozAddonManager r=kmag
authorAndrew Swan <aswan@mozilla.com>
Fri, 07 Oct 2016 12:54:03 -0700
changeset 326965 ab439ec85d1556fdeaf5aafb5261bfa452a69f4e
parent 326964 c3861ac69c78994cf478e07ce467880f881d7a45
child 326966 b6fc4e878493f949125b6adae8a7b0ed1628d44f
push id31116
push userkwierso@gmail.com
push dateFri, 23 Dec 2016 02:37:16 +0000
treeherdermozilla-central@2785aaf276ba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1295324
milestone53.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 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>