OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 import pyauto_functional # Must be imported before pyauto | 6 import pyauto_functional # Must be imported before pyauto |
7 import pyauto | 7 import pyauto |
8 import test_utils | 8 import test_utils |
9 | 9 |
10 | 10 |
11 class PasswordTest(pyauto.PyUITest): | 11 class PasswordTest(pyauto.PyUITest): |
12 """Tests that passwords work correctly""" | 12 """Tests that passwords work correctly.""" |
13 | 13 |
14 def Debug(self): | 14 def Debug(self): |
15 """Test method for experimentation. | 15 """Test method for experimentation. |
16 | 16 |
17 This method will not run automatically. | 17 This method will not run automatically. |
18 """ | 18 """ |
19 while True: | 19 while True: |
20 raw_input('Interact with the browser and hit <enter> to dump passwords. ') | 20 raw_input('Interact with the browser and hit <enter> to dump passwords. ') |
21 print '*' * 20 | 21 print '*' * 20 |
22 import pprint | 22 import pprint |
23 pp = pprint.PrettyPrinter(indent=2) | 23 pp = pprint.PrettyPrinter(indent=2) |
24 pp.pprint(self.GetSavedPasswords()) | 24 pp.pprint(self.GetSavedPasswords()) |
25 | 25 |
26 def _AssertWithinOneSecond(self, time1, time2): | 26 def _AssertWithinOneSecond(self, time1, time2): |
27 self.assertTrue(abs(time1 - time2) < 1.0, | 27 self.assertTrue(abs(time1 - time2) < 1.0, |
28 'Times not within an acceptable range. ' | 28 'Times not within an acceptable range. ' |
29 'First was %lf, second was %lf' % (time1, time2)) | 29 'First was %lf, second was %lf' % (time1, time2)) |
30 | 30 |
| 31 def _ConstructPasswordDictionary(self, username_value, password_value, |
| 32 signon_realm, origin_url, username_element, |
| 33 password_element, action_target, |
| 34 time=1279650942.0, submit_element='submit', |
| 35 blacklist=False): |
| 36 """Construct a password dictionary with all the required fields.""" |
| 37 return {'username_value': username_value, |
| 38 'password_value': password_value, |
| 39 'signon_realm': signon_realm, |
| 40 'time': time, |
| 41 'origin_url': origin_url, |
| 42 'username_element': username_element, |
| 43 'password_element': password_element, |
| 44 'submit_element': submit_element, |
| 45 'action_target': action_target, |
| 46 'blacklist': blacklist} |
| 47 |
31 def testSavePassword(self): | 48 def testSavePassword(self): |
32 """Test saving a password and getting saved passwords.""" | 49 """Test saving a password and getting saved passwords.""" |
33 password1 = { 'username_value': 'user@example.com', | 50 password1 = self._ConstructPasswordDictionary( |
34 'password_value': 'test.password', | 51 'user@example.com', 'test.password', |
35 'signon_realm': 'https://www.example.com/', | 52 'https://www.example.com/', 'https://www.example.com/login', |
36 'time': 1279650942.0, | 53 'username', 'password', 'https://www.example.com/login/') |
37 'origin_url': 'https://www.example.com/login', | |
38 'username_element': 'username', | |
39 'password_element': 'password', | |
40 'submit_element': 'submit', | |
41 'action_target': 'https://www.example.com/login/', | |
42 'blacklist': False } | |
43 self.assertTrue(self.AddSavedPassword(password1)) | 54 self.assertTrue(self.AddSavedPassword(password1)) |
44 self.assertEquals(self.GetSavedPasswords(), [password1]) | 55 self.assertEquals(self.GetSavedPasswords(), [password1]) |
45 | 56 |
| 57 def testRemovePasswords(self): |
| 58 """Verify that saved passwords can be removed.""" |
| 59 password1 = self._ConstructPasswordDictionary( |
| 60 'user1@example.com', 'test1.password', |
| 61 'https://www.example.com/', 'https://www.example.com/login', |
| 62 'username1', 'password', 'https://www.example.com/login/') |
| 63 password2 = self._ConstructPasswordDictionary( |
| 64 'user2@example.com', 'test2.password', |
| 65 'https://www.example.com/', 'https://www.example.com/login', |
| 66 'username2', 'password2', 'https://www.example.com/login/') |
| 67 self.AddSavedPassword(password1) |
| 68 self.AddSavedPassword(password2) |
| 69 self.assertEquals(2, len(self.GetSavedPasswords())) |
| 70 self.assertEquals([password1, password2], self.GetSavedPasswords()) |
| 71 self.RemoveSavedPassword(password1) |
| 72 self.assertEquals(1, len(self.GetSavedPasswords())) |
| 73 self.assertEquals([password2], self.GetSavedPasswords()) |
| 74 self.RemoveSavedPassword(password2) |
| 75 # TODO: GetSavedPasswords() doesn't return anything when empty. |
| 76 # http://crbug.com/64603 |
| 77 # self.assertFalse(self.GetSavedPasswords()) |
| 78 |
46 def testDisplayAndSavePasswordInfobar(self): | 79 def testDisplayAndSavePasswordInfobar(self): |
47 """Verify password infobar displays and able to save password.""" | 80 """Verify password infobar displays and able to save password.""" |
48 url_https = 'https://www.google.com/accounts/' | 81 url_https = 'https://www.google.com/accounts/' |
49 url_logout = 'https://www.google.com/accounts/Logout' | 82 url_logout = 'https://www.google.com/accounts/Logout' |
50 creds = self.GetPrivateInfo()['test_google_account'] | 83 creds = self.GetPrivateInfo()['test_google_account'] |
51 username = creds['username'] | 84 username = creds['username'] |
52 password = creds['password'] | 85 password = creds['password'] |
53 test_utils.GoogleAccountsLogin(self, ['url'], username, password) | 86 test_utils.GoogleAccountsLogin(self, username, password) |
54 # Wait until page completes loading. | 87 # Wait until page completes loading. |
55 self.WaitUntil( | 88 self.WaitUntil( |
56 lambda: self.GetDOMValue('document.readyState'), 'complete') | 89 lambda: self.GetDOMValue('document.readyState'), 'complete') |
57 self.assertTrue(self.WaitForInfobarCount(1), | 90 self.assertTrue(self.WaitForInfobarCount(1), |
58 'Did not get save password infobar') | 91 'Did not get save password infobar') |
59 infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] | 92 infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] |
60 self.assertEqual(infobar[0]['type'], 'confirm_infobar') | 93 self.assertEqual(infobar[0]['type'], 'confirm_infobar') |
61 self.PerformActionOnInfobar('accept', infobar_index=0) | 94 self.PerformActionOnInfobar('accept', infobar_index=0) |
62 self.NavigateToURL(url_logout) | 95 self.NavigateToURL(url_logout) |
63 self.NavigateToURL(url_https) | 96 self.NavigateToURL(url_https) |
64 test_utils.VerifyGoogleAccountCredsFilled(self, username, password) | 97 test_utils.VerifyGoogleAccountCredsFilled(self, username, password) |
65 self.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' | 98 self.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' |
66 'window.domAutomationController.send("done")') | 99 'window.domAutomationController.send("done")') |
67 test_utils.ClearPasswords(self) | 100 test_utils.ClearPasswords(self) |
68 | 101 |
| 102 def testNeverSavePasswords(self): |
| 103 """Verify that we don't save passwords and delete saved passwords |
| 104 for a domain when 'never for this site' is chosen.""" |
| 105 creds1 = self.GetPrivateInfo()['test_google_account'] |
| 106 test_utils.GoogleAccountsLogin( |
| 107 self, creds1['username'], creds1['password']) |
| 108 self.assertTrue(self.WaitForInfobarCount(1)) |
| 109 self.PerformActionOnInfobar('accept', infobar_index=0) |
| 110 self.assertEquals(1, len(self.GetSavedPasswords())) |
| 111 self.AppendTab(pyauto.GURL(creds1['logout_url'])) |
| 112 |
| 113 creds2 = self.GetPrivateInfo()['etouchqa_google_account'] |
| 114 test_utils.GoogleAccountsLogin( |
| 115 self, creds2['username'], creds2['password'], tab_index=1) |
| 116 self.assertTrue(self.WaitForInfobarCount(1, tab_index=1)) |
| 117 # Selecting 'Never for this site' option on password infobar. |
| 118 self.PerformActionOnInfobar('cancel', infobar_index=0, tab_index=1) |
| 119 |
| 120 # TODO: GetSavedPasswords() doesn't return anything when empty. |
| 121 # http://crbug.com/64603 |
| 122 # self.assertFalse(self.GetSavedPasswords()) |
| 123 # TODO: Check the exceptions list |
| 124 |
69 | 125 |
70 if __name__ == '__main__': | 126 if __name__ == '__main__': |
71 pyauto_functional.Main() | 127 pyauto_functional.Main() |
OLD | NEW |