Bug 1315611 - Ignore GFX sanity check window during startup of Firefox. r=ato, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Tue, 07 Mar 2017 19:38:51 +0100
changeset 379398 0c8604d19f4a6908cab007b06241be907a87eeba
parent 379397 05ed2e45839dd668c2fcb3ae81a9276cc6349272
child 379399 a7cd0fc138fbf8f91f5ba95bcb76972639f879b5
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1315611
milestone53.0
Bug 1315611 - Ignore GFX sanity check window during startup of Firefox. r=ato, a=test-only On Windows systems an additional chrome window will be opened during startup. It's used for testing specific GFX related features. It's located off-screen and will usually be closed immediately. But in some situations it can take longer. To avoid an inconsistent list of start window handles Marionette should wait with starting the test until this window has actually been closed. MozReview-Commit-ID: Izh3dPQSHC
testing/marionette/components/marionette.js
testing/marionette/driver.js
--- a/testing/marionette/components/marionette.js
+++ b/testing/marionette/components/marionette.js
@@ -50,16 +50,17 @@ MarionetteComponent.prototype = {
   contractID: MARIONETTE_CONTRACTID,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler, Ci.nsIObserver]),
   _xpcom_categories: [
     {category: "command-line-handler", entry: "b-marionette"},
     {category: "profile-after-change", service: true}
   ],
   enabled: false,
   finalUiStartup: false,
+  gfxWindow: null,
   server: null,
 };
 
 MarionetteComponent.prototype.setupLogger_ = function (level) {
   let log = Log.repository.getLogger("Marionette");
   log.level = level;
   log.addAppender(new Log.DumpAppender());
   return log;
@@ -108,49 +109,78 @@ MarionetteComponent.prototype.handle = f
   // if the CLI is there then lets do work otherwise nothing to see
   if (cmdLine.handleFlag("marionette", false)) {
     this.enabled = true;
     this.logger.debug("Marionette enabled via command-line flag");
     this.init();
   }
 };
 
