Esempio n. 1
0
  def test_no_adb(self):
    options = browser_options.BrowserOptions()

    def NoAdb(*args, **kargs): # pylint: disable=W0613
      raise OSError('not found')
    self._stubs.subprocess.Popen = NoAdb
    browsers = android_browser_finder.FindAllAvailableBrowsers(options)
    self.assertEquals(0, len(browsers))
Esempio n. 2
0
def GetAllAvailableBrowserTypes(options):
    """Returns an array of browser types supported on this system."""
    browsers = []
    browsers.extend(desktop_browser_finder.FindAllAvailableBrowsers(options))
    browsers.extend(android_browser_finder.FindAllAvailableBrowsers(options))
    browsers.extend(cros_browser_finder.FindAllAvailableBrowsers(options))

    type_list = set([browser.browser_type for browser in browsers])
    type_list = list(type_list)
    type_list.sort()
    return type_list
Esempio n. 3
0
  def test_adb_two_devices(self):
    options = browser_options.BrowserOptions()

    self._stubs.adb_commands.attached_devices = ['015d14fec128220c',
                                                 '015d14fec128220d']

    log_stub = LoggingStub()
    browsers = android_browser_finder.FindAllAvailableBrowsers(
      options, log_stub)
    self.assertEquals(1, len(log_stub.warnings))
    self.assertEquals(0, len(browsers))
Esempio n. 4
0
  def test_adb_permissions_error(self):
    options = browser_options.BrowserOptions()

    self._stubs.subprocess.Popen.communicate_result = (
        """List of devices attached
????????????\tno permissions""",
        """* daemon not running. starting it now on port 5037 *
* daemon started successfully *
""")

    log_stub = LoggingStub()
    browsers = android_browser_finder.FindAllAvailableBrowsers(
      options, log_stub)
    self.assertEquals(3, len(log_stub.warnings))
    self.assertEquals(0, len(browsers))
Esempio n. 5
0
  def test_adb_one_device(self):
    options = browser_options.BrowserOptions()

    self._stubs.adb_commands.attached_devices = ['015d14fec128220c']

    def OnPM(args):
      assert args[0] == 'pm'
      assert args[1] == 'list'
      assert args[2] == 'packages'
      return ['package:org.chromium.content_shell',
              'package.com.google.android.setupwizard']

    self._stubs.adb_commands.shell_command_handlers['pm'] = OnPM

    browsers = android_browser_finder.FindAllAvailableBrowsers(options)
    self.assertEquals(1, len(browsers))
Esempio n. 6
0
def FindBrowser(options):
    """Finds the best PossibleBrowser object to run given the provided
  BrowserOptions object. The returned possiblity object can then be used to
  connect to and control the located browser.
  """
    if options.browser_type == 'exact' and options.browser_executable == None:
        raise Exception(
            '--browser=exact requires --browser-executable to be set.')

    if options.browser_type != 'exact' and options.browser_executable != None:
        raise Exception('--browser-executable requires --browser=exact.')

    if options.browser_type == None:
        raise BrowserTypeRequiredException('browser_type must be specified')

    browsers = []
    browsers.extend(desktop_browser_finder.FindAllAvailableBrowsers(options))
    browsers.extend(android_browser_finder.FindAllAvailableBrowsers(options))
    browsers.extend(cros_browser_finder.FindAllAvailableBrowsers(options))

    if options.browser_type == 'any':
        types = ALL_BROWSER_TYPES.split(',')

        def compare_browsers_on_type_priority(x, y):
            x_idx = types.index(x.browser_type)
            y_idx = types.index(y.browser_type)
            return x_idx - y_idx

        browsers.sort(compare_browsers_on_type_priority)
        if len(browsers) >= 1:
            return browsers[0]
        else:
            return None

    matching_browsers = [
        b for b in browsers if b.browser_type == options.browser_type
    ]

    if len(matching_browsers) == 1:
        return matching_browsers[0]
    elif len(matching_browsers) > 1:
        logging.warning('Multiple browsers of the same type found: %s' %
                        (repr(matching_browsers)))
        return matching_browsers[0]
    else:
        return None
Esempio n. 7
0
  def test_adb_no_devices(self):
    options = browser_options.BrowserOptions()

    browsers = android_browser_finder.FindAllAvailableBrowsers(options)
    self.assertEquals(0, len(browsers))