1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 """Finds CrOS browsers that can be controlled by telemetry."""
8 from telemetry.core import browser
9 from telemetry.core import possible_browser
10 from telemetry.core.backends.chrome import cros_browser_with_oobe
11 from telemetry.core.backends.chrome import cros_browser_backend
12 from telemetry.core.backends.chrome import cros_interface
13 from telemetry.core.platform import cros_platform_backend
22 class PossibleCrOSBrowser(possible_browser.PossibleBrowser):
23 """A launchable chromeos browser instance."""
24 def __init__(self, browser_type, finder_options, cri, is_guest):
25 super(PossibleCrOSBrowser, self).__init__(browser_type, 'cros',
27 assert browser_type in ALL_BROWSER_TYPES, \
28 'Please add %s to ALL_BROWSER_TYPES' % browser_type
30 self._is_guest = is_guest
33 return 'PossibleCrOSBrowser(browser_type=%s)' % self.browser_type
36 if self.finder_options.output_profile_path:
37 raise Exception("Profile generation is not currently supported on Chrome"
40 browser_options = self.finder_options.browser_options
41 backend = cros_browser_backend.CrOSBrowserBackend(
42 self.browser_type, browser_options, self._cri, self._is_guest,
43 extensions_to_load=self.finder_options.extensions_to_load)
44 platform = cros_platform_backend.CrosPlatformBackend(self._cri)
45 if browser_options.create_browser_with_oobe:
46 return cros_browser_with_oobe.CrOSBrowserWithOOBE(backend, platform)
48 return browser.Browser(backend, platform)
50 def SupportsOptions(self, finder_options):
51 if (len(finder_options.extensions_to_load) != 0) and self._is_guest:
55 def UpdateExecutableIfNeeded(self):
58 def SelectDefaultBrowser(possible_browsers):
59 if cros_interface.IsRunningOnCrosDevice():
60 for b in possible_browsers:
61 if b.browser_type == 'system':
65 def CanFindAvailableBrowsers(finder_options):
66 return (cros_interface.IsRunningOnCrosDevice() or
67 finder_options.cros_remote or
68 cros_interface.HasSSH())
70 def FindAllAvailableBrowsers(finder_options):
71 """Finds all available chromeos browsers, locally and remotely."""
72 if cros_interface.IsRunningOnCrosDevice():
73 return [PossibleCrOSBrowser('system', finder_options,
74 cros_interface.CrOSInterface(),
76 PossibleCrOSBrowser('system-guest', finder_options,
77 cros_interface.CrOSInterface(),
80 if finder_options.cros_remote == None:
81 logging.debug('No --remote specified, will not probe for CrOS.')
84 if not cros_interface.HasSSH():
85 logging.debug('ssh not found. Cannot talk to CrOS devices.')
87 cri = cros_interface.CrOSInterface(finder_options.cros_remote,
88 finder_options.cros_ssh_identity)
93 except cros_interface.LoginException, ex:
94 if isinstance(ex, cros_interface.KeylessLoginRequiredException):
95 logging.warn('Could not ssh into %s. Your device must be configured',
96 finder_options.cros_remote)
97 logging.warn('to allow passwordless login as root.')
98 logging.warn('For a test-build device, pass this to your script:')
99 logging.warn(' --identity $(CHROMITE)/ssh_keys/testing_rsa')
101 logging.warn('For a developer-mode device, the steps are:')
102 logging.warn(' - Ensure you have an id_rsa.pub (etc) on this computer')
103 logging.warn(' - On the chromebook:')
104 logging.warn(' - Control-Alt-T; shell; sudo -s')
105 logging.warn(' - openssh-server start')
106 logging.warn(' - scp <this machine>:.ssh/id_rsa.pub /tmp/')
107 logging.warn(' - mkdir /root/.ssh')
108 logging.warn(' - chown go-rx /root/.ssh')
109 logging.warn(' - cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys')
110 logging.warn(' - chown 0600 /root/.ssh/authorized_keys')
111 logging.warn('There, that was easy!')
113 logging.warn('P.S. Please, tell your manager how INANE this is.')
115 from telemetry.core import browser_finder
116 raise browser_finder.BrowserFinderException(str(ex))
118 if not cri.FileExistsOnDevice('/opt/google/chrome/chrome'):
119 logging.warn('Could not find a chrome on ' % cri.hostname)
121 return [PossibleCrOSBrowser('cros-chrome', finder_options, cri,
123 PossibleCrOSBrowser('cros-chrome-guest', finder_options, cri,