Exemple #1
0
def _FindExecutableInPath(relative_executable_path, *extra_search_paths):
  search_paths = list(extra_search_paths) + os.environ['PATH'].split(os.pathsep)
  for search_path in search_paths:
    executable_path = os.path.join(search_path, relative_executable_path)
    if path.IsExecutable(executable_path):
      return executable_path
  return None
Exemple #2
0
 def _GetCdbPath(self):
     # cdb.exe might have been co-located with the browser's executable
     # during the build, but that's not a certainty. (This is only done
     # in Chromium builds on the bots, which is why it's not a hard
     # requirement.) See if it's available.
     colocated_cdb = os.path.join(self._build_dir, 'cdb', 'cdb.exe')
     if path.IsExecutable(colocated_cdb):
         return colocated_cdb
     possible_paths = (
         # Installed copies of the Windows SDK.
         os.path.join('Windows Kits', '*', 'Debuggers', 'x86'),
         os.path.join('Windows Kits', '*', 'Debuggers', 'x64'),
         # Old copies of the Debugging Tools for Windows.
         'Debugging Tools For Windows',
         'Debugging Tools For Windows (x86)',
         'Debugging Tools For Windows (x64)',
         # The hermetic copy of the Windows toolchain in depot_tools.
         os.path.join('win_toolchain', 'vs_files', '*', 'win_sdk',
                      'Debuggers', 'x86'),
         os.path.join('win_toolchain', 'vs_files', '*', 'win_sdk',
                      'Debuggers', 'x64'),
     )
     for possible_path in possible_paths:
         app_path = os.path.join(possible_path, 'cdb.exe')
         app_path = path.FindInstalledWindowsApplication(app_path)
         if app_path:
             return app_path
     return None
Exemple #3
0
 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
Exemple #4
0
 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
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
Exemple #6
0
 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
Exemple #7
0
 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
Exemple #8
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
Exemple #9
0
 def testIsExecutable(self):
     self.assertFalse(path.IsExecutable('nonexistent_file'))
     self.assertTrue(path.IsExecutable(sys.executable))
Exemple #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') == 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
Exemple #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

    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
Exemple #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

    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
Exemple #13
0
    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.
    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(
Exemple #14
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