OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | |
5 import logging | 4 import logging |
6 | 5 |
7 import telemetry | 6 from telemetry.core import util |
8 from telemetry import util | |
9 | 7 |
10 | 8 |
11 def _WaitForLoginFormToLoad(backend, login_form_id, tab): | 9 def _WaitForLoginFormToLoad(backend, login_form_id, tab): |
12 def IsFormLoadedOrAlreadyLoggedIn(): | 10 def IsFormLoadedOrAlreadyLoggedIn(): |
13 return tab.EvaluateJavaScript( | 11 return tab.EvaluateJavaScript( |
14 'document.querySelector("#%s")!== null' % login_form_id) or \ | 12 'document.querySelector("#%s")!== null' % login_form_id) or \ |
15 backend.IsAlreadyLoggedIn(tab) | 13 backend.IsAlreadyLoggedIn(tab) |
16 | 14 |
17 # Wait until the form is submitted and the page completes loading. | 15 # Wait until the form is submitted and the page completes loading. |
18 util.WaitFor(lambda: IsFormLoadedOrAlreadyLoggedIn(), # pylint: disable=W0108 | 16 util.WaitFor(lambda: IsFormLoadedOrAlreadyLoggedIn(), # pylint: disable=W0108 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 self.login_form_id, self.login_input_id, config['username']) | 95 self.login_form_id, self.login_input_id, config['username']) |
98 password = 'document.querySelector("#%s").%s.value = "%s"; ' % ( | 96 password = 'document.querySelector("#%s").%s.value = "%s"; ' % ( |
99 self.login_form_id, self.password_input_id, config['password']) | 97 self.login_form_id, self.password_input_id, config['password']) |
100 tab.ExecuteJavaScript(email_id) | 98 tab.ExecuteJavaScript(email_id) |
101 tab.ExecuteJavaScript(password) | 99 tab.ExecuteJavaScript(password) |
102 | 100 |
103 _SubmitFormAndWait(self.login_form_id, tab) | 101 _SubmitFormAndWait(self.login_form_id, tab) |
104 | 102 |
105 self._logged_in = True | 103 self._logged_in = True |
106 return True | 104 return True |
107 except telemetry.TimeoutException: | 105 except util.TimeoutException: |
108 logging.warning('Timed out while loading: %s', self.url) | 106 logging.warning('Timed out while loading: %s', self.url) |
109 return False | 107 return False |
110 | 108 |
111 def LoginNoLongerNeeded(self, tab): # pylint: disable=W0613 | 109 def LoginNoLongerNeeded(self, tab): # pylint: disable=W0613 |
112 assert self._logged_in | 110 assert self._logged_in |
OLD | NEW |