Index: chrome/test/functional/webpagereplay.py |
diff --git a/tools/python/google/webpagereplay_utils.py b/chrome/test/functional/webpagereplay.py |
similarity index 78% |
rename from tools/python/google/webpagereplay_utils.py |
rename to chrome/test/functional/webpagereplay.py |
index 595cff82d3e8d43b15dc25f35e2ff0ece82a1f99..97a6b990b4daa0214ccc33629d257383918dbe4d 100755 |
--- a/tools/python/google/webpagereplay_utils.py |
+++ b/chrome/test/functional/webpagereplay.py |
@@ -5,14 +5,11 @@ |
"""A class to help start/stop a Web Page Replay Server. |
-The page cycler tests use this module to run Web Page Replay |
-(see tools/build/scripts/slave/runtest.py). |
- |
If run from the command-line, the module will launch Web Page Replay |
and the specified test: |
- ./webpagereplay_utils.py --help # list options |
- ./webpagereplay_utils.py 2012Q2 # run a WPR-enabled test |
+ python webpagereplay.py --help # list options |
+ python webpagereplay.py CHROME_EXE 2012Q2 # run a WPR-enabled test |
""" |
import logging |
@@ -33,6 +30,7 @@ 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' |
class ReplayError(Exception): |
@@ -46,11 +44,11 @@ class ReplayNotStartedError(Exception): |
pass |
-class ReplayLauncher(object): |
+class ReplayServer(object): |
tonyg
2012/05/18 15:37:54
Probably worth a brief comment explaining how this
slamm_google
2012/05/18 23:59:29
Done.
|
LOG_FILE = 'log.txt' |
def __init__(self, replay_dir, archive_path, log_dir, replay_options=None): |
- """Initialize ReplayLauncher. |
+ """Initialize ReplayServer. |
Args: |
replay_dir: directory that has replay.py and related modules. |
@@ -85,19 +83,6 @@ class ReplayLauncher(object): |
os.makedirs(self.log_dir) |
return open(self.log_name, 'w') |
- def StartServer(self): |
- cmd_line = [self.wpr_py] |
- cmd_line.extend(self.wpr_options) |
- # TODO(slamm): Support choosing archive on-the-fly. |
- cmd_line.append(self.archive_path) |
- self.log_fh = self._OpenLogFile() |
- logging.debug('Starting Web-Page-Replay: %s', cmd_line) |
- self.proxy_process = subprocess.Popen( |
- cmd_line, stdout=self.log_fh, stderr=subprocess.STDOUT) |
- if not self.IsStarted(): |
- raise ReplayNotStartedError( |
- 'Web Page Replay failed to start. See the log file: ' + self.log_name) |
- |
def IsStarted(self): |
"""Checks to see if the server is up and running.""" |
for _ in range(5): |
@@ -115,7 +100,20 @@ class ReplayLauncher(object): |
time.sleep(1) |
return False |
- def StopServer(self): |
+ def __enter__(self): |
+ cmd_line = [self.wpr_py] |
+ cmd_line.extend(self.wpr_options) |
+ # TODO(slamm): Support choosing archive on-the-fly. |
+ cmd_line.append(self.archive_path) |
+ self.log_fh = self._OpenLogFile() |
+ logging.debug('Starting Web-Page-Replay: %s', cmd_line) |
+ self.proxy_process = subprocess.Popen( |
+ cmd_line, stdout=self.log_fh, stderr=subprocess.STDOUT) |
+ if not self.IsStarted(): |
+ raise ReplayNotStartedError( |
+ 'Web Page Replay failed to start. See the log file: ' + self.log_name) |
+ |
+ def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): |
if self.proxy_process: |
logging.debug('Stopping Web-Page-Replay') |
# Use a SIGINT here so that it can do graceful cleanup. |
@@ -132,7 +130,8 @@ class ChromiumPaths(object): |
'archives': 'src/data/page_cycler/webpagereplay', |
'.wpr': 'src/data/page_cycler/webpagereplay/{TEST_NAME}.wpr', |
'.wpr_alt': 'src/tools/page_cycler/webpagereplay/tests/{TEST_NAME}.wpr', |
- 'start.html': 'src/tools/page_cycler/webpagereplay/start.html', |
+ 'start_url': ('src/tools/page_cycler/webpagereplay/start.html' |
+ '?test={TEST_NAME}'), |
'extension': 'src/tools/page_cycler/webpagereplay/extension', |
'replay': 'src/third_party/webpagereplay', |
'logs': 'src/webpagereplay_logs/{TEST_EXE_NAME}', |
@@ -150,20 +149,63 @@ class ChromiumPaths(object): |
module_dir, '..', '..', '..', '..')) |
self.replacements = replacements |
+ def GetArchivePath(self): |
+ if os.path.exists(self['archives']): |
+ return self['.wpr'] |
+ return self['.wpr_alt'] |
+ |
+ def GetStartUrl(self, iterations=None, use_auto=False): |
+ start_url = self['start_url'] |
+ if iterations is not None: |
+ start_url += '&iterations=%d' % iterations |
+ if use_auto: |
+ start_url += '&auto=1' |
+ return start_url |
+ |
def __getitem__(self, key): |
path_parts = [x.format(**self.replacements) |
for x in self.PATHS[key].split('/')] |
return os.path.join(self.base_dir, *path_parts) |
-def LaunchChromium(chrome_exe, chromium_paths, test_name, |
+def ChromeFlags(existing_flags=None, extension_path=None, |
+ is_dns_forwarded=False): |
+ flags = [] |
+ if existing_flags: |
+ flags.extend(existing_flags) |
+ if extension_path: |
+ flags.append('--load-extension=%s' % extension_path) |
+ if not is_dns_forwarded: |
+ flags.append('--host-resolver-rules=MAP * %s' % REPLAY_HOST) |
+ flags.extend([ |
+ '--testing-fixed-http-port=%s' % HTTP_PORT, |
+ '--testing-fixed-https-port=%s' % HTTPS_PORT, |
+ '--log-level=0', |
+ ]) |
+ extra_flags = [ |
+ '--disable-background-networking', |
+ '--enable-experimental-extension-apis', |
+ '--enable-file-cookies', |
tonyg
2012/05/18 15:37:54
This one isn't necessary since we aren't using fil
slamm_google
2012/05/18 23:59:29
The start URL is a file URL, and that is where the
|
+ '--enable-logging', |
+ '--enable-stats-table', |
+ '--enable-benchmarking', |
+ '--ignore-certificate-errors', |
+ '--metrics-recording-only', |
+ '--activate-on-launch', |
+ '--no-first-run', |
+ '--no-proxy-server', |
+ ] |
+ flags.extend(f for f in extra_flags if f not in flags) |
+ return flags |
+ |
+ |
+def LaunchChrome(chrome_exe, chromium_paths, test_name, |
is_dns_forwarded, use_auto): |
- """Launch chromium to run WPR-backed page cycler tests. |
+ """Launch chrome to run WPR-backed page cycler tests. |
These options need to be kept in sync with |
src/chrome/test/perf/page_cycler_test.cc. |
""" |
- REPLAY_HOST='127.0.0.1' |
user_data_dir = USER_DATA_DIR.format(**{'TEMP': tempfile.gettempdir()}) |
chromium_args = [ |
chrome_exe, |
@@ -182,14 +224,14 @@ def LaunchChromium(chrome_exe, chromium_paths, test_name, |
'--activate-on-launch', |
'--no-first-run', |
'--no-proxy-server', |
slamm_google
2012/05/18 00:20:24
This list will go away in favor of the one above.
|
+ |
+ |
'--user-data-dir=%s' % user_data_dir, |
'--window-size=1280,1024', |
] |
if not is_dns_forwarded: |
chromium_args.append('--host-resolver-rules=MAP * %s' % REPLAY_HOST) |
- start_url = 'file://%s?test=%s' % (chromium_paths['start.html'], test_name) |
- if use_auto: |
- start_url += '&auto=1' |
+ start_url = chromium_paths.GetStartUrl(test_name, use_auto=use_auto) |
chromium_args.append(start_url) |
if os.path.exists(user_data_dir): |
shutil.rmtree(user_data_dir) |
@@ -237,10 +279,7 @@ def main(): |
chromium_paths = ChromiumPaths( |
TEST_NAME=test_name, |
TEST_EXE_NAME='webpagereplay_utils') |
- if os.path.exists(chromium_paths['archives']): |
- archive_path = chromium_paths['.wpr'] |
- else: |
- archive_path = chromium_paths['.wpr_alt'] |
+ archive_path = chromium_paths.GetArchivePath() |
if not os.path.exists(archive_path) and not options.record: |
print >>sys.stderr, 'Archive does not exist:', archive_path |
return 1 |
@@ -255,14 +294,10 @@ def main(): |
replay_dir = options.replay_dir |
else: |
replay_dir = chromium_paths['replay'] |
- wpr = ReplayLauncher(replay_dir, archive_path, |
- chromium_paths['logs'], replay_options) |
- try: |
- wpr.StartServer() |
- LaunchChromium(chrome_exe, chromium_paths, test_name, |
- options.dns_forwarding, options.auto) |
- finally: |
- wpr.StopServer() |
+ with ReplayServer( |
+ replay_dir, archive_path, chromium_paths['logs'], replay_options): |
+ LaunchChrome(chrome_exe, chromium_paths, test_name, |
+ options.dns_forwarding, options.auto) |
return 0 |
if '__main__' == __name__: |