Index: chrome/test/functional/webpagereplay.py |
diff --git a/chrome/test/functional/webpagereplay.py b/chrome/test/functional/webpagereplay.py |
index 082b079b363d871600a1f8bb3398d6b5586eede0..14a796aefb027343f05fdf675efd73726340591b 100755 |
--- a/chrome/test/functional/webpagereplay.py |
+++ b/chrome/test/functional/webpagereplay.py |
@@ -6,24 +6,22 @@ |
"""Start and stop Web Page Replay.""" |
import logging |
-import optparse |
import os |
-import shutil |
import signal |
import subprocess |
-import sys |
-import tempfile |
import time |
import urllib |
-USAGE = '%s [options] CHROME_EXE TEST_NAME' % os.path.basename(sys.argv[0]) |
-USER_DATA_DIR = '{TEMP}/webpagereplay_utils-chrome' |
- |
-# The port numbers must match those in chrome/test/perf/page_cycler_test.cc. |
HTTP_PORT = 8080 |
HTTPS_PORT = 8413 |
REPLAY_HOST='127.0.0.1' |
+CHROME_FLAGS = [ |
+ '--host-resolver-rules=MAP * %s,EXCLUDE localhost' % REPLAY_HOST, |
+ '--testing-fixed-http-port=%s' % HTTP_PORT, |
+ '--testing-fixed-https-port=%s' % HTTPS_PORT, |
+ '--ignore-certificate-errors', |
+ ] |
class ReplayError(Exception): |
@@ -135,3 +133,59 @@ class ReplayServer(object): |
def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): |
"""Add support for with-statement.""" |
self.StopServer() |
+ |
+ |
+class ChromiumPaths(object): |
+ """Convert POSIX-style Chromium tree paths to OS-specific absolute paths.""" |
+ _BASE_DIR = os.path.abspath(os.path.join( |
+ os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) |
+ |
+ @classmethod |
+ def Format(cls, relative_path, **kwargs): |
+ return cls.AbsPath(relative_path.format(**kwargs)) |
+ |
+ @classmethod |
+ def AbsPath(cls, relative_path): |
+ return os.path.join(cls._BASE_DIR, *relative_path.split('/')) |
+ |
+ |
+class PerfReplayServer(ReplayServer): |
+ """Run tests with network simulation via Web Page Replay. |
+ |
+ Web Page Replay is a proxy that can record and "replay" web pages with |
+ simulated network characteristics -- without having to edit the pages |
+ by hand. With WPR, tests can use "real" web content, and catch |
+ performance issues that may result from introducing network delays and |
+ bandwidth throttling. |
+ |
+ Environment Variables: |
+ WPR_ARCHIVE_PATH: path to alternate archive file (e.g. '/tmp/foo.wpr'). |
+ WPR_RECORD: if set, puts Web Page Replay in record mode instead of replay. |
+ WPR_REPLAY_DIR: path to alternate Web Page Replay source (for development). |
+ """ |
+ REPLAY_DIR = 'src/third_party/webpagereplay' |
+ LOGS_DIR = 'src/webpagereplay_logs' |
+ |
+ def __init__(self, archive_path): |
+ self.is_record_mode = 'WPR_RECORD' in os.environ |
+ archive_path = os.environ.get('WPR_ARCHIVE_PATH', archive_path) |
+ replay_dir = os.environ.get('WPR_REPLAY_DIR', |
+ ChromiumPaths.AbsPath(self.REPLAY_DIR)) |
+ logs_dir = ChromiumPaths.AbsPath(self.LOGS_DIR) |
+ |
+ replay_options = [] |
+ replay_options.append('--no-dns_forwarding') |
+ if self.is_record_mode: |
+ replay_options.append('--record') |
+ |
+ assert archive_path, 'Archive path is not set.' |
+ if self.is_record_mode: |
+ archive_dir = os.path.dirname(archive_path) |
+ assert os.path.exists(archive_dir), \ |
+ 'Archive directory does not exist: %s' % archive_dir |
+ else: |
+ assert os.path.exists(archive_path), \ |
+ 'Archive file path does not exist: %s' % archive_path |
+ |
+ super(PerfWebPageReplay, self).__init__( |
+ replay_dir, archive_path, logs_dir, replay_options) |