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
This commit is contained in:
Andreas Tolfsen 2016-12-09 14:33:16 -10:00
parent 6c70e46f72
commit ff735c7c6c
4 changed files with 39 additions and 12 deletions

View File

@ -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}

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

View File

@ -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() {},