Bug 1374672 - Return early if event for page load is uninteresting. r=automatedtester
authorHenrik Skupin <mail@hskupin.info>
Fri, 07 Jul 2017 16:38:41 +0200
changeset 368144 f6817b119e1c847e83c5fac110b555ac5c53418f
parent 368143 555bd3e550b570f313468101f281da1c4c342211
child 368145 914fc90581c481dc80b97da80e22b42c69f1068d
push id32158
push usercbook@mozilla.com
push dateTue, 11 Jul 2017 10:48:59 +0000
treeherdermozilla-central@5e2692f8a367 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester
bugs1374672
milestone56.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 1374672 - Return early if event for page load is uninteresting. r=automatedtester While observing page loads the only interesting events are for the current browsing context, and its document. While most events have the document as target, and bubble up, the hashchange event only fires for the window. MozReview-Commit-ID: CiqkV4DuH48
testing/marionette/listener.js
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -217,46 +217,51 @@ var loadListener = {
       Services.obs.removeObserver(this, "outer-window-destroyed");
     } catch (e) {}
   },
 
   /**
    * Callback for registered DOM events.
    */
   handleEvent(event) {
+    // Only care about events from the currently selected browsing context,
+    // whereby some of those do not bubble up to the window.
+    if (event.target != curContainer.frame &&
+        event.target != curContainer.frame.document) {
+      return;
+    }
+
     let location = event.target.documentURI || event.target.location.href;
     logger.debug(`Received DOM event "${event.type}" for "${location}"`);
 
     switch (event.type) {
       case "beforeunload":
         this.seenBeforeUnload = true;
         break;
 
       case "unload":
         this.seenUnload = true;
         break;
 
       case "pagehide":
-        if (event.target === curContainer.frame.document) {
-          this.seenUnload = true;
+        this.seenUnload = true;
+
+        removeEventListener("hashchange", this);
+        removeEventListener("pagehide", this);
 
-          removeEventListener("hashchange", this);
-          removeEventListener("pagehide", this);
+        // Now wait until the target page has been loaded
+        addEventListener("DOMContentLoaded", this, false);
+        addEventListener("pageshow", this, false);
 
-          // Now wait until the target page has been loaded
-          addEventListener("DOMContentLoaded", this, false);
-          addEventListener("pageshow", this, false);
-        }
         break;
 
       case "hashchange":
-        if (event.target === curContainer.frame) {
-          this.stop();
-          sendOk(this.command_id);
-        }
+        this.stop();
+        sendOk(this.command_id);
+
         break;
 
       case "DOMContentLoaded":
         if (event.target.documentURI.startsWith("about:certerror")) {
           this.stop();
           sendError(new InsecureCertificateError(), this.command_id);
 
         } else if (/about:.*(error)\?/.exec(event.target.documentURI)) {
@@ -268,23 +273,23 @@ var loadListener = {
         // special-case about:blocked pages which should be treated as
         // non-error pages but do not raise a pageshow event.
         } else if ((capabilities.get("pageLoadStrategy") ===
             session.PageLoadStrategy.Eager) ||
             /about:blocked\?/.exec(event.target.documentURI)) {
           this.stop();
           sendOk(this.command_id);
         }
+
         break;
 
       case "pageshow":
-        if (event.target === curContainer.frame.document) {
-          this.stop();
-          sendOk(this.command_id);
-        }
+        this.stop();
+        sendOk(this.command_id);
+
         break;
     }
   },
 
   /**
    * Callback for navigation timeout timer.
    */
   notify(timer) {