Bug 1302707 - Fix type check to allow page loading timeout of 0; r?automatedtester
The `get` function in testing/marionette/listener.js used an evaluated
if-condition test to determine if a page timeout was given. This would
fail if passed 0 because 0 evaluates to false in JavaScript.
This patch fixes the incorrect type check by looking at whether the
variable has been defined or not.
MozReview-Commit-ID: 39vDZRjKAFb
--- a/testing/marionette/harness/marionette/runner/httpd.py
+++ b/testing/marionette/harness/marionette/runner/httpd.py
@@ -1,13 +1,14 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
+import time
from wptserve import server, handlers, routes as default_routes
class FixtureServer(object):
def __init__(self, root, host="127.0.0.1", port=0):
if not os.path.isdir(root):
@@ -15,17 +16,18 @@ class FixtureServer(object):
self.root = root
self.host = host
self.port = port
self._server = None
def start(self, block=False):
if self.alive:
return
- routes = [("POST", "/file_upload", upload_handler)]
+ routes = [("POST", "/file_upload", upload_handler),
+ ("GET", "/slow", slow_loading_document)]
routes.extend(default_routes.routes)
self._server = server.WebTestHttpd(
port=self.port,
doc_root=self.root,
routes=routes,
host=self.host,
)
self._server.start(block=block)
@@ -52,16 +54,24 @@ class FixtureServer(object):
return self._server.router.routes
@handlers.handler
def upload_handler(request, response):
return 200, [], [request.headers.get("Content-Type")] or []
+@handlers.handler
+def slow_loading_document(request, response):
+ time.sleep(5)
+ return """<!doctype html>
+<title>ok</title>
+<p>ok"""
+
+
if __name__ == "__main__":
here = os.path.abspath(os.path.dirname(__file__))
doc_root = os.path.join(os.path.dirname(here), "www")
httpd = FixtureServer(doc_root, port=2829)
print "Started fixture server on http://%s:%d/" % (httpd.host, httpd.port)
try:
httpd.start(True)
except KeyboardInterrupt:
--- a/testing/marionette/harness/marionette/tests/unit/test_navigation.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_navigation.py
@@ -117,28 +117,21 @@ class TestNavigate(MarionetteTestCase):
self.assertEqual(self.marionette.get_url(), "about:blocked")
def test_find_element_state_complete(self):
self.marionette.navigate(self.test_doc)
state = self.marionette.execute_script("return window.document.readyState")
self.assertEqual("complete", state)
self.assertTrue(self.marionette.find_element(By.ID, "mozLink"))
- def test_should_throw_a_timeoutexception_when_loading_page(self):
- try:
+ def test_error_when_exceeding_page_load_timeout(self):
+ with self.assertRaises(TimeoutException):
self.marionette.set_page_load_timeout(0)
- self.marionette.navigate(self.test_doc)
- self.assertTrue(self.marionette.find_element(By.ID, "mozLink"))
- self.fail("Should have thrown a MarionetteException")
- except TimeoutException as e:
- self.assertTrue("Error loading page, timed out" in str(e))
- except Exception as e:
- import traceback
- print traceback.format_exc()
- self.fail("Should have thrown a TimeoutException instead of %s" % type(e))
+ self.marionette.navigate(self.marionette.absolute_url("slow"))
+ self.marionette.find_element(By.TAG_NAME, "p")
def test_navigate_iframe(self):
self.marionette.navigate(self.iframe_doc)
self.assertTrue('test_iframe.html' in self.marionette.get_url())
self.assertTrue(self.marionette.find_element(By.ID, "test_iframe"))
def test_fragment(self):
doc = inline("<p id=foo>")
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -903,32 +903,32 @@ function pollForReadyState(msg, start =
/**
* Navigate to the given URL. The operation will be performed on the
* current browsing context, which means it handles the case where we
* navigate within an iframe. All other navigation is handled by the
* driver (in chrome space).
*/
function get(msg) {
let start = new Date().getTime();
- let command_id = msg.json.command_id;
+ let {pageTimeout, url, command_id} = msg.json;
let docShell = curContainer.frame
.document
.defaultView
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress);
let sawLoad = false;
let requestedURL;
let loadEventExpected = false;
try {
- requestedURL = new URL(msg.json.url).toString();
+ requestedURL = new URL(url).toString();
let curURL = curContainer.frame.location;
loadEventExpected = navigate.isLoadEventExpected(curURL, requestedURL);
} catch (e) {
sendError(new InvalidArgumentError("Malformed URL: " + e.message), command_id);
return;
}
// It's possible that a site we're being sent to will end up redirecting
@@ -998,25 +998,25 @@ function get(msg) {
if (correctFrame && sawLoad && loadedNonAboutBlank) {
webProgress.removeProgressListener(loadListener);
pollForReadyState(msg, start, () => {
removeEventListener("DOMContentLoaded", onDOMContentLoaded, false);
});
}
};
- if (msg.json.pageTimeout) {
+ if (typeof pageTimeout != "undefined") {
let onTimeout = function() {
if (loadEventExpected) {
removeEventListener("DOMContentLoaded", onDOMContentLoaded, false);
}
webProgress.removeProgressListener(loadListener);
sendError(new TimeoutError("Error loading page, timed out (onDOMContentLoaded)"), command_id);
}
- navTimer.initWithCallback(onTimeout, msg.json.pageTimeout, Ci.nsITimer.TYPE_ONE_SHOT);
+ navTimer.initWithCallback(onTimeout, pageTimeout, Ci.nsITimer.TYPE_ONE_SHOT);
}
// in Firefox we need to move to the top frame before navigating
if (!isB2G) {
sendSyncMessage("Marionette:switchedToFrame", {frameValue: null});
curContainer.frame = content;
}