Beispiel #1
0
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 _Go(chrome_controller, urls_filename, output_filename, repeats):
  urls = []
  with open(urls_filename) as f:
    urls = [line.strip() for line in f.readlines()]

  with chrome_controller.Open() as connection:
    for repeat in range(repeats):
      logging.info('Repeat #%d', repeat)
      for url in urls:
        logging.info('\tLoading %s', url)
        page_track.PageTrack(connection)  # Registers the listeners.
        connection.MonitorUrl(url, timeout_seconds=_PAGE_LOAD_TIMEOUT,
                              stop_delay_multiplier=1.5)
        time.sleep(2)  # Reduces flakiness.

  device = chrome_controller.GetDevice()
  device.ForceStop(OPTIONS.ChromePackage().package)
  device.PullFile(prefetch_predictor_common.DatabaseDevicePath(),
                  output_filename)