| 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 4584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4595 cmd_dict = { 'command': 'LoginAsGuest' } | 4595 cmd_dict = { 'command': 'LoginAsGuest' } |
| 4596 # Currently, logging in as guest causes session_manager to | 4596 # Currently, logging in as guest causes session_manager to |
| 4597 # restart Chrome, which will close the testing channel. | 4597 # restart Chrome, which will close the testing channel. |
| 4598 # We need to call SetUp() again to reconnect to the new channel. | 4598 # We need to call SetUp() again to reconnect to the new channel. |
| 4599 assert self._WaitForInodeChange( | 4599 assert self._WaitForInodeChange( |
| 4600 self._named_channel_id, | 4600 self._named_channel_id, |
| 4601 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ | 4601 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ |
| 4602 'Chrome did not reopen the testing channel after login as guest.' | 4602 'Chrome did not reopen the testing channel after login as guest.' |
| 4603 self.SetUp() | 4603 self.SetUp() |
| 4604 | 4604 |
| 4605 def Login(self, username, password): | 4605 def Login(self, username, password, use_cached_credentials=False): |
| 4606 """Login to chromeos. | 4606 """Login to chromeos. |
| 4607 | 4607 |
| 4608 Waits until logged in and browser is ready. | 4608 Waits until logged in and browser is ready. |
| 4609 Should be displaying the login screen to work. | 4609 Should be displaying the login screen to work. |
| 4610 | 4610 |
| 4611 Note that in case of webui auth-extension-based login, gaia auth errors | 4611 Note that in case of webui auth-extension-based login, gaia auth errors |
| 4612 will not be noticed here, because the browser has no knowledge of it. In | 4612 will not be noticed here, because the browser has no knowledge of it. In |
| 4613 this case the GetNextEvent automation command will always time out. | 4613 this case the GetNextEvent automation command will always time out. |
| 4614 | 4614 |
| 4615 Args: |
| 4616 username, password: User credentials for login. |
| 4617 use_cached_credentials: Should we login with cached credentials or |
| 4618 resubmit credentials and wait for validation? |
| 4619 |
| 4615 Returns: | 4620 Returns: |
| 4616 An error string if an error occured. | 4621 An error string if an error occured. |
| 4617 None otherwise. | 4622 None otherwise. |
| 4618 | 4623 |
| 4619 Raises: | 4624 Raises: |
| 4620 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 4625 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
| 4621 """ | 4626 """ |
| 4622 self._GetResultFromJSONRequest({'command': 'AddLoginEventObserver'}, | 4627 self._GetResultFromJSONRequest({'command': 'AddLoginEventObserver'}, |
| 4623 windex=None) | 4628 windex=None) |
| 4624 cmd_dict = { | 4629 cmd_dict = { |
| 4625 'command': 'SubmitLoginForm', | 4630 'command': 'SubmitLoginForm', |
| 4626 'username': username, | 4631 'username': username, |
| 4627 'password': password, | 4632 'password': password, |
| 4633 'use_cached_credentials': use_cached_credentials, |
| 4628 } | 4634 } |
| 4629 self._GetResultFromJSONRequest(cmd_dict, windex=None) | 4635 self._GetResultFromJSONRequest(cmd_dict, windex=None) |
| 4630 self.AddDomEventObserver('loginfail', automation_id=4444) | 4636 self.AddDomEventObserver('loginfail', automation_id=4444) |
| 4631 try: | 4637 try: |
| 4632 # TODO(craigdh): Add login failure events once PyAuto switches to mocked | |
| 4633 # GAIA authentication. | |
| 4634 if self.GetNextEvent().get('name') == 'loginfail': | 4638 if self.GetNextEvent().get('name') == 'loginfail': |
| 4635 raise JSONInterfaceError('Login denied by auth server.') | 4639 raise JSONInterfaceError('Login denied by auth server.') |
| 4636 except JSONInterfaceError as e: | 4640 except JSONInterfaceError as e: |
| 4637 raise JSONInterfaceError('Login failed. Perhaps Chrome crashed, ' | 4641 raise JSONInterfaceError('Login failed. Perhaps Chrome crashed, ' |
| 4638 'failed to start, or the login flow is ' | 4642 'failed to start, or the login flow is ' |
| 4639 'broken? Error message: %s' % str(e)) | 4643 'broken? Error message: %s' % str(e)) |
| 4640 | 4644 |
| 4641 def Logout(self): | 4645 def Logout(self): |
| 4642 """Log out from ChromeOS and wait for session_manager to come up. | 4646 """Log out from ChromeOS and wait for session_manager to come up. |
| 4643 | 4647 |
| (...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6537 successful = result.wasSuccessful() | 6541 successful = result.wasSuccessful() |
| 6538 if not successful: | 6542 if not successful: |
| 6539 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6543 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
| 6540 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6544 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
| 6541 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6545 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
| 6542 sys.exit(not successful) | 6546 sys.exit(not successful) |
| 6543 | 6547 |
| 6544 | 6548 |
| 6545 if __name__ == '__main__': | 6549 if __name__ == '__main__': |
| 6546 Main() | 6550 Main() |
| OLD | NEW |