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 logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 import pyauto_functional # Must be imported before pyauto | 10 import pyauto_functional # Must be imported before pyauto |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 msg='Did not expect crash infobar in tab at index %d' % i) | 176 msg='Did not expect crash infobar in tab at index %d' % i) |
| 177 elif urls_type[i]: | 177 elif urls_type[i]: |
| 178 self.assertTrue( | 178 self.assertTrue( |
| 179 self.WaitForInfobarCount(1, windex=0, tab_index=i), | 179 self.WaitForInfobarCount(1, windex=0, tab_index=i), |
| 180 msg='Expected crash infobar in tab at index %d' % i) | 180 msg='Expected crash infobar in tab at index %d' % i) |
| 181 infobar = self.GetBrowserInfo()['windows'][0]['tabs'][i]['infobars'] | 181 infobar = self.GetBrowserInfo()['windows'][0]['tabs'][i]['infobars'] |
| 182 self.assertEqual(infobar[0]['type'], 'confirm_infobar') | 182 self.assertEqual(infobar[0]['type'], 'confirm_infobar') |
| 183 self.assertEqual(len(infobar), 1) | 183 self.assertEqual(len(infobar), 1) |
| 184 | 184 |
| 185 | 185 |
| 186 class OneClickInfobarTest(pyauto.PyUITest): | |
| 187 """Tests for one-click sign in infobar.""" | |
| 188 | |
| 189 BLOCK_COOKIE_PATTERN = {'https://accounts.google.com/': {'cookies': 2}} | |
| 190 OC_INFOBAR_TYPE = 'oneclicklogin_infobar' | |
| 191 PW_INFOBAR_TYPE = 'password_infobar' | |
| 192 URL = 'https://www.google.com/accounts/ServiceLogin' | |
| 193 URL_LOGIN = 'https://www.google.com/accounts/Login' | |
| 194 URL_LOGOUT = 'https://www.google.com/accounts/Logout' | |
| 195 | |
| 196 def setUp(self): | |
| 197 pyauto.PyUITest.setUp(self) | |
| 198 self._driver = self.NewWebDriver() | |
| 199 | |
| 200 def _LogIntoGoogleAccount(self, tab_index=0, windex=0): | |
| 201 """Log into Google account. | |
| 202 | |
| 203 Args: | |
| 204 tab_index: The tab index, default is 0. | |
| 205 windex: The window index, default is 0. | |
| 206 """ | |
| 207 creds = self.GetPrivateInfo()['test_google_account'] | |
| 208 username = creds['username'] | |
| 209 password = creds['password'] | |
| 210 test_utils.GoogleAccountsLogin(self, username, password, tab_index, windex) | |
| 211 # Wait until page completes loading. | |
|
Nirnimesh
2012/04/24 00:32:14
Remove redundant comment
dyu1
2012/04/24 03:06:15
Done.
| |
| 212 self.WaitUntilNavigationCompletes(tab_index=tab_index, windex=windex) | |
|
Nirnimesh
2012/04/24 00:32:14
Please note that since this hook got added only to
dyu1
2012/04/24 03:06:15
This might not be checked in until tomorrow ;)
On
| |
| 213 | |
| 214 def _PerformActionOnInfobar(self, action): | |
| 215 """Perform an action on the infobar: accept, cancel, or dismiss. | |
| 216 | |
| 217 If action is accept then the account is synced. | |
|
Nirnimesh
2012/04/24 00:32:14
Declare the expectations. One-click infobar must b
dyu1
2012/04/24 03:06:15
Done.
| |
| 218 | |
| 219 Args: | |
| 220 action: The action to perform on the infobar. | |
| 221 """ | |
| 222 self.PerformActionOnInfobar( | |
| 223 action, infobar_index=test_utils.WaitForInfobarTypeAndGetIndex( | |
|
Nirnimesh
2012/04/24 00:32:14
save infobar index to a var before calling Perform
dyu1
2012/04/24 03:06:15
Done.
| |
| 224 self, self.OC_INFOBAR_TYPE)) | |
| 225 | |
| 226 def _DisplayOneClickInfobar(self, tab_index=0, windex=0): | |
| 227 """One-click sign in infobar appears after logging into google account. | |
| 228 | |
| 229 Args: | |
| 230 tab_index=: The tab index, default is 0. | |
|
Nirnimesh
2012/04/24 00:32:14
remove =
dyu1
2012/04/24 03:06:15
Done.
| |
| 231 windex: The window index, default is 0. | |
| 232 """ | |
| 233 self._LogIntoGoogleAccount(tab_index=tab_index, windex=windex) | |
| 234 self.assertTrue(self.WaitUntil( | |
|
Nirnimesh
2012/04/24 00:32:14
multiple lined function nesting while using lambda
dyu1
2012/04/24 03:06:15
I tried this before and I couldn't get it to work.
| |
| 235 lambda: test_utils.GetInfobarIndexByType( | |
| 236 self, self.OC_INFOBAR_TYPE, | |
| 237 tab_index=tab_index, windex=windex) is not None), | |
|
Nirnimesh
2012/04/24 00:32:14
'is not None' is redundant
dyu1
2012/04/24 03:06:15
Done.
| |
| 238 msg='The one-click login infobar did not appear.') | |
| 239 | |
| 240 def testDisplayOneClickInfobar(self): | |
| 241 """Verify one-click infobar appears after logging into google account. | |
|
Nirnimesh
2012/04/24 00:32:14
s/logging/login/
dyu1
2012/04/24 03:06:15
Done.
| |
| 242 | |
| 243 One-click infobar should appear after signing into a google account | |
| 244 for the first time using a clean profile. | |
| 245 """ | |
| 246 self._DisplayOneClickInfobar() | |
| 247 | |
| 248 def testNoOneClickInfobarAfterCancel(self): | |
| 249 """Verify one-click infobar does not appear again after clicking cancel. | |
| 250 | |
| 251 The one-click infobar should not display again after logging into an | |
| 252 account and selecting to reject sync the first time. | |
| 253 | |
| 254 This test also verifies that the password infobar displays. | |
| 255 """ | |
| 256 self._DisplayOneClickInfobar() | |
| 257 self._PerformActionOnInfobar(action='cancel') # Click 'No thanks' button. | |
| 258 self.NavigateToURL(self.URL_LOGOUT) | |
| 259 self._LogIntoGoogleAccount() | |
| 260 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) | |
|
Nirnimesh
2012/04/24 00:32:14
Move this after the next line so that the positive
dyu1
2012/04/24 03:06:15
Done.
| |
| 261 test_utils.WaitForInfobarTypeAndGetIndex(self, self.PW_INFOBAR_TYPE) | |
|
Nirnimesh
2012/04/24 00:32:14
Maybe extend this test.. and verify again after re
dyu1
2012/04/24 03:06:15
Done.
| |
| 262 | |
| 263 def testDisplayOneClickInfobarAfterDismiss(self): | |
| 264 """Verify one-click infobar appears again after clicking dismiss button. | |
| 265 | |
| 266 The one-click infobar should display again after logging into an | |
| 267 account and clicking to dismiss the infobar the first time. | |
| 268 | |
| 269 This test also verifies that the password infobar does not display. | |
| 270 The one-click infobar should supersede the password infobar. | |
| 271 """ | |
| 272 self._DisplayOneClickInfobar() | |
| 273 self._PerformActionOnInfobar(action='dismiss') # Click 'x' button. | |
| 274 self.NavigateToURL(self.URL_LOGOUT) | |
| 275 self._LogIntoGoogleAccount() | |
| 276 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) | |
| 277 test_utils.AssertInfobarTypeDoesNotAppear(self, self.PW_INFOBAR_TYPE) | |
| 278 | |
| 279 def _CheckNumProfiles(self, expected_number): | |
|
Nirnimesh
2012/04/24 00:32:14
'Check' in the function is a misnomer.
How about:
dyu1
2012/04/24 03:06:15
Done.
| |
| 280 """Returns True if |expected_number| is equal to the number of profiles.""" | |
| 281 # TODO(dyu): Remove when crbug.com/108761 is fixed. | |
| 282 multi_profile = self.GetMultiProfileInfo() | |
| 283 return expected_number == len(multi_profile['profiles']) | |
| 284 | |
| 285 def testDisplayOneClickInfobarPerProfile(self): | |
| 286 """Verify one-click infobar appears for each profile after sign-in.""" | |
| 287 # Default profile. | |
| 288 self._DisplayOneClickInfobar() | |
| 289 # Create a new multi-profile user. | |
| 290 self.OpenNewBrowserWindowWithNewProfile() | |
| 291 # Wait until the profile has been created. | |
|
Nirnimesh
2012/04/24 00:32:14
Create a local helper _OpenSecondProfile() instead
dyu1
2012/04/24 03:06:15
Done.
| |
| 292 # TODO(dyu): Remove when crbug.com/108761 is fixed. | |
| 293 # Verify 2 profiles exist. | |
| 294 self.assertTrue( | |
| 295 self.WaitUntil(self._CheckNumProfiles, args=[2]), | |
| 296 msg='The second profile was not created.') | |
| 297 self._DisplayOneClickInfobar(windex=1) | |
| 298 | |
| 299 def testNoSameIDSigninForTwoProfiles(self): | |
| 300 """Verify two profiles cannot be signed in with same ID. | |
| 301 | |
| 302 Make sure that the one-click sign in infobar does not appear for two | |
| 303 profiles trying to sign in with the same ID. This test creates a profile | |
| 304 and connects it to a Google account. Another new profile is created and | |
| 305 tries to login with the connected account from the first profile. | |
| 306 | |
| 307 This test verifies the following bug: crbug.com/122975 | |
| 308 """ | |
| 309 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') | |
| 310 # Create a new multi-profile user. | |
| 311 self.OpenNewBrowserWindowWithNewProfile() | |
| 312 # Wait until the profile has been created. | |
| 313 # TODO(dyu): Remove when crbug.com/108761 is fixed. | |
| 314 # Verify 2 profiles exist. | |
| 315 self.assertTrue( | |
| 316 self.WaitUntil(self._CheckNumProfiles, args=[2]), | |
| 317 msg='The second profile was not created.') | |
| 318 self._LogIntoGoogleAccount(tab_index=0, windex=1) | |
| 319 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
|
Nirnimesh
2012/04/24 00:32:14
why is the waitUntil required?
dyu1
2012/04/24 03:06:15
Done.
| |
| 320 self, self.OC_INFOBAR_TYPE, tab_index=0, windex=1) is None)) | |
| 321 | |
| 322 def testNoOneClickInfobarWhenCookiesBlocked(self): | |
| 323 """Verify one-click infobar does not show when cookies are blocked. | |
| 324 | |
| 325 One-click sign in should not be enabled if cookies are blocked for Google | |
| 326 accounts domain. | |
| 327 | |
| 328 This test verifies the following bug: crbug.com/117841 | |
| 329 """ | |
| 330 # Block cookies for Google accounts domain. | |
| 331 self.SetPrefs(pyauto.kContentSettingsPatternPairs, | |
| 332 self.BLOCK_COOKIE_PATTERN) | |
| 333 self._LogIntoGoogleAccount() | |
| 334 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) | |
| 335 | |
| 336 def testOneClickInfobarShownWhenWinLoseFocus(self): | |
| 337 """Verify one-click infobar still shows when window loses focus. | |
| 338 | |
| 339 This test verifies the following bug: crbug.com/121739 | |
| 340 """ | |
| 341 self._LogIntoGoogleAccount() | |
| 342 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) | |
| 343 # Open new window to shift focus away. | |
| 344 self.OpenNewBrowserWindow(True) | |
| 345 test_utils.GetInfobarIndexByType(self, self.OC_INFOBAR_TYPE) | |
| 346 | |
| 347 def testNoOneClickInfobarInIncognito(self): | |
| 348 """Verify that one-click infobar does not show up in incognito mode.""" | |
| 349 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) | |
| 350 self._LogIntoGoogleAccount(windex=1) | |
| 351 test_utils.AssertInfobarTypeDoesNotAppear( | |
| 352 self, self.OC_INFOBAR_TYPE, windex=1) | |
| 353 | |
| 354 | |
| 186 if __name__ == '__main__': | 355 if __name__ == '__main__': |
| 187 pyauto_functional.Main() | 356 pyauto_functional.Main() |
| OLD | NEW |