Esempio n. 1
0
def _FindAllPossibleBrowsers(finder_options, android_platform):
  """Testable version of FindAllAvailableBrowsers."""
  if not android_platform:
    return []
  possible_browsers = []

  for apk in finder_options.webview_embedder_apk:
    if not os.path.exists(apk):
      raise exceptions.PathMissingError(
          'Unable to find apk specified by --webview-embedder-apk=%s' % apk)

  # Add the exact APK if given.
  if _CanPossiblyHandlePath(finder_options.browser_executable):
    if not os.path.exists(finder_options.browser_executable):
      raise exceptions.PathMissingError(
          'Unable to find exact apk specified by --browser-executable=%s' %
          finder_options.browser_executable)

    package_name = apk_helper.GetPackageName(finder_options.browser_executable)
    try:
      backend_settings = next(
          b for b in ANDROID_BACKEND_SETTINGS if b.package == package_name)
    except StopIteration:
      raise exceptions.UnknownPackageError(
          '%s specified by --browser-executable has an unknown package: %s' %
          (finder_options.browser_executable, package_name))

    possible_browsers.append(PossibleAndroidBrowser(
        'exact',
        finder_options,
        android_platform,
        backend_settings,
        finder_options.browser_executable))

  if finder_options.IsBrowserTypeRelevant('reference'):
    reference_browser = _GetReferenceAndroidBrowser(
        android_platform, finder_options)
    if reference_browser:
      possible_browsers.append(reference_browser)

  # Add any other known available browsers.
  for settings in ANDROID_BACKEND_SETTINGS:
    if finder_options.IsBrowserTypeRelevant(settings.browser_type):
      local_apk = None
      if finder_options.IsBrowserTypeReference():
        local_apk = _FetchReferenceApk(
            android_platform, finder_options.IsBrowserTypeBundle())

      if settings.IsWebView():
        p_browser = PossibleAndroidBrowser(
            settings.browser_type, finder_options, android_platform, settings,
            local_apk=local_apk, target_os='android_webview')
      else:
        p_browser = PossibleAndroidBrowser(
            settings.browser_type, finder_options, android_platform, settings,
            local_apk=local_apk)
      if p_browser.IsAvailable():
        possible_browsers.append(p_browser)
  return possible_browsers
    def __init__(self, browser_type, finder_options, android_platform,
                 backend_settings, apk_name):
        super(PossibleAndroidBrowser,
              self).__init__(browser_type, 'android',
                             backend_settings.supports_tab_control)
        assert browser_type in FindAllBrowserTypes(finder_options), (
            'Please add %s to android_browser_finder.FindAllBrowserTypes' %
            browser_type)
        self._platform = android_platform
        self._platform_backend = (android_platform._platform_backend)  # pylint: disable=protected-access
        self._backend_settings = backend_settings
        self._local_apk = None
        self._flag_changer = None

        if browser_type == 'exact':
            if not os.path.exists(apk_name):
                raise exceptions.PathMissingError(
                    'Unable to find exact apk %s specified by --browser-executable'
                    % apk_name)
            self._local_apk = apk_name
        elif browser_type == 'reference':
            if not os.path.exists(apk_name):
                raise exceptions.PathMissingError(
                    'Unable to find reference apk at expected location %s.' %
                    apk_name)
            self._local_apk = apk_name
        elif apk_name:
            assert finder_options.chrome_root, (
                'Must specify Chromium source to use apk_name')
            chrome_root = finder_options.chrome_root
            candidate_apks = []
            for build_path in util.GetBuildDirectories(chrome_root):
                apk_full_name = os.path.join(build_path, 'apks', apk_name)
                if os.path.exists(apk_full_name):
                    last_changed = os.path.getmtime(apk_full_name)
                    candidate_apks.append((last_changed, apk_full_name))

            if candidate_apks:
                # Find the candidate .apk with the latest modification time.
                newest_apk_path = sorted(candidate_apks)[-1][1]
                self._local_apk = newest_apk_path

        self._webview_embedder_apk = None
        if finder_options.webview_embedder_apk:
            self._webview_embedder_apk = finder_options.webview_embedder_apk
            assert os.path.exists(
                self._webview_embedder_apk), ('%s does not exist.' %
                                              self._webview_embedder_apk)
    def __init__(self, browser_type, finder_options, android_platform,
                 backend_settings, apk_name):
        super(PossibleAndroidBrowser,
              self).__init__(browser_type, 'android',
                             backend_settings.supports_tab_control)
        assert browser_type in FindAllBrowserTypes(finder_options), (
            'Please add %s to android_browser_finder.FindAllBrowserTypes' %
            browser_type)
        self._platform = android_platform
        self._platform_backend = (android_platform._platform_backend)  # pylint: disable=W0212
        self._backend_settings = backend_settings
        self._local_apk = None

        if browser_type == 'exact':
            if not os.path.exists(apk_name):
                raise exceptions.PathMissingError(
                    'Unable to find exact apk %s specified by --browser-executable'
                    % apk_name)
            self._local_apk = apk_name
        elif apk_name:
            chrome_root = util.GetChromiumSrcDir()
            candidate_apks = []
            for build_dir, build_type in util.GetBuildDirectories():
                apk_full_name = os.path.join(chrome_root, build_dir,
                                             build_type, 'apks', apk_name)
                if os.path.exists(apk_full_name):
                    last_changed = os.path.getmtime(apk_full_name)
                    candidate_apks.append((last_changed, apk_full_name))

            if candidate_apks:
                # Find the candidate .apk with the latest modification time.
                newest_apk_path = sorted(candidate_apks)[-1][1]
                self._local_apk = newest_apk_path
