Chromium Code Reviews| Index: chrome/test/functional/sync.py |
| =================================================================== |
| --- chrome/test/functional/sync.py (revision 132411) |
| +++ chrome/test/functional/sync.py (working copy) |
| @@ -6,6 +6,8 @@ |
| import pyauto_functional # Must be imported before pyauto |
| import pyauto |
| import test_utils |
| +from webdriver_pages import settings |
| +from webdriver_pages.settings import Behaviors, ContentTypes |
|
Nirnimesh
2012/04/20 00:43:13
unused
dyu1
2012/04/20 01:44:14
Done.
|
| class SyncTest(pyauto.PyUITest): |
| @@ -221,5 +223,208 @@ |
| msg='Browser 2 unexpectedly contains credit card info.') |
| +class OneClickInfobarTest(pyauto.PyUITest): |
| + """Tests for one click infobar.""" |
| + |
| + OC_INFOBAR_TYPE = 'oneclicklogin_infobar' |
| + PW_INFOBAR_TYPE = 'password_infobar' |
| + URL = 'https://www.google.com/accounts/ServiceLogin' |
| + URL_HTTPS = 'https://www.google.com/accounts/Login' |
| + URL_LOGOUT = 'https://www.google.com/accounts/Logout' |
| + |
| + def setUp(self): |
| + pyauto.PyUITest.setUp(self) |
| + self._driver = self.NewWebDriver() |
| + |
| + def _ClickOnLoginPage(self, window_index, tab_index): |
| + # In some cases (such as on Windows) the current page displays an account |
| + # name and e-mail, rather than an e-mail and password. Clicking on a |
| + # particular DOM element causes the e-mail and password to be displayed. |
| + click_js = """ |
| + var elements = document.getElementsByClassName("accounts"); |
| + if (elements && elements.length > 0) { |
| + elements = elements[0].getElementsByTagName("p"); |
| + if (elements && elements.length > 0) |
| + elements[0].onclick(); |
| + } |
| + window.domAutomationController.send("done"); |
| + """ |
| + self.ExecuteJavascript(click_js, tab_index, window_index) |
| + |
| + # Wait until username/password is filled by the Password manager on the |
| + # login page. |
| + js_template = """ |
| + var value = ""; |
| + var element = document.getElementById("%s"); |
| + if (element) |
| + value = element.value; |
| + window.domAutomationController.send(value); |
| + """ |
| + self.assertTrue(self.WaitUntil( |
| + lambda: self.ExecuteJavascript(js_template % 'Email', |
|
Nirnimesh
2012/04/20 00:43:13
lambda should not be used with multiline functiona
dyu1
2012/04/20 01:44:14
Turns out this function is not even used anywhere
|
| + tab_index, window_index) != '' and |
| + self.ExecuteJavascript(js_template % 'Passwd', |
| + tab_index, window_index) != '')) |
| + |
| + def _LogIntoGoogleAccount(self, tab_index=0, windex=0): |
| + """Log into Google account. |
| + |
| + Args: |
| + tab_index: The tab index, default is 0. |
| + windex: The window index, default is 0. |
| + """ |
| + test_utils.ClearPasswords(self) |
| + creds = self.GetPrivateInfo()['test_google_account'] |
| + username = creds['username'] |
| + password = creds['password'] |
| + test_utils.GoogleAccountsLogin(self, username, password, tab_index, windex) |
| + # Wait until page completes loading. |
| + self.WaitUntil( |
| + lambda: self.GetDOMValue('document.readyState'), |
| + expect_retval='complete') |
| + |
| + def _PerformActionOnInfobar(self, action): |
| + """Perform an action on the infobar: accept, cancel, or dismiss. |
| + |
| + If action is accept then the account is synced. |
| + |
| + Args: |
| + action: The action to perform on the infobar. |
| + """ |
| + self.PerformActionOnInfobar( |
| + action, infobar_index=test_utils.WaitForInfobarTypeAndGetIndex( |
| + self, self.OC_INFOBAR_TYPE)) |
| + |
| + def testDisplayOneClickInfobar(self): |
| + """Verify one-click infobar appears after logging into google account. |
| + |
| + One-click infobar should appear after signing into a google account |
| + for the first time using a clean profile. |
| + """ |
| + self._LogIntoGoogleAccount() |
| + self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( |
| + self, self.OC_INFOBAR_TYPE) is not None)) |
| + |
| + def testNoOneClickInfobarAfterCancel(self): |
| + """Verify one-click infobar does not appear again after clicking cancel. |
| + |
| + The one-click infobar should not display again after logging into an |
| + account and selecting to reject sync the first time. |
| + |
| + This test also verifies that the password infobar displays. |
| + """ |
| + self._LogIntoGoogleAccount() |
| + self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( |
| + self, self.OC_INFOBAR_TYPE) is not None)) |
| + self._PerformActionOnInfobar(action='cancel') # Click 'No thanks' button. |
| + self.NavigateToURL(self.URL_LOGOUT) |
| + self._LogIntoGoogleAccount() |
| + test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) |
| + test_utils.WaitForInfobarTypeAndGetIndex(self, self.PW_INFOBAR_TYPE) |
| + |
| + def testDisplayOneClickInfobarAfterDismiss(self): |
| + """Verify one-click infobar appear again after clicking dismiss button. |
| + |
| + The one-click infobar should display again after logging into an |
| + account and clicking to dismiss the infobar the first time. |
| + |
| + This test also verifies that the password infobar does not display. |
| + The one-click infobar should superceed the password infobar. |
| + """ |
| + self._LogIntoGoogleAccount() |
| + self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( |
| + self, self.OC_INFOBAR_TYPE) is not None)) |
| + self._PerformActionOnInfobar(action='dismiss') # Click 'x' button. |
| + self.NavigateToURL(self.URL_LOGOUT) |
| + self._LogIntoGoogleAccount() |
| + test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) |
| + test_utils.AssertInfobarTypeDoesNotAppear(self, self.PW_INFOBAR_TYPE) |
| + |
| + def _CheckNumProfiles(self, expected_number): |
| + """Returns True if |expected_number| is equal to the number of profiles.""" |
| + # TODO: Remove when crbug.com/108761 is fixed. |
| + multi_profile = self.GetMultiProfileInfo() |
| + return expected_number == len(multi_profile['profiles']) |
| + |
| + def testDisplayOneClickInfobarPerProfile(self): |
| + """Verify one-click infobar appears for each profile after sign-in.""" |
| + # Default profile. |
| + self._LogIntoGoogleAccount() |
| + self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( |
| + self, self.OC_INFOBAR_TYPE) is not None)) |
| + # Create a new multi-profile user. |
| + self.OpenNewBrowserWindowWithNewProfile() |
| + # Wait until the profile has been created. |
| + # TODO: Remove when crbug.com/108761 is fixed. |
| + self.WaitUntil(self._CheckNumProfiles, args=[2]) # Verify 2 profiles exist. |
| + self._LogIntoGoogleAccount(tab_index=0, windex=1) |
| + self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( |
| + self, self.OC_INFOBAR_TYPE, tab_index=0, windex=1) is not None)) |
| + |
| + def testNoSameIDSigninForTwoProfiles(self): |
| + """Verify two profiles cannot be signed in with same ID. |
| + |
| + Make sure that the one-click sign in infobar does not appear for two |
| + profiles trying to sign in with the same ID. This test creates a profile |
| + and connect it to a Google account. Another new profile is created and |
| + tries to login with the connected account from the first profile. |
| + |
| + Regress crbug.com/122975 |
| + """ |
| + test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') |
| + # Create a new multi-profile user. |
| + self.OpenNewBrowserWindowWithNewProfile() |
| + # Wait until the profile has been created. |
| + # TODO: Remove when crbug.com/108761 is fixed. |
| + self.WaitUntil(self._CheckNumProfiles, args=[2]) # Verify 2 profiles exist. |
| + self._LogIntoGoogleAccount(tab_index=0, windex=1) |
| + self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( |
| + self, self.OC_INFOBAR_TYPE, tab_index=0, windex=1) is None)) |
| + |
| + def _VerifyContentExceptionUI(self, content_type, hostname_pattern, behavior, |
| + incognito=False): |
| + """Find hostname pattern and behavior within UI on content exceptions page. |
| + |
| + Args: |
| + content_type: The string content settings type to manage. |
| + hostname_pattern: The URL or pattern associated with the behavior. |
| + behavior: The exception to allow or block the hostname. |
| + incognito: Incognito list displayed on exceptions settings page. |
| + Default to False. |
| + """ |
| + page = settings.ManageExceptionsPage.FromNavigation( |
| + self._driver, content_type) |
| + self.assertTrue(page.GetExceptions(incognito).has_key(hostname_pattern), |
| + msg=('No displayed host name matches pattern "%s"' |
| + % hostname_pattern)) |
| + self.assertEqual(behavior, page.GetExceptions(incognito)[hostname_pattern], |
| + msg=('Displayed behavior "%s" does not match behavior "%s"' |
| + % (page.GetExceptions(incognito)[hostname_pattern], |
| + behavior))) |
| + |
| + def testNoOneClickInfobarWhenCookiesBlocked(self): |
| + """Verify one-click infobar does not show when cookies are blocked. |
| + |
| + One-click sign in should not be enabled if cookies are blocked for Google |
| + accounts domain. Regress crbug.com/117841 |
| + """ |
| + # Block cookies for Google accounts domain. |
| + self.SetPrefs(pyauto.kContentSettingsPatternPairs, |
| + {'https://accounts.google.com/': {'cookies': 2}}) |
| + self._LogIntoGoogleAccount() |
| + test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) |
| + |
| + def testOneClickInfobarShownWhenWinLoseFocus(self): |
| + """Verify one-click infobar still shows when window loses focus. |
| + |
| + Regress crbug.com/121739 |
| + """ |
| + self._LogIntoGoogleAccount() |
| + test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) |
| + # Open new window to shift focus away. |
| + self.RunCommand(pyauto.IDC_NEW_WINDOW) |
|
Nirnimesh
2012/04/20 00:43:13
use pyauto call:
OpenNewBrowserWindow()
dyu1
2012/04/20 01:44:14
Done.
|
| + test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) |
| + |
| + |
| if __name__ == '__main__': |
| pyauto_functional.Main() |