Chromium Code Reviews| 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 pyauto_functional # Must be imported before pyauto | 6 import pyauto_functional # Must be imported before pyauto |
| 7 import pyauto | 7 import pyauto |
| 8 import test_utils | 8 import test_utils |
| 9 from webdriver_pages import settings | |
| 10 from webdriver_pages.settings import Behaviors, ContentTypes | |
|
Nirnimesh
2012/04/20 00:43:13
unused
dyu1
2012/04/20 01:44:14
Done.
| |
| 9 | 11 |
| 10 | 12 |
| 11 class SyncTest(pyauto.PyUITest): | 13 class SyncTest(pyauto.PyUITest): |
| 12 """Tests for sync.""" | 14 """Tests for sync.""" |
| 13 | 15 |
| 14 def testSignInToSync(self): | 16 def testSignInToSync(self): |
| 15 """Sign in to sync.""" | 17 """Sign in to sync.""" |
| 16 new_timeout = pyauto.PyUITest.ActionTimeoutChanger(self, | 18 new_timeout = pyauto.PyUITest.ActionTimeoutChanger(self, |
| 17 60 * 1000) # 1 min. | 19 60 * 1000) # 1 min. |
| 18 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') | 20 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 test_utils.SignInToSyncAndVerifyState(browser2, account_key) | 216 test_utils.SignInToSyncAndVerifyState(browser2, account_key) |
| 215 browser2.AwaitSyncCycleCompletion() | 217 browser2.AwaitSyncCycleCompletion() |
| 216 | 218 |
| 217 # Verify browser 2 does not contain credit card info. | 219 # Verify browser 2 does not contain credit card info. |
| 218 browser2_profile = browser2.GetAutofillProfile() | 220 browser2_profile = browser2.GetAutofillProfile() |
| 219 num_cc_profiles = len(browser2_profile['credit_cards']) | 221 num_cc_profiles = len(browser2_profile['credit_cards']) |
| 220 self.assertEqual(0, num_cc_profiles, | 222 self.assertEqual(0, num_cc_profiles, |
| 221 msg='Browser 2 unexpectedly contains credit card info.') | 223 msg='Browser 2 unexpectedly contains credit card info.') |
| 222 | 224 |
| 223 | 225 |
| 226 class OneClickInfobarTest(pyauto.PyUITest): | |
| 227 """Tests for one click infobar.""" | |
| 228 | |
| 229 OC_INFOBAR_TYPE = 'oneclicklogin_infobar' | |
| 230 PW_INFOBAR_TYPE = 'password_infobar' | |
| 231 URL = 'https://www.google.com/accounts/ServiceLogin' | |
| 232 URL_HTTPS = 'https://www.google.com/accounts/Login' | |
| 233 URL_LOGOUT = 'https://www.google.com/accounts/Logout' | |
| 234 | |
| 235 def setUp(self): | |
| 236 pyauto.PyUITest.setUp(self) | |
| 237 self._driver = self.NewWebDriver() | |
| 238 | |
| 239 def _ClickOnLoginPage(self, window_index, tab_index): | |
| 240 # In some cases (such as on Windows) the current page displays an account | |
| 241 # name and e-mail, rather than an e-mail and password. Clicking on a | |
| 242 # particular DOM element causes the e-mail and password to be displayed. | |
| 243 click_js = """ | |
| 244 var elements = document.getElementsByClassName("accounts"); | |
| 245 if (elements && elements.length > 0) { | |
| 246 elements = elements[0].getElementsByTagName("p"); | |
| 247 if (elements && elements.length > 0) | |
| 248 elements[0].onclick(); | |
| 249 } | |
| 250 window.domAutomationController.send("done"); | |
| 251 """ | |
| 252 self.ExecuteJavascript(click_js, tab_index, window_index) | |
| 253 | |
| 254 # Wait until username/password is filled by the Password manager on the | |
| 255 # login page. | |
| 256 js_template = """ | |
| 257 var value = ""; | |
| 258 var element = document.getElementById("%s"); | |
| 259 if (element) | |
| 260 value = element.value; | |
| 261 window.domAutomationController.send(value); | |
| 262 """ | |
| 263 self.assertTrue(self.WaitUntil( | |
| 264 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
| |
| 265 tab_index, window_index) != '' and | |
| 266 self.ExecuteJavascript(js_template % 'Passwd', | |
| 267 tab_index, window_index) != '')) | |
| 268 | |
| 269 def _LogIntoGoogleAccount(self, tab_index=0, windex=0): | |
| 270 """Log into Google account. | |
| 271 | |
| 272 Args: | |
| 273 tab_index: The tab index, default is 0. | |
| 274 windex: The window index, default is 0. | |
| 275 """ | |
| 276 test_utils.ClearPasswords(self) | |
| 277 creds = self.GetPrivateInfo()['test_google_account'] | |
| 278 username = creds['username'] | |
| 279 password = creds['password'] | |
| 280 test_utils.GoogleAccountsLogin(self, username, password, tab_index, windex) | |
| 281 # Wait until page completes loading. | |
| 282 self.WaitUntil( | |
| 283 lambda: self.GetDOMValue('document.readyState'), | |
| 284 expect_retval='complete') | |
| 285 | |
| 286 def _PerformActionOnInfobar(self, action): | |
| 287 """Perform an action on the infobar: accept, cancel, or dismiss. | |
| 288 | |
| 289 If action is accept then the account is synced. | |
| 290 | |
| 291 Args: | |
| 292 action: The action to perform on the infobar. | |
| 293 """ | |
| 294 self.PerformActionOnInfobar( | |
| 295 action, infobar_index=test_utils.WaitForInfobarTypeAndGetIndex( | |
| 296 self, self.OC_INFOBAR_TYPE)) | |
| 297 | |
| 298 def testDisplayOneClickInfobar(self): | |
| 299 """Verify one-click infobar appears after logging into google account. | |
| 300 | |
| 301 One-click infobar should appear after signing into a google account | |
| 302 for the first time using a clean profile. | |
| 303 """ | |
| 304 self._LogIntoGoogleAccount() | |
| 305 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
| 306 self, self.OC_INFOBAR_TYPE) is not None)) | |
| 307 | |
| 308 def testNoOneClickInfobarAfterCancel(self): | |
| 309 """Verify one-click infobar does not appear again after clicking cancel. | |
| 310 | |
| 311 The one-click infobar should not display again after logging into an | |
| 312 account and selecting to reject sync the first time. | |
| 313 | |
| 314 This test also verifies that the password infobar displays. | |
| 315 """ | |
| 316 self._LogIntoGoogleAccount() | |
| 317 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
| 318 self, self.OC_INFOBAR_TYPE) is not None)) | |
| 319 self._PerformActionOnInfobar(action='cancel') # Click 'No thanks' button. | |
| 320 self.NavigateToURL(self.URL_LOGOUT) | |
| 321 self._LogIntoGoogleAccount() | |
| 322 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) | |
| 323 test_utils.WaitForInfobarTypeAndGetIndex(self, self.PW_INFOBAR_TYPE) | |
| 324 | |
| 325 def testDisplayOneClickInfobarAfterDismiss(self): | |
| 326 """Verify one-click infobar appear again after clicking dismiss button. | |
| 327 | |
| 328 The one-click infobar should display again after logging into an | |
| 329 account and clicking to dismiss the infobar the first time. | |
| 330 | |
| 331 This test also verifies that the password infobar does not display. | |
| 332 The one-click infobar should superceed the password infobar. | |
| 333 """ | |
| 334 self._LogIntoGoogleAccount() | |
| 335 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
| 336 self, self.OC_INFOBAR_TYPE) is not None)) | |
| 337 self._PerformActionOnInfobar(action='dismiss') # Click 'x' button. | |
| 338 self.NavigateToURL(self.URL_LOGOUT) | |
| 339 self._LogIntoGoogleAccount() | |
| 340 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) | |
| 341 test_utils.AssertInfobarTypeDoesNotAppear(self, self.PW_INFOBAR_TYPE) | |
| 342 | |
| 343 def _CheckNumProfiles(self, expected_number): | |
| 344 """Returns True if |expected_number| is equal to the number of profiles.""" | |
| 345 # TODO: Remove when crbug.com/108761 is fixed. | |
| 346 multi_profile = self.GetMultiProfileInfo() | |
| 347 return expected_number == len(multi_profile['profiles']) | |
| 348 | |
| 349 def testDisplayOneClickInfobarPerProfile(self): | |
| 350 """Verify one-click infobar appears for each profile after sign-in.""" | |
| 351 # Default profile. | |
| 352 self._LogIntoGoogleAccount() | |
| 353 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
| 354 self, self.OC_INFOBAR_TYPE) is not None)) | |
| 355 # Create a new multi-profile user. | |
| 356 self.OpenNewBrowserWindowWithNewProfile() | |
| 357 # Wait until the profile has been created. | |
| 358 # TODO: Remove when crbug.com/108761 is fixed. | |
| 359 self.WaitUntil(self._CheckNumProfiles, args=[2]) # Verify 2 profiles exist. | |
| 360 self._LogIntoGoogleAccount(tab_index=0, windex=1) | |
| 361 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
| 362 self, self.OC_INFOBAR_TYPE, tab_index=0, windex=1) is not None)) | |
| 363 | |
| 364 def testNoSameIDSigninForTwoProfiles(self): | |
| 365 """Verify two profiles cannot be signed in with same ID. | |
| 366 | |
| 367 Make sure that the one-click sign in infobar does not appear for two | |
| 368 profiles trying to sign in with the same ID. This test creates a profile | |
| 369 and connect it to a Google account. Another new profile is created and | |
| 370 tries to login with the connected account from the first profile. | |
| 371 | |
| 372 Regress crbug.com/122975 | |
| 373 """ | |
| 374 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') | |
| 375 # Create a new multi-profile user. | |
| 376 self.OpenNewBrowserWindowWithNewProfile() | |
| 377 # Wait until the profile has been created. | |
| 378 # TODO: Remove when crbug.com/108761 is fixed. | |
| 379 self.WaitUntil(self._CheckNumProfiles, args=[2]) # Verify 2 profiles exist. | |
| 380 self._LogIntoGoogleAccount(tab_index=0, windex=1) | |
| 381 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
| 382 self, self.OC_INFOBAR_TYPE, tab_index=0, windex=1) is None)) | |
| 383 | |
| 384 def _VerifyContentExceptionUI(self, content_type, hostname_pattern, behavior, | |
| 385 incognito=False): | |
| 386 """Find hostname pattern and behavior within UI on content exceptions page. | |
| 387 | |
| 388 Args: | |
| 389 content_type: The string content settings type to manage. | |
| 390 hostname_pattern: The URL or pattern associated with the behavior. | |
| 391 behavior: The exception to allow or block the hostname. | |
| 392 incognito: Incognito list displayed on exceptions settings page. | |
| 393 Default to False. | |
| 394 """ | |
| 395 page = settings.ManageExceptionsPage.FromNavigation( | |
| 396 self._driver, content_type) | |
| 397 self.assertTrue(page.GetExceptions(incognito).has_key(hostname_pattern), | |
| 398 msg=('No displayed host name matches pattern "%s"' | |
| 399 % hostname_pattern)) | |
| 400 self.assertEqual(behavior, page.GetExceptions(incognito)[hostname_pattern], | |
| 401 msg=('Displayed behavior "%s" does not match behavior "%s"' | |
| 402 % (page.GetExceptions(incognito)[hostname_pattern], | |
| 403 behavior))) | |
| 404 | |
| 405 def testNoOneClickInfobarWhenCookiesBlocked(self): | |
| 406 """Verify one-click infobar does not show when cookies are blocked. | |
| 407 | |
| 408 One-click sign in should not be enabled if cookies are blocked for Google | |
| 409 accounts domain. Regress crbug.com/117841 | |
| 410 """ | |
| 411 # Block cookies for Google accounts domain. | |
| 412 self.SetPrefs(pyauto.kContentSettingsPatternPairs, | |
| 413 {'https://accounts.google.com/': {'cookies': 2}}) | |
| 414 self._LogIntoGoogleAccount() | |
| 415 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) | |
| 416 | |
| 417 def testOneClickInfobarShownWhenWinLoseFocus(self): | |
| 418 """Verify one-click infobar still shows when window loses focus. | |
| 419 | |
| 420 Regress crbug.com/121739 | |
| 421 """ | |
| 422 self._LogIntoGoogleAccount() | |
| 423 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) | |
| 424 # Open new window to shift focus away. | |
| 425 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.
| |
| 426 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) | |
| 427 | |
| 428 | |
| 224 if __name__ == '__main__': | 429 if __name__ == '__main__': |
| 225 pyauto_functional.Main() | 430 pyauto_functional.Main() |
| OLD | NEW |