Beispiel #1
0
    def testSetUpCommandLineFlagsCmdRestored(self):
        """Test that a previous command line file is restored.

    Requires a device connected to the host.
    """
        device = self._GetDeviceForTest()
        if not device:
            logging.warning(
                'Skip the test because we cannot find any healthy device')
            return
        cmd_file = '/data/local/tmp/test_cmd2'
        backend_settings = _MockBackendSettings(cmd_file)
        startup_args = ['--some', '--test', '--args']
        try:
            device.WriteFile(cmd_file, 'chrome --args --to --save')
            self.assertEqual('chrome --args --to --save',
                             device.ReadFile(cmd_file).strip())
            with android_command_line_backend.SetUpCommandLineFlags(
                    device, backend_settings, startup_args):
                self.assertItemsEqual(['--some', '--test', '--args'],
                                      _dummyArgsParse(
                                          device.ReadFile(cmd_file)))
            self.assertItemsEqual(['--args', '--to', '--save'],
                                  _dummyArgsParse(device.ReadFile(cmd_file)))
        finally:
            device.RunShellCommand(['rm', '-f', cmd_file], check_return=True)
Beispiel #2
0
    def Start(self):
        self._adb.device().RunShellCommand('logcat -c')
        if self.browser_options.startup_url:
            url = self.browser_options.startup_url
        elif self.browser_options.profile_dir:
            url = None
        else:
            # If we have no existing tabs start with a blank page since default
            # startup with the NTP can lead to race conditions with Telemetry
            url = 'about:blank'

        self.platform_backend.DismissCrashDialogIfNeeded()

        browser_startup_args = self.GetBrowserStartupArgs()
        with android_command_line_backend.SetUpCommandLineFlags(
                self._adb, self._backend_settings, browser_startup_args):
            self._adb.device().StartActivity(intent.Intent(
                package=self._backend_settings.package,
                activity=self._backend_settings.activity,
                action=None,
                data=url,
                category=None),
                                             blocking=True)

            remote_devtools_port = self._backend_settings.GetDevtoolsRemotePort(
                self._adb)
            self.platform_backend.ForwardHostToDevice(self._port,
                                                      remote_devtools_port)
            try:
                self._WaitForBrowserToComeUp()
                self._InitDevtoolsClientBackend(remote_devtools_port)
            except exceptions.BrowserGoneException:
                logging.critical('Failed to connect to browser.')
                device = self._adb.device()
                if not device.old_interface.CanAccessProtectedFileContents():
                    logging.critical(
                        'Resolve this by either: '
                        '(1) Flashing to a userdebug build OR '
                        '(2) Manually enabling web debugging in Chrome at '
                        'Settings > Developer tools > Enable USB Web debugging.'
                    )
                sys.exit(1)
            except:
                import traceback
                traceback.print_exc()
                self.Close()
                raise
Beispiel #3
0
    def Start(self):
        """Start an Android app and wait for it to finish launching.

    AppStory derivations can customize the wait-for-ready-state to wait
    for a more specific event if needed.
    """
        webview_startup_args = self.GetWebviewStartupArgs()
        backend_settings = android_browser_backend_settings.WebviewBackendSettings(
            'android-webview')
        with android_command_line_backend.SetUpCommandLineFlags(
                self._adb, backend_settings, webview_startup_args):
            # TODO(slamm): check if can use "blocking=True" instead of needing to
            # sleep. If "blocking=True" does not work, switch sleep to "ps" check.
            self._adb.device().StartActivity(self._start_intent,
                                             blocking=False)
            util.WaitFor(self._IsAppReady, timeout=60)
        self._is_running = True
  def testSetUpCommandLineFlagsCmdRemoved(self):
    """Test that the command line file is removed if it did not exist before.

    Requires a device connected to the host.
    """
    device = self._GetDeviceForTest()
    if not device:
      logging.warning('Skip the test because we cannot find any healthy device')
      return
    cmd_file = '/data/local/tmp/test_cmd'
    backend_settings = _MockBackendSettings(cmd_file)
    startup_args = ['--some', '--test', '--args']
    device.RunShellCommand(['rm', '-f', cmd_file], check_return=True)
    with android_command_line_backend.SetUpCommandLineFlags(
        device, backend_settings, startup_args):
      self.assertEqual('chrome --some --test --args',
                       device.ReadFile(cmd_file).strip())
    self.assertFalse(device.FileExists(cmd_file))
