Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/test/pyautolib/pyauto.py

Issue 10533038: Switch back to the old method of launching the login flow while keeping some of the benefits of the… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Nirnimesh's comments and fixed chromeos_login.py to work with these changes. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/functional/chromeos_login.py ('k') | chrome/test/pyautolib/pyauto_errors.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
89 from pyauto_errors import NTPThumbnailNotShownError 88 from pyauto_errors import NTPThumbnailNotShownError
90 import pyauto_utils 89 import pyauto_utils
91 import simplejson as json # found in third_party 90 import simplejson as json # found in third_party
92 91
93 _CHROME_DRIVER_FACTORY = None 92 _CHROME_DRIVER_FACTORY = None
94 _HTTP_SERVER = None 93 _HTTP_SERVER = None
95 _REMOTE_PROXY = None 94 _REMOTE_PROXY = None
96 _OPTIONS = None 95 _OPTIONS = None
97 _BROWSER_PID = None 96 _BROWSER_PID = None
98 97
(...skipping 2977 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 MutationObserver returns an error. 3075 MutationObserver returns an error.
3077 """ 3076 """
3078 observer_id = self.AddDomMutationObserver('exists', xpath, attribute, 3077 observer_id = self.AddDomMutationObserver('exists', xpath, attribute,
3079 expected_value, exec_js=exec_js, 3078 expected_value, exec_js=exec_js,
3080 **kwargs) 3079 **kwargs)
3081 try: 3080 try:
3082 self.GetNextEvent(observer_id, timeout=timeout) 3081 self.GetNextEvent(observer_id, timeout=timeout)
3083 except JSONInterfaceError: 3082 except JSONInterfaceError:
3084 raise JSONInterfaceError(msg) 3083 raise JSONInterfaceError(msg)
3085 3084
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): 3085 def GetNextEvent(self, observer_id=-1, blocking=True, timeout=-1):
3104 """Waits for an observed event to occur. 3086 """Waits for an observed event to occur.
3105 3087
3106 The returned event is removed from the Event Queue. If there is already a 3088 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 3089 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 3090 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. 3091 matching event is in the queue this function will immediately return None.
3110 3092
3111 Args: 3093 Args:
3112 observer_id: The id of the observer to wait for, matches any event by 3094 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
4127 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \ 4109 lambda: self._GetResultFromJSONRequest(cmd_dict, windex=None)), \
4128 'Chrome did not reopen the testing channel after login as guest.' 4110 'Chrome did not reopen the testing channel after login as guest.'
4129 self.SetUp() 4111 self.SetUp()
4130 4112
4131 def Login(self, username, password): 4113 def Login(self, username, password):
4132 """Login to chromeos. 4114 """Login to chromeos.
4133 4115
4134 Waits until logged in and browser is ready. 4116 Waits until logged in and browser is ready.
4135 Should be displaying the login screen to work. 4117 Should be displaying the login screen to work.
4136 4118
4119 Note that in case of webui auth-extension-based login, gaia auth errors
4120 will not be noticed here, because the browser has no knowledge of it. In
4121 this case the GetNextEvent automation command will always time out.
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': 'SubmitLoginForm',
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, '
4150 str(e) + '\n Perhaps Chrome crashed or login is broken?') 4144 'failed to start, or the login flow is '
4151 if 'error_string' in response: 4145 'broken?' % str(e))
4152 raise LoginError(response['error_string'])
4153 4146
4154 def Logout(self): 4147 def Logout(self):
4155 """Log out from ChromeOS and wait for session_manager to come up. 4148 """Log out from ChromeOS and wait for session_manager to come up.
4156 4149
4157 This is equivalent to pressing the 'Sign out' button from the 4150 This is equivalent to pressing the 'Sign out' button from the
4158 aura shell tray when logged in. 4151 aura shell tray when logged in.
4159 4152
4160 Should be logged in to work. Re-initializes the automation channel 4153 Should be logged in to work. Re-initializes the automation channel
4161 after logout. 4154 after logout.
4162 """ 4155 """
(...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after
5783 successful = result.wasSuccessful() 5776 successful = result.wasSuccessful()
5784 if not successful: 5777 if not successful:
5785 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename) 5778 pyauto_tests_file = os.path.join(self.TestsDir(), self._tests_filename)
5786 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \ 5779 print >>sys.stderr, 'Tests can be disabled by editing %s. ' \
5787 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL) 5780 'Ref: %s' % (pyauto_tests_file, _PYAUTO_DOC_URL)
5788 sys.exit(not successful) 5781 sys.exit(not successful)
5789 5782
5790 5783
5791 if __name__ == '__main__': 5784 if __name__ == '__main__':
5792 Main() 5785 Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/chromeos_login.py ('k') | chrome/test/pyautolib/pyauto_errors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698