OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """PyAuto: Python Interface to Chromium's Automation Proxy. | 6 """PyAuto: Python Interface to Chromium's Automation Proxy. |
7 | 7 |
8 PyAuto uses swig to expose Automation Proxy interfaces to Python. | 8 PyAuto uses swig to expose Automation Proxy interfaces to Python. |
9 For complete documentation on the functionality available, | 9 For complete documentation on the functionality available, |
10 run pydoc on this file. | 10 run pydoc on this file. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 # Sometimes flash files loaded too quickly after firing browser | 202 # Sometimes flash files loaded too quickly after firing browser |
203 # ends up getting downloaded, which seems to indicate that the plugin | 203 # ends up getting downloaded, which seems to indicate that the plugin |
204 # hasn't been registered yet. | 204 # hasn't been registered yet. |
205 if not self.IsChromeOS(): | 205 if not self.IsChromeOS(): |
206 self.GetPluginsInfo() | 206 self.GetPluginsInfo() |
207 | 207 |
208 # TODO(dtu): Remove this after crosbug.com/4558 is fixed. | 208 # TODO(dtu): Remove this after crosbug.com/4558 is fixed. |
209 if self.IsChromeOS(): | 209 if self.IsChromeOS(): |
210 self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode']) | 210 self.WaitUntil(lambda: not self.GetNetworkInfo()['offline_mode']) |
211 | 211 |
212 if (self.IsChromeOS() and self.ShouldOOBESkipToLogin() and | 212 if (self.IsChromeOS() and not self.GetLoginInfo()['is_logged_in'] and |
213 not self.GetLoginInfo()['is_logged_in'] and | 213 self.ShouldOOBESkipToLogin()): |
214 self.GetOOBEScreenInfo()['screen_name'] != 'login'): | 214 if self.GetOOBEScreenInfo()['screen_name'] != 'login': |
215 self.SkipToLogin() | 215 self.SkipToLogin() |
| 216 if self.ShouldAutoLogin(): |
| 217 # Login with default creds. |
| 218 sys.path.append('/usr/local') # to import autotest libs |
| 219 from autotest.cros import constants |
| 220 creds = constants.CREDENTIALS['$default'] |
| 221 self.Login(creds[0], creds[1]) |
| 222 assert self.GetLoginInfo()['is_logged_in'] |
| 223 logging.info('Logged in as %s.' % creds[0]) |
216 | 224 |
217 # If we are connected to any RemoteHosts, create PyAuto | 225 # If we are connected to any RemoteHosts, create PyAuto |
218 # instances on the remote sides and set them up too. | 226 # instances on the remote sides and set them up too. |
219 for remote in self.remotes: | 227 for remote in self.remotes: |
220 remote.CreateTarget(self) | 228 remote.CreateTarget(self) |
221 remote.setUp() | 229 remote.setUp() |
222 | 230 |
223 def setUp(self): | 231 def setUp(self): |
224 """Override this method to launch browser differently. | 232 """Override this method to launch browser differently. |
225 | 233 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 example. Calling this function directly will have no effect. | 303 example. Calling this function directly will have no effect. |
296 | 304 |
297 Returns: | 305 Returns: |
298 True, if the OOBE should be skipped and automation should | 306 True, if the OOBE should be skipped and automation should |
299 go to the 'Add user' login screen directly | 307 go to the 'Add user' login screen directly |
300 False, if the OOBE should not be skipped. | 308 False, if the OOBE should not be skipped. |
301 """ | 309 """ |
302 assert self.IsChromeOS() | 310 assert self.IsChromeOS() |
303 return True | 311 return True |
304 | 312 |
| 313 def ShouldAutoLogin(self): |
| 314 """Determine if we should auto-login on ChromeOS at browser startup. |
| 315 |
| 316 To be used for tests that expect user to be logged in before running test, |
| 317 without caring which user. ShouldOOBESkipToLogin() should return True |
| 318 for this to take effect. |
| 319 |
| 320 Override and return False to not auto login, for tests where login is part |
| 321 of the use case. |
| 322 |
| 323 Returns: |
| 324 True, if chrome should auto login after startup. |
| 325 False, otherwise. |
| 326 """ |
| 327 assert self.IsChromeOS() |
| 328 return True |
| 329 |
305 def CloseChromeOnChromeOS(self): | 330 def CloseChromeOnChromeOS(self): |
306 """Gracefully exit chrome on ChromeOS.""" | 331 """Gracefully exit chrome on ChromeOS.""" |
307 | 332 |
308 def _GetListOfChromePids(): | 333 def _GetListOfChromePids(): |
309 """Retrieves the list of currently-running Chrome process IDs. | 334 """Retrieves the list of currently-running Chrome process IDs. |
310 | 335 |
311 Returns: | 336 Returns: |
312 A list of strings, where each string represents a currently-running | 337 A list of strings, where each string represents a currently-running |
313 'chrome' process ID. | 338 'chrome' process ID. |
314 """ | 339 """ |
(...skipping 6345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6660 successful = result.wasSuccessful() | 6685 successful = result.wasSuccessful() |
6661 if not successful: | 6686 if not successful: |
6662 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6687 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
6663 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6688 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
6664 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6689 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
6665 sys.exit(not successful) | 6690 sys.exit(not successful) |
6666 | 6691 |
6667 | 6692 |
6668 if __name__ == '__main__': | 6693 if __name__ == '__main__': |
6669 Main() | 6694 Main() |
OLD | NEW |