diff options
author | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-06 17:33:56 +0000 |
---|---|---|
committer | cbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-06 17:33:56 +0000 |
commit | b0dcb9339511b02acbe62c17070415faf1baa7dd (patch) | |
tree | 8d5061a971186e672173321bacc8f0f6d3010fad /net | |
parent | ba50d192694e3bbdd99d153205e7fcef236abf8a (diff) | |
download | chromium_src-b0dcb9339511b02acbe62c17070415faf1baa7dd.zip chromium_src-b0dcb9339511b02acbe62c17070415faf1baa7dd.tar.gz chromium_src-b0dcb9339511b02acbe62c17070415faf1baa7dd.tar.bz2 |
SSLUITest's work with ephemeral port testserver.
Many of the tests depend on a file served from one server to reference resources on a different server to exercise mixed content warnings.
To handle this, I added replace_orig and replace_new query parameters to /files/ based paths which do simple string substitution.
BUG=56814
TEST=browser_tests --gtest_filter="*SSLUI*"
Review URL: http://codereview.chromium.org/4429001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65311 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rwxr-xr-x[-rw-r--r--] | net/tools/testserver/testserver.py | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py index c54d425..55aa6a9 100644..100755 --- a/net/tools/testserver/testserver.py +++ b/net/tools/testserver/testserver.py @@ -21,7 +21,7 @@ import shutil import SocketServer import sys import time -import urllib2 +import urlparse import warnings # Ignore deprecation warnings, they make our output more cluttered. @@ -573,6 +573,24 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.end_headers() return True + def _ReplaceFileData(self, data, query_parameters): + """Replaces matching substrings in a file. + + If the 'replace_orig' and 'replace_new' URL query parameters are present, + a new string is returned with all occasions of the 'replace_orig' value + replaced by the 'replace_new' value. + + If the parameters are not present, |data| is returned. + """ + query_dict = cgi.parse_qs(query_parameters) + orig_values = query_dict.get('replace_orig', []) + new_values = query_dict.get('replace_new', []) + if not orig_values or not new_values: + return data + orig_value = orig_values[0] + new_value = new_values[0] + return data.replace(orig_value, new_value) + def FileHandler(self): """This handler sends the contents of the requested file. Wow, it's like a real webserver!""" @@ -585,29 +603,27 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler): if self.command == 'POST' or self.command == 'PUT' : self.rfile.read(int(self.headers.getheader('content-length'))) - file = self.path[len(prefix):] - if file.find('?') > -1: - # Ignore the query parameters entirely. - url, querystring = file.split('?') - else: - url = file - entries = url.split('/') - path = os.path.join(self.server.data_dir, *entries) - if os.path.isdir(path): - path = os.path.join(path, 'index.html') - - if not os.path.isfile(path): - print "File not found " + file + " full path:" + path + _, _, url_path, _, query, _ = urlparse.urlparse(self.path) + sub_path = url_path[len(prefix):] + entries = sub_path.split('/') + file_path = os.path.join(self.server.data_dir, *entries) + if os.path.isdir(file_path): + file_path = os.path.join(file_path, 'index.html') + + if not os.path.isfile(file_path): + print "File not found " + sub_path + " full path:" + file_path self.send_error(404) return True - f = open(path, "rb") + f = open(file_path, "rb") data = f.read() f.close() + data = self._ReplaceFileData(data, query) + # If file.mock-http-headers exists, it contains the headers we # should send. Read them in and parse them. - headers_path = path + '.mock-http-headers' + headers_path = file_path + '.mock-http-headers' if os.path.isfile(headers_path): f = open(headers_path, "r") @@ -627,7 +643,7 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler): # Could be more generic once we support mime-type sniffing, but for # now we need to set it explicitly. self.send_response(200) - self.send_header('Content-type', self.GetMIMETypeFromName(file)) + self.send_header('Content-type', self.GetMIMETypeFromName(file_path)) self.send_header('Content-Length', len(data)) self.end_headers() |