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 4676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4687 cmd_dict = { 'command': 'LoginAsGuest' } | 4687 cmd_dict = { 'command': 'LoginAsGuest' } |
4688 # Currently, logging in as guest causes session_manager to | 4688 # Currently, logging in as guest causes session_manager to |
4689 # restart Chrome, which will close the testing channel. | 4689 # restart Chrome, which will close the testing channel. |
4690 # We need to call SetUp() again to reconnect to the new channel. | 4690 # We need to call SetUp() again to reconnect to the new channel. |
4691 assert self._WaitForInodeChange( | 4691 assert self._WaitForInodeChange( |
4692 self._named_channel_id, | 4692 self._named_channel_id, |
4693 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ | 4693 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ |
4694 'Chrome did not reopen the testing channel after login as guest.' | 4694 'Chrome did not reopen the testing channel after login as guest.' |
4695 self.SetUp() | 4695 self.SetUp() |
4696 | 4696 |
4697 def LoginWithCachedCredentials(self, username, password): | |
beeps
2012/09/18 17:59:14
Mimics def Login except for the actual hook it cal
craigdh
2012/09/18 18:16:35
Following my suggestion in testing_automation_prov
beeps
2012/09/19 16:29:02
Done.
| |
4698 """Login to chromeos with cached credentials. | |
4699 | |
4700 Returns: | |
4701 An error string if an error occured. | |
4702 None otherwise. | |
4703 | |
4704 Raises: | |
4705 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
4706 """ | |
4707 self._GetResultFromJSONRequest({'command': 'AddLoginEventObserver'}, | |
4708 windex=None) | |
4709 cmd_dict = { | |
4710 'command': 'LoginWithCachedCredentials', | |
4711 'username': username, | |
4712 'password': password, | |
4713 } | |
4714 self._GetResultFromJSONRequest(cmd_dict, windex=None) | |
4715 self.AddDomEventObserver('loginfail', automation_id=4444) | |
4716 try: | |
4717 # TODO(craigdh): Add login failure events once PyAuto switches to mocked | |
4718 # GAIA authentication. | |
craigdh
2012/09/18 18:16:35
Please remove this todo, I already did this but mi
beeps
2012/09/19 16:29:02
Done.
| |
4719 if self.GetNextEvent().get('name') == 'loginfail': | |
4720 raise JSONInterfaceError('Login denied by auth server.') | |
4721 except JSONInterfaceError as e: | |
4722 raise JSONInterfaceError('Login failed. Perhaps Chrome crashed, ' | |
4723 'failed to start, or the login flow is ' | |
4724 'broken? Error message: %s' % str(e)) | |
4725 | |
4697 def Login(self, username, password): | 4726 def Login(self, username, password): |
4698 """Login to chromeos. | 4727 """Login to chromeos. |
4699 | 4728 |
4700 Waits until logged in and browser is ready. | 4729 Waits until logged in and browser is ready. |
4701 Should be displaying the login screen to work. | 4730 Should be displaying the login screen to work. |
4702 | 4731 |
4703 Note that in case of webui auth-extension-based login, gaia auth errors | 4732 Note that in case of webui auth-extension-based login, gaia auth errors |
4704 will not be noticed here, because the browser has no knowledge of it. In | 4733 will not be noticed here, because the browser has no knowledge of it. In |
4705 this case the GetNextEvent automation command will always time out. | 4734 this case the GetNextEvent automation command will always time out. |
4706 | 4735 |
(...skipping 1922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6629 successful = result.wasSuccessful() | 6658 successful = result.wasSuccessful() |
6630 if not successful: | 6659 if not successful: |
6631 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 6660 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
6632 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 6661 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
6633 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 6662 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
6634 sys.exit(not successful) | 6663 sys.exit(not successful) |
6635 | 6664 |
6636 | 6665 |
6637 if __name__ == '__main__': | 6666 if __name__ == '__main__': |
6638 Main() | 6667 Main() |
OLD | NEW |