Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: chrome/test/functional/passwords.py

Issue 10383241: Fix and enable testPasswordAutofilledInIncognito. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 from webdriver_pages import settings 11 from webdriver_pages import settings
12 12
13 13
14 class PasswordTest(pyauto.PyUITest): 14 class PasswordTest(pyauto.PyUITest):
15 """Tests that passwords work correctly.""" 15 """Tests that passwords work correctly."""
16 16
17 INFOBAR_TYPE = 'password_infobar' 17 INFOBAR_TYPE = 'password_infobar'
18 URL = 'https://accounts.google.com/ServiceLogin' 18 URL = 'https://accounts.google.com/ServiceLogin'
19 URL_HTTPS = 'https://accounts.google.com/Login' 19 URL_HTTPS = 'https://accounts.google.com/Login'
20 URL_LOGOUT = 'https://accounts.google.com/Logout' 20 URL_LOGOUT = 'https://accounts.google.com/Logout'
21 # Create a list of each bit between slashes.
22 SLASHPARTS = URL.split('/')
23 # Join the first three sections.
24 HOSTNAME = '/'.join(SLASHPARTS[:3]) + '/'
Ilya Sherman 2012/05/19 01:08:57 Hmm, you should probably use something like the ur
dyu1 2012/05/19 02:21:47 Done.
25 USERNAME_ELEM = 'Email'
26 PASSWORD_ELEM = 'Passwd'
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
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
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 """
219 driver = self.NewWebDriver()
220 username = 'test@google.com' 225 username = 'test@google.com'
221 password = 'test.password' 226 password = 'test.password'
227 action_target = self.HOSTNAME
228
229 driver = self.NewWebDriver()
222 password_dict = self._ConstructPasswordDictionary( 230 password_dict = self._ConstructPasswordDictionary(
223 username, password, 231 username, password, self.HOSTNAME, self.URL,
224 'https://www.google.com/', 'https://www.google.com/accounts', 232 self.USERNAME_ELEM, self.PASSWORD_ELEM, action_target)
225 'Email', 'Passwd', 'https://www.google.com/accounts')
226 self.AddSavedPassword(password_dict) 233 self.AddSavedPassword(password_dict)
227 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) 234 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
228 self.NavigateToURL(self.URL, 1, 0) 235 self.NavigateToURL(self.URL, 1, 0)
229 # Switch to window 1. 236 # Switch to window 1.
230 driver.switch_to_window(driver.window_handles[1]) 237 driver.switch_to_window(driver.window_handles[1])
231 driver.find_element_by_id('Email').send_keys(username + '\t') 238 driver.find_element_by_id(self.USERNAME_ELEM).send_keys(username + '\t')
232 incognito_passwd = self.GetDOMValue( 239 incognito_passwd = self.GetDOMValue(
233 'document.getElementById("Passwd").value', tab_index=0, windex=1) 240 'document.getElementById("Passwd").value', tab_index=0, windex=1)
234 self.assertEqual(incognito_passwd, password, 241 self.assertEqual(incognito_passwd, password,
235 msg='Password creds did not autofill in incognito mode.') 242 msg='Password creds did not autofill in incognito mode.')
Ilya Sherman 2012/05/19 01:08:57 nit: indent one more space
dyu1 2012/05/19 02:21:47 Done.
236 243
237 def testInfoBarDisappearByNavigatingPage(self): 244 def testInfoBarDisappearByNavigatingPage(self):
238 """Test password infobar is dismissed when navigating to different page.""" 245 """Test password infobar is dismissed when navigating to different page."""
239 creds = self.GetPrivateInfo()['test_google_account'] 246 creds = self.GetPrivateInfo()['test_google_account']
240 # Disable one-click login infobar for sync. 247 # Disable one-click login infobar for sync.
241 self.SetPrefs(pyauto.kReverseAutologinEnabled, False) 248 self.SetPrefs(pyauto.kReverseAutologinEnabled, False)
242 # Login to Google account. 249 # Login to Google account.
243 test_utils.GoogleAccountsLogin(self, creds['username'], creds['password']) 250 test_utils.GoogleAccountsLogin(self, creds['username'], creds['password'])
244 self.PerformActionOnInfobar( 251 self.PerformActionOnInfobar(
245 'accept', infobar_index=test_utils.WaitForInfobarTypeAndGetIndex( 252 'accept', infobar_index=test_utils.WaitForInfobarTypeAndGetIndex(
(...skipping 17 matching lines...) Expand all
263 self.GetBrowserWindow(0).GetTab(0).Reload() 270 self.GetBrowserWindow(0).GetTab(0).Reload()
264 test_utils.AssertInfobarTypeDoesNotAppear(self, self.INFOBAR_TYPE) 271 test_utils.AssertInfobarTypeDoesNotAppear(self, self.INFOBAR_TYPE)
265 272
266 def testPasswdInfoNotStoredWhenAutocompleteOff(self): 273 def testPasswdInfoNotStoredWhenAutocompleteOff(self):
267 """Verify that password infobar does not appear when autocomplete is off. 274 """Verify that password infobar does not appear when autocomplete is off.
268 275
269 If the password field has autocomplete turned off, then the password infobar 276 If the password field has autocomplete turned off, then the password infobar
270 should not offer to save the password info. 277 should not offer to save the password info.
271 """ 278 """
272 password_info = {'Email': 'test@google.com', 279 password_info = {'Email': 'test@google.com',
273 'Passwd': 'test12345'} 280 'Passwd': 'test12345'}
Ilya Sherman 2012/05/19 01:08:57 nit: Please update these to use the named constant
dyu1 2012/05/19 02:21:47 Done.
Ilya Sherman 2012/05/19 07:47:34 I mean the 'Email' and 'Passwd' strings, though th
274 281
275 # Disable one-click login infobar for sync. 282 # Disable one-click login infobar for sync.
276 self.SetPrefs(pyauto.kReverseAutologinEnabled, False) 283 self.SetPrefs(pyauto.kReverseAutologinEnabled, False)
277 url = self.GetHttpURLForDataPath( 284 url = self.GetHttpURLForDataPath(
278 os.path.join('password', 'password_autocomplete_off_test.html')) 285 os.path.join('password', 'password_autocomplete_off_test.html'))
279 self.NavigateToURL(url) 286 self.NavigateToURL(url)
280 for key, value in password_info.iteritems(): 287 for key, value in password_info.iteritems():
281 script = ('document.getElementById("%s").value = "%s"; ' 288 script = ('document.getElementById("%s").value = "%s"; '
282 'window.domAutomationController.send("done");') % (key, value) 289 'window.domAutomationController.send("done");') % (key, value)
283 self.ExecuteJavascript(script, 0, 0) 290 self.ExecuteJavascript(script, 0, 0)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 password = creds['password'] 353 password = creds['password']
347 # Block cookies for Google accounts domain. 354 # Block cookies for Google accounts domain.
348 self.SetPrefs(pyauto.kContentSettingsPatternPairs, 355 self.SetPrefs(pyauto.kContentSettingsPatternPairs,
349 {'https://accounts.google.com/': {'cookies': 2}}) 356 {'https://accounts.google.com/': {'cookies': 2}})
350 test_utils.GoogleAccountsLogin(self, username, password) 357 test_utils.GoogleAccountsLogin(self, username, password)
351 test_utils.WaitForInfobarTypeAndGetIndex(self, self.INFOBAR_TYPE) 358 test_utils.WaitForInfobarTypeAndGetIndex(self, self.INFOBAR_TYPE)
352 359
353 360
354 if __name__ == '__main__': 361 if __name__ == '__main__':
355 pyauto_functional.Main() 362 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/test/functional/PYAUTO_TESTS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698