def RunChrome(device, cold, chrome_args, package_info): """Runs Chrome on the device. Args: device: (DeviceUtils) device to run the tests on. cold: (bool) Whether caches should be dropped. chrome_args: ([str]) List of arguments to pass to Chrome. package_info: (PackageInfo) Chrome package info. """ if not device.HasRoot(): device.EnableRoot() cmdline_file = package_info.cmdline_file package = package_info.package with flag_changer.CustomCommandLineFlags(device, cmdline_file, chrome_args): device.ForceStop(package) if cold: chrome_setup.ResetChromeLocalState(device, package) cache_control.CacheControl(device).DropRamCaches() start_intent = intent.Intent(package=package, data='about:blank', activity=package_info.activity) try: device.StartActivity(start_intent, blocking=True) print('\n\n' ' +---------------------------------------------+\n' ' | Chrome launched, press Ctrl-C to interrupt. |\n' ' +---------------------------------------------+') while True: time.sleep(1) except KeyboardInterrupt: pass finally: device.ForceStop(package)
def RunOnce(device, url, warmup, speculation_mode, delay_to_may_launch_url, delay_to_launch_url, cold, chrome_args, reset_chrome_state): """Runs a test on a device once. Args: device: (DeviceUtils) device to run the tests on. url: (str) URL to load. warmup: (bool) Whether to call warmup. speculation_mode: (str) Speculation Mode. delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. delay_to_launch_url: (int) Delay to launchUrl() in ms. cold: (bool) Whether the page cache should be dropped. chrome_args: ([str]) List of arguments to pass to Chrome. reset_chrome_state: (bool) Whether to reset the Chrome local state before the run. Returns: The output line (str), like this (one line only): <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>, <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>, <first_contentful_paint> or None on error. """ if not device.HasRoot(): device.EnableRoot() timeout_s = 20 logcat_timeout = int(timeout_s + delay_to_may_launch_url / 1000. + delay_to_launch_url / 1000.) + 3 with device_setup.FlagReplacer(device, _COMMAND_LINE_FILE, chrome_args): launch_intent = intent.Intent( action='android.intent.action.MAIN', package=_TEST_APP_PACKAGE_NAME, activity='org.chromium.customtabs.test.MainActivity', extras={ 'url': str(url), 'warmup': warmup, 'speculation_mode': str(speculation_mode), 'delay_to_may_launch_url': delay_to_may_launch_url, 'delay_to_launch_url': delay_to_launch_url, 'timeout': timeout_s }) result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)') logcat_monitor = device.GetLogcatMonitor(clear=True) logcat_monitor.Start() device.ForceStop(_CHROME_PACKAGE) device.ForceStop(_TEST_APP_PACKAGE_NAME) if reset_chrome_state: chrome_setup.ResetChromeLocalState(device, _CHROME_PACKAGE) if cold: cache_control.CacheControl(device).DropRamCaches() device.StartActivity(launch_intent, blocking=True) match = None try: match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout) except device_errors.CommandTimeoutError as _: logging.warning('Timeout waiting for the result line') logcat_monitor.Stop() logcat_monitor.Close() return match.group(1) if match is not None else None
def RunOnce(device, url, speculated_url, parallel_url, warmup, skip_launcher_activity, speculation_mode, delay_to_may_launch_url, delay_to_launch_url, cold, pinning_benchmark, pin_filename, pin_offset, pin_length, extra_brief_memory_mb, chrome_args, reset_chrome_state): """Runs a test on a device once. Args: device: (DeviceUtils) device to run the tests on. url: (str) URL to load. End of the redirect chain when using a parallel request. speculated_url: (str) Speculated URL. parallel_url: ([str]) URL to load in parallel, typically the start of the redirect chain. warmup: (bool) Whether to call warmup. skip_launcher_activity: (bool) Whether to skip the launcher activity. speculation_mode: (str) Speculation Mode. delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms. delay_to_launch_url: (int) Delay to launchUrl() in ms. cold: (bool) Whether the page cache should be dropped. pinning_benchmark: (bool) Whether to perform the 'pinning benchmark'. pin_filename: (str) The file to pin on the device. pin_offset: (int) Start offset of the range to pin. pin_length: (int) Number of bytes to pin. extra_brief_memory_mb: (int) Number of MiB to consume before starting Chrome. Applies only to the 'pinning benchmark' scenario. chrome_args: ([str]) List of arguments to pass to Chrome. reset_chrome_state: (bool) Whether to reset the Chrome local state before the run. Returns: The output line (str), like this (one line only): <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>, <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>, <first_contentful_paint> or None on error. """ if not device.HasRoot(): device.EnableRoot() timeout_s = 64 logcat_timeout = int(timeout_s + delay_to_may_launch_url / 1000. + delay_to_launch_url / 1000.) with flag_changer.CustomCommandLineFlags(device, _COMMAND_LINE_FILE, chrome_args): launch_intent = intent.Intent( action='android.intent.action.MAIN', package=_TEST_APP_PACKAGE_NAME, activity='org.chromium.customtabs.test.MainActivity', extras={ 'url': str(url), 'speculated_url': str(speculated_url), 'parallel_url': str(parallel_url), 'warmup': warmup, 'skip_launcher_activity': skip_launcher_activity, 'speculation_mode': str(speculation_mode), 'delay_to_may_launch_url': delay_to_may_launch_url, 'delay_to_launch_url': delay_to_launch_url, 'pinning_benchmark': pinning_benchmark, 'pin_filename': str(pin_filename), 'pin_offset': pin_offset, 'pin_length': pin_length, 'extra_brief_memory_mb': extra_brief_memory_mb, 'timeout': timeout_s }) result_line_re = re.compile(r'CUSTOMTABSBENCHCSV.*: (.*)') logcat_monitor = device.GetLogcatMonitor(clear=True) logcat_monitor.Start() device.ForceStop(_CHROME_PACKAGE) device.ForceStop(_TEST_APP_PACKAGE_NAME) if reset_chrome_state: chrome_setup.ResetChromeLocalState(device, _CHROME_PACKAGE) if cold: cache_control.CacheControl(device).DropRamCaches() device.StartActivity(launch_intent, blocking=True) match = None try: match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout) except device_errors.CommandTimeoutError as _: logging.warning('Timeout waiting for the result line') logcat_monitor.Stop() logcat_monitor.Close() return match.group(1) if match is not None else None
def ResetBrowserState(self): """Override resetting Chrome local state.""" logging.info('Resetting Chrome local state') chrome_setup.ResetChromeLocalState(self._device, OPTIONS.ChromePackage().package)