Bug 1291320 - Disallow slow loading page to be put into the cache. draft
authorHenrik Skupin <mail@hskupin.info>
Mon, 03 Apr 2017 22:40:48 +0200
changeset 555183 12ffa6866da00ee7062ad9a3bcdff1da2f40e424
parent 555171 52fac7dcc5b44072dd3b755cf9683ca94fbd39ac
child 555184 666dbea90d69aacbf914e4c980f86d731bfca1d7
push id52189
push userbmo:hskupin@gmail.com
push dateMon, 03 Apr 2017 20:41:37 +0000
bugs1291320
milestone55.0a1
Bug 1291320 - Disallow slow loading page to be put into the cache. To delay the page load for our slowly served example page when using the back or forward commands, the page doesn't have to be put into the browser cache. MozReview-Commit-ID: 4xMjR3SakZn
testing/marionette/harness/marionette_harness/runner/httpd.py
--- a/testing/marionette/harness/marionette_harness/runner/httpd.py
+++ b/testing/marionette/harness/marionette_harness/runner/httpd.py
@@ -54,20 +54,29 @@ def http_auth_handler(req, response):
 
 @handlers.handler
 def upload_handler(request, response):
     return 200, [], [request.headers.get("Content-Type")] or []
 
 
 @handlers.handler
 def slow_loading_handler(request, response):
-    time.sleep(5)
-    return """<!doctype html>
-<title>ok</title>
-<p>ok"""
+    # Allow the test specify the delay for delivering the content
+    params = dict(urlparse.parse_qsl(request.url_parts.query))
+    delay = int(params.get('delay', 5))
+    time.sleep(delay)
+
+    # Do not allow the page to be cached to circumvent the bfcache of the browser
+    response.headers.set("Cache-Control", "no-cache, no-store")
+    response.content = """<!doctype html>
+<meta charset="UTF-8">
+<title>Slow page loading</title>
+
+<p>Delay: <span id="delay">{}</span></p>
+""".format(delay)
 
 
 class NotAliveError(Exception):
     """Occurs when attempting to run a function that requires the HTTPD
     to have been started, and it has not.
 
     """
     pass