From ff735c7c6cef2bfe73c23981c81614b3181b38ed Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Fri, 9 Dec 2016 14:33:16 -1000 Subject: [PATCH] Bug 1322772 - Poll for ready state on web progress stop state for image documents; r=maja_zf,whimboo 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 --HG-- extra : rebase_source : 01fa5826badc806ef5ac2de35d88452a0df15201 --- .../tests/unit/test_navigation.py | 13 ++++++ .../harness/marionette_harness/www/black.png | Bin 0 -> 150 bytes .../harness/marionette_harness/www/white.png | Bin 0 -> 150 bytes testing/marionette/listener.js | 38 ++++++++++++------ 4 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 testing/marionette/harness/marionette_harness/www/black.png create mode 100644 testing/marionette/harness/marionette_harness/www/white.png diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py b/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py index fdb18814b7be..8ed83b224080 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py +++ b/testing/marionette/harness/marionette_harness/tests/unit/test_navigation.py @@ -168,6 +168,19 @@ class TestNavigate(WindowManagerMixin, MarionetteTestCase): 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} diff --git a/testing/marionette/harness/marionette_harness/www/black.png b/testing/marionette/harness/marionette_harness/www/black.png new file mode 100644 index 0000000000000000000000000000000000000000..b62a3a7bc8e59cfe7a51a021f4ab89c9fe467a1a GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#0gtSJh0LPW6P5ynWHUn|N}Tg^b5rw5fLsO!=c3falGGH1^30M91$R&1fE2w{ mcAz+qr;B3<$Mxg~4<7<8^I=e}bYI~O(%|Xp=d#Wzp$P!kej^6} literal 0 HcmV?d00001 diff --git a/testing/marionette/harness/marionette_harness/www/white.png b/testing/marionette/harness/marionette_harness/www/white.png new file mode 100644 index 0000000000000000000000000000000000000000..8a68c11548ac6a8dc582d65c59af6452576db517 GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#0gtSJnb7SC6Lf$=vY8S|xv6<2KrRD=b5UwyNotBhd1gt5g1e`0K#E=} nJ5Zd*)5S4_<9hOs|Nre7SpPBoyK^S;IY@)2tDnm{r-UW|^hqW8 literal 0 HcmV?d00001 diff --git a/testing/marionette/listener.js b/testing/marionette/listener.js index 8490febab5ce..f3b62b51b4ad 100644 --- a/testing/marionette/listener.js +++ b/testing/marionette/listener.js @@ -988,24 +988,38 @@ function get(msg) { 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() {},