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