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 OC_INFOBAR_TYPE = 'oneclicklogin_infobar' | |
190 PW_INFOBAR_TYPE = 'password_infobar' | |
191 URL = 'https://www.google.com/accounts/ServiceLogin' | |
192 URL_HTTPS = 'https://www.google.com/accounts/Login' | |
dennis_jeffrey
2012/04/20 17:35:04
maybe name this URL_LOGIN to correspond with URL_L
dyu1
2012/04/23 21:46:10
Done.
| |
193 URL_LOGOUT = 'https://www.google.com/accounts/Logout' | |
194 | |
195 def setUp(self): | |
196 pyauto.PyUITest.setUp(self) | |
197 self._driver = self.NewWebDriver() | |
198 | |
199 def _LogIntoGoogleAccount(self, tab_index=0, windex=0): | |
200 """Log into Google account. | |
201 | |
202 Args: | |
203 tab_index: The tab index, default is 0. | |
204 windex: The window index, default is 0. | |
205 """ | |
206 test_utils.ClearPasswords(self) | |
Nirnimesh
2012/04/20 18:12:05
Each test begins with a clean profile. This is not
dyu1
2012/04/23 21:46:10
Done.
| |
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.WaitUntil( | |
213 lambda: self.GetDOMValue('document.readyState'), | |
214 expect_retval='complete') | |
215 | |
216 def _PerformActionOnInfobar(self, action): | |
217 """Perform an action on the infobar: accept, cancel, or dismiss. | |
218 | |
219 If action is accept then the account is synced. | |
220 | |
221 Args: | |
222 action: The action to perform on the infobar. | |
223 """ | |
224 self.PerformActionOnInfobar( | |
225 action, infobar_index=test_utils.WaitForInfobarTypeAndGetIndex( | |
226 self, self.OC_INFOBAR_TYPE)) | |
dennis_jeffrey
2012/04/20 17:35:04
Probably not worth declaring this as a function.
dyu1
2012/04/23 21:46:10
Yes I thought about it, I left it for later, when
| |
227 | |
228 def testDisplayOneClickInfobar(self): | |
229 """Verify one-click infobar appears after logging into google account. | |
230 | |
231 One-click infobar should appear after signing into a google account | |
232 for the first time using a clean profile. | |
233 """ | |
234 self._LogIntoGoogleAccount() | |
235 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
Nirnimesh
2012/04/20 18:12:05
Use WaitForInfobarCount(1)
Then verify that it's
dyu1
2012/04/23 21:46:10
I'm hesitant on using WaitForInfobarCount(1) since
| |
236 self, self.OC_INFOBAR_TYPE) is not None)) | |
Nirnimesh
2012/04/20 18:12:05
add a msg= param
dyu1
2012/04/23 21:46:10
Done.
| |
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._LogIntoGoogleAccount() | |
247 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
Nirnimesh
2012/04/20 18:12:05
just call test testDisplayOneClickInfobar() instea
dyu1
2012/04/23 21:46:10
Done.
| |
248 self, self.OC_INFOBAR_TYPE) is not None)) | |
249 self._PerformActionOnInfobar(action='cancel') # Click 'No thanks' button. | |
250 self.NavigateToURL(self.URL_LOGOUT) | |
251 self._LogIntoGoogleAccount() | |
252 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) | |
253 test_utils.WaitForInfobarTypeAndGetIndex(self, self.PW_INFOBAR_TYPE) | |
254 | |
255 def testDisplayOneClickInfobarAfterDismiss(self): | |
256 """Verify one-click infobar appear again after clicking dismiss button. | |
dennis_jeffrey
2012/04/20 17:35:04
'appear' --> 'appears'
dyu1
2012/04/23 21:46:10
Done.
| |
257 | |
258 The one-click infobar should display again after logging into an | |
259 account and clicking to dismiss the infobar the first time. | |
260 | |
261 This test also verifies that the password infobar does not display. | |
262 The one-click infobar should superceed the password infobar. | |
dennis_jeffrey
2012/04/20 17:35:04
'superceed' --> 'supersede'
dyu1
2012/04/23 21:46:10
Done.
| |
263 """ | |
264 self._LogIntoGoogleAccount() | |
265 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
266 self, self.OC_INFOBAR_TYPE) is not None)) | |
Nirnimesh
2012/04/20 18:12:05
use testDisplayOneClickInfobar. Repeat elsewhere
dyu1
2012/04/23 21:46:10
Done.
| |
267 self._PerformActionOnInfobar(action='dismiss') # Click 'x' button. | |
268 self.NavigateToURL(self.URL_LOGOUT) | |
269 self._LogIntoGoogleAccount() | |
270 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) | |
271 test_utils.AssertInfobarTypeDoesNotAppear(self, self.PW_INFOBAR_TYPE) | |
272 | |
273 def _CheckNumProfiles(self, expected_number): | |
274 """Returns True if |expected_number| is equal to the number of profiles.""" | |
275 # TODO: Remove when crbug.com/108761 is fixed. | |
dennis_jeffrey
2012/04/20 17:35:04
add LDAP to the TODO
dyu1
2012/04/23 21:46:10
Done.
| |
276 multi_profile = self.GetMultiProfileInfo() | |
277 return expected_number == len(multi_profile['profiles']) | |
278 | |
279 def testDisplayOneClickInfobarPerProfile(self): | |
280 """Verify one-click infobar appears for each profile after sign-in.""" | |
281 # Default profile. | |
282 self._LogIntoGoogleAccount() | |
283 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
284 self, self.OC_INFOBAR_TYPE) is not None)) | |
285 # Create a new multi-profile user. | |
286 self.OpenNewBrowserWindowWithNewProfile() | |
287 # Wait until the profile has been created. | |
288 # TODO: Remove when crbug.com/108761 is fixed. | |
dennis_jeffrey
2012/04/20 17:35:04
add LDAP
dyu1
2012/04/23 21:46:10
Done.
| |
289 self.WaitUntil(self._CheckNumProfiles, args=[2]) # Verify 2 profiles exist. | |
Nirnimesh
2012/04/20 18:12:05
wrap inside assertTrue
dyu1
2012/04/23 21:46:10
Done.
| |
290 self._LogIntoGoogleAccount(tab_index=0, windex=1) | |
291 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
292 self, self.OC_INFOBAR_TYPE, tab_index=0, windex=1) is not None)) | |
293 | |
294 def testNoSameIDSigninForTwoProfiles(self): | |
295 """Verify two profiles cannot be signed in with same ID. | |
296 | |
297 Make sure that the one-click sign in infobar does not appear for two | |
298 profiles trying to sign in with the same ID. This test creates a profile | |
299 and connect it to a Google account. Another new profile is created and | |
dennis_jeffrey
2012/04/20 17:35:04
'connect' --> 'connects'
dyu1
2012/04/23 21:46:10
Done.
| |
300 tries to login with the connected account from the first profile. | |
301 | |
302 Regress crbug.com/122975 | |
dennis_jeffrey
2012/04/20 17:35:04
what does this mean?
dyu1
2012/04/23 21:46:10
I wrote a test for that bug. So if the test fails
| |
303 """ | |
304 test_utils.SignInToSyncAndVerifyState(self, 'test_google_account') | |
Nirnimesh
2012/04/20 18:12:05
The sync tests are disabled. Are you sure this wor
dyu1
2012/04/23 21:46:10
Yes, this function works. This is the only way to
| |
305 # Create a new multi-profile user. | |
306 self.OpenNewBrowserWindowWithNewProfile() | |
Nirnimesh
2012/04/20 18:12:05
I'd suggest creating a local wrapper function with
dyu1
2012/04/23 21:46:10
Do you mean 306 to 309? 307 and 308 are just comme
| |
307 # Wait until the profile has been created. | |
308 # TODO: Remove when crbug.com/108761 is fixed. | |
dennis_jeffrey
2012/04/20 17:35:04
add LDAP
dyu1
2012/04/23 21:46:10
Done.
| |
309 self.WaitUntil(self._CheckNumProfiles, args=[2]) # Verify 2 profiles exist. | |
310 self._LogIntoGoogleAccount(tab_index=0, windex=1) | |
311 self.assertTrue(self.WaitUntil(lambda: test_utils.GetInfobarIndexByType( | |
312 self, self.OC_INFOBAR_TYPE, tab_index=0, windex=1) is None)) | |
313 | |
314 def _VerifyContentExceptionUI(self, content_type, hostname_pattern, behavior, | |
Nirnimesh
2012/04/20 18:12:05
unused?
dyu1
2012/04/23 21:46:10
Done.
| |
315 incognito=False): | |
316 """Find hostname pattern and behavior within UI on content exceptions page. | |
317 | |
318 Args: | |
319 content_type: The string content settings type to manage. | |
320 hostname_pattern: The URL or pattern associated with the behavior. | |
321 behavior: The exception to allow or block the hostname. | |
322 incognito: Incognito list displayed on exceptions settings page. | |
323 Default to False. | |
324 """ | |
325 page = settings.ManageExceptionsPage.FromNavigation( | |
326 self._driver, content_type) | |
327 self.assertTrue(page.GetExceptions(incognito).has_key(hostname_pattern), | |
328 msg=('No displayed host name matches pattern "%s"' | |
329 % hostname_pattern)) | |
330 self.assertEqual(behavior, page.GetExceptions(incognito)[hostname_pattern], | |
331 msg=('Displayed behavior "%s" does not match behavior "%s"' | |
332 % (page.GetExceptions(incognito)[hostname_pattern], | |
333 behavior))) | |
334 | |
335 def testNoOneClickInfobarWhenCookiesBlocked(self): | |
336 """Verify one-click infobar does not show when cookies are blocked. | |
337 | |
338 One-click sign in should not be enabled if cookies are blocked for Google | |
339 accounts domain. | |
340 | |
341 Regress crbug.com/117841 | |
342 """ | |
343 # Block cookies for Google accounts domain. | |
344 self.SetPrefs(pyauto.kContentSettingsPatternPairs, | |
345 {'https://accounts.google.com/': {'cookies': 2}}) | |
Nirnimesh
2012/04/20 18:12:05
move the pattern at the top, along with all the ot
dyu1
2012/04/23 21:46:10
Done.
| |
346 self._LogIntoGoogleAccount() | |
347 test_utils.AssertInfobarTypeDoesNotAppear(self, self.OC_INFOBAR_TYPE) | |
348 | |
349 def testOneClickInfobarShownWhenWinLoseFocus(self): | |
350 """Verify one-click infobar still shows when window loses focus. | |
351 | |
352 Regress crbug.com/121739 | |
353 """ | |
354 self._LogIntoGoogleAccount() | |
355 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) | |
356 # Open new window to shift focus away. | |
357 self.OpenNewBrowserWindow(True) | |
358 test_utils.WaitForInfobarTypeAndGetIndex(self, self.OC_INFOBAR_TYPE) | |
Nirnimesh
2012/04/20 18:12:05
you should not "wait" anymore. Just check that the
dyu1
2012/04/23 21:46:10
Done.
| |
359 | |
360 | |
186 if __name__ == '__main__': | 361 if __name__ == '__main__': |
187 pyauto_functional.Main() | 362 pyauto_functional.Main() |
OLD | NEW |