OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
7 from telemetry.testing import simple_mock | 7 from telemetry.testing import simple_mock |
8 | 8 |
9 _ = simple_mock.DONT_CARE | 9 _ = simple_mock.DONT_CARE |
10 | 10 |
11 | 11 |
12 class FormBasedCredentialsBackendUnitTestBase(unittest.TestCase): | 12 class FormBasedCredentialsBackendUnitTestBase(unittest.TestCase): |
13 def setUp(self): | 13 def setUp(self): |
14 self._credentials_type = None | 14 self._credentials_type = None |
15 | 15 |
16 def testLoginUsingMock(self): | 16 def testLoginUsingMock(self): |
17 raise NotImplementedError() | 17 raise NotImplementedError() |
18 | 18 |
19 def _LoginUsingMock(self, backend, login_page_url, email_element_id, | 19 def _LoginUsingMock(self, backend, login_page_url, email_element_id, |
20 password_element_id, form_element_id, | 20 password_element_id, form_element_id, |
21 already_logged_in_js): # pylint: disable=no-self-use | 21 already_logged_in_js): # pylint: disable=no-self-use |
22 del form_element_id # Unused. | |
22 tab = simple_mock.MockObject() | 23 tab = simple_mock.MockObject() |
23 ar = simple_mock.MockObject() | 24 ar = simple_mock.MockObject() |
24 | 25 |
25 config = {'username': 'blah', | 26 config = {'username': 'blah', |
26 'password': 'blargh'} | 27 'password': 'blargh'} |
27 | 28 |
28 tab.ExpectCall('Navigate', login_page_url) | 29 tab.ExpectCall('Navigate', login_page_url) |
29 tab.ExpectCall('EvaluateJavaScript', already_logged_in_js).WillReturn(False) | 30 tab.ExpectCall('EvaluateJavaScript', already_logged_in_js).WillReturn(False) |
30 tab.ExpectCall('WaitForDocumentReadyStateToBeInteractiveOrBetter') | 31 tab.ExpectCall('WaitForDocumentReadyStateToBeInteractiveOrBetter') |
31 | 32 |
32 ar.ExpectCall('WaitForJavaScriptCondition', | 33 ar.ExpectCall( |
33 '(document.querySelector("#%s") !== null) || (%s)' % ( | 34 'WaitForJavaScriptCondition', |
34 form_element_id, already_logged_in_js), 60) | 35 '(document.querySelector({{ form_id }}) !== null) || ({{ @code }})') |
perezju
2017/01/09 13:13:20
This wasn't a great test to begin with. Looks very
| |
35 ar.ExpectCall('WaitForNavigate') | 36 ar.ExpectCall('WaitForNavigate') |
36 | 37 |
37 def VerifyEmail(js): | 38 def VerifyEmail(js): |
38 assert email_element_id in js | 39 assert email_element_id in js |
39 assert 'blah' in js | 40 assert 'blah' in js |
40 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifyEmail) | 41 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifyEmail) |
41 | 42 |
42 def VerifyPw(js): | 43 def VerifyPw(js): |
43 assert password_element_id in js | 44 assert password_element_id in js |
44 assert 'largh' in js | 45 assert 'largh' in js |
45 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifyPw) | 46 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifyPw) |
46 | 47 |
47 def VerifySubmit(js): | 48 def VerifySubmit(js): |
48 assert '.submit' in js or '.click' in js | 49 assert '.submit' in js or '.click' in js |
49 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifySubmit) | 50 tab.ExpectCall('ExecuteJavaScript', _).WhenCalled(VerifySubmit) |
50 | 51 |
51 # Checking for form still up. | 52 # Checking for form still up. |
52 tab.ExpectCall('EvaluateJavaScript', _).WillReturn(False) | 53 tab.ExpectCall('EvaluateJavaScript', _).WillReturn(False) |
53 | 54 |
54 backend.LoginNeeded(tab, ar, config) | 55 backend.LoginNeeded(tab, ar, config) |
OLD | NEW |