Esempio n. 4
0
def GetReplayArgs(network_backend, supports_spki_list=True):
  args = []
  if not network_backend.is_open:
    return args

  # Send all browser traffic (including requests to 127.0.0.1 and localhost) to
  # ts_proxy_server.
  proxy_port = network_backend.forwarder.remote_port
  args.append('--proxy-server=socks://localhost:%s' % proxy_port)
  args.append('--proxy-bypass-list=<-loopback>')

  if not network_backend.use_live_traffic:
    if supports_spki_list:
      # Ignore certificate errors for certs that are signed with Wpr's root.
      # For more details on this flag, see crbug.com/753948.
      wpr_public_hash_file = os.path.join(
          util.GetCatapultDir(), 'web_page_replay_go', 'wpr_public_hash.txt')
      if not os.path.exists(wpr_public_hash_file):
        raise exceptions.PathMissingError(
            'Unable to find %s' % wpr_public_hash_file)
      with open(wpr_public_hash_file) as f:
        wpr_public_hash = f.readline().strip()
      args.append('--ignore-certificate-errors-spki-list=' + wpr_public_hash)
    else:
      # If --ignore-certificate-errors-spki-list is not supported ignore all
      # certificate errors.
      args.append('--ignore-certificate-errors')

  return args
 def GetReplayBrowserStartupArgs(self):
     replay_args = []
     network_backend = self.platform_backend.network_controller_backend
     if not network_backend.is_initialized:
         return []
     proxy_port = network_backend.forwarder.port_pair.remote_port
     replay_args.append('--proxy-server=socks://localhost:%s' % proxy_port)
     if not self.is_webview:
         # Ignore certificate errors for certs that are signed with Wpr's root.
         # For more details on this flag, see crbug.com/753948.
         wpr_public_hash_file = os.path.join(util.GetCatapultDir(),
                                             'web_page_replay_go',
                                             'wpr_public_hash.txt')
         if not os.path.exists(wpr_public_hash_file):
             raise exceptions.PathMissingError('Unable to find %s' %
                                               wpr_public_hash_file)
         with open(wpr_public_hash_file) as f:
             wpr_public_hash = f.readline().strip()
             replay_args.append('--ignore-certificate-errors-spki-list=' +
                                wpr_public_hash)
     elif self.is_webview:
         # --ignore-certificate-errors-spki-list doesn't work with webview yet
         # (crbug.com/753948)
         replay_args.append('--ignore-certificate-errors')
     return replay_args
def _FindAllPossibleBrowsers(finder_options, android_platform):
    """Testable version of FindAllAvailableBrowsers."""
    if not android_platform:
        return []
    possible_browsers = []

    # Add the exact APK if given.
    if _CanPossiblyHandlePath(finder_options.browser_executable):
        if not os.path.exists(finder_options.browser_executable):
            raise exceptions.PathMissingError(
                'Unable to find exact apk specified by --browser-executable=%s'
                % finder_options.browser_executable)

        package_name = apk_helper.GetPackageName(
            finder_options.browser_executable)
        try:
            backend_settings = next(backend_settings
                                    for target_package, backend_settings in
                                    CHROME_PACKAGE_NAMES.itervalues()
                                    if package_name == target_package)
        except StopIteration:
            raise exceptions.UnknownPackageError(
                '%s specified by --browser-executable has an unknown package: %s'
                % (finder_options.browser_executable, package_name))

        possible_browsers.append(
            PossibleAndroidBrowser('exact', finder_options, android_platform,
                                   backend_settings(package_name),
                                   finder_options.browser_executable))

    # Add the reference build if found.
    os_version = dependency_util.GetChromeApkOsVersion(
        android_platform.GetOSVersionName())
    arch = android_platform.GetArchName()
    try:
        reference_build = binary_manager.FetchPath('chrome_stable', arch,
                                                   'android', os_version)
    except (binary_manager.NoPathFoundError, binary_manager.CloudStorageError):
        reference_build = None

    if reference_build and os.path.exists(reference_build):
        # TODO(aiolos): how do we stably map the android chrome_stable apk to the
        # correct package name?
        package, backend_settings = CHROME_PACKAGE_NAMES['android-chrome']
        possible_browsers.append(
            PossibleAndroidBrowser('reference',
                                   finder_options, android_platform,
                                   backend_settings(package), reference_build))

    # Add any known local versions.
    for name, package_info in CHROME_PACKAGE_NAMES.iteritems():
        package, backend_settings = package_info
        p_browser = PossibleAndroidBrowser(name, finder_options,
                                           android_platform,
                                           backend_settings(package))
        if p_browser.IsAvailable():
            possible_browsers.append(p_browser)
    return possible_browsers
def FindAllAvailableBrowsers(finder_options, device):
    """Finds all the desktop mandoline browsers available on this machine."""
    if not isinstance(device, desktop_device.DesktopDevice):
        return []

    browsers = []

    if not CanFindAvailableBrowsers():
        return []

    # Look for a browser in the standard chrome build locations.
    if finder_options.chrome_root:
        chrome_root = finder_options.chrome_root
    else:
        chrome_root = path.GetChromiumSrcDir()

    if sys.platform.startswith('linux'):
        mandoline_app_name = 'mandoline'
    elif sys.platform.startswith('win'):
        mandoline_app_name = 'mandoline.exe'
    else:
        raise Exception('Platform not recognized')

    # Add the explicit browser executable if given and we can handle it.
    if (finder_options.browser_executable
            and CanPossiblyHandlePath(finder_options.browser_executable)):
        normalized_executable = os.path.expanduser(
            finder_options.browser_executable)
        if path.IsExecutable(normalized_executable):
            browser_directory = os.path.dirname(
                finder_options.browser_executable)
            browsers.append(
                PossibleDesktopMandolineBrowser('exact', finder_options,
                                                normalized_executable,
                                                browser_directory))
        else:
            raise exceptions.PathMissingError(
                '%s specified by --browser-executable does not exist',
                normalized_executable)

    def AddIfFound(browser_type, build_dir, type_dir, app_name):
        browser_directory = os.path.join(chrome_root, build_dir, type_dir)
        app = os.path.join(browser_directory, app_name)
        if path.IsExecutable(app):
            browsers.append(
                PossibleDesktopMandolineBrowser(browser_type, finder_options,
                                                app, browser_directory))
            return True
        return False

    # Add local builds.
    for build_dir, build_type in path.GetBuildDirectories():
        AddIfFound('mandoline-' + build_type.lower(), build_dir, build_type,
                   mandoline_app_name)

    return browsers
