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

Unified Diff: chrome/test/webdriver/test/chromedriver_test.py

Issue 10828135: Allow popups, mouselock, and https media-stream content by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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
« no previous file with comments | « chrome/test/webdriver/test/cert.pem ('k') | chrome/test/webdriver/test/chromedriver_tests.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/test/chromedriver_test.py
diff --git a/chrome/test/webdriver/test/chromedriver_test.py b/chrome/test/webdriver/test/chromedriver_test.py
index e9d51df49a3325bdf533843ebc2d2a1535a5de68..4bcd23c3d4c9e77899c6760c74b67a69374b8e85 100644
--- a/chrome/test/webdriver/test/chromedriver_test.py
+++ b/chrome/test/webdriver/test/chromedriver_test.py
@@ -4,7 +4,10 @@
"""Factory that creates ChromeDriver instances."""
+import BaseHTTPServer
import os
+import ssl
+import threading
import unittest
from chromedriver_factory import ChromeDriverFactory
@@ -12,6 +15,54 @@ from chromedriver_launcher import ChromeDriverLauncher
import test_paths
+class _FileRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+ """Sends back file resources relative to the server's |root_dir|."""
+
+ def do_GET(self):
+ if self.path.endswith('favicon.ico'):
+ self.send_error(404)
+ return
+ path = os.path.join(self.server.root_dir, *self.path.split('/'))
+ data = open(path, 'r').read()
+ self.send_response(200)
+ self.send_header('Content-Length', len(data))
+ self.end_headers()
+ self.wfile.write(data)
+
+
+class _HttpsServer(object):
+ """An HTTPS server that serves files on its own thread."""
+
+ def __init__(self, server_cert_and_key_path, root_dir):
+ """Starts the HTTPS server on its own thread on an ephemeral port.
+
+ After this function returns, it is safe to assume the server is ready
+ to receive requests.
+
+ Args:
+ server_cert_and_key_path: path to a PEM file containing the cert and key.
+ root_dir: root path to serve files from.
+ """
+ self._server = BaseHTTPServer.HTTPServer(
+ ('127.0.0.1', 0), _FileRequestHandler)
+ self._server.root_dir = root_dir
+ self._server.socket = ssl.wrap_socket(
+ self._server.socket, certfile=server_cert_and_key_path,
+ server_side=True)
+
+ self._thread = threading.Thread(target=self._server.serve_forever)
+ self._thread.start()
+
+ def GetUrl(self):
+ """Returns the base URL of the server."""
+ return 'https://127.0.0.1:%s' % self._server.server_port
+
+ def Shutdown(self):
+ """Shuts down the server synchronously."""
+ self._server.shutdown()
+ self._thread.join()
+
+
class ChromeDriverTest(unittest.TestCase):
"""Fixture for tests that need to instantiate ChromeDriver(s)."""
@@ -27,18 +78,26 @@ class ChromeDriverTest(unittest.TestCase):
ChromeDriverTest._driver_path = driver_path
ChromeDriverTest._chrome_path = chrome_path
ChromeDriverTest._server = ChromeDriverLauncher(driver_path).Launch()
- ChromeDriverTest._webserver = ChromeDriverLauncher(
+ ChromeDriverTest._http_server = ChromeDriverLauncher(
driver_path, test_paths.TEST_DATA_PATH).Launch()
+ ChromeDriverTest._https_server = _HttpsServer(
+ test_paths.PEM_CERT_AND_KEY, test_paths.TEST_DATA_PATH)
@staticmethod
def GlobalTearDown():
ChromeDriverTest._server.Kill()
- ChromeDriverTest._webserver.Kill()
+ ChromeDriverTest._http_server.Kill()
+ ChromeDriverTest._https_server.Shutdown()
@staticmethod
def GetTestDataUrl():
- """Returns the base url for serving files from the ChromeDriver test dir."""
- return ChromeDriverTest._webserver.GetUrl()
+ """Returns the base http url for serving files from the test dir."""
+ return ChromeDriverTest._http_server.GetUrl()
+
+ @staticmethod
+ def GetHttpsTestDataUrl():
+ """Returns the base https url for serving files from the test dir."""
+ return ChromeDriverTest._https_server.GetUrl()
@staticmethod
def GetDriverPath():
« no previous file with comments | « chrome/test/webdriver/test/cert.pem ('k') | chrome/test/webdriver/test/chromedriver_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698