Bug 1484326 - Load customElements.js even for windowless browsers in xpcshell tests;r=kmag
authorBrian Grinstead <bgrinstead@mozilla.com>
Mon, 20 Aug 2018 16:22:47 +0000
changeset 487470 c218b23035ed1417b50aa32b03cb4145ac44b887
parent 487469 9c1fc2ff3a2f5b7a96116cda06612550c1d167f1
child 487471 48c49635edb98eaa43f025d8e5f6ee79304c42c0
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1484326
milestone63.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 1484326 - Load customElements.js even for windowless browsers in xpcshell tests;r=kmag Differential Revision: https://phabricator.services.mozilla.com/D3660
browser/base/content/test/performance/browser_startup.js
toolkit/components/extensions/ExtensionXPCShellUtils.jsm
toolkit/components/processsingleton/CustomElementsListener.jsm
toolkit/components/processsingleton/MainProcessSingleton.js
toolkit/components/processsingleton/moz.build
--- a/browser/base/content/test/performance/browser_startup.js
+++ b/browser/base/content/test/performance/browser_startup.js
@@ -31,16 +31,17 @@ const startupPhases = {
       "MainProcessSingleton.js",
 
       // Bugs to fix: The following components shouldn't be initialized that early.
       "PushComponents.js", // bug 1369436
     ]),
     modules: new Set([
       "resource://gre/modules/AppConstants.jsm",
       "resource://gre/modules/ActorManagerParent.jsm",
+      "resource://gre/modules/CustomElementsListener.jsm",
       "resource://gre/modules/ExtensionUtils.jsm",
       "resource://gre/modules/XPCOMUtils.jsm",
       "resource://gre/modules/Services.jsm",
     ])
   }},
 
   // For the following phases of startup we have only a black list for now
 
--- a/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
+++ b/toolkit/components/extensions/ExtensionXPCShellUtils.jsm
@@ -6,16 +6,19 @@
 "use strict";
 
 var EXPORTED_SYMBOLS = ["ExtensionTestUtils"];
 
 ChromeUtils.import("resource://gre/modules/ActorManagerParent.jsm");
 ChromeUtils.import("resource://gre/modules/ExtensionUtils.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
+// Windowless browsers can create documents that rely on XUL Custom Elements:
+ChromeUtils.import("resource://gre/modules/CustomElementsListener.jsm", null);
+
 ChromeUtils.defineModuleGetter(this, "AddonManager",
                                "resource://gre/modules/AddonManager.jsm");
 ChromeUtils.defineModuleGetter(this, "AddonTestUtils",
                                "resource://testing-common/AddonTestUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "ContentTask",
                                "resource://testing-common/ContentTask.jsm");
 ChromeUtils.defineModuleGetter(this, "Extension",
                                "resource://gre/modules/Extension.jsm");
new file mode 100644
--- /dev/null
+++ b/toolkit/components/processsingleton/CustomElementsListener.jsm
@@ -0,0 +1,22 @@
+/* -*-  indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* 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/. */
+
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+// Set up Custom Elements for XUL and XHTML documents before anything else
+// happens. Anything loaded here should be considered part of core XUL functionality.
+// Any window-specific elements can be registered via <script> tags at the
+// top of individual documents.
+Services.obs.addObserver({
+  observe(doc) {
+    if (doc.nodePrincipal.isSystemPrincipal && (
+      doc.contentType == "application/vnd.mozilla.xul+xml" ||
+      doc.contentType == "application/xhtml+xml"
+    )) {
+      Services.scriptloader.loadSubScript(
+        "chrome://global/content/customElements.js", doc.ownerGlobal);
+    }
+  }
+}, "document-element-inserted");
--- a/toolkit/components/processsingleton/MainProcessSingleton.js
+++ b/toolkit/components/processsingleton/MainProcessSingleton.js
@@ -55,44 +55,28 @@ MainProcessSingleton.prototype = {
 
       Services.search.addEngine(engineURL.spec, null, iconURL ? iconURL.spec : null, true);
     });
   },
 
   observe(subject, topic, data) {
     switch (topic) {
     case "app-startup": {
+      ChromeUtils.import("resource://gre/modules/CustomElementsListener.jsm", null);
       Services.obs.addObserver(this, "xpcom-shutdown");
-      Services.obs.addObserver(this, "document-element-inserted");
 
       // Load this script early so that console.* is initialized
       // before other frame scripts.
       Services.mm.loadFrameScript("chrome://global/content/browser-content.js", true, true);
       Services.ppmm.loadProcessScript("chrome://global/content/process-content.js", true, true);
       Services.mm.addMessageListener("Search:AddEngine", this.addSearchEngine);
       Services.ppmm.loadProcessScript("resource:///modules/ContentObservers.js", true);
       break;
     }
 
-    case "document-element-inserted":
-      // Set up Custom Elements for XUL and XHTML documents before anything else
-      // happens. Anything loaded here should be considered part of core XUL functionality.
-      // Any window-specific elements can be registered via <script> tags at the
-      // top of individual documents.
-      const doc = subject;
-      if (doc.nodePrincipal.isSystemPrincipal && (
-            doc.contentType == "application/vnd.mozilla.xul+xml" ||
-            doc.contentType == "application/xhtml+xml"
-        )) {
-        Services.scriptloader.loadSubScript(
-          "chrome://global/content/customElements.js", doc.ownerGlobal);
-      }
-      break;
-
     case "xpcom-shutdown":
       Services.mm.removeMessageListener("Search:AddEngine", this.addSearchEngine);
-      Services.obs.removeObserver(this, "document-element-inserted");
       break;
     }
   },
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MainProcessSingleton]);
--- a/toolkit/components/processsingleton/moz.build
+++ b/toolkit/components/processsingleton/moz.build
@@ -7,8 +7,12 @@
 with Files('**'):
     BUG_COMPONENT = ('Toolkit', 'General')
 
 EXTRA_COMPONENTS += [
     'ContentProcessSingleton.js',
     'MainProcessSingleton.js',
     'ProcessSingleton.manifest',
 ]
+
+EXTRA_JS_MODULES += [
+    'CustomElementsListener.jsm',
+]