Esempio n. 8
0
def _FindAllPossibleBrowsers(finder_options, android_platform):
    """Testable version of FindAllAvailableBrowsers."""
    if not android_platform:
        return []
    possible_browsers = []

    # Add the exact APK if given.
    if _CanPossiblyHandlePath(finder_options.browser_executable):
        if not os.path.exists(finder_options.browser_executable):
            raise exceptions.PathMissingError(
                'Unable to find exact apk specified by --browser-executable=%s'
                % finder_options.browser_executable)

        package_name = apk_helper.GetPackageName(
            finder_options.browser_executable)
        try:
            backend_settings = next(b for b in ANDROID_BACKEND_SETTINGS
                                    if b.package == package_name)
        except StopIteration:
            raise exceptions.UnknownPackageError(
                '%s specified by --browser-executable has an unknown package: %s'
                % (finder_options.browser_executable, package_name))

        possible_browsers.append(
            PossibleAndroidBrowser('exact', finder_options, android_platform,
                                   backend_settings,
                                   finder_options.browser_executable))

    # Add the reference build if found.
    os_version = dependency_util.GetChromeApkOsVersion(
        android_platform.GetOSVersionName())
    arch = android_platform.GetArchName()
    try:
        reference_build = binary_manager.FetchPath('chrome_stable', arch,
                                                   'android', os_version)
    except (binary_manager.NoPathFoundError, binary_manager.CloudStorageError):
        reference_build = None

    if reference_build and os.path.exists(reference_build):
        # TODO(aiolos): how do we stably map the android chrome_stable apk to the
        # correct backend settings?
        possible_browsers.append(
            PossibleAndroidBrowser(
                'reference', finder_options, android_platform,
                android_browser_backend_settings.ANDROID_CHROME,
                reference_build))

    # Add any other known available browsers.
    for settings in ANDROID_BACKEND_SETTINGS:
        p_browser = PossibleAndroidBrowser(settings.browser_type,
                                           finder_options, android_platform,
                                           settings)
        if p_browser.IsAvailable():
            possible_browsers.append(p_browser)
    return possible_browsers
Esempio n. 9
0
def GetReplayArgs(network_backend, supports_spki_list=True):
    args = []
    if not network_backend.is_open:
        return args

    # Send all browser traffic (including requests to 127.0.0.1 and localhost) to
    # ts_proxy_server.
    # The proxy should NOT be set to "localhost", otherwise Chrome will first
    # attempt to use the IPv6 version (::1) before falling back to IPv4. This
    # causes issues if the IPv4 port we got randomly assigned on the device is
    # also being used in IPv6 by some other process. See
    # https://crbug.com/1005971 for more information.
    proxy_port = network_backend.forwarder.remote_port
    args.append('--proxy-server=socks://127.0.0.1:%s' % proxy_port)
    args.append('--proxy-bypass-list=<-loopback>')

    if not network_backend.use_live_traffic:
        if supports_spki_list:
            # Ignore certificate errors for certs that are signed with Wpr's root.
            # For more details on this flag, see crbug.com/753948.
            wpr_public_hash_file = os.path.join(util.GetCatapultDir(),
                                                'web_page_replay_go',
                                                'wpr_public_hash.txt')
            if not os.path.exists(wpr_public_hash_file):
                raise exceptions.PathMissingError('Unable to find %s' %
                                                  wpr_public_hash_file)
            with open(wpr_public_hash_file) as f:
                wpr_public_hash = f.readline().strip()
            args.append('--ignore-certificate-errors-spki-list=' +
                        wpr_public_hash)
        else:
            # If --ignore-certificate-errors-spki-list is not supported ignore all
            # certificate errors.
            args.append('--ignore-certificate-errors')

    return args
