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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 raise | 78 raise |
79 | 79 |
80 # Should go after sys.path is set appropriately | 80 # Should go after sys.path is set appropriately |
81 import bookmark_model | 81 import bookmark_model |
82 import download_info | 82 import download_info |
83 import history_info | 83 import history_info |
84 import omnibox_info | 84 import omnibox_info |
85 import plugins_info | 85 import plugins_info |
86 import prefs_info | 86 import prefs_info |
87 from pyauto_errors import JSONInterfaceError | 87 from pyauto_errors import JSONInterfaceError |
88 from pyauto_errors import LoginError | 88 from pyauto_errors import LoginError |
Nirnimesh
2012/06/07 00:30:55
remove?
craigdh
2012/06/07 19:12:01
Done.
| |
89 from pyauto_errors import NTPThumbnailNotShownError | 89 from pyauto_errors import NTPThumbnailNotShownError |
90 import pyauto_utils | 90 import pyauto_utils |
91 import simplejson as json # found in third_party | 91 import simplejson as json # found in third_party |
92 | 92 |
93 _CHROME_DRIVER_FACTORY = None | 93 _CHROME_DRIVER_FACTORY = None |
94 _HTTP_SERVER = None | 94 _HTTP_SERVER = None |
95 _REMOTE_PROXY = None | 95 _REMOTE_PROXY = None |
96 _OPTIONS = None | 96 _OPTIONS = None |
97 _BROWSER_PID = None | 97 _BROWSER_PID = None |
98 | 98 |
(...skipping 2977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3076 MutationObserver returns an error. | 3076 MutationObserver returns an error. |
3077 """ | 3077 """ |
3078 observer_id = self.AddDomMutationObserver('exists', xpath, attribute, | 3078 observer_id = self.AddDomMutationObserver('exists', xpath, attribute, |
3079 expected_value, exec_js=exec_js, | 3079 expected_value, exec_js=exec_js, |
3080 **kwargs) | 3080 **kwargs) |
3081 try: | 3081 try: |
3082 self.GetNextEvent(observer_id, timeout=timeout) | 3082 self.GetNextEvent(observer_id, timeout=timeout) |
3083 except JSONInterfaceError: | 3083 except JSONInterfaceError: |
3084 raise JSONInterfaceError(msg) | 3084 raise JSONInterfaceError(msg) |
3085 | 3085 |
3086 def _AddLoginEventObserver(self): | |
3087 """Adds a LoginEventObserver associated with the AutomationEventQueue. | |
3088 | |
3089 The LoginEventObserver will generate an event when login completes. | |
3090 | |
3091 Returns: | |
3092 The id of the created observer, which can be used with GetNextEvent(id) | |
3093 and RemoveEventObserver(id). | |
3094 | |
3095 Raises: | |
3096 pyauto_errors.JSONInterfaceError if the automation call returns an error. | |
3097 """ | |
3098 cmd_dict = { | |
3099 'command': 'AddLoginEventObserver', | |
3100 } | |
3101 return self._GetResultFromJSONRequest(cmd_dict, windex=None)['observer_id'] | |
3102 | |
3103 def GetNextEvent(self, observer_id=-1, blocking=True, timeout=-1): | 3086 def GetNextEvent(self, observer_id=-1, blocking=True, timeout=-1): |
3104 """Waits for an observed event to occur. | 3087 """Waits for an observed event to occur. |
3105 | 3088 |
3106 The returned event is removed from the Event Queue. If there is already a | 3089 The returned event is removed from the Event Queue. If there is already a |
3107 matching event in the queue it is returned immediately, otherwise the call | 3090 matching event in the queue it is returned immediately, otherwise the call |
3108 blocks until a matching event occurs. If blocking is disabled and no | 3091 blocks until a matching event occurs. If blocking is disabled and no |
3109 matching event is in the queue this function will immediately return None. | 3092 matching event is in the queue this function will immediately return None. |
3110 | 3093 |
3111 Args: | 3094 Args: |
3112 observer_id: The id of the observer to wait for, matches any event by | 3095 observer_id: The id of the observer to wait for, matches any event by |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4127 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ | 4110 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ |
4128 'Chrome did not reopen the testing channel after login as guest.' | 4111 'Chrome did not reopen the testing channel after login as guest.' |
4129 self.SetUp() | 4112 self.SetUp() |
4130 | 4113 |
4131 def Login(self, username, password): | 4114 def Login(self, username, password): |
4132 """Login to chromeos. | 4115 """Login to chromeos. |
4133 | 4116 |
4134 Waits until logged in and browser is ready. | 4117 Waits until logged in and browser is ready. |
4135 Should be displaying the login screen to work. | 4118 Should be displaying the login screen to work. |
4136 | 4119 |
4120 Note that in case of webui auth-extension-based login, gaia auth errors | |
4121 will not be noticed here, because the browser has no knowledge of it. | |
Nirnimesh
2012/06/07 00:30:55
Add: All such scenarios will lead to timeout of th
craigdh
2012/06/07 19:12:01
Done.
| |
4122 | |
4123 Returns: | |
4124 An error string if an error occured. | |
4125 None otherwise. | |
4126 | |
4137 Raises: | 4127 Raises: |
4138 pyauto_errors.JSONInterfaceError if the automation call returns an error. | 4128 pyauto_errors.JSONInterfaceError if the automation call returns an error. |
4139 pyauto_errors.LoginError if the login fails. | |
4140 """ | 4129 """ |
4141 observer_id = self._AddLoginEventObserver() | 4130 self._GetResultFromJSONRequest({'command': 'AddLoginEventObserver'}, |
4142 ret = self.ExecuteJavascriptInOOBEWebUI(""" | 4131 windex=None) |
4143 chrome.send("completeLogin", ["%s", "%s"] ); | 4132 cmd_dict = { |
4144 window.domAutomationController.send("success");""" % | 4133 'command': 'StartLogin', |
4145 (username, password)); | 4134 'username': username, |
4135 'password': password, | |
4136 } | |
4137 self._GetResultFromJSONRequest(cmd_dict, windex=None) | |
4146 try: | 4138 try: |
4147 response = self.GetNextEvent(observer_id) | 4139 # TODO(craigdh): Add login failure events once PyAuto switches to mocked |
4140 # GAIA authentication. | |
4141 self.GetNextEvent() | |
4148 except JSONInterfaceError as e: | 4142 except JSONInterfaceError as e: |
4149 raise JSONInterfaceError( | 4143 raise JSONInterfaceError('%s\nLogin failed. Perhaps Chrome crashed or ' |
4150 str(e) + '\n Perhaps Chrome crashed or login is broken?') | 4144 'the login flow is broken?' % str(e)) |
4151 if 'error_string' in response: | |
4152 raise LoginError(response['error_string']) | |
4153 | 4145 |
4154 def Logout(self): | 4146 def Logout(self): |
4155 """Log out from ChromeOS and wait for session_manager to come up. | 4147 """Log out from ChromeOS and wait for session_manager to come up. |
4156 | 4148 |
4157 This is equivalent to pressing the 'Sign out' button from the | 4149 This is equivalent to pressing the 'Sign out' button from the |
4158 aura shell tray when logged in. | 4150 aura shell tray when logged in. |
4159 | 4151 |
4160 Should be logged in to work. Re-initializes the automation channel | 4152 Should be logged in to work. Re-initializes the automation channel |
4161 after logout. | 4153 after logout. |
4162 """ | 4154 """ |
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5783 successful = result.wasSuccessful() | 5775 successful = result.wasSuccessful() |
5784 if not successful: | 5776 if not successful: |
5785 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) | 5777 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) |
5786 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ | 5778 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ |
5787 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) | 5779 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) |
5788 sys.exit(not successful) | 5780 sys.exit(not successful) |
5789 | 5781 |
5790 | 5782 |
5791 if __name__ == '__main__': | 5783 if __name__ == '__main__': |
5792 Main() | 5784 Main() |
OLD | NEW |