Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 INFOBAR_BUTTON_TEXT = 'Save password' | 16 INFOBAR_TYPE = 'password_infobar' |
| 17 | 17 |
| 18 def Debug(self): | 18 def Debug(self): |
| 19 """Test method for experimentation. | 19 """Test method for experimentation. |
| 20 | 20 |
| 21 This method will not run automatically. | 21 This method will not run automatically. |
| 22 """ | 22 """ |
| 23 while True: | 23 while True: |
| 24 raw_input('Interact with the browser and hit <enter> to dump passwords. ') | 24 raw_input('Interact with the browser and hit <enter> to dump passwords. ') |
| 25 print '*' * 20 | 25 print '*' * 20 |
| 26 self.pprint(self.GetSavedPasswords()) | 26 self.pprint(self.GetSavedPasswords()) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 if (element) | 74 if (element) |
| 75 value = element.value; | 75 value = element.value; |
| 76 window.domAutomationController.send(value); | 76 window.domAutomationController.send(value); |
| 77 """ | 77 """ |
| 78 self.assertTrue(self.WaitUntil( | 78 self.assertTrue(self.WaitUntil( |
| 79 lambda: self.ExecuteJavascript(js_template % 'Email', | 79 lambda: self.ExecuteJavascript(js_template % 'Email', |
| 80 tab_index, window_index) != '' and | 80 tab_index, window_index) != '' and |
| 81 self.ExecuteJavascript(js_template % 'Passwd', | 81 self.ExecuteJavascript(js_template % 'Passwd', |
| 82 tab_index, window_index) != '')) | 82 tab_index, window_index) != '')) |
| 83 | 83 |
| 84 def _InfobarButtonContainsText(self, search_text, windex, tab_index): | 84 def _InfobarTypeDisplayed(self, infobar_type, windex, tab_index): |
|
dennis_jeffrey
2012/03/20 21:17:58
Change the function name to something like "_GetIn
dyu1
2012/03/20 22:24:35
Done.
| |
| 85 """Identifies whether an infobar button exists with the specified text. | 85 """Identifies whether an infobar displays and get the index. |
|
dennis_jeffrey
2012/03/20 21:17:58
Returns the index of the infobar of the given type
dyu1
2012/03/20 22:24:35
Done.
| |
| 86 | 86 |
| 87 Args: | 87 Args: |
| 88 search_text: The text to search for on the infobar buttons. | 88 infobar_type: The infobar type displayed. |
| 89 windex: Window index. | 89 windex: Window index. |
| 90 tab_index: Tab index. | 90 tab_index: Tab index. |
| 91 | 91 |
| 92 Returns: | 92 Returns: |
| 93 True, if search_text is found in the buttons, or False otherwise. | 93 Index of infobar for infobar type, or -1 if not found. |
|
dennis_jeffrey
2012/03/20 21:17:58
Maybe we should return None in the event it's not
dyu1
2012/03/20 22:24:35
Done.
| |
| 94 """ | 94 """ |
| 95 infobar = ( | 95 infobar_list = ( |
| 96 self.GetBrowserInfo()['windows'][windex]['tabs'][tab_index] \ | 96 self.GetBrowserInfo()['windows'][windex]['tabs'][tab_index] \ |
| 97 ['infobars']) | 97 ['infobars']) |
| 98 for infobar_info in infobar: | 98 for infobar in infobar_list: |
| 99 if search_text in infobar_info['buttons']: | 99 if infobar_type == infobar['type']: |
| 100 return True | 100 return infobar_list.index(infobar) |
| 101 return False | 101 return -1 |
|
dennis_jeffrey
2012/03/20 21:17:58
recommend changing '-1' to 'None'
dyu1
2012/03/20 22:24:35
Done.
| |
| 102 | 102 |
| 103 def _WaitForSavePasswordInfobar(self, windex=0, tab_index=0): | 103 def _WaitForSavePasswordInfobar(self, windex=0, tab_index=0): |
| 104 """Wait for and asserts that the save password infobar appears. | 104 """Wait for and asserts that the save password infobar appears. |
| 105 | 105 |
| 106 Args: | 106 Args: |
| 107 windex: Window index. Defaults to 0 (first window). | 107 windex: Window index. Defaults to 0 (first window). |
| 108 tab_index: Tab index. Defaults to 0 (first tab). | 108 tab_index: Tab index. Defaults to 0 (first tab). |
| 109 | |
| 110 Returns: | |
| 111 Index of infobar for infobar type. | |
| 109 """ | 112 """ |
| 110 self.assertTrue( | 113 self.assertTrue( |
| 111 self.WaitUntil(lambda: self._InfobarButtonContainsText( | 114 self.WaitUntil(lambda: self._InfobarTypeDisplayed( |
| 112 self.INFOBAR_BUTTON_TEXT, windex, tab_index)), | 115 self.INFOBAR_TYPE, windex, tab_index) is not -1), |
|
dennis_jeffrey
2012/03/20 21:17:58
we can remove 'is not -1' if you address comment a
dyu1
2012/03/20 22:24:35
Done.
| |
| 113 msg='Save password infobar did not appear.') | 116 msg='Save password infobar did not appear.') |
| 117 infobar_index = self._InfobarTypeDisplayed( | |
| 118 self.INFOBAR_TYPE, windex, tab_index) | |
| 119 return infobar_index | |
|
dennis_jeffrey
2012/03/20 21:17:58
combine the above 2 statements into a single state
dyu1
2012/03/20 22:24:35
Done
On 2012/03/20 21:17:58, dennis_jeffrey wrot
| |
| 114 | 120 |
| 115 def testSavePassword(self): | 121 def testSavePassword(self): |
| 116 """Test saving a password and getting saved passwords.""" | 122 """Test saving a password and getting saved passwords.""" |
| 117 password1 = self._ConstructPasswordDictionary( | 123 password1 = self._ConstructPasswordDictionary( |
| 118 'user@example.com', 'test.password', | 124 'user@example.com', 'test.password', |
| 119 'https://www.example.com/', 'https://www.example.com/login', | 125 'https://www.example.com/', 'https://www.example.com/login', |
| 120 'username', 'password', 'https://www.example.com/login/') | 126 'username', 'password', 'https://www.example.com/login/') |
| 121 self.assertTrue(self.AddSavedPassword(password1)) | 127 self.assertTrue(self.AddSavedPassword(password1)) |
| 122 self.assertEqual(self.GetSavedPasswords(), [password1]) | 128 self.assertEqual(self.GetSavedPasswords(), [password1]) |
| 123 | 129 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 self.ExecuteJavascript(set_focus, 0, 0) | 315 self.ExecuteJavascript(set_focus, 0, 0) |
| 310 self._SendCharToPopulateField('t', tab_index=0, windex=0) | 316 self._SendCharToPopulateField('t', tab_index=0, windex=0) |
| 311 passwd_value = self.GetDOMValue('document.getElementById("Passwd").value') | 317 passwd_value = self.GetDOMValue('document.getElementById("Passwd").value') |
| 312 self.assertFalse(passwd_value, | 318 self.assertFalse(passwd_value, |
| 313 msg='Password field not empty for new username.') | 319 msg='Password field not empty for new username.') |
| 314 test_utils.ClearPasswords(self) | 320 test_utils.ClearPasswords(self) |
| 315 | 321 |
| 316 | 322 |
| 317 if __name__ == '__main__': | 323 if __name__ == '__main__': |
| 318 pyauto_functional.Main() | 324 pyauto_functional.Main() |
| OLD | NEW |