Esempio n. 10
0
def FindAllAvailableBrowsers(finder_options, device):
  """Finds all the desktop browsers available on this machine."""
  if not isinstance(device, desktop_device.DesktopDevice):
    return []

  browsers = []

  if not CanFindAvailableBrowsers():
    return []

  has_x11_display = True
  if sys.platform.startswith('linux') and os.getenv('DISPLAY') is None:
    has_x11_display = False

  os_name = platform_module.GetHostPlatform().GetOSName()
  arch_name = platform_module.GetHostPlatform().GetArchName()
  try:
    flash_path = binary_manager.LocalPath('flash', arch_name, os_name)
  except dependency_manager.NoPathFoundError:
    flash_path = None
    logging.warning(
        'Chrome build location for %s_%s not found. Browser will be run '
        'without Flash.', os_name, arch_name)

  chromium_app_names = []
  if sys.platform == 'darwin':
    chromium_app_names.append('Chromium.app/Contents/MacOS/Chromium')
    chromium_app_names.append('Google Chrome.app/Contents/MacOS/Google Chrome')
    content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell'
  elif sys.platform.startswith('linux'):
    chromium_app_names.append('chrome')
    content_shell_app_name = 'content_shell'
  elif sys.platform.startswith('win'):
    chromium_app_names.append('chrome.exe')
    content_shell_app_name = 'content_shell.exe'
  else:
    raise Exception('Platform not recognized')

  # Add the explicit browser executable if given and we can handle it.
  if finder_options.browser_executable:
    is_content_shell = finder_options.browser_executable.endswith(
        content_shell_app_name)

    # It is okay if the executable name doesn't match any of known chrome
    # browser executables, since it may be of a different browser.
    normalized_executable = os.path.expanduser(
        finder_options.browser_executable)
    if path_module.IsExecutable(normalized_executable):
      browser_directory = os.path.dirname(finder_options.browser_executable)
      browsers.append(PossibleDesktopBrowser(
          'exact', finder_options, normalized_executable, flash_path,
          is_content_shell,
          browser_directory))
    else:
      raise exceptions.PathMissingError(
          '%s specified by --browser-executable does not exist or is not '
          'executable' %
          normalized_executable)

  def AddIfFound(browser_type, build_path, app_name, content_shell):
    app = os.path.join(build_path, app_name)
    if path_module.IsExecutable(app):
      browsers.append(PossibleDesktopBrowser(
          browser_type, finder_options, app, flash_path,
          content_shell, build_path, is_local_build=True))
      return True
    return False

  # Add local builds
  for build_path in path_module.GetBuildDirectories(finder_options.chrome_root):
    # TODO(agrieve): Extract browser_type from args.gn's is_debug.
    browser_type = os.path.basename(build_path).lower()
    for chromium_app_name in chromium_app_names:
      AddIfFound(browser_type, build_path, chromium_app_name, False)
    AddIfFound('content-shell-' + browser_type, build_path,
               content_shell_app_name, True)

  reference_build = None
  if finder_options.browser_type == 'reference':
    # Reference builds are only available in a Chromium checkout. We should not
    # raise an error just because they don't exist.
    os_name = platform_module.GetHostPlatform().GetOSName()
    arch_name = platform_module.GetHostPlatform().GetArchName()
    reference_build = binary_manager.FetchPath(
        'chrome_stable', arch_name, os_name)

  # Mac-specific options.
  if sys.platform == 'darwin':
    mac_canary_root = '/Applications/Google Chrome Canary.app/'
    mac_canary = mac_canary_root + 'Contents/MacOS/Google Chrome Canary'
    mac_system_root = '/Applications/Google Chrome.app'
    mac_system = mac_system_root + '/Contents/MacOS/Google Chrome'
    if path_module.IsExecutable(mac_canary):
      browsers.append(PossibleDesktopBrowser('canary', finder_options,
                                             mac_canary, None, False,
                                             mac_canary_root))

    if path_module.IsExecutable(mac_system):
      browsers.append(PossibleDesktopBrowser('system', finder_options,
                                             mac_system, None, False,
                                             mac_system_root))

    if reference_build and path_module.IsExecutable(reference_build):
      reference_root = os.path.dirname(os.path.dirname(os.path.dirname(
          reference_build)))
      browsers.append(PossibleDesktopBrowser('reference', finder_options,
                                             reference_build, None, False,
                                             reference_root))

  # Linux specific options.
  if sys.platform.startswith('linux'):
    versions = {
        'system': os.path.split(os.path.realpath('/usr/bin/google-chrome'))[0],
        'stable': '/opt/google/chrome',
        'beta': '/opt/google/chrome-beta',
        'dev': '/opt/google/chrome-unstable'
    }

    for version, root in versions.iteritems():
      browser_path = os.path.join(root, 'chrome')
      if path_module.IsExecutable(browser_path):
        browsers.append(PossibleDesktopBrowser(version, finder_options,
                                               browser_path, None, False, root))
    if reference_build and path_module.IsExecutable(reference_build):
      reference_root = os.path.dirname(reference_build)
      browsers.append(PossibleDesktopBrowser('reference', finder_options,
                                             reference_build, None, False,
                                             reference_root))

  # Win32-specific options.
  if sys.platform.startswith('win'):
    app_paths = [
        ('system', os.path.join('Google', 'Chrome', 'Application')),
        ('canary', os.path.join('Google', 'Chrome SxS', 'Application')),
    ]
    if reference_build:
      app_paths.append(
          ('reference', os.path.dirname(reference_build)))

    for browser_name, app_path in app_paths:
      for chromium_app_name in chromium_app_names:
        full_path = path_module.FindInstalledWindowsApplication(
            os.path.join(app_path, chromium_app_name))
        if full_path:
          browsers.append(PossibleDesktopBrowser(
              browser_name, finder_options, full_path,
              None, False, os.path.dirname(full_path)))

  has_ozone_platform = False
  for arg in finder_options.browser_options.extra_browser_args:
    if "--ozone-platform" in arg:
      has_ozone_platform = True

  if len(browsers) and not has_x11_display and not has_ozone_platform:
    logging.warning(
        'Found (%s), but you do not have a DISPLAY environment set.', ','.join(
            [b.browser_type for b in browsers]))
    return []

  return browsers
