def __init__(self, test, finder_options, story_set, possible_browser=None):
   """
   Args:
     test: opaquely passed to parent class constructor.
     finder_options: A BrowserFinderOptions object.
     story_set: opaquely passed to parent class constructor.
   """
   super(_MobileStartupSharedState, self).__init__(
       test, finder_options, story_set, possible_browser)
   self._finder_options = finder_options
   if not self._possible_browser:
     self._possible_browser = browser_finder.FindBrowser(self._finder_options)
   self._current_story = None
   # Allow using this shared state only on Android.
   assert isinstance(self.platform, android_platform.AndroidPlatform)
   self._finder_options.browser_options.browser_user_agent_type = 'mobile'
   self._finder_options.browser_options.AppendExtraBrowserArgs(
       '--skip-webapk-verification')
   self.platform.Initialize()
   self.platform.SetFullPerformanceModeEnabled(True)
   self.platform.InstallApplication(core_util.FindLatestApkOnHost(
       finder_options.chrome_root, 'MapsWebApk.apk'))
   wpr_mode = wpr_modes.WPR_REPLAY
   self._number_of_iterations = _NUMBER_OF_ITERATIONS
   if finder_options.use_live_sites:
     wpr_mode = wpr_modes.WPR_OFF
   elif finder_options.browser_options.wpr_mode == wpr_modes.WPR_RECORD:
     wpr_mode = wpr_modes.WPR_RECORD
     # When recording a WPR archive only load the story page once.
     self._number_of_iterations = 1
   self.platform.network_controller.Open(wpr_mode)
   self._story_set = story_set
 def FindLocalApk(self, device, chrome_root):
     apk_name = self.GetApkName(device)
     logging.info('Picked apk name %s for browser_type %s', apk_name,
                  self.browser_type)
     if apk_name is None:
         return None
     else:
         return util.FindLatestApkOnHost(chrome_root, apk_name)
 def FindEmbedderApk(self, apk_path, chrome_root):
     # Try to find the embedder next to the local APK found.
     if apk_path is not None:
         embedder_apk_path = os.path.join(os.path.dirname(apk_path),
                                          self.embedder_apk_name)
         if os.path.exists(embedder_apk_path):
             return embedder_apk_path
     # Otherwise fall back to an APK found among possible build directories.
     return util.FindLatestApkOnHost(chrome_root, self.embedder_apk_name)
Example #4
0
  def SetUpProcess(cls):
    """Prepares the test device"""
    super(WebViewCrxSmokeTests, cls).SetUpProcess()
    assert cls._finder_options.crx_file, '--crx-file is required'
    assert cls._finder_options.component_name, '--component-name is required'

    cls.SetBrowserOptions(cls._finder_options)
    webview_package_name = cls._finder_options.webview_package_name

    if not webview_package_name:
      webview_provider_apk = (cls._browser_to_create
                              .settings.GetApkName(cls._device))
      webview_apk_path = util.FindLatestApkOnHost(
          cls._finder_options.chrome_root, webview_provider_apk)
      webview_package_name = apk_helper.GetPackageName(webview_apk_path)

    cls._device_components_dir = ('/data/data/%s/app_webview/components' %
                                  webview_package_name)
    logcat_output_dir = (
        os.path.dirname(cls._typ_runner.args.write_full_results_to or '') or
        os.getcwd())

    # Set up a logcat monitor
    cls._logcat_monitor = logcat_monitor.LogcatMonitor(
        cls._device.adb,
        output_file=os.path.join(logcat_output_dir,
                                 '%s_logcat.txt' % cls.Name()),
        filter_specs=_LOGCAT_FILTERS)
    cls._logcat_monitor.Start()

    cls._MaybeClearOutComponentsDir()
    component_id = _COMPONENT_NAME_TO_DATA.get(
        cls._finder_options.component_name).component_id
    with zipfile.ZipFile(cls._finder_options.crx_file) as crx_archive, \
        NamedTemporaryDirectory() as tmp_dir,                          \
        crx_archive.open('manifest.json') as manifest:
      crx_device_dir = posixpath.join(
          cls._device_components_dir, 'cps',
          component_id, '1_%s' % json.loads(manifest.read())['version'])

      try:
        # Create directory on the test device for the CRX files
        logger.info('Creating directory %r on device' % crx_device_dir)
        output = cls._device.RunShellCommand(
            ['mkdir', '-p', crx_device_dir])
        logger.debug('Recieved the following output from adb: %s' % output)
      except Exception as e:
        logger.exception('Exception %r was raised' % str(e))
        raise

      # Move CRX files to the device directory
      crx_archive.extractall(tmp_dir)
      cls._MoveNewCrxToDevice(tmp_dir, crx_device_dir)

    # Start the browser after the device is in a clean state and the CRX
    # files are loaded onto the device
    cls.StartBrowser()
 def FindSupportApks(self, apk_path, chrome_root):
     # Try to find the WebView embedder next to the local APK found.
     if apk_path is not None:
         embedder_apk_path = os.path.join(os.path.dirname(apk_path),
                                          self.embedder_apk_name)
         if os.path.exists(embedder_apk_path):
             return [embedder_apk_path]
     # Otherwise fall back to an APK found among possible build directories.
     apk = util.FindLatestApkOnHost(chrome_root, self.embedder_apk_name)
     return [apk] if apk else []
Example #6
0
 def __init__(self, test, finder_options, story_set, possible_browser=None):
     """
 Args:
   test: opaquely passed to parent class constructor.
   finder_options: A BrowserFinderOptions object.
   story_set: opaquely passed to parent class constructor.
 """
     super(_MobileStartupSharedState,
           self).__init__(test, finder_options, story_set, possible_browser)
     self._finder_options = finder_options
     if not self._possible_browser:
         self._possible_browser = browser_finder.FindBrowser(
             self._finder_options)
     self._current_story = None
     # Allow using this shared state only on Android.
     assert isinstance(self.platform, android_platform.AndroidPlatform)
     self._finder_options.browser_options.browser_user_agent_type = 'mobile'
     self._finder_options.browser_options.AppendExtraBrowserArgs(
         '--skip-webapk-verification')
     self.platform.Initialize()
     self.platform.SetPerformanceMode(finder_options.performance_mode)
     self._perf_mode_set = (finder_options.performance_mode !=
                            android_device.KEEP_PERFORMANCE_MODE)
     maps_webapk = core_util.FindLatestApkOnHost(finder_options.chrome_root,
                                                 'MapsWebApk.apk')
     if not maps_webapk:
         raise Exception('MapsWebApk not found! Follow the Mini-HOWTO in '
                         'startup_mobile.py')
     self.platform.InstallApplication(maps_webapk)
     wpr_mode = wpr_modes.WPR_REPLAY
     self._number_of_iterations = _NUMBER_OF_ITERATIONS
     if 'android-weblayer' in self._possible_browser.GetTypExpectationsTags(
     ):
         # As discussed in crbug.com/1032364, use a higher number to reduce noise.
         self._number_of_iterations = _NUMBER_OF_ITERATIONS_FOR_WEBLAYER
     if finder_options.use_live_sites:
         wpr_mode = wpr_modes.WPR_OFF
     elif finder_options.browser_options.wpr_mode == wpr_modes.WPR_RECORD:
         wpr_mode = wpr_modes.WPR_RECORD
         # When recording a WPR archive only load the story page once.
         self._number_of_iterations = 1
     self.platform.network_controller.Open(wpr_mode)
     self._story_set = story_set