Bug 1322772 - Poll for ready state on web progress stop state for image documents; r=maja_zf,whimboo a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 09 Dec 2016 14:33:16 -1000
changeset 366121 20c1ed9c6d76e6bfff8eac616305fbda059acc2c
parent 366120 8749c6b1cd970896c1ad84cc4ac05a245b19426b
child 366122 d01aa3ae2908a2882dbcc71c7e3b26ee74900526
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, whimboo, test-only
bugs1322772
milestone52.0a2
Bug 1322772 - Poll for ready state on web progress stop state for image documents; r=maja_zf,whimboo a=test-only Image documents do not fire DOMContentLoaded events, but we can use the web progress listener to call the ready state checks when the document's progress state reaches `nsIWebProgressListener.STATE_STOP`. This change makes it possible to navigate to image documents, such as .jpg and .gif images with Marionette. Documents with the text/html MIME are not affected by this because they are parsed as HTML documents with a special style. MozReview-Commit-ID: I92FDXDIdz9
testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
testing/marionette/harness/marionette_harness/www/black.png
testing/marionette/harness/marionette_harness/www/white.png
testing/marionette/listener.js
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py
@@ -163,16 +163,29 @@ class TestNavigate(WindowManagerMixin, M
         self.marionette.navigate('about:blank')
         self.marionette.close()
         self.marionette.switch_to_window(self.start_window)
 
     def test_error_on_tls_navigation(self):
         self.assertRaises(errors.InsecureCertificateException,
                           self.marionette.navigate, self.fixtures.where_is("/test.html", on="https"))
 
+    def test_html_document_to_image_document(self):
+        self.marionette.navigate(self.fixtures.where_is("test.html"))
+        self.marionette.navigate(self.fixtures.where_is("white.png"))
+        self.assertIn("white.png", self.marionette.title)
+
+    def test_image_document_to_image_document(self):
+        self.marionette.navigate(self.fixtures.where_is("test.html"))
+
+        self.marionette.navigate(self.fixtures.where_is("white.png"))
+        self.assertIn("white.png", self.marionette.title)
+        self.marionette.navigate(self.fixtures.where_is("black.png"))
+        self.assertIn("black.png", self.marionette.title)
+
 
 class TestTLSNavigation(MarionetteTestCase):
     insecure_tls = {"acceptInsecureCerts": True}
     secure_tls = {"acceptInsecureCerts": False}
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.delete_session()
new file mode 100644
index 0000000000000000000000000000000000000000..b62a3a7bc8e59cfe7a51a021f4ab89c9fe467a1a
GIT binary patch
literal 150
zc%17D@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GG!XV7ZFl&wkP>{XE
z)7O>#0gtSJh0LPW6P5ynWHUn|N}Tg^b5rw57(l?eC^fMpHASI3vm`^o-P1Q9MK6^d
lD9+>Q;uyklJ^8`Ihd|4G7*s3WS9pUoc)I$ztaD0e0sz>4BL@Hg
new file mode 100644
index 0000000000000000000000000000000000000000..8a68c11548ac6a8dc582d65c59af6452576db517
GIT binary patch
literal 150
zc%17D@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GG!XV7ZFl&wkP>{XE
z)7O>#0gtSJnb7SC6Lf$=vY8<fCC>S|xv6<23?SfKl$uzQnxasiS(2gP?&%wlqL<1J
m6zB1DaSY+Op8Vtge|rYje@y@GoQZr6(%|Xp=d#Wzp$P!=NhSFJ
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -944,34 +944,48 @@ function get(msg) {
     QueryInterface: XPCOMUtils.generateQI(
         [Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]),
 
     onStateChange(webProgress, request, state, status) {
       if (!(request instanceof Ci.nsIChannel)) {
         return;
       }
 
-      let isDocument = state & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT;
-      let isStart = state & Ci.nsIWebProgressListener.STATE_START;
-      let loadedURL = request.URI.spec;
-      // We have to look at the originalURL because for about: pages,
+      const isDocument = state & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT;
+      const loadedURL = request.URI.spec;
+
+      // We have to look at the originalURL because of about: pages,
       // the loadedURL is what the about: page resolves to, and is
       // not the one that was requested.
-      let originalURL = request.originalURI.spec;
-      let isRequestedURL = loadedURL == requestedURL ||
+      const originalURL = request.originalURI.spec;
+      const isRequestedURL = loadedURL == requestedURL ||
           originalURL == requestedURL;
 
-      if (isDocument && isStart && isRequestedURL) {
-        // We started loading the requested document. This document
-        // might not be the one that ends up firing DOMContentLoaded
-        // (if it, for example, redirects), but because we've started
-        // loading this URL, we know that any future DOMContentLoaded's
-        // are fair game to tell the Marionette client about.
+      if (!isDocument || !isRequestedURL) {
+        return;
+      }
+
+      // We started loading the requested document. This document
+      // might not be the one that ends up firing DOMContentLoaded
+      // (if it, for example, redirects), but because we've started
+      // loading this URL, we know that any future DOMContentLoaded's
+      // are fair game to tell the Marionette client about.
+      if (state & Ci.nsIWebProgressListener.STATE_START) {
         sawLoad = true;
       }
+
+      // This indicates network stop or last request stop outside of
+      // loading the document.  We hit this when DOMContentLoaded is
+      // not triggered, which is the case for image documents.
+      else if (state & Ci.nsIWebProgressListener.STATE_STOP &&
+          content.document instanceof content.ImageDocument) {
+        pollForReadyState(msg, start, () => {
+          removeEventListener("DOMContentLoaded", onDOMContentLoaded, false);
+        });
+      }
     },
 
     onLocationChange() {},
     onProgressChange() {},
     onStatusChange() {},
     onSecurityChange() {},
   };