Esempio n. 11
0
def FindAllAvailableBrowsers(finder_options, device):
    """Finds all the desktop browsers available on this machine."""
    if not isinstance(device, desktop_device.DesktopDevice):
        return []

    browsers = []

    if not CanFindAvailableBrowsers():
        return []

    has_x11_display = True
    if (sys.platform.startswith('linux') and os.getenv('DISPLAY') == None):
        has_x11_display = False

    # Look for a browser in the standard chrome build locations.
    if finder_options.chrome_root:
        chrome_root = finder_options.chrome_root
    else:
        chrome_root = path.GetChromiumSrcDir()

    flash_bin_dir = os.path.join(chrome_root, 'third_party', 'adobe', 'flash',
                                 'binaries', 'ppapi')

    chromium_app_names = []
    if sys.platform == 'darwin':
        chromium_app_names.append('Chromium.app/Contents/MacOS/Chromium')
        chromium_app_names.append(
            'Google Chrome.app/Contents/MacOS/Google Chrome')
        content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell'
        flash_bin = 'PepperFlashPlayer.plugin'
        flash_path = os.path.join(flash_bin_dir, 'mac', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'mac_64', flash_bin)
    elif sys.platform.startswith('linux'):
        chromium_app_names.append('chrome')
        content_shell_app_name = 'content_shell'
        flash_bin = 'libpepflashplayer.so'
        flash_path = os.path.join(flash_bin_dir, 'linux', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'linux_x64', flash_bin)
    elif sys.platform.startswith('win'):
        chromium_app_names.append('chrome.exe')
        content_shell_app_name = 'content_shell.exe'
        flash_bin = 'pepflashplayer.dll'
        flash_path = os.path.join(flash_bin_dir, 'win', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'win_x64', flash_bin)
    else:
        raise Exception('Platform not recognized')

    # Add the explicit browser executable if given and we can handle it.
    if (finder_options.browser_executable
            and CanPossiblyHandlePath(finder_options.browser_executable)):
        normalized_executable = os.path.expanduser(
            finder_options.browser_executable)
        if path.IsExecutable(normalized_executable):
            browser_directory = os.path.dirname(
                finder_options.browser_executable)
            browsers.append(
                PossibleDesktopBrowser('exact', finder_options,
                                       normalized_executable, flash_path,
                                       False, browser_directory))
        else:
            raise exceptions.PathMissingError(
                '%s specified by --browser-executable does not exist' %
                normalized_executable)

    def AddIfFound(browser_type, build_dir, type_dir, app_name, content_shell):
        browser_directory = os.path.join(chrome_root, build_dir, type_dir)
        app = os.path.join(browser_directory, app_name)
        if path.IsExecutable(app):
            is_64 = browser_type.endswith('_x64')
            browsers.append(
                PossibleDesktopBrowser(browser_type,
                                       finder_options,
                                       app,
                                       flash_path_64 if is_64 else flash_path,
                                       content_shell,
                                       browser_directory,
                                       is_local_build=True))
            return True
        return False

    # Add local builds
    for build_dir, build_type in path.GetBuildDirectories():
        for chromium_app_name in chromium_app_names:
            AddIfFound(build_type.lower(), build_dir, build_type,
                       chromium_app_name, False)
        AddIfFound('content-shell-' + build_type.lower(), build_dir,
                   build_type, content_shell_app_name, True)

    reference_build_root = os.path.join(chrome_root, 'chrome', 'tools', 'test',
                                        'reference_build')

    # Mac-specific options.
    if sys.platform == 'darwin':
        mac_canary_root = '/Applications/Google Chrome Canary.app/'
        mac_canary = mac_canary_root + 'Contents/MacOS/Google Chrome Canary'
        mac_system_root = '/Applications/Google Chrome.app'
        mac_system = mac_system_root + '/Contents/MacOS/Google Chrome'
        mac_reference_root = reference_build_root + '/chrome_mac/Google Chrome.app/'
        mac_reference = mac_reference_root + 'Contents/MacOS/Google Chrome'
        if path.IsExecutable(mac_canary):
            browsers.append(
                PossibleDesktopBrowser('canary', finder_options, mac_canary,
                                       None, False, mac_canary_root))

        if path.IsExecutable(mac_system):
            browsers.append(
                PossibleDesktopBrowser('system', finder_options, mac_system,
                                       None, False, mac_system_root))
        if path.IsExecutable(mac_reference):
            browsers.append(
                PossibleDesktopBrowser('reference', finder_options,
                                       mac_reference, None, False,
                                       mac_reference_root))

    # Linux specific options.
    if sys.platform.startswith('linux'):
        # Look for a google-chrome instance.
        found = False
        try:
            with open(os.devnull, 'w') as devnull:
                found = subprocess.call(['google-chrome', '--version'],
                                        stdout=devnull,
                                        stderr=devnull) == 0
        except OSError:
            pass
        if found:
            browsers.append(
                PossibleDesktopBrowser('system', finder_options,
                                       'google-chrome', None, False,
                                       '/opt/google/chrome'))
        linux_reference_root = os.path.join(reference_build_root,
                                            'chrome_linux')
        linux_reference = os.path.join(linux_reference_root, 'chrome')
        if path.IsExecutable(linux_reference):
            browsers.append(
                PossibleDesktopBrowser('reference', finder_options,
                                       linux_reference, None, False,
                                       linux_reference_root))

    # Win32-specific options.
    if sys.platform.startswith('win'):
        app_paths = (
            ('system', os.path.join('Google', 'Chrome', 'Application')),
            ('canary', os.path.join('Google', 'Chrome SxS', 'Application')),
            ('reference', os.path.join(reference_build_root, 'chrome_win')),
        )

        for browser_name, app_path in app_paths:
            for chromium_app_name in chromium_app_names:
                app_path = os.path.join(app_path, chromium_app_name)
                app_path = path.FindInstalledWindowsApplication(app_path)
                if app_path:
                    browsers.append(
                        PossibleDesktopBrowser(browser_name, finder_options,
                                               app_path, None, False,
                                               os.path.dirname(app_path)))

    has_ozone_platform = False
    for arg in finder_options.browser_options.extra_browser_args:
        if "--ozone-platform" in arg:
            has_ozone_platform = True

    if len(browsers) and not has_x11_display and not has_ozone_platform:
        logging.warning(
            'Found (%s), but you do not have a DISPLAY environment set.' %
            ','.join([b.browser_type for b in browsers]))
        return []

    return browsers
