Chromium Code Reviews| 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/09 00:25:14
no need to add another blank line here
sunandt
2010/12/09 00:47:46
I already did remove this. Forgot to update. :)
| |
| 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.""" | |
| 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 # Remove the comment when that gets fixed. | |
|
Nirnimesh
2010/11/29 22:42:58
add the bug# here
sunandt
2010/12/07 23:47:45
Done.
| |
| 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 testFetchAnotherUser(self): | |
| 104 """Verify that another user's password is autofilled when | |
| 105 username is selected.""" | |
| 106 # Save credentials of first account | |
| 107 creds1 = self.GetPrivateInfo()['test_google_account'] | |
| 108 test_utils.GoogleAccountsLogin(self, creds1['login_url'], | |
|
Nirnimesh
2010/11/29 22:42:58
You should directly call AddSavedPassword, instead
sunandt
2010/12/07 23:47:45
Removing this testcase.
| |
| 109 creds1['username'], creds1['password']) | |
| 110 self.WaitForInfobarCount(1) | |
| 111 self.PerformActionOnInfobar('accept', 0) | |
| 112 # Logout | |
| 113 self.AppendTab(pyauto.GURL(creds1['logout_url'])) | |
| 114 | |
| 115 # Save credentials of second account | |
| 116 creds2 = self.GetPrivateInfo()['etouchqa_google_account'] | |
|
Nirnimesh
2010/11/29 22:42:58
Please create an internal CL for adding this entry
| |
| 117 test_utils.GoogleAccountsLogin(self, creds2['login_url'], | |
| 118 creds2['username'], creds2['password'], 0, 1) | |
|
Nirnimesh
2010/11/29 22:42:58
pass as named args:
tab_index=1, windex=0
Repeat e
sunandt
2010/12/07 23:47:45
Removing this testcase.
| |
| 119 self.WaitForInfobarCount(1, 0, 1) | |
| 120 self.PerformActionOnInfobar('accept', 0, 0, 1) | |
| 121 self.AppendTab(pyauto.GURL(creds2['logout_url'])) | |
| 122 | |
| 123 # Populate the username field with the first saved credentials. | |
|
Nirnimesh
2010/11/29 22:42:58
This comment is misleading.
Wait for username fie
sunandt
2010/12/07 23:47:45
Removing this testcase.
| |
| 124 self.WaitUntil( | |
| 125 lambda: self.GetDOMValue('document.getElementById("Email").value', 0, 2) , | |
|
Nirnimesh
2010/11/29 22:42:58
80+ chars
sunandt
2010/12/07 23:47:45
Removing this testcase.
| |
| 126 expect_retval=creds2['username']) | |
| 127 email_id = 'document.getElementById("Email").value = \"%s\"; ' \ | |
| 128 'window.domAutomationController.send("done")' % creds1['username'] | |
| 129 self.ExecuteJavascript(email_id, 0, 2); | |
| 130 self.assertEqual(creds2['password'], | |
| 131 self.GetDOMValue('document.getElementById("Passwd").value', 0, 2)) | |
| 132 | |
| 133 def testNeverSavePasswords(self): | |
|
Nirnimesh
2010/11/29 22:42:58
testNeverSavePasswordsPref
sunandt
2010/12/07 23:47:45
This is not the preference test.
| |
| 134 """Verify that we don't save passwords and delete saved passwords | |
| 135 for a domain when 'never for this site' is chosen.""" | |
| 136 creds1 = self.GetPrivateInfo()['test_google_account'] | |
| 137 test_utils.GoogleAccountsLogin(self, creds1['login_url'], | |
| 138 creds1['username'], creds1['password']) | |
| 139 self.WaitForInfobarCount(1) | |
| 140 self.PerformActionOnInfobar('accept', 0) | |
| 141 self.assertEquals(1, len(self.GetSavedPasswords())) | |
| 142 self.AppendTab(pyauto.GURL(creds1['logout_url'])) | |
| 143 | |
| 144 self.RunCommand(pyauto.IDC_NEW_TAB) | |
|
Nirnimesh
2010/11/29 22:42:58
use AppendTab
sunandt
2010/12/07 23:47:45
Removed.
| |
| 145 creds2 = self.GetPrivateInfo()['etouchqa_google_account'] | |
| 146 test_utils.GoogleAccountsLogin(self, creds2['login_url'], | |
| 147 creds2['username'], creds2['password'], 0, 2) | |
|
Nirnimesh
2010/11/29 22:42:58
use named args for windex, tab_index
sunandt
2010/12/07 23:47:45
Done.
| |
| 148 self.WaitForInfobarCount(1, 0, 2) | |
| 149 self.PerformActionOnInfobar('cancel', 0, 0, 2) | |
| 150 | |
| 151 # TODO: Remove comment when GetSavedPasswords() is fixed. | |
|
Nirnimesh
2010/11/29 22:42:58
won't this have 1 entry at this point?
sunandt
2010/12/07 23:47:45
GetSavedPasswords() isn't returning anything from
| |
| 152 # self.assertFalse(self.GetSavedPasswords()) | |
| 153 # TODO: Check the exceptions list | |
| 154 | |
| 69 | 155 |
| 70 if __name__ == '__main__': | 156 if __name__ == '__main__': |
| 71 pyauto_functional.Main() | 157 pyauto_functional.Main() |
| OLD | NEW |