summaryrefslogtreecommitdiff
path: root/testing/variations/smoke/test_utils/http.py
diff options
context:
space:
mode:
Diffstat (limited to 'testing/variations/smoke/test_utils/http.py')
-rw-r--r--testing/variations/smoke/test_utils/http.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/testing/variations/smoke/test_utils/http.py b/testing/variations/smoke/test_utils/http.py
new file mode 100644
index 000000000..c02286d7f
--- /dev/null
+++ b/testing/variations/smoke/test_utils/http.py
@@ -0,0 +1,29 @@
+# Copyright 2023 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import functools
+import http
+import logging
+import os
+import threading
+
+from http.server import SimpleHTTPRequestHandler
+
+SRC_DIR = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), *([os.pardir] * 4)))
+
+HTTP_DATA_BASEDIR = os.path.join(
+ SRC_DIR, 'chrome', 'test', 'data', 'chromedriver')
+
+def start_http_server(port:int = 8000,
+ directory: str = None) -> http.server.HTTPServer:
+ """Starts a HTTP server serving the given directory."""
+ if directory is None:
+ directory = HTTP_DATA_BASEDIR
+ http_server = http.server.HTTPServer(('', port),
+ functools.partial(SimpleHTTPRequestHandler, directory=directory))
+ logging.info('local http server is running as http://%s:%s',
+ http_server.server_name, http_server.server_port)
+ threading.Thread(target=http_server.serve_forever).start()
+ return http_server