OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/signin/signin_header_helper.h" | 23 #include "chrome/browser/signin/signin_header_helper.h" |
24 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 26 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
29 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
30 #include "components/signin/core/browser/signin_manager.h" | 30 #include "components/signin/core/browser/signin_manager.h" |
31 #include "components/signin/core/common/profile_management_switches.h" | 31 #include "components/signin/core/common/profile_management_switches.h" |
32 | 32 |
| 33 const std::string kGaiaId = "gaiaid-user@gmail.com"; |
33 const std::string kEmail = "user@gmail.com"; | 34 const std::string kEmail = "user@gmail.com"; |
34 const std::string kSecondaryEmail = "user2@gmail.com"; | 35 const std::string kSecondaryEmail = "user2@gmail.com"; |
35 const std::string kLoginToken = "oauth2_login_token"; | 36 const std::string kLoginToken = "oauth2_login_token"; |
36 | 37 |
37 class ProfileChooserControllerTest : public CocoaProfileTest { | 38 class ProfileChooserControllerTest : public CocoaProfileTest { |
38 public: | 39 public: |
39 ProfileChooserControllerTest() { | 40 ProfileChooserControllerTest() { |
40 TestingProfile::TestingFactories factories; | 41 TestingProfile::TestingFactories factories; |
41 factories.push_back( | 42 factories.push_back( |
42 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), | 43 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 [activeCardLinks objectAtIndex:1]); | 308 [activeCardLinks objectAtIndex:1]); |
308 EXPECT_GT([[promo stringValue] length], 0U); | 309 EXPECT_GT([[promo stringValue] length], 0U); |
309 } | 310 } |
310 | 311 |
311 TEST_F(ProfileChooserControllerTest, | 312 TEST_F(ProfileChooserControllerTest, |
312 SignedInProfileActiveCardLinksWithAccountConsistency) { | 313 SignedInProfileActiveCardLinksWithAccountConsistency) { |
313 switches::EnableAccountConsistencyForTesting( | 314 switches::EnableAccountConsistencyForTesting( |
314 base::CommandLine::ForCurrentProcess()); | 315 base::CommandLine::ForCurrentProcess()); |
315 // Sign in the first profile. | 316 // Sign in the first profile. |
316 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 317 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
317 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 318 cache->SetAuthInfoOfProfileAtIndex(0, kGaiaId, base::ASCIIToUTF16(kEmail)); |
318 | 319 |
319 StartProfileChooserController(); | 320 StartProfileChooserController(); |
320 NSArray* subviews = [[[controller() window] contentView] subviews]; | 321 NSArray* subviews = [[[controller() window] contentView] subviews]; |
321 ASSERT_EQ(2U, [subviews count]); | 322 ASSERT_EQ(2U, [subviews count]); |
322 subviews = [[subviews objectAtIndex:0] subviews]; | 323 subviews = [[subviews objectAtIndex:0] subviews]; |
323 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 324 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
324 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 325 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
325 | 326 |
326 // There is one link: manage accounts. | 327 // There is one link: manage accounts. |
327 ASSERT_EQ(1U, [activeCardLinks count]); | 328 ASSERT_EQ(1U, [activeCardLinks count]); |
328 NSButton* manageAccountsLink = | 329 NSButton* manageAccountsLink = |
329 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); | 330 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); |
330 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); | 331 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); |
331 EXPECT_EQ(controller(), [manageAccountsLink target]); | 332 EXPECT_EQ(controller(), [manageAccountsLink target]); |
332 } | 333 } |
333 | 334 |
334 TEST_F(ProfileChooserControllerTest, | 335 TEST_F(ProfileChooserControllerTest, |
335 SignedInProfileActiveCardLinksWithNewMenu) { | 336 SignedInProfileActiveCardLinksWithNewMenu) { |
336 switches::EnableNewAvatarMenuForTesting( | 337 switches::EnableNewAvatarMenuForTesting( |
337 base::CommandLine::ForCurrentProcess()); | 338 base::CommandLine::ForCurrentProcess()); |
338 // Sign in the first profile. | 339 // Sign in the first profile. |
339 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 340 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
340 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 341 cache->SetAuthInfoOfProfileAtIndex(0, kGaiaId, base::ASCIIToUTF16(kEmail)); |
341 | 342 |
342 StartProfileChooserController(); | 343 StartProfileChooserController(); |
343 NSArray* subviews = [[[controller() window] contentView] subviews]; | 344 NSArray* subviews = [[[controller() window] contentView] subviews]; |
344 ASSERT_EQ(2U, [subviews count]); | 345 ASSERT_EQ(2U, [subviews count]); |
345 subviews = [[subviews objectAtIndex:0] subviews]; | 346 subviews = [[subviews objectAtIndex:0] subviews]; |
346 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 347 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
347 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 348 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
348 | 349 |
349 // There is one disabled button with the user's email. | 350 // There is one disabled button with the user's email. |
350 ASSERT_EQ(1U, [activeCardLinks count]); | 351 ASSERT_EQ(1U, [activeCardLinks count]); |
351 NSButton* emailButton = | 352 NSButton* emailButton = |
352 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); | 353 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); |
353 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title])); | 354 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title])); |
354 EXPECT_EQ(nil, [emailButton action]); | 355 EXPECT_EQ(nil, [emailButton action]); |
355 EXPECT_FALSE([emailButton isEnabled]); | 356 EXPECT_FALSE([emailButton isEnabled]); |
356 } | 357 } |
357 | 358 |
358 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { | 359 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { |
359 switches::EnableAccountConsistencyForTesting( | 360 switches::EnableAccountConsistencyForTesting( |
360 base::CommandLine::ForCurrentProcess()); | 361 base::CommandLine::ForCurrentProcess()); |
361 // Sign in the first profile. | 362 // Sign in the first profile. |
362 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 363 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
363 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 364 cache->SetAuthInfoOfProfileAtIndex(0, kGaiaId, base::ASCIIToUTF16(kEmail)); |
364 | 365 |
365 // Mark that we are using the profile name on purpose, so that we don't | 366 // Mark that we are using the profile name on purpose, so that we don't |
366 // fallback to testing the algorithm that chooses which default name | 367 // fallback to testing the algorithm that chooses which default name |
367 // should be used. | 368 // should be used. |
368 cache->SetProfileIsUsingDefaultNameAtIndex(0, false); | 369 cache->SetProfileIsUsingDefaultNameAtIndex(0, false); |
369 | 370 |
370 // Set up the signin manager and the OAuth2Tokens. | 371 // Set up the signin manager and the OAuth2Tokens. |
371 Profile* profile = browser()->profile(); | 372 Profile* profile = browser()->profile(); |
372 SigninManagerFactory::GetForProfile(profile)-> | 373 SigninManagerFactory::GetForProfile(profile)-> |
373 SetAuthenticatedAccountInfo(kEmail, kEmail); | 374 SetAuthenticatedAccountInfo(kEmail, kEmail); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 [linksSubviews objectAtIndex:0]); | 468 [linksSubviews objectAtIndex:0]); |
468 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); | 469 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); |
469 EXPECT_EQ(controller(), [link target]); | 470 EXPECT_EQ(controller(), [link target]); |
470 } | 471 } |
471 | 472 |
472 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) { | 473 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) { |
473 switches::EnableNewProfileManagementForTesting( | 474 switches::EnableNewProfileManagementForTesting( |
474 base::CommandLine::ForCurrentProcess()); | 475 base::CommandLine::ForCurrentProcess()); |
475 // Sign in the first profile. | 476 // Sign in the first profile. |
476 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 477 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
477 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 478 cache->SetAuthInfoOfProfileAtIndex(0, kGaiaId, base::ASCIIToUTF16(kEmail)); |
478 // The preference, not the email, determines whether the profile can lock. | 479 // The preference, not the email, determines whether the profile can lock. |
479 browser()->profile()->GetPrefs()->SetString( | 480 browser()->profile()->GetPrefs()->SetString( |
480 prefs::kGoogleServicesHostedDomain, "chromium.org"); | 481 prefs::kGoogleServicesHostedDomain, "chromium.org"); |
481 | 482 |
482 StartProfileChooserController(); | 483 StartProfileChooserController(); |
483 NSArray* subviews = [[[controller() window] contentView] subviews]; | 484 NSArray* subviews = [[[controller() window] contentView] subviews]; |
484 ASSERT_EQ(2U, [subviews count]); | 485 ASSERT_EQ(2U, [subviews count]); |
485 subviews = [[subviews objectAtIndex:0] subviews]; | 486 subviews = [[subviews objectAtIndex:0] subviews]; |
486 | 487 |
487 // There will be two buttons and one separators in the option buttons view. | 488 // There will be two buttons and one separators in the option buttons view. |
488 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 489 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
489 ASSERT_EQ(3U, [buttonSubviews count]); | 490 ASSERT_EQ(3U, [buttonSubviews count]); |
490 | 491 |
491 // The last button should not be the lock button. | 492 // The last button should not be the lock button. |
492 NSButton* lastButton = | 493 NSButton* lastButton = |
493 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 494 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
494 ASSERT_TRUE(lastButton); | 495 ASSERT_TRUE(lastButton); |
495 EXPECT_NE(@selector(lockProfile:), [lastButton action]); | 496 EXPECT_NE(@selector(lockProfile:), [lastButton action]); |
496 } | 497 } |
497 | 498 |
498 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) { | 499 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) { |
499 switches::EnableNewProfileManagementForTesting( | 500 switches::EnableNewProfileManagementForTesting( |
500 base::CommandLine::ForCurrentProcess()); | 501 base::CommandLine::ForCurrentProcess()); |
501 // Sign in the first profile. | 502 // Sign in the first profile. |
502 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 503 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
503 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 504 cache->SetAuthInfoOfProfileAtIndex(0, kGaiaId, base::ASCIIToUTF16(kEmail)); |
504 // The preference, not the email, determines whether the profile can lock. | 505 // The preference, not the email, determines whether the profile can lock. |
505 browser()->profile()->GetPrefs()->SetString( | 506 browser()->profile()->GetPrefs()->SetString( |
506 prefs::kGoogleServicesHostedDomain, "google.com"); | 507 prefs::kGoogleServicesHostedDomain, "google.com"); |
507 // Lock is only available where a supervised user is present. | 508 // Lock is only available where a supervised user is present. |
508 cache->SetSupervisedUserIdOfProfileAtIndex(1, kEmail); | 509 cache->SetSupervisedUserIdOfProfileAtIndex(1, kEmail); |
509 | 510 |
510 StartProfileChooserController(); | 511 StartProfileChooserController(); |
511 NSArray* subviews = [[[controller() window] contentView] subviews]; | 512 NSArray* subviews = [[[controller() window] contentView] subviews]; |
512 ASSERT_EQ(2U, [subviews count]); | 513 ASSERT_EQ(2U, [subviews count]); |
513 subviews = [[subviews objectAtIndex:0] subviews]; | 514 subviews = [[subviews objectAtIndex:0] subviews]; |
514 | 515 |
515 // There will be three buttons and two separators in the option buttons view. | 516 // There will be three buttons and two separators in the option buttons view. |
516 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 517 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
517 ASSERT_EQ(5U, [buttonSubviews count]); | 518 ASSERT_EQ(5U, [buttonSubviews count]); |
518 | 519 |
519 // There should be a lock button. | 520 // There should be a lock button. |
520 NSButton* lockButton = | 521 NSButton* lockButton = |
521 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 522 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
522 ASSERT_TRUE(lockButton); | 523 ASSERT_TRUE(lockButton); |
523 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | 524 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); |
524 EXPECT_EQ(controller(), [lockButton target]); | 525 EXPECT_EQ(controller(), [lockButton target]); |
525 EXPECT_TRUE([lockButton isEnabled]); | 526 EXPECT_TRUE([lockButton isEnabled]); |
526 } | 527 } |
OLD | NEW |