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 |
| 6 import os | 6 import os |
| 7 | 7 |
| 8 import pyauto_functional # Must be imported before pyauto | 8 import pyauto_functional # Must be imported before pyauto |
| 9 import pyauto | 9 import pyauto |
| 10 import test_utils | 10 import test_utils |
| 11 | 11 |
| 12 | 12 |
| 13 class PasswordTest(pyauto.PyUITest): | 13 class PasswordTest(pyauto.PyUITest): |
| 14 """Tests that passwords work correctly.""" | 14 """Tests that passwords work correctly.""" |
| 15 | 15 |
| 16 def Debug(self): | 16 def Debug(self): |
| 17 """Test method for experimentation. | 17 """Test method for experimentation. |
| 18 | 18 |
| 19 This method will not run automatically. | 19 This method will not run automatically. |
| 20 """ | 20 """ |
| 21 while True: | 21 while True: |
| 22 raw_input('Interact with the browser and hit <enter> to dump passwords. ') | 22 raw_input('Interact with the browser and hit <enter> to dump passwords. ') |
| 23 print '*' * 20 | 23 print '*' * 20 |
| 24 import pprint | 24 import pprint |
| 25 pp = pprint.PrettyPrinter(indent=2) | 25 pp = pprint.PrettyPrinter(indent=2) |
| 26 pp.pprint(self.GetSavedPasswords()) | 26 pp.pprint(self.GetSavedPasswords()) |
| 27 | 27 |
| 28 def setUp(self): | |
| 29 pyauto.PyUITest.setUp(self) | |
| 30 self.assertEqual(self.GetSavedPasswords(), []) | |
|
Nirnimesh
2011/05/17 20:23:25
self.assertFalse(self.GetSavedPasswords())
| |
| 31 | |
| 28 def _AssertWithinOneSecond(self, time1, time2): | 32 def _AssertWithinOneSecond(self, time1, time2): |
| 29 self.assertTrue(abs(time1 - time2) < 1.0, | 33 self.assertTrue(abs(time1 - time2) < 1.0, |
| 30 'Times not within an acceptable range. ' | 34 'Times not within an acceptable range. ' |
| 31 'First was %lf, second was %lf' % (time1, time2)) | 35 'First was %lf, second was %lf' % (time1, time2)) |
| 32 | 36 |
| 33 def _ConstructPasswordDictionary(self, username_value, password_value, | 37 def _ConstructPasswordDictionary(self, username_value, password_value, |
| 34 signon_realm, origin_url, username_element, | 38 signon_realm, origin_url, username_element, |
| 35 password_element, action_target, | 39 password_element, action_target, |
| 36 time=1279650942.0, submit_element='submit', | 40 time=1279650942.0, submit_element='submit', |
| 37 blacklist=False): | 41 blacklist=False): |
| 38 """Construct a password dictionary with all the required fields.""" | 42 """Construct a password dictionary with all the required fields.""" |
| 39 return {'username_value': username_value, | 43 return {'username_value': username_value, |
| 40 'password_value': password_value, | 44 'password_value': password_value, |
| 41 'signon_realm': signon_realm, | 45 'signon_realm': signon_realm, |
| 42 'time': time, | 46 'time': time, |
| 43 'origin_url': origin_url, | 47 'origin_url': origin_url, |
| 44 'username_element': username_element, | 48 'username_element': username_element, |
| 45 'password_element': password_element, | 49 'password_element': password_element, |
| 46 'submit_element': submit_element, | 50 'submit_element': submit_element, |
| 47 'action_target': action_target, | 51 'action_target': action_target, |
| 48 'blacklist': blacklist} | 52 'blacklist': blacklist} |
| 49 | 53 |
| 50 def testSavePassword(self): | 54 def testSavePassword(self): |
| 51 """Test saving a password and getting saved passwords.""" | 55 """Test saving a password and getting saved passwords.""" |
| 52 password1 = self._ConstructPasswordDictionary( | 56 password1 = self._ConstructPasswordDictionary( |
| 53 'user@example.com', 'test.password', | 57 'user@example.com', 'test.password', |
| 54 'https://www.example.com/', 'https://www.example.com/login', | 58 'https://www.example.com/', 'https://www.example.com/login', |
| 55 'username', 'password', 'https://www.example.com/login/') | 59 'username', 'password', 'https://www.example.com/login/') |
| 56 self.assertTrue(self.AddSavedPassword(password1)) | 60 self.assertTrue(self.AddSavedPassword(password1)) |
| 57 self.assertEquals(self.GetSavedPasswords(), [password1]) | 61 self.assertEqual(self.GetSavedPasswords(), [password1]) |
| 58 | 62 |
| 59 def testRemovePasswords(self): | 63 def testRemovePasswords(self): |
| 60 """Verify that saved passwords can be removed.""" | 64 """Verify that saved passwords can be removed.""" |
| 61 password1 = self._ConstructPasswordDictionary( | 65 password1 = self._ConstructPasswordDictionary( |
| 62 'user1@example.com', 'test1.password', | 66 'user1@example.com', 'test1.password', |
| 63 'https://www.example.com/', 'https://www.example.com/login', | 67 'https://www.example.com/', 'https://www.example.com/login', |
| 64 'username1', 'password', 'https://www.example.com/login/') | 68 'username1', 'password', 'https://www.example.com/login/') |
| 65 password2 = self._ConstructPasswordDictionary( | 69 password2 = self._ConstructPasswordDictionary( |
| 66 'user2@example.com', 'test2.password', | 70 'user2@example.com', 'test2.password', |
| 67 'https://www.example.com/', 'https://www.example.com/login', | 71 'https://www.example.com/', 'https://www.example.com/login', |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 self.ExecuteJavascript(set_focus, 0, 0) | 271 self.ExecuteJavascript(set_focus, 0, 0) |
| 268 self._SendCharToPopulateField('t', tab_index=0, windex=0) | 272 self._SendCharToPopulateField('t', tab_index=0, windex=0) |
| 269 passwd_value = self.GetDOMValue('document.getElementById("Passwd").value') | 273 passwd_value = self.GetDOMValue('document.getElementById("Passwd").value') |
| 270 self.assertFalse(passwd_value, | 274 self.assertFalse(passwd_value, |
| 271 msg='Password field not empty for new username.') | 275 msg='Password field not empty for new username.') |
| 272 test_utils.ClearPasswords(self) | 276 test_utils.ClearPasswords(self) |
| 273 | 277 |
| 274 | 278 |
| 275 if __name__ == '__main__': | 279 if __name__ == '__main__': |
| 276 pyauto_functional.Main() | 280 pyauto_functional.Main() |
| OLD | NEW |