Chromium Code Reviews| Index: tools/android/loading/run_sandwich.py |
| diff --git a/tools/android/loading/run_sandwich.py b/tools/android/loading/run_sandwich.py |
| index 422134fb154664ff17e3ea85a9b0585a94d2e448..f44edb3089a97ce591bb189cb017b511c872d246 100755 |
| --- a/tools/android/loading/run_sandwich.py |
| +++ b/tools/android/loading/run_sandwich.py |
| @@ -33,6 +33,7 @@ sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) |
| from pylib import constants |
| import devil_chromium |
| +import chrome_setup |
| import device_setup |
| import devtools_monitor |
| import options |
| @@ -64,6 +65,10 @@ _TIME_TO_DEVICE_IDLE_SECONDS = 2 |
| # Cache directory's path on the device. |
| _REMOTE_CACHE_DIRECTORY = '/data/data/' + _CHROME_PACKAGE + '/cache/Cache' |
| +# Websocket timeout of 1 minute to avoid websocket timeout on slow |
|
Benoit L
2016/02/18 13:01:25
As above, need a better name (and comment).
gabadie
2016/02/18 13:21:58
Done.
|
| +# network condition. |
| +_WEBSOCKET_TIMEOUT = 60 |
| + |
| def _ReadUrlsFromJobDescription(job_name): |
| """Retrieves the list of URLs associated with the job name.""" |
| @@ -257,11 +262,9 @@ def _CleanPreviousTraces(output_directories_path): |
| shutil.rmtree(directory_path) |
| -def main(): |
| - logging.basicConfig(level=logging.INFO) |
| - devil_chromium.Initialize() |
| - options.OPTIONS.ParseArgs([]) |
| - |
| +def _ArgumentParser(): |
| + """Build a command line argument's parser. |
| + """ |
| parser = argparse.ArgumentParser() |
| parser.add_argument('--job', required=True, |
| help='JSON file with job description.') |
| @@ -283,7 +286,22 @@ def main(): |
| help='Disable WPR default script injection such as ' + |
| 'overriding javascript\'s Math.random() and Date() ' + |
| 'with deterministic implementations.') |
| - args = parser.parse_args() |
| + parser.add_argument('--network-condition', default=None, |
| + choices=sorted(chrome_setup.NETWORK_CONDITIONS.keys()), |
| + help='Set a network profile.') |
| + parser.add_argument('--network-emulator', default='browser', |
| + choices=['browser', 'wpr'], |
| + help='Set which component is emulating the network condition.' + |
| + ' (Default to browser)') |
| + return parser |
| + |
| + |
| +def main(): |
| + logging.basicConfig(level=logging.INFO) |
| + devil_chromium.Initialize() |
| + options.OPTIONS.ParseArgs([]) |
|
Benoit L
2016/02/18 13:01:25
Don't you want to pass the command line here?
gabadie
2016/02/18 13:21:58
No. This is just a work around that has been added
mattcary
2016/02/19 15:40:17
The problem though is that many of the other libra
|
| + |
| + args = _ArgumentParser().parse_args() |
| if not os.path.isdir(args.output): |
| try: |
| @@ -303,22 +321,41 @@ def main(): |
| device = device_utils.DeviceUtils.HealthyDevices()[0] |
| local_cache_archive_path = os.path.join(args.output, 'cache.zip') |
| local_cache_directory_path = None |
| + wpr_network_condition_name = None |
| + browser_network_condition_name = None |
| + if args.network_emulator == 'wpr': |
| + wpr_network_condition_name = args.network_condition |
| + elif args.network_emulator == 'browser': |
| + browser_network_condition_name = args.network_condition |
| + else: |
| + assert False |
| if args.cache_op == 'push': |
| assert os.path.isfile(local_cache_archive_path) |
| local_cache_directory_path = tempfile.mkdtemp(suffix='.cache') |
| _UnzipDirectoryContent(local_cache_archive_path, local_cache_directory_path) |
| - with device_setup.WprHost(device, args.wpr_archive, args.wpr_record, |
| - args.disable_wpr_script_injection) as additional_flags: |
| + with device_setup.WprHost(device, args.wpr_archive, |
| + record=args.wpr_record, |
| + network_condition_name=wpr_network_condition_name, |
| + disable_script_injection=args.disable_wpr_script_injection |
| + ) as additional_flags: |
| def _RunNavigation(url, clear_cache, trace_id): |
| with device_setup.DeviceConnection( |
| device=device, |
| additional_flags=additional_flags) as connection: |
| + additional_metadata = {} |
| + if browser_network_condition_name: |
| + additional_metadata = chrome_setup.SetUpEmulationAndReturnMetadata( |
| + connection=connection, |
| + emulated_device_name=None, |
| + emulated_network_name=browser_network_condition_name) |
| loading_trace = trace_recorder.MonitorUrl( |
| connection, url, |
| clear_cache=clear_cache, |
| - categories=pull_sandwich_metrics.CATEGORIES) |
| + categories=pull_sandwich_metrics.CATEGORIES, |
| + timeout=_WEBSOCKET_TIMEOUT) |
| + loading_trace.metadata.update(additional_metadata) |
| if trace_id != None: |
| loading_trace_path = os.path.join( |
| args.output, str(trace_id), 'trace.json') |