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-Original-Commit-Position: refs/heads/master@{#297182}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 14c66460be23532452ae32f3546e5578ab48c590
diff --git a/testserver.py b/testserver.py
index d020ca3..7739902 100755
--- a/testserver.py
+++ b/testserver.py
@@ -331,6 +331,7 @@
self.ContentTypeHandler,
self.NoContentHandler,
self.ServerRedirectHandler,
+ self.CrossSiteRedirectHandler,
self.ClientRedirectHandler,
self.GetSSLSessionCacheHandler,
self.SSLManySmallRecords,
@@ -1418,6 +1419,36 @@
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