Esempio n. 12
0
def FindAllAvailableBrowsers(finder_options, device):
    """Finds all the desktop browsers available on this machine."""
    if not isinstance(device, desktop_device.DesktopDevice):
        return []

    browsers = []

    if not CanFindAvailableBrowsers():
        return []

    has_x11_display = True
    if (sys.platform.startswith('linux') and os.getenv('DISPLAY') == None):
        has_x11_display = False

    os_name = platform_module.GetHostPlatform().GetOSName()
    arch_name = platform_module.GetHostPlatform().GetArchName()
    try:
        flash_path = binary_manager.LocalPath('flash', arch_name, os_name)
    except dm_exceptions.NoPathFoundError:
        flash_path = None
        logging.warning(
            'Chrome build location is not specified. Browser will be run without '
            'Flash.')

    chromium_app_names = []
    if sys.platform == 'darwin':
        chromium_app_names.append('Vivaldi.app/Contents/MacOS/Vivaldi')
        chromium_app_names.append('Vivaldi.app/Contents/MacOS/Vivaldi')
        content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell'
    elif sys.platform.startswith('linux'):
        chromium_app_names.append('vivaldi')
        content_shell_app_name = 'content_shell'
    elif sys.platform.startswith('win'):
        chromium_app_names.append('vivaldi.exe')
        content_shell_app_name = 'content_shell.exe'
    else:
        raise Exception('Platform not recognized')

    # Add the explicit browser executable if given and we can handle it.
    if (finder_options.browser_executable
            and CanPossiblyHandlePath(finder_options.browser_executable)):
        is_content_shell = finder_options.browser_executable.endswith(
            content_shell_app_name)
        is_chrome_or_chromium = len([
            x for x in chromium_app_names
            if finder_options.browser_executable.endswith(x)
        ]) != 0

        # It is okay if the executable name doesn't match any of known chrome
        # browser executables, since it may be of a different browser (say,
        # mandoline).
        if is_chrome_or_chromium or is_content_shell:
            normalized_executable = os.path.expanduser(
                finder_options.browser_executable)
            if path_module.IsExecutable(normalized_executable):
                browser_directory = os.path.dirname(
                    finder_options.browser_executable)
                browsers.append(
                    PossibleDesktopBrowser('exact', finder_options,
                                           normalized_executable, flash_path,
                                           is_content_shell,
                                           browser_directory))
            else:
                raise exceptions.PathMissingError(
                    '%s specified by --browser-executable does not exist or is not '
                    'executable' % normalized_executable)

    def AddIfFound(browser_type, build_dir, type_dir, app_name, content_shell):
        if not finder_options.chrome_root:
            return False
        browser_directory = os.path.join(finder_options.chrome_root, "..",
                                         build_dir, type_dir)
        app = os.path.join(browser_directory, app_name)
        if path_module.IsExecutable(app):
            browsers.append(
                PossibleDesktopBrowser(browser_type,
                                       finder_options,
                                       app,
                                       flash_path,
                                       content_shell,
                                       browser_directory,
                                       is_local_build=True))
            return True
        return False

    # Add local builds
    for build_dir, build_type in path_module.GetBuildDirectories():
        for chromium_app_name in chromium_app_names:
            AddIfFound(build_type.lower(), build_dir, build_type,
                       chromium_app_name, False)
        AddIfFound('content-shell-' + build_type.lower(), build_dir,
                   build_type, content_shell_app_name, True)

    reference_build = None
    if finder_options.browser_type == 'reference':
        # Reference builds are only available in a Chromium checkout. We should not
        # raise an error just because they don't exist.
        os_name = platform_module.GetHostPlatform().GetOSName()
        arch_name = platform_module.GetHostPlatform().GetArchName()
        reference_build = binary_manager.FetchPath('reference_build',
                                                   arch_name, os_name)

    # Mac-specific options.
    if sys.platform == 'darwin':
        mac_canary_root = '/Applications/Vivaldi Canary.app/'
        mac_canary = mac_canary_root + 'Contents/MacOS/Vivaldi Canary'
        mac_system_root = '/Applications/Vivaldi.app'
        mac_system = mac_system_root + '/Contents/MacOS/Vivaldi'
        if path_module.IsExecutable(mac_canary):
            browsers.append(
                PossibleDesktopBrowser('canary', finder_options, mac_canary,
                                       None, False, mac_canary_root))

        if path_module.IsExecutable(mac_system):
            browsers.append(
                PossibleDesktopBrowser('system', finder_options, mac_system,
                                       None, False, mac_system_root))

        if reference_build and path_module.IsExecutable(reference_build):
            reference_root = os.path.dirname(
                os.path.dirname(os.path.dirname(reference_build)))
            browsers.append(
                PossibleDesktopBrowser('reference', finder_options,
                                       reference_build, None, False,
                                       reference_root))

    # Linux specific options.
    if sys.platform.startswith('linux'):
        # look for a vivaldi instance
        versions = {
            'system': ('vivaldi', '/opt/vivaldi'),
            'stable': '/opt/vivaldi',
            'beta': '/opt/vivaldi',
            'dev': '/opt/vivaldi'
        }

        for version, root in versions.iteritems():
            browser_path = os.path.join(root, 'chrome')
            if path_module.IsExecutable(browser_path):
                browsers.append(
                    PossibleDesktopBrowser(version, finder_options,
                                           browser_path, None, False, root))
        if reference_build and path_module.IsExecutable(reference_build):
            reference_root = os.path.dirname(reference_build)
            browsers.append(
                PossibleDesktopBrowser('reference', finder_options,
                                       reference_build, None, False,
                                       reference_root))

    # Win32-specific options.
    if sys.platform.startswith('win'):
        app_paths = [
            ('system', os.path.join('Vivaldi', 'Vivaldi', 'Application')),
            ('canary', os.path.join('Vivaldi', 'Vivaldi', 'Application')),
        ]
        if reference_build:
            app_paths.append(('reference', os.path.dirname(reference_build)))

        for browser_name, app_path in app_paths:
            for chromium_app_name in chromium_app_names:
                app_path = os.path.join(app_path, chromium_app_name)
                app_path = path_module.FindInstalledWindowsApplication(
                    app_path)
                if app_path:
                    browsers.append(
                        PossibleDesktopBrowser(browser_name, finder_options,
                                               app_path, None, False,
                                               os.path.dirname(app_path)))

    has_ozone_platform = False
    for arg in finder_options.browser_options.extra_browser_args:
        if "--ozone-platform" in arg:
            has_ozone_platform = True

    if len(browsers) and not has_x11_display and not has_ozone_platform:
        logging.warning(
            'Found (%s), but you do not have a DISPLAY environment set.' %
            ','.join([b.browser_type for b in browsers]))
        return []

    return browsers
