| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Loops Custom Tabs tests and outputs the results into a CSV file.""" | 7 """Loops Custom Tabs tests and outputs the results into a CSV file.""" |
| 8 | 8 |
| 9 import collections | 9 import collections |
| 10 import contextlib | 10 import contextlib |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 import device_setup | 34 import device_setup |
| 35 | 35 |
| 36 | 36 |
| 37 # Local build of Chrome (not Chromium). | 37 # Local build of Chrome (not Chromium). |
| 38 _CHROME_PACKAGE = 'com.google.android.apps.chrome' | 38 _CHROME_PACKAGE = 'com.google.android.apps.chrome' |
| 39 _COMMAND_LINE_FILE = 'chrome-command-line' | 39 _COMMAND_LINE_FILE = 'chrome-command-line' |
| 40 _TEST_APP_PACKAGE_NAME = 'org.chromium.customtabs.test' | 40 _TEST_APP_PACKAGE_NAME = 'org.chromium.customtabs.test' |
| 41 _INVALID_VALUE = -1 | 41 _INVALID_VALUE = -1 |
| 42 | 42 |
| 43 | 43 |
| 44 def RunOnce(device, url, warmup, speculation_mode, delay_to_may_launch_url, | 44 def RunOnce(device, url, speculated_url, warmup, speculation_mode, |
| 45 delay_to_launch_url, cold, chrome_args, reset_chrome_state): | 45 delay_to_may_launch_url, delay_to_launch_url, cold, chrome_args, |
| 46 reset_chrome_state): |
| 46 """Runs a test on a device once. | 47 """Runs a test on a device once. |
| 47 | 48 |
| 48 Args: | 49 Args: |
| 49 device: (DeviceUtils) device to run the tests on. | 50 device: (DeviceUtils) device to run the tests on. |
| 50 url: (str) URL to load. | 51 url: (str) URL to load. |
| 52 speculated_url: (str) Speculated URL. |
| 51 warmup: (bool) Whether to call warmup. | 53 warmup: (bool) Whether to call warmup. |
| 52 speculation_mode: (str) Speculation Mode. | 54 speculation_mode: (str) Speculation Mode. |
| 53 delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. | 55 delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. |
| 54 delay_to_launch_url: (int) Delay to launchUrl() in ms. | 56 delay_to_launch_url: (int) Delay to launchUrl() in ms. |
| 55 cold: (bool) Whether the page cache should be dropped. | 57 cold: (bool) Whether the page cache should be dropped. |
| 56 chrome_args: ([str]) List of arguments to pass to Chrome. | 58 chrome_args: ([str]) List of arguments to pass to Chrome. |
| 57 reset_chrome_state: (bool) Whether to reset the Chrome local state before | 59 reset_chrome_state: (bool) Whether to reset the Chrome local state before |
| 58 the run. | 60 the run. |
| 59 | 61 |
| 60 Returns: | 62 Returns: |
| 61 The output line (str), like this (one line only): | 63 The output line (str), like this (one line only): |
| 62 <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>, | 64 <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>, |
| 63 <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>, | 65 <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>, |
| 64 <first_contentful_paint> | 66 <first_contentful_paint> |
| 65 or None on error. | 67 or None on error. |
| 66 """ | 68 """ |
| 67 if not device.HasRoot(): | 69 if not device.HasRoot(): |
| 68 device.EnableRoot() | 70 device.EnableRoot() |
| 69 | 71 |
| 70 timeout_s = 20 | 72 timeout_s = 20 |
| 71 logcat_timeout = int(timeout_s + delay_to_may_launch_url / 1000. | 73 logcat_timeout = int(timeout_s + delay_to_may_launch_url / 1000. |
| 72 + delay_to_launch_url / 1000.) + 3; | 74 + delay_to_launch_url / 1000.) + 3; |
| 73 | 75 |
| 74 with flag_changer.CustomCommandLineFlags( | 76 with flag_changer.CustomCommandLineFlags( |
| 75 device, _COMMAND_LINE_FILE, chrome_args): | 77 device, _COMMAND_LINE_FILE, chrome_args): |
| 76 launch_intent = intent.Intent( | 78 launch_intent = intent.Intent( |
| 77 action='android.intent.action.MAIN', | 79 action='android.intent.action.MAIN', |
| 78 package=_TEST_APP_PACKAGE_NAME, | 80 package=_TEST_APP_PACKAGE_NAME, |
| 79 activity='org.chromium.customtabs.test.MainActivity', | 81 activity='org.chromium.customtabs.test.MainActivity', |
| 80 extras={'url': str(url), 'warmup': warmup, | 82 extras={'url': str(url), |
| 83 'speculated_url': str(speculated_url), |
| 84 'warmup': warmup, |
| 81 'speculation_mode': str(speculation_mode), | 85 'speculation_mode': str(speculation_mode), |
| 82 'delay_to_may_launch_url': delay_to_may_launch_url, | 86 'delay_to_may_launch_url': delay_to_may_launch_url, |
| 83 'delay_to_launch_url': delay_to_launch_url, | 87 'delay_to_launch_url': delay_to_launch_url, |
| 84 'timeout': timeout_s}) | 88 'timeout': timeout_s}) |
| 85 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') | 89 result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') |
| 86 logcat_monitor = device.GetLogcatMonitor(clear=True) | 90 logcat_monitor = device.GetLogcatMonitor(clear=True) |
| 87 logcat_monitor.Start() | 91 logcat_monitor.Start() |
| 88 device.ForceStop(_CHROME_PACKAGE) | 92 device.ForceStop(_CHROME_PACKAGE) |
| 89 device.ForceStop(_TEST_APP_PACKAGE_NAME) | 93 device.ForceStop(_TEST_APP_PACKAGE_NAME) |
| 90 | 94 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 '--force-fieldtrials=trial/group', | 164 '--force-fieldtrials=trial/group', |
| 161 '--force-fieldtrial-params=trial.group:mode/no_state_prefetch', | 165 '--force-fieldtrial-params=trial.group:mode/no_state_prefetch', |
| 162 '--enable-features=NoStatePrefetch<trial']) | 166 '--enable-features=NoStatePrefetch<trial']) |
| 163 elif config['speculation_mode'] == 'speculative_prefetch': | 167 elif config['speculation_mode'] == 'speculative_prefetch': |
| 164 # Speculative Prefetch is enabled through an experiment. | 168 # Speculative Prefetch is enabled through an experiment. |
| 165 chrome_args.extend([ | 169 chrome_args.extend([ |
| 166 '--force-fieldtrials=trial/group', | 170 '--force-fieldtrials=trial/group', |
| 167 '--force-fieldtrial-params=trial.group:mode/external-prefetching', | 171 '--force-fieldtrial-params=trial.group:mode/external-prefetching', |
| 168 '--enable-features=SpeculativeResourcePrefetching<trial']) | 172 '--enable-features=SpeculativeResourcePrefetching<trial']) |
| 169 | 173 |
| 170 result = RunOnce(device, config['url'], config['warmup'], | 174 result = RunOnce(device, config['url'], config['speculated_url'], |
| 171 config['speculation_mode'], | 175 config['warmup'], config['speculation_mode'], |
| 172 config['delay_to_may_launch_url'], | 176 config['delay_to_may_launch_url'], |
| 173 config['delay_to_launch_url'], config['cold'], | 177 config['delay_to_launch_url'], config['cold'], |
| 174 chrome_args, reset_chrome_state=True) | 178 chrome_args, reset_chrome_state=True) |
| 175 if result is not None: | 179 if result is not None: |
| 176 out.write(result + '\n') | 180 out.write(result + '\n') |
| 177 out.flush() | 181 out.flush() |
| 178 if once: | 182 if once: |
| 179 return | 183 return |
| 180 if should_stop is not None: | 184 if should_stop is not None: |
| 181 should_stop.wait(10.) | 185 should_stop.wait(10.) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 211 result['plt'] = data[:, 5] | 215 result['plt'] = data[:, 5] |
| 212 result['first_contentful_paint'] = data[:, 6] | 216 result['first_contentful_paint'] = data[:, 6] |
| 213 return result | 217 return result |
| 214 | 218 |
| 215 | 219 |
| 216 def _CreateOptionParser(): | 220 def _CreateOptionParser(): |
| 217 parser = optparse.OptionParser(description='Loops Custom Tabs tests on a ' | 221 parser = optparse.OptionParser(description='Loops Custom Tabs tests on a ' |
| 218 'device, and outputs the navigation timings ' | 222 'device, and outputs the navigation timings ' |
| 219 'in a CSV file.') | 223 'in a CSV file.') |
| 220 parser.add_option('--device', help='Device ID') | 224 parser.add_option('--device', help='Device ID') |
| 225 parser.add_option('--speculated_url', |
| 226 help='URL to call mayLaunchUrl() with.',) |
| 221 parser.add_option('--url', help='URL to navigate to.', | 227 parser.add_option('--url', help='URL to navigate to.', |
| 222 default='https://www.android.com') | 228 default='https://www.android.com') |
| 223 parser.add_option('--warmup', help='Call warmup.', default=False, | 229 parser.add_option('--warmup', help='Call warmup.', default=False, |
| 224 action='store_true') | 230 action='store_true') |
| 225 parser.add_option('--speculation_mode', default='prerender', | 231 parser.add_option('--speculation_mode', default='prerender', |
| 226 help='The speculation mode (prerender, ' | 232 help='The speculation mode (prerender, ' |
| 227 'speculative_prefetch or no_state_prefetch).', | 233 'speculative_prefetch or no_state_prefetch).', |
| 228 choices=['disabled', 'prerender', 'hidden_tab']) | 234 choices=['disabled', 'prerender', 'hidden_tab']) |
| 229 parser.add_option('--delay_to_may_launch_url', | 235 parser.add_option('--delay_to_may_launch_url', |
| 230 help='Delay before calling mayLaunchUrl() in ms.', | 236 help='Delay before calling mayLaunchUrl() in ms.', |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 sys.exit(0) | 288 sys.exit(0) |
| 283 if options.device is not None: | 289 if options.device is not None: |
| 284 matching_devices = [d for d in devices if str(d) == options.device] | 290 matching_devices = [d for d in devices if str(d) == options.device] |
| 285 if not matching_devices: | 291 if not matching_devices: |
| 286 logging.error('Device not found.') | 292 logging.error('Device not found.') |
| 287 sys.exit(0) | 293 sys.exit(0) |
| 288 device = matching_devices[0] | 294 device = matching_devices[0] |
| 289 | 295 |
| 290 config = { | 296 config = { |
| 291 'url': options.url, | 297 'url': options.url, |
| 298 'speculated_url': options.speculated_url or options.url, |
| 292 'warmup': options.warmup, | 299 'warmup': options.warmup, |
| 293 'speculation_mode': options.speculation_mode, | 300 'speculation_mode': options.speculation_mode, |
| 294 'delay_to_may_launch_url': options.delay_to_may_launch_url, | 301 'delay_to_may_launch_url': options.delay_to_may_launch_url, |
| 295 'delay_to_launch_url': options.delay_to_launch_url, | 302 'delay_to_launch_url': options.delay_to_launch_url, |
| 296 'cold': options.cold, | 303 'cold': options.cold, |
| 297 } | 304 } |
| 298 LoopOnDevice(device, [config], options.output_file, options.wpr_archive, | 305 LoopOnDevice(device, [config], options.output_file, options.wpr_archive, |
| 299 options.record, options.network_condition, options.wpr_log, | 306 options.record, options.network_condition, options.wpr_log, |
| 300 once=options.once) | 307 once=options.once) |
| 301 | 308 |
| 302 | 309 |
| 303 if __name__ == '__main__': | 310 if __name__ == '__main__': |
| 304 main() | 311 main() |
| OLD | NEW |