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

Unified Diff: chrome/test/chromedriver/test/webserver.py

Issue 288193004: [Chromedriver] Add Device Metrics override support to ChromeDriver via Capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/test/webserver.py
diff --git a/chrome/test/chromedriver/test/webserver.py b/chrome/test/chromedriver/test/webserver.py
index 716e0f4a9b47d96cf4775667e6e9ff4df580952f..9de03395b9f744cee3fbaf7f4f743f00fb1735fc 100644
--- a/chrome/test/chromedriver/test/webserver.py
+++ b/chrome/test/chromedriver/test/webserver.py
@@ -48,6 +48,9 @@ class Request(object):
def GetPath(self):
return self._handler.path
+ def GetHeader(self, name):
+ return self._handler.headers.getheader(name)
+
class _BaseServer(BaseHTTPServer.HTTPServer):
"""Internal server that throws if timed out waiting for a request."""
@@ -120,19 +123,28 @@ class WebServer(object):
self._thread.daemon = True
self._thread.start()
self._path_data_map = {}
- self._path_data_lock = threading.Lock()
+ self._path_callback_map = {}
+ self._path_maps_lock = threading.Lock()
def _OnRequest(self, request, responder):
path = request.GetPath().split('?')[0]
- # Serve from path -> data map.
- self._path_data_lock.acquire()
+ # Serve from path -> callback and data maps.
+ self._path_maps_lock.acquire()
try:
+ if path in self._path_callback_map:
+ body = self._path_callback_map[path](request)
+ if body:
+ responder.SendResponse(body)
+ else:
+ responder.SendError(503)
+ return
+
if path in self._path_data_map:
responder.SendResponse(self._path_data_map[path])
return
finally:
- self._path_data_lock.release()
+ self._path_maps_lock.release()
# Serve from file.
path = os.path.normpath(
@@ -146,11 +158,19 @@ class WebServer(object):
responder.SendResponseFromFile(path)
def SetDataForPath(self, path, data):
- self._path_data_lock.acquire()
+ self._path_maps_lock.acquire()
try:
self._path_data_map[path] = data
finally:
- self._path_data_lock.release()
+ self._path_maps_lock.release()
+
+ def SetCallbackForPath(self, path, func):
+ self._path_maps_lock.acquire()
+ try:
+ self._path_callback_map[path] = func
+ finally:
+ self._path_maps_lock.release()
+
def GetUrl(self):
"""Returns the base URL of the server."""

Powered by Google App Engine
This is Rietveld 408576698