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

Side by Side Diff: chrome/test/functional/webpagereplay.py

Issue 10825025: Make it easy to use Web Page Replay with non-page_cycler tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minimize CL diff Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Start and stop Web Page Replay.""" 6 """Start and stop Web Page Replay."""
7 7
8 import logging 8 import logging
9 import optparse
10 import os 9 import os
11 import shutil
12 import signal 10 import signal
13 import subprocess 11 import subprocess
14 import sys
15 import tempfile
16 import time 12 import time
17 import urllib 13 import urllib
18 14
19 15
20 USAGE = '%s [options] CHROME_EXE TEST_NAME' % os.path.basename(sys.argv[0])
21 USER_DATA_DIR = '{TEMP}/webpagereplay_utils-chrome'
22
23 # The port numbers must match those in chrome/test/perf/page_cycler_test.cc.
24 HTTP_PORT = 8080 16 HTTP_PORT = 8080
25 HTTPS_PORT = 8413 17 HTTPS_PORT = 8413
26 REPLAY_HOST='127.0.0.1' 18 REPLAY_HOST='127.0.0.1'
19 CHROME_FLAGS = [
20 '--host-resolver-rules=MAP * %s,EXCLUDE localhost' % REPLAY_HOST,
21 '--testing-fixed-http-port=%s' % HTTP_PORT,
22 '--testing-fixed-https-port=%s' % HTTPS_PORT,
23 '--ignore-certificate-errors',
24 ]
27 25
28 26
29 class ReplayError(Exception): 27 class ReplayError(Exception):
30 """Catch-all exception for the module.""" 28 """Catch-all exception for the module."""
31 pass 29 pass
32 30
33 class ReplayNotFoundError(ReplayError): 31 class ReplayNotFoundError(ReplayError):
34 pass 32 pass
35 33
36 class ReplayNotStartedError(ReplayError): 34 class ReplayNotStartedError(ReplayError):
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if self.log_fh: 126 if self.log_fh:
129 self.log_fh.close() 127 self.log_fh.close()
130 128
131 def __enter__(self): 129 def __enter__(self):
132 """Add support for with-statement.""" 130 """Add support for with-statement."""
133 self.StartServer() 131 self.StartServer()
134 132
135 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): 133 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb):
136 """Add support for with-statement.""" 134 """Add support for with-statement."""
137 self.StopServer() 135 self.StopServer()
136
137
138 class ChromiumPaths(object):
139 """Convert POSIX-style Chromium tree paths to OS-specific absolute paths."""
140 _BASE_DIR = os.path.abspath(os.path.join(
141 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir))
142
143 @classmethod
144 def Format(cls, relative_path, **kwargs):
145 return cls.AbsPath(relative_path.format(**kwargs))
146
147 @classmethod
148 def AbsPath(cls, relative_path):
149 return os.path.join(cls._BASE_DIR, *relative_path.split('/'))
150
151
152 class PerfReplayServer(ReplayServer):
153 """Run tests with network simulation via Web Page Replay.
154
155 Web Page Replay is a proxy that can record and "replay" web pages with
156 simulated network characteristics -- without having to edit the pages
157 by hand. With WPR, tests can use "real" web content, and catch
158 performance issues that may result from introducing network delays and
159 bandwidth throttling.
160
161 Environment Variables:
162 WPR_ARCHIVE_PATH: path to alternate archive file (e.g. '/tmp/foo.wpr').
163 WPR_RECORD: if set, puts Web Page Replay in record mode instead of replay.
164 WPR_REPLAY_DIR: path to alternate Web Page Replay source (for development).
165 """
166 REPLAY_DIR = 'src/third_party/webpagereplay'
167 LOGS_DIR = 'src/webpagereplay_logs'
168
169 def __init__(self, archive_path):
170 self.is_record_mode = 'WPR_RECORD' in os.environ
171 archive_path = os.environ.get('WPR_ARCHIVE_PATH', archive_path)
172 replay_dir = os.environ.get('WPR_REPLAY_DIR',
173 ChromiumPaths.AbsPath(self.REPLAY_DIR))
174 logs_dir = ChromiumPaths.AbsPath(self.LOGS_DIR)
175
176 replay_options = []
177 replay_options.append('--no-dns_forwarding')
178 if self.is_record_mode:
179 replay_options.append('--record')
180
181 assert archive_path, 'Archive path is not set.'
182 if self.is_record_mode:
183 archive_dir = os.path.dirname(archive_path)
184 assert os.path.exists(archive_dir), \
185 'Archive directory does not exist: %s' % archive_dir
186 else:
187 assert os.path.exists(archive_path), \
188 'Archive file path does not exist: %s' % archive_path
189
190 super(PerfWebPageReplay, self).__init__(
191 replay_dir, archive_path, logs_dir, replay_options)
OLDNEW
« chrome/test/functional/perf.py ('K') | « chrome/test/functional/perf.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698