Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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 = 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))
Ejemplo n.º 4
0
    def testSetUpCommandLineFlagsCmdRestored(self):
        """Test that a previous command line file is restored.

    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.WriteFile(cmd_file, 'chrome --args --to --save')
        with android_command_line_backend.SetUpCommandLineFlags(
                adb, backend_settings, startup_args):
            self.assertEqual('chrome --some --test --args',
                             device.ReadFile(cmd_file).strip())
        self.assertEqual('chrome --args --to --save',
                         device.ReadFile(cmd_file).strip())
        device.RunShellCommand(['rm', '-f', cmd_file], check_return=True)