Bug 1199832 - [webext] browser.tabs.executeScript must create a context (r=gabor)
authorBill McCloskey <billm@mozilla.com>
Fri, 28 Aug 2015 16:00:40 -0700
changeset 260932 03e18dc3de5060a9f8428d0fe28b8e017f5c2285
parent 260931 56c54e7c4006cf6cb6e68f681de01622028d4bc3
child 260933 6ede4c1ffefd73719209163ba9fe0b3cd9f7993d
push id64624
push userwmccloskey@mozilla.com
push dateFri, 04 Sep 2015 16:45:15 +0000
treeherdermozilla-inbound@3be72de9ac6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1199832
milestone43.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 1199832 - [webext] browser.tabs.executeScript must create a context (r=gabor)
browser/components/extensions/test/browser/browser.ini
browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js
toolkit/components/extensions/ExtensionContent.jsm
--- a/browser/components/extensions/test/browser/browser.ini
+++ b/browser/components/extensions/test/browser/browser.ini
@@ -1,3 +1,4 @@
 [browser_extensions_simple.js]
+[browser_ext_tabs_executeScript.js]
 [browser_ext_tabs_query.js]
 [browser_ext_tabs_update.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js
@@ -0,0 +1,32 @@
+add_task(function* () {
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "http://mochi.test:8888/");
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "permissions": ["tabs"]
+    },
+
+    background: function() {
+      browser.runtime.onMessage.addListener((msg, sender) => {
+        browser.test.assertEq(msg, "script ran", "script ran");
+        browser.test.notifyPass("executeScript");
+      });
+
+      browser.tabs.executeScript({
+        file: "script.js"
+      });
+    },
+
+    files: {
+      "script.js": function() {
+        browser.runtime.sendMessage("script ran");
+      }
+    }
+  });
+
+  yield extension.startup();
+  yield extension.awaitFinish("executeScript");
+  yield extension.unload();
+
+  yield BrowserTestUtils.removeTab(tab);
+});
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -331,21 +331,17 @@ let DocumentManager = {
       this.trigger("document_end", window);
     } else if (event.type == "load") {
       this.trigger("document_idle", window);
     }
   },
 
   executeScript(global, extensionId, script) {
     let window = global.content;
-    let extensions = this.windows.get(window);
-    if (!extensions) {
-      return;
-    }
-    let context = extensions.get(extensionId);
+    let context = this.getContext(extensionId, window);
     if (!context) {
       return;
     }
 
     // TODO: Somehow make sure we have the right permissions for this origin!
 
     // FIXME: Script should be executed only if current state has
     // already reached its run_at state, or we have to keep it around