Esempio n. 13
0
def FindAllAvailableBrowsers(finder_options, device):
    """Finds all the desktop browsers available on this machine."""
    if not isinstance(device, desktop_device.DesktopDevice):
        return []

    browsers = []

    if not CanFindAvailableBrowsers():
        return []

    has_x11_display = True
    if (sys.platform.startswith('linux') and os.getenv('DISPLAY') == None):
        has_x11_display = False

    flash_bin_dir = None
    # Define flash_bin_dir when the standard chrome build locations is specified.
    if finder_options.chrome_root:
        flash_bin_dir = os.path.join(finder_options.chrome_root, 'third_party',
                                     'adobe', 'flash', 'binaries', 'ppapi')

    if not flash_bin_dir:
        logging.warning(
            'Chrome build location is not specified. Browser will be run without '
            'Flash.')

    chromium_app_names = []
    if sys.platform == 'darwin':
        chromium_app_names.append('Chromium.app/Contents/MacOS/Chromium')
        chromium_app_names.append(
            'Google Chrome.app/Contents/MacOS/Google Chrome')
        content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell'
        if flash_bin_dir:
            flash_bin = 'PepperFlashPlayer.plugin'
            flash_path = os.path.join(flash_bin_dir, 'mac', flash_bin)
            flash_path_64 = os.path.join(flash_bin_dir, 'mac_64', flash_bin)
    elif sys.platform.startswith('linux'):
        chromium_app_names.append('chrome')
        content_shell_app_name = 'content_shell'
        if flash_bin_dir:
            flash_bin = 'libpepflashplayer.so'
            flash_path = os.path.join(flash_bin_dir, 'linux', flash_bin)
            flash_path_64 = os.path.join(flash_bin_dir, 'linux_x64', flash_bin)
    elif sys.platform.startswith('win'):
        chromium_app_names.append('chrome.exe')
        content_shell_app_name = 'content_shell.exe'
        if flash_bin_dir:
            flash_bin = 'pepflashplayer.dll'
            flash_path = os.path.join(flash_bin_dir, 'win', flash_bin)
            flash_path_64 = os.path.join(flash_bin_dir, 'win_x64', flash_bin)
    else:
        raise Exception('Platform not recognized')

    # Add the explicit browser executable if given and we can handle it.
    if (finder_options.browser_executable
            and CanPossiblyHandlePath(finder_options.browser_executable)):
        app_name = os.path.basename(finder_options.browser_executable)

        # It is okay if the executable name doesn't match any of known chrome
        # browser executables, since it may be of a different browser (say,
        # mandoline).
        if app_name in chromium_app_names or app_name == content_shell_app_name:
            normalized_executable = os.path.expanduser(
                finder_options.browser_executable)
            if path_module.IsExecutable(normalized_executable):
                browser_directory = os.path.dirname(
                    finder_options.browser_executable)
                browsers.append(
                    PossibleDesktopBrowser('exact', finder_options,
                                           normalized_executable, flash_path,
                                           app_name == content_shell_app_name,
                                           browser_directory))
            else:
                raise exceptions.PathMissingError(
                    '%s specified by --browser-executable does not exist or is not '
                    'executable' % normalized_executable)

    def AddIfFound(browser_type, build_dir, type_dir, app_name, content_shell):
        if not finder_options.chrome_root:
            return False
        browser_directory = os.path.join(finder_options.chrome_root, build_dir,
                                         type_dir)
        app = os.path.join(browser_directory, app_name)
        if path_module.IsExecutable(app):
            is_64 = browser_type.endswith('_x64')
            browsers.append(
                PossibleDesktopBrowser(browser_type,
                                       finder_options,
                                       app,
                                       flash_path_64 if is_64 else flash_path,
                                       content_shell,
                                       browser_directory,
                                       is_local_build=True))
            return True
        return False

    # Add local builds
    for build_dir, build_type in path_module.GetBuildDirectories():
        for chromium_app_name in chromium_app_names:
            AddIfFound(build_type.lower(), build_dir, build_type,
                       chromium_app_name, False)
        AddIfFound('content-shell-' + build_type.lower(), build_dir,
                   build_type, content_shell_app_name, True)

    reference_build_root = None
    if finder_options.chrome_root:
        reference_build_root = os.path.join(finder_options.chrome_root,
                                            'chrome', 'tools', 'test',
                                            'reference_build')

    # Mac-specific options.
    if sys.platform == 'darwin':
        mac_canary_root = '/Applications/Google Chrome Canary.app/'
        mac_canary = mac_canary_root + 'Contents/MacOS/Google Chrome Canary'
        mac_system_root = '/Applications/Google Chrome.app'
        mac_system = mac_system_root + '/Contents/MacOS/Google Chrome'
        if path_module.IsExecutable(mac_canary):
            browsers.append(
                PossibleDesktopBrowser('canary', finder_options, mac_canary,
                                       None, False, mac_canary_root))

        if path_module.IsExecutable(mac_system):
            browsers.append(
                PossibleDesktopBrowser('system', finder_options, mac_system,
                                       None, False, mac_system_root))
        if reference_build_root:
            mac_reference_root = (reference_build_root +
                                  '/chrome_mac/Google Chrome.app/')
            mac_reference = mac_reference_root + 'Contents/MacOS/Google Chrome'
            if path_module.IsExecutable(mac_reference):
                browsers.append(
                    PossibleDesktopBrowser('reference', finder_options,
                                           mac_reference, None, False,
                                           mac_reference_root))

    # Linux specific options.
    if sys.platform.startswith('linux'):
        versions = {
            'system':
            os.path.split(os.path.realpath('/usr/bin/google-chrome'))[0],
            'stable': '/opt/google/chrome',
            'beta': '/opt/google/chrome-beta',
            'dev': '/opt/google/chrome-unstable'
        }

        for version, root in versions.iteritems():
            browser_path = os.path.join(root, 'chrome')
            if path_module.IsExecutable(browser_path):
                browsers.append(
                    PossibleDesktopBrowser(version, finder_options,
                                           browser_path, None, False, root))
        if reference_build_root:
            linux_reference_root = os.path.join(reference_build_root,
                                                'chrome_linux')
            linux_reference = os.path.join(linux_reference_root, 'chrome')
            if path_module.IsExecutable(linux_reference):
                browsers.append(
                    PossibleDesktopBrowser('reference', finder_options,
                                           linux_reference, None, False,
                                           linux_reference_root))

    # Win32-specific options.
    if sys.platform.startswith('win'):
        app_paths = [
            ('system', os.path.join('Google', 'Chrome', 'Application')),
            ('canary', os.path.join('Google', 'Chrome SxS', 'Application')),
        ]
        if reference_build_root:
            app_paths.append(
                ('reference', os.path.join(reference_build_root,
                                           'chrome_win')))

        for browser_name, app_path in app_paths:
            for chromium_app_name in chromium_app_names:
                app_path = os.path.join(app_path, chromium_app_name)
                app_path = path_module.FindInstalledWindowsApplication(
                    app_path)
                if app_path:
                    browsers.append(
                        PossibleDesktopBrowser(browser_name, finder_options,
                                               app_path, None, False,
                                               os.path.dirname(app_path)))

    has_ozone_platform = False
    for arg in finder_options.browser_options.extra_browser_args:
        if "--ozone-platform" in arg:
            has_ozone_platform = True

    if len(browsers) and not has_x11_display and not has_ozone_platform:
        logging.warning(
            'Found (%s), but you do not have a DISPLAY environment set.' %
            ','.join([b.browser_type for b in browsers]))
        return []

    return browsers
