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