diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-10 23:51:08 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-10 23:51:08 +0000 |
commit | 0c2cba5686b58a90173084128b0e0b3b8534b995 (patch) | |
tree | 452b2a98950f3eec97299e50bccfb7fdb33ccc99 | |
parent | cb8788d6c79b11391d330d2831a9aef4d7ac4441 (diff) | |
download | chromium_src-0c2cba5686b58a90173084128b0e0b3b8534b995.zip chromium_src-0c2cba5686b58a90173084128b0e0b3b8534b995.tar.gz chromium_src-0c2cba5686b58a90173084128b0e0b3b8534b995.tar.bz2 |
Adding pyauto tests to passwords.py
Added tests
1. testRemovePasswords
2. testFetchAnotherUser
3. testNeverSavePasswords
Added a method for constructing password dictionary
Modified testSavePassword in passwords.py
MOdified GoogleAccountsLogin and VerifyGoogleAccountCredsFilled in test_utils.py to take window index and tab index
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/5379007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68909 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/functional/passwords.py | 81 | ||||
-rw-r--r-- | chrome/test/functional/test_utils.py | 28 |
2 files changed, 87 insertions, 22 deletions
diff --git a/chrome/test/functional/passwords.py b/chrome/test/functional/passwords.py index f344897..f7527bd 100644 --- a/chrome/test/functional/passwords.py +++ b/chrome/test/functional/passwords.py @@ -9,7 +9,7 @@ import test_utils class PasswordTest(pyauto.PyUITest): - """Tests that passwords work correctly""" + """Tests that passwords work correctly.""" def Debug(self): """Test method for experimentation. @@ -28,29 +28,63 @@ class PasswordTest(pyauto.PyUITest): 'Times not within an acceptable range. ' 'First was %lf, second was %lf' % (time1, time2)) + def _ConstructPasswordDictionary(self, username_value, password_value, + signon_realm, origin_url, username_element, + password_element, action_target, + time=1279650942.0, submit_element='submit', + blacklist=False): + """Construct a password dictionary with all the required fields.""" + return {'username_value': username_value, + 'password_value': password_value, + 'signon_realm': signon_realm, + 'time': time, + 'origin_url': origin_url, + 'username_element': username_element, + 'password_element': password_element, + 'submit_element': submit_element, + 'action_target': action_target, + 'blacklist': blacklist} + def testSavePassword(self): """Test saving a password and getting saved passwords.""" - password1 = { 'username_value': 'user@example.com', - 'password_value': 'test.password', - 'signon_realm': 'https://www.example.com/', - 'time': 1279650942.0, - 'origin_url': 'https://www.example.com/login', - 'username_element': 'username', - 'password_element': 'password', - 'submit_element': 'submit', - 'action_target': 'https://www.example.com/login/', - 'blacklist': False } + password1 = self._ConstructPasswordDictionary( + 'user@example.com', 'test.password', + 'https://www.example.com/', 'https://www.example.com/login', + 'username', 'password', 'https://www.example.com/login/') self.assertTrue(self.AddSavedPassword(password1)) self.assertEquals(self.GetSavedPasswords(), [password1]) + def testRemovePasswords(self): + """Verify that saved passwords can be removed.""" + password1 = self._ConstructPasswordDictionary( + 'user1@example.com', 'test1.password', + 'https://www.example.com/', 'https://www.example.com/login', + 'username1', 'password', 'https://www.example.com/login/') + password2 = self._ConstructPasswordDictionary( + 'user2@example.com', 'test2.password', + 'https://www.example.com/', 'https://www.example.com/login', + 'username2', 'password2', 'https://www.example.com/login/') + self.AddSavedPassword(password1) + self.AddSavedPassword(password2) + self.assertEquals(2, len(self.GetSavedPasswords())) + self.assertEquals([password1, password2], self.GetSavedPasswords()) + self.RemoveSavedPassword(password1) + self.assertEquals(1, len(self.GetSavedPasswords())) + self.assertEquals([password2], self.GetSavedPasswords()) + self.RemoveSavedPassword(password2) + # TODO: GetSavedPasswords() doesn't return anything when empty. + # http://crbug.com/64603 + # self.assertFalse(self.GetSavedPasswords()) + def testDisplayAndSavePasswordInfobar(self): """Verify password infobar displays and able to save password.""" + test_utils.ClearPasswords(self) url_https = 'https://www.google.com/accounts/' url_logout = 'https://www.google.com/accounts/Logout' creds = self.GetPrivateInfo()['test_google_account'] username = creds['username'] password = creds['password'] - test_utils.GoogleAccountsLogin(self, ['url'], username, password) + test_utils.GoogleAccountsLogin(self, username, password) # Wait until page completes loading. self.WaitUntil( lambda: self.GetDOMValue('document.readyState'), 'complete') @@ -66,6 +100,29 @@ class PasswordTest(pyauto.PyUITest): 'window.domAutomationController.send("done")') test_utils.ClearPasswords(self) + def testNeverSavePasswords(self): + """Verify that we don't save passwords and delete saved passwords + for a domain when 'never for this site' is chosen.""" + creds1 = self.GetPrivateInfo()['test_google_account'] + test_utils.GoogleAccountsLogin( + self, creds1['username'], creds1['password']) + self.assertTrue(self.WaitForInfobarCount(1)) + self.PerformActionOnInfobar('accept', infobar_index=0) + self.assertEquals(1, len(self.GetSavedPasswords())) + self.AppendTab(pyauto.GURL(creds1['logout_url'])) + + creds2 = self.GetPrivateInfo()['etouchqa_google_account'] + test_utils.GoogleAccountsLogin( + self, creds2['username'], creds2['password'], tab_index=1) + self.assertTrue(self.WaitForInfobarCount(1, tab_index=1)) + # Selecting 'Never for this site' option on password infobar. + self.PerformActionOnInfobar('cancel', infobar_index=0, tab_index=1) + + # TODO: GetSavedPasswords() doesn't return anything when empty. + # http://crbug.com/64603 + # self.assertFalse(self.GetSavedPasswords()) + # TODO: Check the exceptions list + if __name__ == '__main__': pyauto_functional.Main() diff --git a/chrome/test/functional/test_utils.py b/chrome/test/functional/test_utils.py index 39bffd8..cdd3f05 100644 --- a/chrome/test/functional/test_utils.py +++ b/chrome/test/functional/test_utils.py @@ -46,7 +46,7 @@ def RemoveDownloadedTestFile(test, file_name): pyauto_utils.RemovePath(downloaded_pkg + '.crdownload') -def GoogleAccountsLogin(test, url, username, password): +def GoogleAccountsLogin(test, username, password, tab_index=0, windex=0): """Log into Google Accounts. Attempts to login to Google by entering the username/password into the google @@ -56,28 +56,36 @@ def GoogleAccountsLogin(test, url, username, password): test: derived from pyauto.PyUITest - base class for UI test cases. username: users login input. password: users login password input. + tab_index: The tab index, default is 0. + windex: The window index, default is 0. """ - test.NavigateToURL('https://www.google.com/accounts/') - email_id = 'document.getElementById("Email").value = \"%s\"; ' \ + test.NavigateToURL('https://www.google.com/accounts/', windex, tab_index) + email_id = 'document.getElementById("Email").value = "%s"; ' \ 'window.domAutomationController.send("done")' % username - password = 'document.getElementById("Passwd").value = \"%s\"; ' \ + password = 'document.getElementById("Passwd").value = "%s"; ' \ 'window.domAutomationController.send("done")' % password - test.ExecuteJavascript(email_id); - test.ExecuteJavascript(password); + test.ExecuteJavascript(email_id, windex, tab_index); + test.ExecuteJavascript(password, windex, tab_index); test.ExecuteJavascript('document.getElementById("gaia_loginform").submit();' - 'window.domAutomationController.send("done")') + 'window.domAutomationController.send("done")', + windex, tab_index) -def VerifyGoogleAccountCredsFilled(test, username, password): +def VerifyGoogleAccountCredsFilled(test, username, password, tab_index=0, + windex=0): """Verify stored/saved user and password values to the values in the field. Args: test: derived from pyauto.PyUITest - base class for UI test cases. username: user log in input. password: user log in password input. + tab_index: The tab index, default is 0. + windex: The window index, default is 0. """ - email_value = test.GetDOMValue('document.getElementById("Email").value') - passwd_value = test.GetDOMValue('document.getElementById("Passwd").value') + email_value = test.GetDOMValue('document.getElementById("Email").value', + windex, tab_index) + passwd_value = test.GetDOMValue('document.getElementById("Passwd").value', + windex, tab_index) test.assertEqual(email_value, username) test.assertEqual(passwd_value, password) |