Esempio n. 14
0
        finder_options.browser_executable.endswith(x)]) != 0

    # It is okay if the executable name doesn't match any of known chrome
    # browser executables, since it may be of a different browser.
    if is_chrome_or_chromium or is_content_shell:
      normalized_executable = os.path.expanduser(
          finder_options.browser_executable)
      if path_module.IsExecutable(normalized_executable):
        browser_directory = os.path.dirname(finder_options.browser_executable)
        browsers.append(PossibleDesktopBrowser(
            'exact', finder_options, normalized_executable, flash_path,
            is_content_shell,
            browser_directory))
      else:
        raise exceptions.PathMissingError(
            '%s specified by --browser-executable does not exist or is not '
            'executable' %
            normalized_executable)

  def AddIfFound(browser_type, build_path, app_name, content_shell):
    app = os.path.join(build_path, app_name)
    if path_module.IsExecutable(app):
      browsers.append(PossibleDesktopBrowser(
          browser_type, finder_options, app, flash_path,
          content_shell, build_path, is_local_build=True))
      return True
    return False

  # Add local builds
  for build_path in path_module.GetBuildDirectories(finder_options.chrome_root):
    # TODO(agrieve): Extract browser_type from args.gn's is_debug.
    browser_type = os.path.basename(build_path).lower()
Esempio n. 15
0
def FindAllAvailableBrowsers(finder_options, device):
    """Finds all the desktop mandoline browsers available on this machine."""
    if not isinstance(device, desktop_device.DesktopDevice):
        return []

    browsers = []

    if not CanFindAvailableBrowsers():
        return []

    if sys.platform.startswith('linux'):
        mandoline_app_name = 'mandoline'
    elif sys.platform.startswith('win'):
        mandoline_app_name = 'mandoline.exe'
    else:
        raise Exception('Platform not recognized')

    # Add the explicit browser executable if given and we can handle it.
    if (finder_options.browser_executable
            and CanPossiblyHandlePath(finder_options.browser_executable)):
        app_name = os.path.basename(finder_options.browser_executable)

        # It is okay if the executable name doesn't match any of known chrome
        # browser executables, since it may be of a different browser (say,
        # chrome).
        if app_name == mandoline_app_name:
            normalized_executable = os.path.expanduser(
                finder_options.browser_executable)
            if path.IsExecutable(normalized_executable):
                browser_directory = os.path.dirname(
                    finder_options.browser_executable)
                browsers.append(
                    PossibleDesktopMandolineBrowser('exact', finder_options,
                                                    normalized_executable,
                                                    browser_directory))
            else:
                raise exceptions.PathMissingError(
                    '%s specified by --browser-executable does not exist',
                    normalized_executable)

    if not finder_options.chrome_root:
        logging.warning(
            'Chrome build directory is not specified. Skip looking for'
            'for madonline build in the chrome build directories.')
        return browsers

    def AddIfFound(browser_type, build_dir, type_dir, app_name):
        browser_directory = os.path.join(finder_options.chrome_root, build_dir,
                                         type_dir)
        app = os.path.join(browser_directory, app_name)
        if path.IsExecutable(app):
            browsers.append(
                PossibleDesktopMandolineBrowser(browser_type, finder_options,
                                                app, browser_directory))
            return True
        return False

    # Add local builds.
    for build_dir, build_type in path.GetBuildDirectories():
        AddIfFound('mandoline-' + build_type.lower(), build_dir, build_type,
                   mandoline_app_name)

    return browsers