def _Setup(device, database_filename): """Sets up a device and returns an instance of RemoteChromeController.""" chrome_controller = prefetch_predictor_common.Setup(device, ['']) chrome_package = OPTIONS.ChromePackage() device.ForceStop(chrome_package.package) chrome_controller.ResetBrowserState() device_database_filename = prefetch_predictor_common.DatabaseDevicePath() owner = group = None # Make sure that the speculative prefetch predictor is enabled to ensure # that the disk database is re-created. command_line_path = '/data/local/tmp/chrome-command-line' with device_setup.FlagReplacer(device, command_line_path, ['--disable-fre', _EXTERNAL_PREFETCH_FLAG]): # Launch Chrome for the first time to recreate the local state. launch_intent = intent.Intent(action='android.intent.action.MAIN', package=chrome_package.package, activity=chrome_package.activity) device.StartActivity(launch_intent, blocking=True) time.sleep(5) device.ForceStop(chrome_package.package) assert device.FileExists(device_database_filename) stats = device.StatPath(device_database_filename) owner = stats['st_owner'] group = stats['st_group'] # Now push the database. Needs to be done after the first launch, otherwise # the profile directory is owned by root. Also change the owner of the # database, since adb push sets it to root. database_content = open(database_filename, 'r').read() device.WriteFile(device_database_filename, database_content, force_push=True) command = 'chown %s:%s \'%s\'' % (owner, group, device_database_filename) device.RunShellCommand(command, as_root=True)
def _GenerateWprArchive(device, url, archive_path): with device_setup.RemoteWprHost(device, archive_path, record=True) as wpr: chrome_controller = prefetch_predictor_common.Setup( device, wpr.chrome_args) with chrome_controller.Open() as connection: page_track.PageTrack(connection) # Registers the listeners. connection.MonitorUrl(url, timeout_seconds=_PAGE_LOAD_TIMEOUT, stop_delay_multiplier=1.5)
def main(): devil_chromium.Initialize() logging.basicConfig(level=logging.INFO) parser = _CreateArgumentParser() args = parser.parse_args() OPTIONS.SetParsedArgs(args) device = prefetch_predictor_common.FindDevice(args.device) if device is None: logging.error('Could not find device: %s.', args.device) sys.exit(1) chrome_controller = prefetch_predictor_common.Setup( device, ['--speculative-resource-prefetching=learning']) _Go(chrome_controller, args.urls_filename, args.output_filename, int(args.url_repeat))
def main(): devil_chromium.Initialize() logging.basicConfig(level=logging.INFO) parser = _CreateArgumentParser() args = parser.parse_args() OPTIONS.SetParsedArgs(args) device = prefetch_predictor_common.FindDevice(args.device) if device is None: logging.error('Could not find device: %s.', args.device) sys.exit(1) chrome_controller = prefetch_predictor_common.Setup(device, _LEARNING_FLAGS) _GenerateDatabase(chrome_controller, args.urls_filename, args.output_filename, int(args.url_repeat)) _GenerateWprArchive(device, args.test_url, args.wpr_archive)