diff options
author | hartmanng@chromium.org <hartmanng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-04 17:54:51 +0000 |
---|---|---|
committer | hartmanng@chromium.org <hartmanng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-04 17:54:51 +0000 |
commit | d0274482cbfce3d738f34efbf7a3a9a4c3d0cad4 (patch) | |
tree | 7f6496ae3aab3aa2913a8694f697bc746802eb3b | |
parent | fed76dedba96586df3585f75fbb9beab34cb8081 (diff) | |
download | chromium_src-d0274482cbfce3d738f34efbf7a3a9a4c3d0cad4.zip chromium_src-d0274482cbfce3d738f34efbf7a3a9a4c3d0cad4.tar.gz chromium_src-d0274482cbfce3d738f34efbf7a3a9a4c3d0cad4.tar.bz2 |
[telemetry] Removing globals from webpagereplay.py.
This is another clean-up patch for https://codereview.chromium.org/11348217/#msg10.
These globals have been complicating things, so it should be cleaner to have them
explicitly passed in when needed.
BUG=157459
TBR=kkania
Review URL: https://chromiumcodereview.appspot.com/11740020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175149 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | chrome/test/functional/devtools_test_base.py | 15 | ||||
-rwxr-xr-x | chrome/test/functional/perf.py | 35 | ||||
-rwxr-xr-x | chrome/test/functional/perf_endure.py | 16 | ||||
-rwxr-xr-x | chrome/test/functional/webpagereplay.py | 36 | ||||
-rw-r--r-- | tools/telemetry/telemetry/browser.py | 7 | ||||
-rw-r--r-- | tools/telemetry/telemetry/browser_backend.py | 9 | ||||
-rw-r--r-- | tools/telemetry/telemetry/wpr_server.py | 24 |
7 files changed, 100 insertions, 42 deletions
diff --git a/chrome/test/functional/devtools_test_base.py b/chrome/test/functional/devtools_test_base.py index bf938d8..b89fda1 100755 --- a/chrome/test/functional/devtools_test_base.py +++ b/chrome/test/functional/devtools_test_base.py @@ -33,6 +33,10 @@ class DevToolsTestBase(pyauto.PyUITest): os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'data', 'devtools_test_pages')) + WEBPAGEREPLAY_HOST = '127.0.0.1' + WEBPAGEREPLAY_HTTP_PORT = 8080 + WEBPAGEREPLAY_HTTPS_PORT = 8413 + def ExtraChromeFlags(self): """Ensures Chrome is launched with custom flags. @@ -41,7 +45,10 @@ class DevToolsTestBase(pyauto.PyUITest): """ # Ensure Chrome enables remote debugging on port 9222. This is required to # interact with Chrome's remote inspector. - extra_flags = ['--remote-debugging-port=9222'] + webpagereplay.CHROME_FLAGS + extra_flags = ['--remote-debugging-port=9222'] + \ + webpagereplay.GetChromeFlags(self.WEBPAGEREPLAY_HOST, + self.WEBPAGEREPLAY_HTTP_PORT, + self.WEBPAGEREPLAY_HTTPS_PORT) return (pyauto.PyUITest.ExtraChromeFlags(self) + extra_flags) def setUp(self): @@ -63,7 +70,11 @@ class DevToolsTestBase(pyauto.PyUITest): replay_options = None hostname = urlparse(url).hostname archive_path = os.path.join(self.DATA_PATH, hostname + '.wpr') - with webpagereplay.ReplayServer(archive_path, replay_options): + with webpagereplay.ReplayServer(archive_path, + self.WEBPAGEREPLAY_HOST, + self.WEBPAGEREPLAY_HTTP_PORT, + self.WEBPAGEREPLAY_HTTPS_PORT, + replay_options): self.NavigateToURL(url) snapshot = self._remote_inspector_client.GetProcessMemoryDistribution() logging.info('Got snapshot for url: %s' % url) diff --git a/chrome/test/functional/perf.py b/chrome/test/functional/perf.py index f82c709..df8caad 100755 --- a/chrome/test/functional/perf.py +++ b/chrome/test/functional/perf.py @@ -2286,17 +2286,24 @@ class PageCyclerReplay(object): 'extension': 'src/tools/page_cycler/webpagereplay/extension', } - CHROME_FLAGS = webpagereplay.CHROME_FLAGS + [ - '--log-level=0', - '--disable-background-networking', - '--enable-experimental-extension-apis', - '--enable-logging', - '--enable-benchmarking', - '--metrics-recording-only', - '--activate-on-launch', - '--no-first-run', - '--no-proxy-server', - ] + WEBPAGEREPLAY_HOST = '127.0.0.1' + WEBPAGEREPLAY_HTTP_PORT = 8080 + WEBPAGEREPLAY_HTTPS_PORT = 8413 + + CHROME_FLAGS = webpagereplay.GetChromeFlags( + self.WEBPAGEREPLAY_HOST, + self.WEBPAGEREPLAY_HTTP_PORT, + self.WEBPAGEREPLAY_HTTPS_PORT) + [ + '--log-level=0', + '--disable-background-networking', + '--enable-experimental-extension-apis', + '--enable-logging', + '--enable-benchmarking', + '--metrics-recording-only', + '--activate-on-launch', + '--no-first-run', + '--no-proxy-server', + ] @classmethod def Path(cls, key, **kwargs): @@ -2305,7 +2312,11 @@ class PageCyclerReplay(object): @classmethod def ReplayServer(cls, test_name, replay_options=None): archive_path = cls.Path('archive', test_name=test_name) - return webpagereplay.ReplayServer(archive_path, replay_options) + return webpagereplay.ReplayServer(archive_path, + self.WEBPAGEREPLAY_HOST, + self.WEBPAGEREPLAY_HTTP_PORT, + self.WEBPAGEREPLAY_HTTPS_PORT, + replay_options) class PageCyclerNetSimTest(BasePageCyclerTest): diff --git a/chrome/test/functional/perf_endure.py b/chrome/test/functional/perf_endure.py index c45c0df..b351831 100755 --- a/chrome/test/functional/perf_endure.py +++ b/chrome/test/functional/perf_endure.py @@ -1287,7 +1287,15 @@ class ChromeEndureReplay(object): 'scripts': 'src/chrome/test/data/chrome_endure/webpagereplay/wpr_deterministic.js', } - CHROME_FLAGS = webpagereplay.CHROME_FLAGS + + WEBPAGEREPLAY_HOST = '127.0.0.1' + WEBPAGEREPLAY_HTTP_PORT = 8080 + WEBPAGEREPLAY_HTTPS_PORT = 8413 + + CHROME_FLAGS = webpagereplay.GetChromeFlags( + self.WEBPAGEREPLAY_HOST, + self.WEBPAGEREPLAY_HTTP_PORT, + self.WEBPAGEREPLAY_HTTPS_PORT) @classmethod def Path(cls, key, **kwargs): @@ -1304,7 +1312,11 @@ class ChromeEndureReplay(object): replay_options = ['--inject_scripts', scripts] if 'WPR_RECORD' in os.environ: replay_options.append('--append') - return webpagereplay.ReplayServer(archive_path, replay_options) + return webpagereplay.ReplayServer(archive_path, + self.WEBPAGEREPLAY_HOST, + self.WEBPAGEREPLAY_HTTP_PORT, + self.WEBPAGEREPLAY_HTTPS_PORT, + replay_options) if __name__ == '__main__': diff --git a/chrome/test/functional/webpagereplay.py b/chrome/test/functional/webpagereplay.py index c6d3350..c86af50 100755 --- a/chrome/test/functional/webpagereplay.py +++ b/chrome/test/functional/webpagereplay.py @@ -5,8 +5,7 @@ """Start and stop Web Page Replay. -Of the public module names, the following ones are key: - CHROME_FLAGS: Chrome options to make it work with Web Page Replay. +Of the public module names, the following one is key: ReplayServer: a class to start/stop Web Page Replay. """ @@ -19,16 +18,6 @@ import time import urllib -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', - ] - _CHROME_BASE_DIR = os.path.abspath(os.path.join( os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) REPLAY_DIR = os.path.join( @@ -37,6 +26,15 @@ LOG_PATH = os.path.join( _CHROME_BASE_DIR, 'src', 'webpagereplay_logs', 'logs.txt') +# Chrome options to make it work with Web Page Replay. +def GetChromeFlags(replay_host, http_port, https_port): + return [ + '--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): """Catch-all exception for the module.""" pass @@ -72,7 +70,8 @@ class ReplayServer(object): WPR_RECORD: if set, puts Web Page Replay in record mode instead of replay. WPR_REPLAY_DIR: path to alternate Web Page Replay source. """ - def __init__(self, archive_path, replay_options=None, replay_dir=None, + def __init__(self, archive_path, replay_host, http_port, https_port, + replay_options=None, replay_dir=None, log_path=None): """Initialize ReplayServer. @@ -86,6 +85,9 @@ class ReplayServer(object): self.replay_options = list(replay_options or ()) self.replay_dir = os.environ.get('WPR_REPLAY_DIR', replay_dir or REPLAY_DIR) self.log_path = log_path or LOG_PATH + self._http_port = http_port + self._https_port = https_port + self._replay_host = replay_host if 'WPR_RECORD' in os.environ and '--record' not in self.replay_options: self.replay_options.append('--record') @@ -106,8 +108,8 @@ class ReplayServer(object): def _AddDefaultReplayOptions(self): """Set WPR command-line options. Can be overridden if needed.""" self.replay_options += [ - '--port', str(HTTP_PORT), - '--ssl_port', str(HTTPS_PORT), + '--port', str(self._http_port), + '--ssl_port', str(self._https_port), '--use_closest_match', '--no-dns_forwarding', ] @@ -130,8 +132,8 @@ class ReplayServer(object): break try: up_url = '%s://localhost:%s/web-page-replay-generate-200' - http_up_url = up_url % ('http', HTTP_PORT) - https_up_url = up_url % ('https', HTTPS_PORT) + http_up_url = up_url % ('http', self._http_port) + https_up_url = up_url % ('https', self._https_port) if (200 == urllib.urlopen(http_up_url, None, {}).getcode() and 200 == urllib.urlopen(https_up_url, None, {}).getcode()): return True diff --git a/tools/telemetry/telemetry/browser.py b/tools/telemetry/telemetry/browser.py index cfa2569..62e31c3 100644 --- a/tools/telemetry/telemetry/browser.py +++ b/tools/telemetry/telemetry/browser.py @@ -118,7 +118,12 @@ class Browser(object): assert os.path.isfile(archive_path) self._wpr_server = wpr_server.ReplayServer( - self._backend, archive_path, use_record_mode) + self._backend, + archive_path, + use_record_mode, + self._backend.WEBPAGEREPLAY_HOST, + self._backend.WEBPAGEREPLAY_HTTP_PORT, + self._backend.WEBPAGEREPLAY_HTTPS_PORT) def GetStandardOutput(self): return self._backend.GetStandardOutput() diff --git a/tools/telemetry/telemetry/browser_backend.py b/tools/telemetry/telemetry/browser_backend.py index ff55af4..a20c06a 100644 --- a/tools/telemetry/telemetry/browser_backend.py +++ b/tools/telemetry/telemetry/browser_backend.py @@ -119,6 +119,11 @@ class TabController(object): class BrowserBackend(object): """A base class for browser backends. Provides basic functionality once a remote-debugger port has been established.""" + + WEBPAGEREPLAY_HOST = '127.0.0.1' + WEBPAGEREPLAY_HTTP_PORT = 8080 + WEBPAGEREPLAY_HTTPS_PORT = 8413 + def __init__(self, is_content_shell, options): self.tabs = None self.browser_type = options.browser_type @@ -141,7 +146,9 @@ class BrowserBackend(object): args.append('--metrics-recording-only') args.append('--no-first-run') if self.options.wpr_mode != wpr_modes.WPR_OFF: - args.extend(wpr_server.CHROME_FLAGS) + args.extend(wpr_server.GetChromeFlags(self.WEBPAGEREPLAY_HOST, + self.WEBPAGEREPLAY_HTTP_PORT, + self.WEBPAGEREPLAY_HTTPS_PORT)) args.extend(user_agent.GetChromeUserAgentArgumentFromType( self.options.browser_user_agent_type)) return args diff --git a/tools/telemetry/telemetry/wpr_server.py b/tools/telemetry/telemetry/wpr_server.py index aa30a18..6c202cf 100644 --- a/tools/telemetry/telemetry/wpr_server.py +++ b/tools/telemetry/telemetry/wpr_server.py @@ -14,29 +14,39 @@ sys.path.append( '../../../chrome/test/functional'))) import webpagereplay # pylint: disable=F0401 -CHROME_FLAGS = webpagereplay.CHROME_FLAGS +def GetChromeFlags(replay_host, http_port, https_port): + return webpagereplay.GetChromeFlags(replay_host, http_port, https_port) class ReplayServer(object): - def __init__(self, browser_backend, path, is_record_mode): + def __init__(self, browser_backend, path, is_record_mode, webpagereplay_host, + webpagereplay_http_port, webpagereplay_https_port): self._browser_backend = browser_backend self._forwarder = None self._web_page_replay = None self._is_record_mode = is_record_mode + self._webpagereplay_host = webpagereplay_host + self._webpagereplay_http_port = webpagereplay_http_port + self._webpagereplay_https_port = webpagereplay_https_port # Note: This can cause flake if server doesn't shut down properly and keeps # ports tied up. See crbug.com/157459. self._forwarder = browser_backend.CreateForwarder( - util.PortPair(webpagereplay.HTTP_PORT, - webpagereplay.HTTP_PORT), - util.PortPair(webpagereplay.HTTPS_PORT, - webpagereplay.HTTPS_PORT)) + util.PortPair(self._webpagereplay_http_port, + self._webpagereplay_http_port), + util.PortPair(self._webpagereplay_https_port, + self._webpagereplay_https_port)) options = [] if self._is_record_mode: options.append('--record') if not browser_backend.options.wpr_make_javascript_deterministic: options.append('--inject_scripts=') - self._web_page_replay = webpagereplay.ReplayServer(path, options) + self._web_page_replay = webpagereplay.ReplayServer( + path, + self._webpagereplay_host, + self._webpagereplay_http_port, + self._webpagereplay_https_port, + options) self._web_page_replay.StartServer() def __enter__(self): |