Beispiel #5
0
    def Start(self):
        """Start an Android app and wait for it to finish launching.

    If the app has webviews, the app is launched with the suitable
    command line arguments.

    AppStory derivations can customize the wait-for-ready-state to wait
    for a more specific event if needed.
    """
        if self._app_has_webviews:
            webview_startup_args = self.GetWebviewStartupArgs()
            backend_settings = (android_browser_backend_settings.
                                WebviewBackendSettings('android-webview'))
            with android_command_line_backend.SetUpCommandLineFlags(
                    self.device, backend_settings, webview_startup_args):
                self._LaunchAndWaitForApplication()
        else:
            self._LaunchAndWaitForApplication()
        self._is_running = True
Beispiel #6
0
    def testSetUpCommandLineFlagsCmdRemoved(self):
        """Test that the command line file is removed if it did not exist before.

    Requires a device connected to the host.
    """
        serial = options_for_unittests.GetCopy().device
        if not serial:
            serial = adb_commands.GetAttachedDevices()[0]
        cmd_file = '/data/local/tmp/test_cmd'
        adb = adb_commands.AdbCommands(device=serial)
        backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd')
        startup_args = ['--some', '--test', '--args']
        device = adb.device()
        device.RunShellCommand(['rm', '-f', cmd_file], check_return=True)
        with android_command_line_backend.SetUpCommandLineFlags(
                adb, backend_settings, startup_args):
            self.assertEqual('chrome --some --test --args',
                             device.ReadFile(cmd_file).strip())
        self.assertFalse(device.FileExists(cmd_file))
Beispiel #7
0
    def Start(self):
        self.device.RunShellCommand('logcat -c')
        if self.browser_options.startup_url:
            url = self.browser_options.startup_url
        elif self.browser_options.profile_dir:
            url = None
        else:
            # If we have no existing tabs start with a blank page since default
            # startup with the NTP can lead to race conditions with Telemetry
            url = 'about:blank'

        self.platform_backend.DismissCrashDialogIfNeeded()

        browser_startup_args = self.GetBrowserStartupArgs()
        with android_command_line_backend.SetUpCommandLineFlags(
                self.device, self._backend_settings, browser_startup_args):
            self.device.StartActivity(intent.Intent(
                package=self._backend_settings.package,
                activity=self._backend_settings.activity,
                action=None,
                data=url,
                category=None),
                                      blocking=True)

            remote_devtools_port = self._backend_settings.GetDevtoolsRemotePort(
                self.device)
            try:
                self.platform_backend.ForwardHostToDevice(
                    self._port, remote_devtools_port)
            except Exception:
                logging.exception('Failed to forward %s to %s.',
                                  str(self._port), str(remote_devtools_port))
                logging.warning('Currently forwarding:')
                try:
                    for line in self.device.adb.ForwardList().splitlines():
                        logging.warning('  %s', line)
                except Exception:
                    logging.warning('Exception raised while listing forwarded '
                                    'connections.')

                logging.warning('Device unix domain sockets in use:')
                try:
                    for line in self.device.ReadFile(
                            '/proc/net/unix', as_root=True,
                            force_pull=True).splitlines():
                        logging.warning('  %s', line)
                except Exception:
                    logging.warning(
                        'Exception raised while listing unix domain sockets.')

                raise

            try:
                self._WaitForBrowserToComeUp()
                self._InitDevtoolsClientBackend(remote_devtools_port)
            except exceptions.BrowserGoneException:
                logging.critical('Failed to connect to browser.')
                if not (self.device.HasRoot() or self.device.NeedsSU()):
                    logging.critical(
                        'Resolve this by either: '
                        '(1) Flashing to a userdebug build OR '
                        '(2) Manually enabling web debugging in Chrome at '
                        'Settings > Developer tools > Enable USB Web debugging.'
                    )
                self.Close()
                raise
            except:
                self.Close()
                raise