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 from urlparse import urlparse | |
7 | 8 |
8 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
9 import pyauto | 10 import pyauto |
10 import test_utils | 11 import test_utils |
11 from webdriver_pages import settings | 12 from webdriver_pages import settings |
12 | 13 |
13 | 14 |
14 class PasswordTest(pyauto.PyUITest): | 15 class PasswordTest(pyauto.PyUITest): |
15 """Tests that passwords work correctly.""" | 16 """Tests that passwords work correctly.""" |
16 | 17 |
17 INFOBAR_TYPE = 'password_infobar' | 18 INFOBAR_TYPE = 'password_infobar' |
18 URL = 'https://accounts.google.com/ServiceLogin' | 19 URL = 'https://accounts.google.com/ServiceLogin' |
19 URL_HTTPS = 'https://accounts.google.com/Login' | 20 URL_HTTPS = 'https://accounts.google.com/Login' |
20 URL_LOGOUT = 'https://accounts.google.com/Logout' | 21 URL_LOGOUT = 'https://accounts.google.com/Logout' |
22 HOSTNAME = 'https://'+urlparse(URL)[1] | |
Ilya Sherman
2012/05/19 07:47:34
nit: HOSTNAME = 'https://' + urlparse(URL).netloc
dyu1
2012/05/22 17:31:38
Done.
| |
23 USERNAME_ELEM = 'Email' | |
24 PASSWORD_ELEM = 'Passwd' | |
25 USERNAME = 'test@google.com' | |
26 PASSWORD = 'test.password' | |
21 | 27 |
22 def Debug(self): | 28 def Debug(self): |
23 """Test method for experimentation. | 29 """Test method for experimentation. |
24 | 30 |
25 This method will not run automatically. | 31 This method will not run automatically. |
26 """ | 32 """ |
27 while True: | 33 while True: |
28 raw_input('Interact with the browser and hit <enter> to dump passwords. ') | 34 raw_input('Interact with the browser and hit <enter> to dump passwords. ') |
29 print '*' * 20 | 35 print '*' * 20 |
30 self.pprint(self.GetSavedPasswords()) | 36 self.pprint(self.GetSavedPasswords()) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 # Wait until username/password is filled by the Password manager on the | 79 # Wait until username/password is filled by the Password manager on the |
74 # login page. | 80 # login page. |
75 js_template = """ | 81 js_template = """ |
76 var value = ""; | 82 var value = ""; |
77 var element = document.getElementById("%s"); | 83 var element = document.getElementById("%s"); |
78 if (element) | 84 if (element) |
79 value = element.value; | 85 value = element.value; |
80 window.domAutomationController.send(value); | 86 window.domAutomationController.send(value); |
81 """ | 87 """ |
82 self.assertTrue(self.WaitUntil( | 88 self.assertTrue(self.WaitUntil( |
83 lambda: self.ExecuteJavascript(js_template % 'Email', | 89 lambda: self.ExecuteJavascript(js_template % self.USERNAME_ELEM, |
84 tab_index, window_index) != '' and | 90 tab_index, window_index) != '' and |
85 self.ExecuteJavascript(js_template % 'Passwd', | 91 self.ExecuteJavascript(js_template % self.PASSWORD_ELEM, |
86 tab_index, window_index) != '')) | 92 tab_index, window_index) != '')) |
87 | 93 |
88 def testSavePassword(self): | 94 def testSavePassword(self): |
89 """Test saving a password and getting saved passwords.""" | 95 """Test saving a password and getting saved passwords.""" |
90 password1 = self._ConstructPasswordDictionary( | 96 password1 = self._ConstructPasswordDictionary( |
91 'user@example.com', 'test.password', | 97 'user@example.com', 'test.password', |
92 'https://www.example.com/', 'https://www.example.com/login', | 98 'https://www.example.com/', 'https://www.example.com/login', |
93 'username', 'password', 'https://www.example.com/login/') | 99 'username', 'password', 'https://www.example.com/login/') |
94 self.assertTrue(self.AddSavedPassword(password1)) | 100 self.assertTrue(self.AddSavedPassword(password1)) |
95 self.assertEqual(self.GetSavedPasswords(), [password1]) | 101 self.assertEqual(self.GetSavedPasswords(), [password1]) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 self.assertEqual(email_value, '', | 215 self.assertEqual(email_value, '', |
210 msg='Email creds displayed %s.' % email_value) | 216 msg='Email creds displayed %s.' % email_value) |
211 self.assertEqual(passwd_value, '', msg='Password creds displayed.') | 217 self.assertEqual(passwd_value, '', msg='Password creds displayed.') |
212 | 218 |
213 def testPasswordAutofilledInIncognito(self): | 219 def testPasswordAutofilledInIncognito(self): |
214 """Verify saved password is autofilled in Incognito mode. | 220 """Verify saved password is autofilled in Incognito mode. |
215 | 221 |
216 Saved passwords should be autofilled once the username is entered in | 222 Saved passwords should be autofilled once the username is entered in |
217 incognito mode. | 223 incognito mode. |
218 """ | 224 """ |
225 action_target = self.HOSTNAME | |
226 | |
219 driver = self.NewWebDriver() | 227 driver = self.NewWebDriver() |
220 username = 'test@google.com' | |
221 password = 'test.password' | |
222 password_dict = self._ConstructPasswordDictionary( | 228 password_dict = self._ConstructPasswordDictionary( |
223 username, password, | 229 self.USERNAME, self.PASSWORD, self.HOSTNAME, self.URL, |
224 'https://www.google.com/', 'https://www.google.com/accounts', | 230 self.USERNAME_ELEM, self.PASSWORD_ELEM, action_target) |
225 'Email', 'Passwd', 'https://www.google.com/accounts') | |
226 self.AddSavedPassword(password_dict) | 231 self.AddSavedPassword(password_dict) |
227 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | 232 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
228 self.NavigateToURL(self.URL, 1, 0) | 233 self.NavigateToURL(self.URL, 1, 0) |
229 # Switch to window 1. | 234 # Switch to window 1. |
230 driver.switch_to_window(driver.window_handles[1]) | 235 driver.switch_to_window(driver.window_handles[1]) |
231 driver.find_element_by_id('Email').send_keys(username + '\t') | 236 driver.find_element_by_id( |
237 self.USERNAME_ELEM).send_keys(self.USERNAME + '\t') | |
232 incognito_passwd = self.GetDOMValue( | 238 incognito_passwd = self.GetDOMValue( |
233 'document.getElementById("Passwd").value', tab_index=0, windex=1) | 239 'document.getElementById("Passwd").value', tab_index=0, windex=1) |
234 self.assertEqual(incognito_passwd, password, | 240 self.assertEqual(incognito_passwd, self.PASSWORD, |
235 msg='Password creds did not autofill in incognito mode.') | 241 msg='Password creds did not autofill in incognito mode.') |
236 | 242 |
237 def testInfoBarDisappearByNavigatingPage(self): | 243 def testInfoBarDisappearByNavigatingPage(self): |
238 """Test password infobar is dismissed when navigating to different page.""" | 244 """Test password infobar is dismissed when navigating to different page.""" |
239 creds = self.GetPrivateInfo()['test_google_account'] | 245 creds = self.GetPrivateInfo()['test_google_account'] |
240 # Disable one-click login infobar for sync. | 246 # Disable one-click login infobar for sync. |
241 self.SetPrefs(pyauto.kReverseAutologinEnabled, False) | 247 self.SetPrefs(pyauto.kReverseAutologinEnabled, False) |
242 # Login to Google account. | 248 # Login to Google account. |
243 test_utils.GoogleAccountsLogin(self, creds['username'], creds['password']) | 249 test_utils.GoogleAccountsLogin(self, creds['username'], creds['password']) |
244 self.PerformActionOnInfobar( | 250 self.PerformActionOnInfobar( |
245 'accept', infobar_index=test_utils.WaitForInfobarTypeAndGetIndex( | 251 'accept', infobar_index=test_utils.WaitForInfobarTypeAndGetIndex( |
(...skipping 16 matching lines...) Expand all Loading... | |
262 self, self.INFOBAR_TYPE)) | 268 self, self.INFOBAR_TYPE)) |
263 self.GetBrowserWindow(0).GetTab(0).Reload() | 269 self.GetBrowserWindow(0).GetTab(0).Reload() |
264 test_utils.AssertInfobarTypeDoesNotAppear(self, self.INFOBAR_TYPE) | 270 test_utils.AssertInfobarTypeDoesNotAppear(self, self.INFOBAR_TYPE) |
265 | 271 |
266 def testPasswdInfoNotStoredWhenAutocompleteOff(self): | 272 def testPasswdInfoNotStoredWhenAutocompleteOff(self): |
267 """Verify that password infobar does not appear when autocomplete is off. | 273 """Verify that password infobar does not appear when autocomplete is off. |
268 | 274 |
269 If the password field has autocomplete turned off, then the password infobar | 275 If the password field has autocomplete turned off, then the password infobar |
270 should not offer to save the password info. | 276 should not offer to save the password info. |
271 """ | 277 """ |
272 password_info = {'Email': 'test@google.com', | 278 password_info = {'Email': self.USERNAME, |
273 'Passwd': 'test12345'} | 279 'Passwd': self.PASSWORD} |
274 | 280 |
275 # Disable one-click login infobar for sync. | 281 # Disable one-click login infobar for sync. |
276 self.SetPrefs(pyauto.kReverseAutologinEnabled, False) | 282 self.SetPrefs(pyauto.kReverseAutologinEnabled, False) |
277 url = self.GetHttpURLForDataPath( | 283 url = self.GetHttpURLForDataPath( |
278 os.path.join('password', 'password_autocomplete_off_test.html')) | 284 os.path.join('password', 'password_autocomplete_off_test.html')) |
279 self.NavigateToURL(url) | 285 self.NavigateToURL(url) |
280 for key, value in password_info.iteritems(): | 286 for key, value in password_info.iteritems(): |
281 script = ('document.getElementById("%s").value = "%s"; ' | 287 script = ('document.getElementById("%s").value = "%s"; ' |
282 'window.domAutomationController.send("done");') % (key, value) | 288 'window.domAutomationController.send("done");') % (key, value) |
283 self.ExecuteJavascript(script, 0, 0) | 289 self.ExecuteJavascript(script, 0, 0) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 password = creds['password'] | 352 password = creds['password'] |
347 # Block cookies for Google accounts domain. | 353 # Block cookies for Google accounts domain. |
348 self.SetPrefs(pyauto.kContentSettingsPatternPairs, | 354 self.SetPrefs(pyauto.kContentSettingsPatternPairs, |
349 {'https://accounts.google.com/': {'cookies': 2}}) | 355 {'https://accounts.google.com/': {'cookies': 2}}) |
350 test_utils.GoogleAccountsLogin(self, username, password) | 356 test_utils.GoogleAccountsLogin(self, username, password) |
351 test_utils.WaitForInfobarTypeAndGetIndex(self, self.INFOBAR_TYPE) | 357 test_utils.WaitForInfobarTypeAndGetIndex(self, self.INFOBAR_TYPE) |
352 | 358 |
353 | 359 |
354 if __name__ == '__main__': | 360 if __name__ == '__main__': |
355 pyauto_functional.Main() | 361 pyauto_functional.Main() |
OLD | NEW |