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 self.WaitUntilNavigationCompletes(tab_index=tab_index, windex=windex) |
| 212 |
| 213 def _PerformActionOnInfobar(self, action): |
| 214 """Perform an action on the infobar: accept, cancel, or dismiss. |
| 215 |
| 216 The one-click sign in infobar must show in the first tab of the first |
| 217 window. If action is 'accept' then the account is synced. If the action is |
| 218 'cancel' then the infobar should be dismissed and never shown again. The |
| 219 account will not be synced. If the action is 'dismiss' then the infobar will |
| 220 shown again after the next login. |
| 221 |
| 222 Args: |
| 223 action: The action to perform on the infobar. |
| 224 """ |
| 225 infobar_index = test_utils.WaitForInfobarTypeAndGetIndex( |
| 226 self, self.OC_INFOBAR_TYPE) |
| 227 self.PerformActionOnInfobar(action, infobar_index) |
| 228 |
| 229 def _DisplayOneClickInfobar(self, tab_index=0, windex=0): |
| 230 """One-click sign in infobar appears after logging into google account. |
| 231 |
| 232 Args: |
| 233 tab_index: The tab index, default is 0. |
| 234 windex: The window index, default is 0. |
| 235 """ |
| 236 self._LogIntoGoogleAccount(tab_index=tab_index, windex=windex) |
| 237 self.assertTrue(self.WaitUntil( |
| 238 lambda: test_utils.GetInfobarIndexByType( |
| 239 self, self.OC_INFOBAR_TYPE, |
| 240 tab_index=tab_index, windex=windex) is not None), |
| 241 msg='The one-click login infobar did not appear.') |
| 242 |
| 243 def testDisplayOneClickInfobar(self): |
| 244 """Verify one-click infobar appears after login into google account. |
| 245 |
| 246 One-click infobar should appear after signing into a google account |
| 247 for the first time using a clean profile. |
| 248 """ |
| 249 self._DisplayOneClickInfobar() |
| 250 |
| 251 def testNoOneClickInfobarAfterCancel(self): |
| 252 """Verify one-click infobar does not appear again after clicking cancel. |
| 253 |
| 254 The one-click infobar should not display again after logging into an |
| 255 account and selecting to reject sync the first time. The test covers |
| 256 restarting the browser with the same profile and verifying the one-click |
| 257 infobar does not show after login. |
| 258 |
| 259 This test also verifies that the password infobar displays. |
| 260 """ |
| 261 self._DisplayOneClickInfobar() |
| 262 self._PerformActionOnInfobar(action='cancel') # Click 'No thanks' button. |
| 263 self.NavigateToURL(self.URL_LOGOUT) |
| 264 self._LogIntoGoogleAccount() |
| 265 test_utils.WaitForInfobarTypeAndGetIndex(self, self.PW_INFOBAR_TYPE) |
| 266 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) |
| 267 # Restart browser with the same profile. |
| 268 self.RestartBrowser(clear_profile=False) |
| 269 self.NavigateToURL(self.URL_LOGOUT) |
| 270 self._LogIntoGoogleAccount() |
| 271 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) |
| 272 |
| 273 def testDisplayOneClickInfobarAfterDismiss(self): |
| 274 """Verify one-click infobar appears again after clicking dismiss button. |
| 275 |
| 276 The one-click infobar should display again after logging into an |
| 277 account and clicking to dismiss the infobar the first time. |
| 278 |
| 279 This test also verifies that the password infobar does not display. |
| 280 The one-click infobar should supersede the password infobar. |
| 281 """ |
| 282 self._DisplayOneClickInfobar() |
| 283 self._PerformActionOnInfobar(action='dismiss') # Click 'x' button. |
| 284 self.NavigateToURL(self.URL_LOGOUT) |
| 285 self._LogIntoGoogleAccount() |
| 286 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) |
| 287 test_utils.AssertInfobarTypeDoesNotAppear(self, self.PW_INFOBAR_TYPE) |
| 288 |
| 289 def _IsNumProfiles(self, expected_number): |
| 290 """Returns True if |expected_number| is equal to the number of profiles.""" |
| 291 # TODO(dyu): Remove when crbug.com/108761 is fixed. |
| 292 multi_profile = self.GetMultiProfileInfo() |
| 293 return expected_number == len(multi_profile['profiles']) |
| 294 |
| 295 def _OpenSecondProfile(self): |
| 296 """Create a second profile.""" |
| 297 self.OpenNewBrowserWindowWithNewProfile() |
| 298 # Wait until the profile has been created. |
| 299 # TODO(dyu): Remove when crbug.com/108761 is fixed. |
| 300 # Verify 2 profiles exist. |
| 301 self.assertTrue( |
| 302 self.WaitUntil(self._IsNumProfiles, args=[2]), |
| 303 msg='The second profile was not created.') |
| 304 |
| 305 def testDisplayOneClickInfobarPerProfile(self): |
| 306 """Verify one-click infobar appears for each profile after sign-in.""" |
| 307 # Default profile. |
| 308 self._DisplayOneClickInfobar() |
| 309 self._OpenSecondProfile() |
| 310 self._DisplayOneClickInfobar(windex=1) |
| 311 |
| 312 def testNoSameIDSigninForTwoProfiles(self): |
| 313 """Verify two profiles cannot be signed in with same ID. |
| 314 |
| 315 Make sure that the one-click sign in infobar does not appear for two |
| 316 profiles trying to sign in with the same ID. This test creates a profile |
| 317 and connects it to a Google account. Another new profile is created and |
| 318 tries to login with the connected account from the first profile. |
| 319 |
| 320 This test verifies the following bug: crbug.com/122975 |
| 321 """ |
| 322 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') |
| 323 self._OpenSecondProfile() |
| 324 self._LogIntoGoogleAccount(tab_index=0, windex=1) |
| 325 self.assertTrue(lambda: test_utils.GetInfobarIndexByType( |
| 326 self, self.OC_INFOBAR_TYPE, tab_index=0, windex=1) is None) |
| 327 |
| 328 def testNoOneClickInfobarWhenCookiesBlocked(self): |
| 329 """Verify one-click infobar does not show when cookies are blocked. |
| 330 |
| 331 One-click sign in should not be enabled if cookies are blocked for Google |
| 332 accounts domain. |
| 333 |
| 334 This test verifies the following bug: crbug.com/117841 |
| 335 """ |
| 336 # Block cookies for Google accounts domain. |
| 337 self.SetPrefs(pyauto.kContentSettingsPatternPairs, |
| 338 self.BLOCK_COOKIE_PATTERN) |
| 339 self._LogIntoGoogleAccount() |
| 340 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) |
| 341 |
| 342 def testOneClickInfobarShownWhenWinLoseFocus(self): |
| 343 """Verify one-click infobar still shows when window loses focus. |
| 344 |
| 345 This test verifies the following bug: crbug.com/121739 |
| 346 """ |
| 347 self._LogIntoGoogleAccount() |
| 348 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) |
| 349 # Open new window to shift focus away. |
| 350 self.OpenNewBrowserWindow(True) |
| 351 test_utils.GetInfobarIndexByType(self, self.OC_INFOBAR_TYPE) |
| 352 |
| 353 def testNoOneClickInfobarInIncognito(self): |
| 354 """Verify that one-click infobar does not show up in incognito mode.""" |
| 355 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW) |
| 356 self._LogIntoGoogleAccount(windex=1) |
| 357 test_utils.AssertInfobarTypeDoesNotAppear( |
| 358 self, self.OC_INFOBAR_TYPE, windex=1) |
| 359 |
| 360 |
186 if __name__ == '__main__': | 361 if __name__ == '__main__': |
187 pyauto_functional.Main() | 362 pyauto_functional.Main() |
OLD | NEW |