Commit 14c66460 authored by nasko's avatar nasko Committed by Commit bot

Add /cross-site/ request handler to testserver.py

Adding this handler will make authoring tests which exercise cross-site navigations much easier. This is harder in the current codebase, because testserver runs on a random port each time it is ran which requires boilerplate code in each test that needs it. Instead of computing the real URL in C++ code, just navigate using "/cross-site/hostname/path/and/more" and the server will redirect to the new host.
This requires browser tests to map all hosts to localhost, which is done by adding 'host_resolver()->AddRule("*", "127.0.0.1");' to the beginning of the test.

BUG=418236

Review URL: https://codereview.chromium.org/612533002

Cr-Commit-Position: refs/heads/master@{#297182}
parent 488516f0
......@@ -331,6 +331,7 @@ class TestPageHandler(testserver_base.BasePageHandler):
self.ContentTypeHandler,
self.NoContentHandler,
self.ServerRedirectHandler,
self.CrossSiteRedirectHandler,
self.ClientRedirectHandler,
self.GetSSLSessionCacheHandler,
self.SSLManySmallRecords,
......@@ -1418,6 +1419,36 @@ class TestPageHandler(testserver_base.BasePageHandler):
return True
def CrossSiteRedirectHandler(self):
"""Sends a server redirect to the given site. The syntax is
'/cross-site/hostname/...' to redirect to //hostname/...
It is used to navigate between different Sites, causing
cross-site/cross-process navigations in the browser."""
test_name = "/cross-site"
if not self._ShouldHandleRequest(test_name):
print "CSRH: not handling request for " + test_name
return False
params = urllib.unquote(self.path[(len(test_name) + 1):])
slash = params.find('/')
if slash < 0:
self.sendRedirectHelp(test_name)
return True
host = params[:slash]
path = params[(slash+1):]
dest = "//%s:%s/%s" % (host, str(self.server.server_port), path)
self.send_response(301) # moved permanently
self.send_header('Location', dest)
self.send_header('Content-Type', 'text/html')
self.end_headers()
self.wfile.write('<html><head>')
self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest)
return True
def ClientRedirectHandler(self):
"""Sends a client redirect to the given URL. The syntax is
'/client-redirect?http://foo.bar/asdf' to redirect to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment