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 _GetInfobarIndexByType(self, infobar_type, windex, tab_index): |
85 """Identifies whether an infobar button exists with the specified text. | 85 """Returns the index of the infobar of the given type. |
86 | 86 |
87 Args: | 87 Args: |
88 search_text: The text to search for on the infobar buttons. | 88 infobar_type: The infobar type to look for. |
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 None if not found. |
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 None |
102 | 102 |
103 def _WaitForSavePasswordInfobar(self, windex=0, tab_index=0): | 103 def _GetIndexForSavePasswordInfobar(self, windex=0, tab_index=0): |
104 """Wait for and asserts that the save password infobar appears. | 104 """Waits for save password infobar to appear and returns its index. |
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._GetInfobarIndexByType( |
112 self.INFOBAR_BUTTON_TEXT, windex, tab_index)), | 115 self.INFOBAR_TYPE, windex, tab_index)), |
113 msg='Save password infobar did not appear.') | 116 msg='Save password infobar did not appear.') |
| 117 # Return the infobar index. |
| 118 # TODO(dyu): Use the return value in future tests. |
| 119 return self._GetInfobarIndexByType( |
| 120 self.INFOBAR_TYPE, windex, tab_index) |
114 | 121 |
115 def testSavePassword(self): | 122 def testSavePassword(self): |
116 """Test saving a password and getting saved passwords.""" | 123 """Test saving a password and getting saved passwords.""" |
117 password1 = self._ConstructPasswordDictionary( | 124 password1 = self._ConstructPasswordDictionary( |
118 'user@example.com', 'test.password', | 125 'user@example.com', 'test.password', |
119 'https://www.example.com/', 'https://www.example.com/login', | 126 'https://www.example.com/', 'https://www.example.com/login', |
120 'username', 'password', 'https://www.example.com/login/') | 127 'username', 'password', 'https://www.example.com/login/') |
121 self.assertTrue(self.AddSavedPassword(password1)) | 128 self.assertTrue(self.AddSavedPassword(password1)) |
122 self.assertEqual(self.GetSavedPasswords(), [password1]) | 129 self.assertEqual(self.GetSavedPasswords(), [password1]) |
123 | 130 |
(...skipping 25 matching lines...) Expand all Loading... |
149 url_https = 'https://www.google.com/accounts/Login' | 156 url_https = 'https://www.google.com/accounts/Login' |
150 url_logout = 'https://www.google.com/accounts/Logout' | 157 url_logout = 'https://www.google.com/accounts/Logout' |
151 creds = self.GetPrivateInfo()['test_google_account'] | 158 creds = self.GetPrivateInfo()['test_google_account'] |
152 username = creds['username'] | 159 username = creds['username'] |
153 password = creds['password'] | 160 password = creds['password'] |
154 test_utils.GoogleAccountsLogin(self, username, password) | 161 test_utils.GoogleAccountsLogin(self, username, password) |
155 # Wait until page completes loading. | 162 # Wait until page completes loading. |
156 self.WaitUntil( | 163 self.WaitUntil( |
157 lambda: self.GetDOMValue('document.readyState'), | 164 lambda: self.GetDOMValue('document.readyState'), |
158 expect_retval='complete') | 165 expect_retval='complete') |
159 self._WaitForSavePasswordInfobar() | 166 self._GetIndexForSavePasswordInfobar() |
160 infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] | 167 infobar = self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars'] |
161 self.assertEqual(infobar[0]['type'], 'confirm_infobar') | 168 self.assertEqual(infobar[0]['type'], 'password_infobar') |
162 self.PerformActionOnInfobar('accept', infobar_index=0) | 169 self.PerformActionOnInfobar('accept', infobar_index=0) |
163 self.NavigateToURL(url_logout) | 170 self.NavigateToURL(url_logout) |
164 self.NavigateToURL(url_https) | 171 self.NavigateToURL(url_https) |
165 self._ClickOnLoginPage(0, 0) | 172 self._ClickOnLoginPage(0, 0) |
166 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, | 173 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, |
167 tab_index=0, windex=0) | 174 tab_index=0, windex=0) |
168 test_utils.ClearPasswords(self) | 175 test_utils.ClearPasswords(self) |
169 | 176 |
170 def testNeverSavePasswords(self): | 177 def testNeverSavePasswords(self): |
171 """Verify passwords not saved/deleted when 'never for this site' chosen.""" | 178 """Verify passwords not saved/deleted when 'never for this site' chosen.""" |
172 creds1 = self.GetPrivateInfo()['test_google_account'] | 179 creds1 = self.GetPrivateInfo()['test_google_account'] |
173 test_utils.GoogleAccountsLogin( | 180 test_utils.GoogleAccountsLogin( |
174 self, creds1['username'], creds1['password']) | 181 self, creds1['username'], creds1['password']) |
175 self._WaitForSavePasswordInfobar() | 182 self._GetIndexForSavePasswordInfobar() |
176 self.PerformActionOnInfobar('accept', infobar_index=0) | 183 self.PerformActionOnInfobar('accept', infobar_index=0) |
177 self.assertEquals(1, len(self.GetSavedPasswords())) | 184 self.assertEquals(1, len(self.GetSavedPasswords())) |
178 self.AppendTab(pyauto.GURL(creds1['logout_url'])) | 185 self.AppendTab(pyauto.GURL(creds1['logout_url'])) |
179 creds2 = self.GetPrivateInfo()['test_google_account_2'] | 186 creds2 = self.GetPrivateInfo()['test_google_account_2'] |
180 test_utils.GoogleAccountsLogin( | 187 test_utils.GoogleAccountsLogin( |
181 self, creds2['username'], creds2['password'], tab_index=1) | 188 self, creds2['username'], creds2['password'], tab_index=1) |
182 self._WaitForSavePasswordInfobar(tab_index=1) | 189 self._GetIndexForSavePasswordInfobar(tab_index=1) |
183 # Selecting 'Never for this site' option on password infobar. | 190 # Selecting 'Never for this site' option on password infobar. |
184 self.PerformActionOnInfobar('cancel', infobar_index=0, tab_index=1) | 191 self.PerformActionOnInfobar('cancel', infobar_index=0, tab_index=1) |
185 | 192 |
186 # TODO: GetSavedPasswords() doesn't return anything when empty. | 193 # TODO: GetSavedPasswords() doesn't return anything when empty. |
187 # http://crbug.com/64603 | 194 # http://crbug.com/64603 |
188 # self.assertFalse(self.GetSavedPasswords()) | 195 # self.assertFalse(self.GetSavedPasswords()) |
189 # TODO: Check the exceptions list | 196 # TODO: Check the exceptions list |
190 | 197 |
191 def testSavedPasswordInTabsAndWindows(self): | 198 def testSavedPasswordInTabsAndWindows(self): |
192 """Verify saved username/password shows in regular/incognito Window, NTP""" | 199 """Verify saved username/password shows in regular/incognito Window, NTP""" |
193 url = 'https://www.google.com/accounts/ServiceLogin' | 200 url = 'https://www.google.com/accounts/ServiceLogin' |
194 url_logout = 'https://www.google.com/accounts/Logout' | 201 url_logout = 'https://www.google.com/accounts/Logout' |
195 creds = self.GetPrivateInfo()['test_google_account'] | 202 creds = self.GetPrivateInfo()['test_google_account'] |
196 username = creds['username'] | 203 username = creds['username'] |
197 password = creds['password'] | 204 password = creds['password'] |
198 # Login to Google a/c | 205 # Login to Google a/c |
199 test_utils.GoogleAccountsLogin(self, username, password) | 206 test_utils.GoogleAccountsLogin(self, username, password) |
200 self._WaitForSavePasswordInfobar() | 207 self._GetIndexForSavePasswordInfobar() |
201 self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) | 208 self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
202 self.PerformActionOnInfobar('accept', infobar_index=0) | 209 self.PerformActionOnInfobar('accept', infobar_index=0) |
203 self.NavigateToURL(url_logout) | 210 self.NavigateToURL(url_logout) |
204 self.NavigateToURL(url) | 211 self.NavigateToURL(url) |
205 self._ClickOnLoginPage(0, 0) | 212 self._ClickOnLoginPage(0, 0) |
206 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, | 213 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, |
207 tab_index=0, windex=0) | 214 tab_index=0, windex=0) |
208 self.AppendTab(pyauto.GURL(url)) | 215 self.AppendTab(pyauto.GURL(url)) |
209 self._ClickOnLoginPage(0, 1) | 216 self._ClickOnLoginPage(0, 1) |
210 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, | 217 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, |
211 tab_index=1, windex=0) | 218 tab_index=1, windex=0) |
212 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 219 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
213 self.NavigateToURL(url, 1, 0) | 220 self.NavigateToURL(url, 1, 0) |
214 self._ClickOnLoginPage(1, 0) | 221 self._ClickOnLoginPage(1, 0) |
215 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, | 222 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, |
216 tab_index=0, windex=1) | 223 tab_index=0, windex=1) |
217 test_utils.ClearPasswords(self) | 224 test_utils.ClearPasswords(self) |
218 | 225 |
219 def testInfoBarDisappearByNavigatingPage(self): | 226 def testInfoBarDisappearByNavigatingPage(self): |
220 """Test password infobar is dismissed when navigating to different page.""" | 227 """Test password infobar is dismissed when navigating to different page.""" |
221 creds = self.GetPrivateInfo()['test_google_account'] | 228 creds = self.GetPrivateInfo()['test_google_account'] |
222 # Login to Google a/c | 229 # Login to Google a/c |
223 test_utils.GoogleAccountsLogin(self, creds['username'], creds['password']) | 230 test_utils.GoogleAccountsLogin(self, creds['username'], creds['password']) |
224 self._WaitForSavePasswordInfobar() | 231 self._GetIndexForSavePasswordInfobar() |
225 self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) | 232 self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
226 self.NavigateToURL('chrome://history') | 233 self.NavigateToURL('chrome://history') |
227 self.assertTrue(self.WaitForInfobarCount(0)) | 234 self.assertTrue(self.WaitForInfobarCount(0)) |
228 # To make sure user is navigated to History page. | 235 # To make sure user is navigated to History page. |
229 self.assertEqual('History', self.GetActiveTabTitle()) | 236 self.assertEqual('History', self.GetActiveTabTitle()) |
230 self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) | 237 self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
231 | 238 |
232 def testInfoBarDisappearByReload(self): | 239 def testInfoBarDisappearByReload(self): |
233 """Test that Password infobar disappears by the page reload.""" | 240 """Test that Password infobar disappears by the page reload.""" |
234 creds = self.GetPrivateInfo()['test_google_account'] | 241 creds = self.GetPrivateInfo()['test_google_account'] |
235 # Login to Google a/c | 242 # Login to Google a/c |
236 test_utils.GoogleAccountsLogin(self, creds['username'], creds['password']) | 243 test_utils.GoogleAccountsLogin(self, creds['username'], creds['password']) |
237 self._WaitForSavePasswordInfobar() | 244 self._GetIndexForSavePasswordInfobar() |
238 self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) | 245 self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
239 self.GetBrowserWindow(0).GetTab(0).Reload() | 246 self.GetBrowserWindow(0).GetTab(0).Reload() |
240 self.assertTrue(self.WaitForInfobarCount(0)) | 247 self.assertTrue(self.WaitForInfobarCount(0)) |
241 self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) | 248 self.assertFalse(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
242 | 249 |
243 def testPasswdInfoNotStoredWhenAutocompleteOff(self): | 250 def testPasswdInfoNotStoredWhenAutocompleteOff(self): |
244 """Verify that password infobar does not appear when autocomplete is off. | 251 """Verify that password infobar does not appear when autocomplete is off. |
245 | 252 |
246 If the password field has autocomplete turned off, then the password infobar | 253 If the password field has autocomplete turned off, then the password infobar |
247 should not offer to save the password info. | 254 should not offer to save the password info. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 This test requires sending key events rather than pasting a new username | 291 This test requires sending key events rather than pasting a new username |
285 into the Email field. | 292 into the Email field. |
286 """ | 293 """ |
287 url = 'https://www.google.com/accounts/ServiceLogin' | 294 url = 'https://www.google.com/accounts/ServiceLogin' |
288 url_logout = 'https://www.google.com/accounts/Logout' | 295 url_logout = 'https://www.google.com/accounts/Logout' |
289 creds = self.GetPrivateInfo()['test_google_account'] | 296 creds = self.GetPrivateInfo()['test_google_account'] |
290 username = creds['username'] | 297 username = creds['username'] |
291 password = creds['password'] | 298 password = creds['password'] |
292 # Login to Google a/c | 299 # Login to Google a/c |
293 test_utils.GoogleAccountsLogin(self, username, password) | 300 test_utils.GoogleAccountsLogin(self, username, password) |
294 self._WaitForSavePasswordInfobar() | 301 self._GetIndexForSavePasswordInfobar() |
295 self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) | 302 self.assertTrue(self.GetBrowserInfo()['windows'][0]['tabs'][0]['infobars']) |
296 self.PerformActionOnInfobar('accept', infobar_index=0) | 303 self.PerformActionOnInfobar('accept', infobar_index=0) |
297 self.NavigateToURL(url_logout) | 304 self.NavigateToURL(url_logout) |
298 self.NavigateToURL(url) | 305 self.NavigateToURL(url) |
299 self._ClickOnLoginPage(0, 0) | 306 self._ClickOnLoginPage(0, 0) |
300 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, | 307 test_utils.VerifyGoogleAccountCredsFilled(self, username, password, |
301 tab_index=0, windex=0) | 308 tab_index=0, windex=0) |
302 clear_username_field = ( | 309 clear_username_field = ( |
303 'document.getElementById("Email").value = ""; ' | 310 'document.getElementById("Email").value = ""; ' |
304 'window.domAutomationController.send("done");') | 311 'window.domAutomationController.send("done");') |
305 set_focus = ( | 312 set_focus = ( |
306 'document.getElementById("Email").focus(); ' | 313 'document.getElementById("Email").focus(); ' |
307 'window.domAutomationController.send("done");') | 314 'window.domAutomationController.send("done");') |
308 self.ExecuteJavascript(clear_username_field, 0, 0) | 315 self.ExecuteJavascript(clear_username_field, 0, 0) |
309 self.ExecuteJavascript(set_focus, 0, 0) | 316 self.ExecuteJavascript(set_focus, 0, 0) |
310 self._SendCharToPopulateField('t', tab_index=0, windex=0) | 317 self._SendCharToPopulateField('t', tab_index=0, windex=0) |
311 passwd_value = self.GetDOMValue('document.getElementById("Passwd").value') | 318 passwd_value = self.GetDOMValue('document.getElementById("Passwd").value') |
312 self.assertFalse(passwd_value, | 319 self.assertFalse(passwd_value, |
313 msg='Password field not empty for new username.') | 320 msg='Password field not empty for new username.') |
314 test_utils.ClearPasswords(self) | 321 test_utils.ClearPasswords(self) |
315 | 322 |
316 | 323 |
317 if __name__ == '__main__': | 324 if __name__ == '__main__': |
318 pyauto_functional.Main() | 325 pyauto_functional.Main() |
OLD | NEW |