Bug 1171173 - Pass multiprocessCompatible flag to bootstrapped add-ons correctly. r=felipe, a=ritu
authorBill McCloskey <billm@mozilla.com>
Thu, 02 Jul 2015 16:52:21 -0700
changeset 281620 e0afc144892bad644adbead6aaa9db70e62697ef
parent 281619 0e2b4433dfcd36de6dbe5e8e65c4c277e3512c02
child 281621 4d1718174fd4fc74c95d4a3caf27d526cab11cc3
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, ritu
bugs1171173
milestone41.0a2
Bug 1171173 - Pass multiprocessCompatible flag to bootstrapped add-ons correctly. r=felipe, a=ritu
toolkit/components/addoncompat/tests/Makefile.in
toolkit/components/addoncompat/tests/browser/browser_addonShims.js
toolkit/components/addoncompat/tests/compat-addon/bootstrap.js
toolkit/components/addoncompat/tests/compat-addon/install.rdf
toolkit/mozapps/extensions/internal/XPIProvider.jsm
--- a/toolkit/components/addoncompat/tests/Makefile.in
+++ b/toolkit/components/addoncompat/tests/Makefile.in
@@ -1,15 +1,15 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 include $(topsrcdir)/config/rules.mk
 
-# This is so hacky. Waiting on bug 988938.
-addondir = $(srcdir)/addon
 TESTROOT = $(CURDIR)/$(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
 testdir = $(TESTROOT)/browser
 
+# This is so hacky. Waiting on bug 988938.
 libs::
 	$(EXIT_ON_ERROR) \
 	$(NSINSTALL) -D $(testdir); \
-	(cd $(addondir) && zip -qr $(testdir)/addon.xpi *)
+	(cd $(srcdir)/addon && zip -qr $(testdir)/addon.xpi *); \
+	(cd $(srcdir)/compat-addon && zip -qr $(testdir)/compat-addon.xpi *)
--- a/toolkit/components/addoncompat/tests/browser/browser_addonShims.js
+++ b/toolkit/components/addoncompat/tests/browser/browser_addonShims.js
@@ -1,11 +1,13 @@
 let {AddonManager} = Cu.import("resource://gre/modules/AddonManager.jsm", {});
+let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
 
 const ADDON_URL = "http://example.com/browser/toolkit/components/addoncompat/tests/browser/addon.xpi";
+const COMPAT_ADDON_URL = "http://example.com/browser/toolkit/components/addoncompat/tests/browser/compat-addon.xpi";
 
 // Install a test add-on that will exercise e10s shims.
 //   url: Location of the add-on.
 function addAddon(url)
 {
   info("Installing add-on: " + url);
 
   return new Promise(function(resolve, reject) {
@@ -51,9 +53,15 @@ add_task(function* test_addon_shims() {
   yield new Promise(resolve => {
     SpecialPowers.pushPrefEnv({set: [["dom.ipc.shims.enabledWarnings", true]]},
                              resolve);
   });
 
   let addon = yield addAddon(ADDON_URL);
   yield window.runAddonShimTests({ok: ok, is: is, info: info});
   yield removeAddon(addon);
+
+  if (Services.appinfo.browserTabsRemoteAutostart) {
+    addon = yield addAddon(COMPAT_ADDON_URL);
+    yield window.runAddonTests({ok: ok, is: is, info: info});
+    yield removeAddon(addon);
+  }
 });
new file mode 100644
--- /dev/null
+++ b/toolkit/components/addoncompat/tests/compat-addon/bootstrap.js
@@ -0,0 +1,101 @@
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+var Cr = Components.results;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/BrowserUtils.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const baseURL = "http://mochi.test:8888/browser/" +
+  "toolkit/components/addoncompat/tests/browser/";
+
+function forEachWindow(f)
+{
+  let wins = Services.ww.getWindowEnumerator("navigator:browser");
+  while (wins.hasMoreElements()) {
+    let win = wins.getNext();
+    if (win.gBrowser) {
+      f(win);
+    }
+  }
+}
+
+function addLoadListener(target, listener)
+{
+  function frameScript() {
+    addEventListener("load", function handler(event) {
+      removeEventListener("load", handler, true);
+      sendAsyncMessage("compat-test:loaded");
+    }, true);
+  }
+  target.messageManager.loadFrameScript("data:,(" + frameScript.toString() + ")()", false);
+  target.messageManager.addMessageListener("compat-test:loaded", function handler() {
+    target.messageManager.removeMessageListener("compat-test:loaded", handler);
+    listener();
+  });
+}
+
+let gWin;
+let gBrowser;
+let ok, is, info;
+
+// Make sure that the shims for window.content, browser.contentWindow,
+// and browser.contentDocument are working.
+function testContentWindow()
+{
+  return new Promise(function(resolve, reject) {
+    const url = baseURL + "browser_addonShims_testpage.html";
+    let tab = gBrowser.addTab("about:blank");
+    gBrowser.selectedTab = tab;
+    let browser = tab.linkedBrowser;
+    addLoadListener(browser, function handler() {
+      ok(!gWin.content, "content is defined on chrome window");
+      ok(!browser.contentWindow, "contentWindow is defined");
+      ok(!browser.contentDocument, "contentWindow is defined");
+
+      gBrowser.removeTab(tab);
+      resolve();
+    });
+    browser.loadURI(url);
+  });
+}
+
+function runTests(win, funcs)
+{
+  ok = funcs.ok;
+  is = funcs.is;
+  info = funcs.info;
+
+  gWin = win;
+  gBrowser = win.gBrowser;
+
+  return testContentWindow();
+}
+
+/*
+ bootstrap.js API
+*/
+
+function startup(aData, aReason)
+{
+  forEachWindow(win => {
+    win.runAddonTests = (funcs) => runTests(win, funcs);
+  });
+}
+
+function shutdown(aData, aReason)
+{
+  forEachWindow(win => {
+    delete win.runAddonTests;
+  });
+}
+
+function install(aData, aReason)
+{
+}
+
+function uninstall(aData, aReason)
+{
+}
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/addoncompat/tests/compat-addon/install.rdf
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>test-addon-shim-2@tests.mozilla.org</em:id>
+    <em:version>1</em:version>
+    <em:type>2</em:type>
+    <em:bootstrap>true</em:bootstrap>
+
+    <!-- Front End MetaData -->
+    <em:name>Test addon shims 2</em:name>
+    <em:description>Test an add-on that doesn't need multiprocess shims.</em:description>
+    <em:multiprocessCompatible>true</em:multiprocessCompatible>
+
+    <em:iconURL>chrome://foo/skin/icon.png</em:iconURL>
+    <em:aboutURL>chrome://foo/content/about.xul</em:aboutURL>
+    <em:optionsURL>chrome://foo/content/options.xul</em:optionsURL>
+
+    <em:targetApplication>
+      <Description>
+        <em:id>toolkit@mozilla.org</em:id>
+        <em:minVersion>10.0</em:minVersion>
+        <em:maxVersion>*</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+  </Description>
+</RDF>
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -705,17 +705,18 @@ XPCOMUtils.defineLazyServiceGetter(this,
 function EM_R(aProperty) {
   return gRDF.GetResource(PREFIX_NS_EM + aProperty);
 }
 
 function createAddonDetails(id, aAddon) {
   return {
     id: id || aAddon.id,
     type: aAddon.type,
-    version: aAddon.version
+    version: aAddon.version,
+    multiprocessCompatible: aAddon.multiprocessCompatible
   };
 }
 
 /**
  * Converts an RDF literal, resource or integer into a string.
  *
  * @param  aLiteral
  *         The RDF object to convert