Bug 1472136 - Detect XML parsing errors during Marionette startup. draft
authorHenrik Skupin <mail@hskupin.info>
Fri, 29 Jun 2018 13:14:32 +0200
changeset 812447 11c74bfa5cb246ba6a45646896dc01728257d2aa
parent 812437 bf149090f6b5db3fe86618b5f1047b70b1bff8b5
push id114550
push userbmo:hskupin@gmail.com
push dateFri, 29 Jun 2018 11:21:55 +0000
bugs1472136
milestone63.0a1
Bug 1472136 - Detect XML parsing errors during Marionette startup. The patch lets Marionette detect a XML parser error window during startup, which usually leaves the browser in an unusable state. Marionette client then times out after 120s with a generic and not helpful error message. In case such a window opens Marionette logs a fatal message to the console, which then can be picked-up by Treeherder for the failure summary. MozReview-Commit-ID: L3zW3TcaJhE
testing/marionette/components/marionette.js
--- a/testing/marionette/components/marionette.js
+++ b/testing/marionette/components/marionette.js
@@ -18,16 +18,18 @@ XPCOMUtils.defineLazyModuleGetters(this,
   TCPListener: "chrome://marionette/content/server.js",
 });
 
 XPCOMUtils.defineLazyGetter(this, "log", Log.get);
 
 XPCOMUtils.defineLazyServiceGetter(
     this, "env", "@mozilla.org/process/environment;1", "nsIEnvironment");
 
+const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml";
+
 const NOTIFY_RUNNING = "remote-active";
 
 // Complements -marionette flag for starting the Marionette server.
 // We also set this if Marionette is running in order to start the server
 // again after a Firefox restart.
 const ENV_ENABLED = "MOZ_MARIONETTE";
 const PREF_ENABLED = "marionette.enabled";
 
@@ -314,16 +316,17 @@ class MarionetteParentProcess {
         } else {
           this.uninit();
         }
         break;
 
       case "profile-after-change":
         Services.obs.addObserver(this, "command-line-startup");
         Services.obs.addObserver(this, "sessionstore-windows-restored");
+        Services.obs.addObserver(this, "toplevel-window-ready");
 
         for (let [pref, value] of EnvironmentPrefs.from(ENV_PRESERVE_PREFS)) {
           Preferences.set(pref, value);
         }
         break;
 
       // In safe mode the command line handlers are getting parsed after the
       // safe mode dialog has been closed. To allow Marionette to start
@@ -354,18 +357,32 @@ class MarionetteParentProcess {
         }
         break;
 
       case "domwindowopened":
         Services.obs.removeObserver(this, topic);
         this.suppressSafeModeDialog(subject);
         break;
 
+      case "toplevel-window-ready":
+        subject.addEventListener("load", ev => {
+          if (ev.target.documentElement.namespaceURI == XMLURI_PARSE_ERROR) {
+            Services.obs.removeObserver(this, topic);
+
+            let parserError = ev.target.querySelector("parsererror");
+            log.fatal(parserError.textContent);
+            this.uninit();
+            Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
+          }
+        }, {once: true});
+        break;
+
       case "sessionstore-windows-restored":
         Services.obs.removeObserver(this, topic);
+        Services.obs.removeObserver(this, "toplevel-window-ready");
 
         // When Firefox starts on Windows, an additional GFX sanity test
         // window may appear off-screen.  Marionette should wait for it
         // to close.
         let winEn = Services.wm.getEnumerator(null);
         while (winEn.hasMoreElements()) {
           let win = winEn.getNext();
           if (win.document.documentURI == "chrome://gfxsanity/content/sanityparent.html") {