Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: net/tools/testserver/testserver.py

Issue 3353015: Implement gallery install API (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: erik comments Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/extensions/api_test/extension_gallery_install/test.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2.4 1 #!/usr/bin/python2.4
2 # Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This is a simple HTTP server used for testing Chrome. 6 """This is a simple HTTP server used for testing Chrome.
7 7
8 It supports several test URLs, as specified by the handlers in TestPageHandler. 8 It supports several test URLs, as specified by the handlers in TestPageHandler.
9 It defaults to living on localhost:8888. 9 It defaults to living on localhost:8888.
10 It can use https if you specify the flag --https=CERT where CERT is the path 10 It can use https if you specify the flag --https=CERT where CERT is the path
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 self.ChromiumSyncConfigureHandler, 144 self.ChromiumSyncConfigureHandler,
145 self.ChromiumSyncCommandHandler, 145 self.ChromiumSyncCommandHandler,
146 self.EchoHandler] + self._get_handlers 146 self.EchoHandler] + self._get_handlers
147 self._put_handlers = [ 147 self._put_handlers = [
148 self.WriteFile, 148 self.WriteFile,
149 self.EchoTitleHandler, 149 self.EchoTitleHandler,
150 self.EchoAllHandler, 150 self.EchoAllHandler,
151 self.EchoHandler] + self._get_handlers 151 self.EchoHandler] + self._get_handlers
152 152
153 self._mime_types = { 153 self._mime_types = {
154 'crx' : 'application/x-chrome-extension',
154 'gif': 'image/gif', 155 'gif': 'image/gif',
155 'jpeg' : 'image/jpeg', 156 'jpeg' : 'image/jpeg',
156 'jpg' : 'image/jpeg', 157 'jpg' : 'image/jpeg',
157 'xml' : 'text/xml' 158 'xml' : 'text/xml'
158 } 159 }
159 self._default_mime_type = 'text/html' 160 self._default_mime_type = 'text/html'
160 161
161 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request, 162 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request,
162 client_address, 163 client_address,
163 socket_server) 164 socket_server)
164 165
165 def log_request(self, *args, **kwargs): 166 def log_request(self, *args, **kwargs):
166 # Disable request logging to declutter test log output. 167 # Disable request logging to declutter test log output.
167 pass 168 pass
168 169
169 def _ShouldHandleRequest(self, handler_name): 170 def _ShouldHandleRequest(self, handler_name):
170 """Determines if the path can be handled by the handler. 171 """Determines if the path can be handled by the handler.
171 172
172 We consider a handler valid if the path begins with the 173 We consider a handler valid if the path begins with the
173 handler name. It can optionally be followed by "?*", "/*". 174 handler name. It can optionally be followed by "?*", "/*".
174 """ 175 """
175 176
176 pattern = re.compile('%s($|\?|/).*' % handler_name) 177 pattern = re.compile('%s($|\?|/).*' % handler_name)
177 return pattern.match(self.path) 178 return pattern.match(self.path)
178 179
179 def GetMIMETypeFromName(self, file_name): 180 def GetMIMETypeFromName(self, file_name):
180 """Returns the mime type for the specified file_name. So far it only looks 181 """Returns the mime type for the specified file_name. So far it only looks
181 at the file extension.""" 182 at the file extension."""
182 183
183 (shortname, extension) = os.path.splitext(file_name) 184 (shortname, extension) = os.path.splitext(file_name.split("?")[0])
184 if len(extension) == 0: 185 if len(extension) == 0:
185 # no extension. 186 # no extension.
186 return self._default_mime_type 187 return self._default_mime_type
187 188
188 # extension starts with a dot, so we need to remove it 189 # extension starts with a dot, so we need to remove it
189 return self._mime_types.get(extension[1:], self._default_mime_type) 190 return self._mime_types.get(extension[1:], self._default_mime_type)
190 191
191 def KillHandler(self): 192 def KillHandler(self):
192 """This request handler kills the server, for use when we're done" 193 """This request handler kills the server, for use when we're done"
193 with the a particular test.""" 194 with the a particular test."""
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 option_parser.add_option('', '--file-root-url', default='/files/', 1322 option_parser.add_option('', '--file-root-url', default='/files/',
1322 help='Specify a root URL for files served.') 1323 help='Specify a root URL for files served.')
1323 option_parser.add_option('', '--never-die', default=False, 1324 option_parser.add_option('', '--never-die', default=False,
1324 action="store_true", 1325 action="store_true",
1325 help='Prevent the server from dying when visiting ' 1326 help='Prevent the server from dying when visiting '
1326 'a /kill URL. Useful for manually running some ' 1327 'a /kill URL. Useful for manually running some '
1327 'tests.') 1328 'tests.')
1328 options, args = option_parser.parse_args() 1329 options, args = option_parser.parse_args()
1329 1330
1330 sys.exit(main(options, args)) 1331 sys.exit(main(options, args))
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/extension_gallery_install/test.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698