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 import os | 4 import os |
5 import unittest | 5 import unittest |
6 | 6 |
7 from telemetry import browser_finder | 7 from telemetry import browser_finder |
8 from telemetry import google_credentials_backend | 8 from telemetry import google_credentials_backend |
9 from telemetry import simple_mock | 9 from telemetry import simple_mock |
10 from telemetry import options_for_unittests | 10 from telemetry import options_for_unittests |
(...skipping 15 matching lines...) Expand all Loading... |
26 return | 26 return |
27 | 27 |
28 options = options_for_unittests.GetCopy() | 28 options = options_for_unittests.GetCopy() |
29 with browser_finder.FindBrowser(options).Create() as b: | 29 with browser_finder.FindBrowser(options).Create() as b: |
30 b.credentials.credentials_path = credentials_path | 30 b.credentials.credentials_path = credentials_path |
31 if not b.credentials.CanLogin('google'): | 31 if not b.credentials.CanLogin('google'): |
32 return | 32 return |
33 ret = b.credentials.LoginNeeded(b.tabs[0], 'google') | 33 ret = b.credentials.LoginNeeded(b.tabs[0], 'google') |
34 self.assertTrue(ret) | 34 self.assertTrue(ret) |
35 | 35 |
| 36 def testRealLoginWithDontOverrideProfileIfPossible(self): |
| 37 credentials_path = os.path.join( |
| 38 os.path.dirname(__file__), |
| 39 '..', '..', 'perf', 'data', 'credentials.json') |
| 40 if not os.path.exists(credentials_path): |
| 41 return |
| 42 |
| 43 options = options_for_unittests.GetCopy() |
| 44 options.dont_override_profile = True |
| 45 |
| 46 # Login once to make sure our default profile is logged in. |
| 47 with browser_finder.FindBrowser(options).Create() as b: |
| 48 b.credentials.credentials_path = credentials_path |
| 49 if not b.credentials.CanLogin('google'): |
| 50 return |
| 51 ret = b.credentials.LoginNeeded(b.tabs[0], 'google') |
| 52 self.assertTrue(ret) |
| 53 |
| 54 # Second time will test that we behave correctly if we're logged in, |
| 55 # but our b.credentials doesn't know yet. |
| 56 with browser_finder.FindBrowser(options).Create() as b: |
| 57 b.credentials.credentials_path = credentials_path |
| 58 if not b.credentials.CanLogin('google'): |
| 59 return |
| 60 ret = b.credentials.LoginNeeded(b.tabs[0], 'google') |
| 61 self.assertTrue(ret) |
| 62 |
36 def testLoginUsingMock(self): # pylint: disable=R0201 | 63 def testLoginUsingMock(self): # pylint: disable=R0201 |
37 tab = MockTab() | 64 tab = MockTab() |
38 | 65 |
39 backend = google_credentials_backend.GoogleCredentialsBackend() | 66 backend = google_credentials_backend.GoogleCredentialsBackend() |
40 config = {'username': 'blah', | 67 config = {'username': 'blah', |
41 'password': 'blargh'} | 68 'password': 'blargh'} |
42 | 69 |
43 tab.page.ExpectCall('Navigate', 'https://accounts.google.com/') | 70 tab.page.ExpectCall('Navigate', 'https://accounts.google.com/') |
44 tab.runtime.ExpectCall('Evaluate', _).WillReturn(False) | 71 tab.runtime.ExpectCall('Evaluate', _).WillReturn(False) |
45 tab.runtime.ExpectCall('Evaluate', _).WillReturn(True) | 72 tab.runtime.ExpectCall('Evaluate', _).WillReturn(True) |
| 73 tab.runtime.ExpectCall('Evaluate', _).WillReturn(False) |
46 tab.ExpectCall('WaitForDocumentReadyStateToBeInteractiveOrBetter') | 74 tab.ExpectCall('WaitForDocumentReadyStateToBeInteractiveOrBetter') |
47 | 75 |
48 def VerifyEmail(js): | 76 def VerifyEmail(js): |
49 assert 'Email' in js | 77 assert 'Email' in js |
50 assert 'blah' in js | 78 assert 'blah' in js |
51 tab.runtime.ExpectCall('Execute', _).WhenCalled(VerifyEmail) | 79 tab.runtime.ExpectCall('Execute', _).WhenCalled(VerifyEmail) |
52 | 80 |
53 def VerifyPw(js): | 81 def VerifyPw(js): |
54 assert 'Passwd' in js | 82 assert 'Passwd' in js |
55 assert 'largh' in js | 83 assert 'largh' in js |
56 tab.runtime.ExpectCall('Execute', _).WhenCalled(VerifyPw) | 84 tab.runtime.ExpectCall('Execute', _).WhenCalled(VerifyPw) |
57 | 85 |
58 def VerifySubmit(js): | 86 def VerifySubmit(js): |
59 assert '.submit' in js | 87 assert '.submit' in js |
60 tab.runtime.ExpectCall('Execute', _).WhenCalled(VerifySubmit) | 88 tab.runtime.ExpectCall('Execute', _).WhenCalled(VerifySubmit) |
61 | 89 |
62 # Checking for form still up. | 90 # Checking for form still up. |
63 tab.runtime.ExpectCall('Evaluate', _).WillReturn(False) | 91 tab.runtime.ExpectCall('Evaluate', _).WillReturn(False) |
64 | 92 |
65 backend.LoginNeeded(tab, config) | 93 backend.LoginNeeded(tab, config) |
66 | 94 |
OLD | NEW |