Exemplo 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))
Exemplo n.º 2
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))
def Main():
    """Turns a MultiPageBenchmark into a command-line program.

  If args is not specified, sys.argv[1:] is used.
  """

    # Naively find the benchmark. If we use the browser options parser, we run
    # the risk of failing to parse if we use a benchmark-specific parameter.
    benchmark_name = None
    for arg in sys.argv:
        if arg in _BENCHMARKS:
            benchmark_name = arg

    options = browser_options.BrowserOptions()
    parser = options.CreateParser('%prog [options] <benchmark> <page_set>')

    benchmark = None
    if benchmark_name is not None:
        benchmark = _BENCHMARKS[benchmark_name]()
        benchmark.AddOptions(parser)

    _, args = parser.parse_args()

    if benchmark is None or len(args) != 2:
        parser.print_usage()
        import page_sets  # pylint: disable=F0401
        print >> sys.stderr, 'Available benchmarks:\n%s\n' % ',\n'.join(
            _BENCHMARKS.keys())
        print >> sys.stderr, 'Available page_sets:\n%s\n' % ',\n'.join(
            [os.path.relpath(f) for f in page_sets.GetAllPageSetFilenames()])
        sys.exit(1)

    ps = page_set.PageSet.FromFile(args[1])

    benchmark.CustomizeBrowserOptions(options)
    possible_browser = browser_finder.FindBrowser(options)
    if not possible_browser:
        print >> sys.stderr, """No browser found.\n
Use --browser=list to figure out which are available.\n"""
        sys.exit(1)

    results = multi_page_benchmark.CsvBenchmarkResults(csv.writer(sys.stdout))
    with page_runner.PageRunner(ps) as runner:
        runner.Run(options, possible_browser, benchmark, results)
    # When using an exact executable, assume it is a reference build for the
    # purpose of outputting the perf results.
    results.PrintSummary(options.browser_executable and '_ref' or '')

    if len(results.page_failures):
        logging.warning(
            'Failed pages: %s', '\n'.join(
                [failure['page'].url for failure in results.page_failures]))
    return min(255, len(results.page_failures))
Exemplo 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))
Exemplo 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))
Exemplo n.º 6
0
def Main(args, start_dir, top_level_dir):
  """Unit test suite that collects all test cases for chrome_remote_control."""
  default_options = browser_options.BrowserOptions()
  default_options.browser_type = 'any'

  parser = default_options.CreateParser('run_tests [options] [test names]')
  parser.add_option('--repeat-count', dest='run_test_repeat_count',
                    type='int', default=1,
                    help='Repeats each a provided number of times.')

  _, args = parser.parse_args(args)

  if default_options.verbosity == 0:
    logging.getLogger().setLevel(logging.ERROR)

  from chrome_remote_control import browser_finder
  browser_to_create = browser_finder.FindBrowser(default_options)
  if browser_to_create == None:
    logging.error('No browser found of type %s. Cannot run tests.',
                  default_options.browser_type)
    logging.error('Re-run with --browser=list to see available browser types.')
    return 1

  options_for_unittests.Set(default_options,
                            browser_to_create.browser_type)
  olddir = os.getcwd()
  num_errors = 0
  try:
    os.chdir(top_level_dir)
    for _ in range(
        default_options.run_test_repeat_count): # pylint: disable=E1101
      num_errors += DiscoverAndRunTests(start_dir, args, top_level_dir)
  finally:
    os.chdir(olddir)
    options_for_unittests.Set(None, None)

  return max(num_errors, 255)
Exemplo n.º 7
0
 def setUp(self):
     self._options = browser_options.BrowserOptions()
     self._options.chrome_root = '../../../'
     self._stubs = system_stub.Override(desktop_browser_finder,
                                        ['os', 'subprocess', 'sys'])
Exemplo n.º 8
0
  def test_adb_no_devices(self):
    options = browser_options.BrowserOptions()

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