-MarionetteComponent.prototype.observe = function (subj, topic, data) {
+MarionetteComponent.prototype.observe = function (subject, topic, data) {
   switch (topic) {
     case "profile-after-change":
+      // Using sessionstore-windows-restored as the xpcom category doesn't seem to work,
+      // so we wait for that by adding an observer here.
+      this.observerService.addObserver(this, "sessionstore-windows-restored", false);
+
       this.maybeReadPrefsFromEnvironment();
-      // Using final-ui-startup as the xpcom category doesn't seem to work,
-      // so we wait for that by adding an observer here.
-      this.observerService.addObserver(this, "final-ui-startup", false);
+
 #ifdef ENABLE_MARIONETTE
       this.enabled = Preferences.get(ENABLED_PREF, false);
       if (this.enabled) {
         this.logger.debug("Marionette enabled via build flag and pref");
 
         // We want to suppress the modal dialog that's shown
         // when starting up in safe-mode to enable testing.
         if (Services.appinfo.inSafeMode) {
           this.observerService.addObserver(this, "domwindowopened", false);
         }
       }
 #endif
       break;
 
-    case "final-ui-startup":
-      this.finalUiStartup = true;
-      this.observerService.removeObserver(this, topic);
-      this.observerService.addObserver(this, "xpcom-shutdown", false);
-      this.init();
+    case "domwindowclosed":
+      if (this.gfxWindow === null || subject === this.gfxWindow) {
+        this.observerService.removeObserver(this, topic);
+
+        this.observerService.addObserver(this, "xpcom-shutdown", false);
+        this.finalUiStartup = true;
+        this.init();
+      }
       break;
 
     case "domwindowopened":
       this.observerService.removeObserver(this, topic);
       this.suppressSafeModeDialog_(subj);
       break;
 
+    case "sessionstore-windows-restored":
+      this.observerService.removeObserver(this, topic);
+
+      // 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") {
+          this.gfxWindow = win;
+          break;
+        }
+      }
+
+      if (this.gfxWindow) {
+        this.observerService.addObserver(this, "domwindowclosed", false);
+      } else {
+        this.observerService.addObserver(this, "xpcom-shutdown", false);
+        this.finalUiStartup = true;
+        this.init();
+      }
+
+      break;
+
     case "xpcom-shutdown":
       this.observerService.removeObserver(this, "xpcom-shutdown");
       this.uninit();
       break;
   }
 };
 
 MarionetteComponent.prototype.maybeReadPrefsFromEnvironment = function() {
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -36,17 +36,17 @@ Cu.import("chrome://marionette/content/m
 Cu.import("chrome://marionette/content/proxy.js");
 Cu.import("chrome://marionette/content/session.js");
 Cu.import("chrome://marionette/content/simpletest.js");
 Cu.import("chrome://marionette/content/wait.js");
 
 this.EXPORTED_SYMBOLS = ["GeckoDriver", "Context"];
 
 var FRAME_SCRIPT = "chrome://marionette/content/listener.js";
-const BROWSER_STARTUP_FINISHED = "browser-delayed-startup-finished";
+
 const CLICK_TO_START_PREF = "marionette.debugging.clicktostart";
 const CONTENT_LISTENER_PREF = "marionette.contentListener";
 
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 const SUPPORTED_STRATEGIES = new Set([
   element.Strategy.ClassName,
   element.Strategy.Selector,
@@ -65,23 +65,16 @@ const globalMessageManager = Cc["@mozill
 // API's are ready; see bug 792647.  This assumes that marionette-server.js
 // will be loaded before the 'system-message-listener-ready' message
 // is fired.  If this stops being true, this approach will have to change.
 var systemMessageListenerReady = false;
 Services.obs.addObserver(function() {
   systemMessageListenerReady = true;
 }, "system-message-listener-ready", false);
 
-// This is used on desktop to prevent newSession from returning before a page
-// load initiated by the Firefox command line has completed.
-var delayedBrowserStarted = false;
-Services.obs.addObserver(function () {
-  delayedBrowserStarted = true;
-}, BROWSER_STARTUP_FINISHED, false);
-
 this.Context = {
   CHROME: "chrome",
   CONTENT: "content",
 };
 
 this.Context.fromString = function (s) {
   s = s.toUpperCase();
   if (s in this) {
@@ -617,39 +610,27 @@ GeckoDriver.prototype.newSession = funct
         let pService = Cc["@mozilla.org/embedcomp/prompt-service;1"]
             .getService(Ci.nsIPromptService);
         pService.alert(win, "", "Click to start execution of marionette tests");
       }
       this.startBrowser(win, true);
     }
   };
 
-  let runSessionStart = function() {
-    if (!Preferences.get(CONTENT_LISTENER_PREF)) {
-      waitForWindow.call(this);
-    } else if (this.appName != "Firefox" && this.curBrowser === null) {
-      // if there is a content listener, then we just wake it up
-      this.addBrowser(this.getCurrentWindow());
-      this.curBrowser.startSession(this.whenBrowserStarted.bind(this));
-      this.mm.broadcastAsyncMessage("Marionette:restart", {});
-    } else {
-      throw new WebDriverError("Session already running");
-    }
-    this.switchToGlobalMessageManager();
-  };
-
-  if (!delayedBrowserStarted && this.appName != "B2G") {
-    let self = this;
-    Services.obs.addObserver(function onStart() {
-      Services.obs.removeObserver(onStart, BROWSER_STARTUP_FINISHED);
-      runSessionStart.call(self);
-    }, BROWSER_STARTUP_FINISHED, false);
+  if (!Preferences.get(CONTENT_LISTENER_PREF)) {
+    waitForWindow.call(this);
+  } else if (this.appName != "Firefox" && this.curBrowser === null) {
+    // if there is a content listener, then we just wake it up
+    this.addBrowser(this.getCurrentWindow());
+    this.curBrowser.startSession(this.whenBrowserStarted.bind(this));
+    this.mm.broadcastAsyncMessage("Marionette:restart", {});
   } else {
-    runSessionStart.call(this);
+    throw new WebDriverError("Session already running");
   }
+  this.switchToGlobalMessageManager();
 
   yield registerBrowsers;
   yield browserListening;
 
   if (this.curBrowser.tab) {
     browser.getBrowserForTab(this.curBrowser.tab).focus();
   }