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" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/prefs/pref_service_syncable.h" | 13 #include "chrome/browser/prefs/pref_service_syncable.h" |
14 #include "chrome/browser/profiles/avatar_menu.h" | 14 #include "chrome/browser/profiles/avatar_menu.h" |
15 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
16 #include "chrome/browser/signin/account_tracker_service_factory.h" | 16 #include "chrome/browser/signin/account_tracker_service_factory.h" |
17 #include "chrome/browser/signin/fake_account_tracker_service.h" | 17 #include "chrome/browser/signin/fake_account_tracker_service.h" |
18 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 18 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
19 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 19 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
21 #include "chrome/browser/signin/signin_header_helper.h" | 21 #include "chrome/browser/signin/signin_header_helper.h" |
22 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 24 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/pref_names.h" |
26 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 27 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
27 #include "components/signin/core/browser/signin_manager.h" | 28 #include "components/signin/core/browser/signin_manager.h" |
28 #include "components/signin/core/common/profile_management_switches.h" | 29 #include "components/signin/core/common/profile_management_switches.h" |
29 | 30 |
30 const std::string kEmail = "user@gmail.com"; | 31 const std::string kEmail = "user@gmail.com"; |
31 const std::string kSecondaryEmail = "user2@gmail.com"; | 32 const std::string kSecondaryEmail = "user2@gmail.com"; |
32 const std::string kLoginToken = "oauth2_login_token"; | 33 const std::string kLoginToken = "oauth2_login_token"; |
33 | 34 |
34 class ProfileChooserControllerTest : public CocoaProfileTest { | 35 class ProfileChooserControllerTest : public CocoaProfileTest { |
35 public: | 36 public: |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 ASSERT_EQ(2U, [subviews count]); | 375 ASSERT_EQ(2U, [subviews count]); |
375 subviews = [[subviews objectAtIndex:0] subviews]; | 376 subviews = [[subviews objectAtIndex:0] subviews]; |
376 | 377 |
377 // There should be one active card, one accounts container, two separators | 378 // There should be one active card, one accounts container, two separators |
378 // and one option buttons view. | 379 // and one option buttons view. |
379 ASSERT_EQ(5U, [subviews count]); | 380 ASSERT_EQ(5U, [subviews count]); |
380 | 381 |
381 // There should be three buttons and two separators in the option | 382 // There should be three buttons and two separators in the option |
382 // buttons view. | 383 // buttons view. |
383 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 384 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
384 ASSERT_EQ(5U, [buttonSubviews count]); | 385 ASSERT_EQ(3U, [buttonSubviews count]); |
385 | |
386 // There should be a lock button. | |
387 NSButton* lockButton = | |
388 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | |
389 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | |
390 EXPECT_EQ(controller(), [lockButton target]); | |
391 | 386 |
392 // There should be a separator. | 387 // There should be a separator. |
393 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | 388 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]); |
394 | 389 |
395 // There should be an incognito button. | 390 // There should be an incognito button. |
396 NSButton* incognitoButton = | 391 NSButton* incognitoButton = |
397 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); | 392 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
398 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); | 393 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); |
399 EXPECT_EQ(controller(), [incognitoButton target]); | 394 EXPECT_EQ(controller(), [incognitoButton target]); |
400 | 395 |
401 // There should be a separator. | 396 // There should be a separator. |
402 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); | 397 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); |
403 | 398 |
404 // There should be a user switcher button. | 399 // There should be a user switcher button. |
405 NSButton* userSwitcherButton = | 400 NSButton* userSwitcherButton = |
406 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:4]); | 401 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); |
407 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); | 402 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); |
408 EXPECT_EQ(controller(), [userSwitcherButton target]); | 403 EXPECT_EQ(controller(), [userSwitcherButton target]); |
409 | 404 |
410 // In the accounts view, there should be the account list container | 405 // In the accounts view, there should be the account list container |
411 // accounts and one "add accounts" button. | 406 // accounts and one "add accounts" button. |
412 NSArray* accountsSubviews = [[subviews objectAtIndex:2] subviews]; | 407 NSArray* accountsSubviews = [[subviews objectAtIndex:2] subviews]; |
413 ASSERT_EQ(2U, [accountsSubviews count]); | 408 ASSERT_EQ(2U, [accountsSubviews count]); |
414 | 409 |
415 NSButton* addAccountsButton = | 410 NSButton* addAccountsButton = |
416 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]); | 411 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); | 452 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); |
458 | 453 |
459 // Profile links. This is a local profile, so there should be a signin button. | 454 // Profile links. This is a local profile, so there should be a signin button. |
460 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 455 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
461 ASSERT_EQ(1U, [linksSubviews count]); | 456 ASSERT_EQ(1U, [linksSubviews count]); |
462 NSButton* link = base::mac::ObjCCast<NSButton>( | 457 NSButton* link = base::mac::ObjCCast<NSButton>( |
463 [linksSubviews objectAtIndex:0]); | 458 [linksSubviews objectAtIndex:0]); |
464 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); | 459 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); |
465 EXPECT_EQ(controller(), [link target]); | 460 EXPECT_EQ(controller(), [link target]); |
466 } | 461 } |
| 462 |
| 463 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) { |
| 464 switches::EnableNewProfileManagementForTesting( |
| 465 CommandLine::ForCurrentProcess()); |
| 466 // Sign in the first profile. |
| 467 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 468 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
| 469 // The preference, not the email, determines whether the profile can lock. |
| 470 browser()->profile()->GetPrefs()->SetString( |
| 471 prefs::kGoogleServicesHostedDomain, "chromium.org"); |
| 472 |
| 473 StartProfileChooserController(); |
| 474 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 475 ASSERT_EQ(2U, [subviews count]); |
| 476 subviews = [[subviews objectAtIndex:0] subviews]; |
| 477 |
| 478 // There will be two buttons and one separators in the option buttons view. |
| 479 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
| 480 ASSERT_EQ(3U, [buttonSubviews count]); |
| 481 |
| 482 // The last button should not be the lock button. |
| 483 NSButton* lastButton = |
| 484 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 485 ASSERT_TRUE(lastButton); |
| 486 EXPECT_NE(@selector(lockProfile:), [lastButton action]); |
| 487 } |
| 488 |
| 489 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) { |
| 490 switches::EnableNewProfileManagementForTesting( |
| 491 CommandLine::ForCurrentProcess()); |
| 492 // Sign in the first profile. |
| 493 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 494 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
| 495 // The preference, not the email, determines whether the profile can lock. |
| 496 browser()->profile()->GetPrefs()->SetString( |
| 497 prefs::kGoogleServicesHostedDomain, "google.com"); |
| 498 |
| 499 StartProfileChooserController(); |
| 500 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 501 ASSERT_EQ(2U, [subviews count]); |
| 502 subviews = [[subviews objectAtIndex:0] subviews]; |
| 503 |
| 504 // There will be three buttons and two separators in the option buttons view. |
| 505 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
| 506 ASSERT_EQ(5U, [buttonSubviews count]); |
| 507 |
| 508 // There should be a lock button. |
| 509 NSButton* lockButton = |
| 510 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 511 ASSERT_TRUE(lockButton); |
| 512 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); |
| 513 EXPECT_EQ(controller(), [lockButton target]); |
| 514 EXPECT_TRUE([lockButton isEnabled]); |
| 515 } |
OLD | NEW |