| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/gcm/fake_gcm_profile_service.h" | 15 #include "chrome/browser/gcm/fake_gcm_profile_service.h" |
| 16 #include "chrome/browser/gcm/gcm_profile_service_factory.h" | 16 #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
| 17 #include "chrome/browser/profiles/avatar_menu.h" | 17 #include "chrome/browser/profiles/avatar_menu.h" |
| 18 #include "chrome/browser/profiles/profile_attributes_entry.h" | 18 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 19 #include "chrome/browser/profiles/profile_attributes_storage.h" | 19 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 20 #include "chrome/browser/signin/account_fetcher_service_factory.h" | 20 #include "chrome/browser/signin/account_fetcher_service_factory.h" |
| 21 #include "chrome/browser/signin/account_tracker_service_factory.h" | 21 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 22 #include "chrome/browser/signin/chrome_signin_helper.h" | 22 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 23 #include "chrome/browser/signin/fake_account_fetcher_service_builder.h" | 23 #include "chrome/browser/signin/fake_account_fetcher_service_builder.h" |
| 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 26 #include "chrome/browser/signin/signin_manager_factory.h" | 26 #include "chrome/browser/signin/signin_manager_factory.h" |
| 27 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 28 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 27 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 28 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 30 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 29 #include "chrome/browser/ui/cocoa/l10n_util.h" | 31 #include "chrome/browser/ui/cocoa/l10n_util.h" |
| 30 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" | 32 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" |
| 31 #include "chrome/browser/ui/cocoa/test/scoped_force_rtl_mac.h" | 33 #include "chrome/browser/ui/cocoa/test/scoped_force_rtl_mac.h" |
| 32 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 34 #include "components/signin/core/browser/fake_account_fetcher_service.h" | 36 #include "components/signin/core/browser/fake_account_fetcher_service.h" |
| 35 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 37 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 36 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 38 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 37 #include "components/signin/core/browser/signin_manager.h" | 39 #include "components/signin/core/browser/signin_manager.h" |
| 38 #include "components/signin/core/common/profile_management_switches.h" | 40 #include "components/signin/core/common/profile_management_switches.h" |
| 39 #include "components/signin/core/common/signin_pref_names.h" | 41 #include "components/signin/core/common/signin_pref_names.h" |
| 40 #include "components/sync_preferences/pref_service_syncable.h" | 42 #include "components/sync_preferences/pref_service_syncable.h" |
| 41 | 43 |
| 44 using ::testing::Return; |
| 45 |
| 42 const std::string kGaiaId = "gaiaid-user@gmail.com"; | 46 const std::string kGaiaId = "gaiaid-user@gmail.com"; |
| 43 const std::string kEmail = "user@gmail.com"; | 47 const std::string kEmail = "user@gmail.com"; |
| 44 const std::string kSecondaryEmail = "user2@gmail.com"; | 48 const std::string kSecondaryEmail = "user2@gmail.com"; |
| 45 const std::string kSecondaryGaiaId = "gaiaid-user2@gmail.com"; | 49 const std::string kSecondaryGaiaId = "gaiaid-user2@gmail.com"; |
| 46 const std::string kLoginToken = "oauth2_login_token"; | 50 const std::string kLoginToken = "oauth2_login_token"; |
| 47 | 51 |
| 48 class ProfileChooserControllerTest : public CocoaProfileTest { | 52 class ProfileChooserControllerTest : public CocoaProfileTest { |
| 49 public: | 53 public: |
| 50 ProfileChooserControllerTest() { | 54 ProfileChooserControllerTest() { |
| 51 TestingProfile::TestingFactories factories; | 55 TestingProfile::TestingFactories factories; |
| 52 factories.push_back( | 56 factories.push_back( |
| 53 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), | 57 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 54 BuildFakeProfileOAuth2TokenService)); | 58 BuildFakeProfileOAuth2TokenService)); |
| 55 factories.push_back( | 59 factories.push_back( |
| 56 std::make_pair(AccountFetcherServiceFactory::GetInstance(), | 60 std::make_pair(AccountFetcherServiceFactory::GetInstance(), |
| 57 FakeAccountFetcherServiceBuilder::BuildForTests)); | 61 FakeAccountFetcherServiceBuilder::BuildForTests)); |
| 62 factories.push_back(std::make_pair(ProfileSyncServiceFactory::GetInstance(), |
| 63 BuildMockProfileSyncService)); |
| 58 AddTestingFactories(factories); | 64 AddTestingFactories(factories); |
| 59 } | 65 } |
| 60 | 66 |
| 61 void SetUp() override { | 67 void SetUp() override { |
| 62 CocoaProfileTest::SetUp(); | 68 CocoaProfileTest::SetUp(); |
| 63 | 69 |
| 64 ASSERT_TRUE(browser()->profile()); | 70 ASSERT_TRUE(browser()->profile()); |
| 65 | 71 |
| 66 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( | 72 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( |
| 67 browser()->profile(), gcm::FakeGCMProfileService::Build); | 73 browser()->profile(), gcm::FakeGCMProfileService::Build); |
| 68 | 74 |
| 69 testing_profile_manager()->CreateTestingProfile( | 75 testing_profile_manager()->CreateTestingProfile( |
| 70 "test1", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), | 76 "test1", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
| 71 base::ASCIIToUTF16("Test 1"), 0, std::string(), testing_factories()); | 77 base::ASCIIToUTF16("Test 1"), 0, std::string(), testing_factories()); |
| 72 testing_profile_manager()->CreateTestingProfile( | 78 testing_profile_manager()->CreateTestingProfile( |
| 73 "test2", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), | 79 "test2", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
| 74 base::ASCIIToUTF16("Test 2"), 1, std::string(), | 80 base::ASCIIToUTF16("Test 2"), 1, std::string(), |
| 75 TestingProfile::TestingFactories()); | 81 TestingProfile::TestingFactories()); |
| 76 | 82 |
| 83 mock_sync_service_ = static_cast<browser_sync::ProfileSyncServiceMock*>( |
| 84 ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
| 85 browser()->profile())); |
| 86 |
| 77 menu_ = new AvatarMenu( | 87 menu_ = new AvatarMenu( |
| 78 testing_profile_manager()->profile_attributes_storage(), NULL, NULL); | 88 testing_profile_manager()->profile_attributes_storage(), NULL, NULL); |
| 79 menu_->RebuildMenu(); | 89 menu_->RebuildMenu(); |
| 80 | 90 |
| 81 // There should be the default profile + two profiles we created. | 91 // There should be the default profile + two profiles we created. |
| 82 EXPECT_EQ(3U, menu_->GetNumberOfItems()); | 92 EXPECT_EQ(3U, menu_->GetNumberOfItems()); |
| 83 } | 93 } |
| 84 | 94 |
| 85 void TearDown() override { | 95 void TearDown() override { |
| 86 [controller() close]; | 96 [controller() close]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 102 } | 112 } |
| 103 | 113 |
| 104 void SignInFirstProfile() { | 114 void SignInFirstProfile() { |
| 105 std::vector<ProfileAttributesEntry*> entries = testing_profile_manager()-> | 115 std::vector<ProfileAttributesEntry*> entries = testing_profile_manager()-> |
| 106 profile_attributes_storage()->GetAllProfilesAttributes(); | 116 profile_attributes_storage()->GetAllProfilesAttributes(); |
| 107 ASSERT_LE(1U, entries.size()); | 117 ASSERT_LE(1U, entries.size()); |
| 108 ProfileAttributesEntry* entry = entries.front(); | 118 ProfileAttributesEntry* entry = entries.front(); |
| 109 entry->SetAuthInfo(kGaiaId, base::ASCIIToUTF16(kEmail)); | 119 entry->SetAuthInfo(kGaiaId, base::ASCIIToUTF16(kEmail)); |
| 110 } | 120 } |
| 111 | 121 |
| 122 void SuppressSyncConfirmationError() { |
| 123 EXPECT_CALL(*mock_sync_service_, IsFirstSetupComplete()) |
| 124 .WillRepeatedly(Return(false)); |
| 125 EXPECT_CALL(*mock_sync_service_, IsFirstSetupInProgress()) |
| 126 .WillRepeatedly(Return(true)); |
| 127 EXPECT_CALL(*mock_sync_service_, IsSyncConfirmationNeeded()) |
| 128 .WillRepeatedly(Return(false)); |
| 129 } |
| 130 |
| 112 ProfileChooserController* controller() { return controller_; } | 131 ProfileChooserController* controller() { return controller_; } |
| 113 AvatarMenu* menu() { return menu_; } | 132 AvatarMenu* menu() { return menu_; } |
| 114 | 133 |
| 115 private: | 134 private: |
| 116 base::scoped_nsobject<ProfileChooserController> controller_; | 135 base::scoped_nsobject<ProfileChooserController> controller_; |
| 136 browser_sync::ProfileSyncServiceMock* mock_sync_service_ = nullptr; |
| 117 | 137 |
| 118 // Weak; owned by |controller_|. | 138 // Weak; owned by |controller_|. |
| 119 AvatarMenu* menu_; | 139 AvatarMenu* menu_; |
| 120 | 140 |
| 121 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); | 141 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); |
| 122 }; | 142 }; |
| 123 | 143 |
| 124 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { | 144 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { |
| 125 StartProfileChooserController(); | 145 StartProfileChooserController(); |
| 126 | 146 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 ->SetAuthenticatedAccountInfo(kGaiaId, kEmail); | 303 ->SetAuthenticatedAccountInfo(kGaiaId, kEmail); |
| 284 std::string account_id = | 304 std::string account_id = |
| 285 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); | 305 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); |
| 286 ProfileOAuth2TokenServiceFactory::GetForProfile(profile) | 306 ProfileOAuth2TokenServiceFactory::GetForProfile(profile) |
| 287 ->UpdateCredentials(account_id, kLoginToken); | 307 ->UpdateCredentials(account_id, kLoginToken); |
| 288 account_id = AccountTrackerServiceFactory::GetForProfile(profile) | 308 account_id = AccountTrackerServiceFactory::GetForProfile(profile) |
| 289 ->PickAccountIdForAccount(kSecondaryGaiaId, kSecondaryEmail); | 309 ->PickAccountIdForAccount(kSecondaryGaiaId, kSecondaryEmail); |
| 290 ProfileOAuth2TokenServiceFactory::GetForProfile(profile) | 310 ProfileOAuth2TokenServiceFactory::GetForProfile(profile) |
| 291 ->UpdateCredentials(account_id, kLoginToken); | 311 ->UpdateCredentials(account_id, kLoginToken); |
| 292 | 312 |
| 313 SuppressSyncConfirmationError(); |
| 314 |
| 293 StartProfileChooserController(); | 315 StartProfileChooserController(); |
| 294 [controller() initMenuContentsWithView: | 316 [controller() initMenuContentsWithView: |
| 295 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 317 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
| 296 | 318 |
| 297 NSArray* subviews = [[[controller() window] contentView] subviews]; | 319 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 298 ASSERT_EQ(2U, [subviews count]); | 320 ASSERT_EQ(2U, [subviews count]); |
| 299 subviews = [[subviews objectAtIndex:0] subviews]; | 321 subviews = [[subviews objectAtIndex:0] subviews]; |
| 300 | 322 |
| 301 // There should be one active card, one accounts container, two separators | 323 // There should be one active card, one accounts container, two separators |
| 302 // and one option buttons view. In the MD User Menu, there are 2 more buttons. | 324 // and one option buttons view. In the MD User Menu, there are 2 more buttons. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 ASSERT_EQ(3U, [buttonSubviews count]); | 423 ASSERT_EQ(3U, [buttonSubviews count]); |
| 402 | 424 |
| 403 // There should be a lock button. | 425 // There should be a lock button. |
| 404 NSButton* lockButton = | 426 NSButton* lockButton = |
| 405 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 427 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 406 ASSERT_TRUE(lockButton); | 428 ASSERT_TRUE(lockButton); |
| 407 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | 429 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); |
| 408 EXPECT_EQ(controller(), [lockButton target]); | 430 EXPECT_EQ(controller(), [lockButton target]); |
| 409 EXPECT_TRUE([lockButton isEnabled]); | 431 EXPECT_TRUE([lockButton isEnabled]); |
| 410 } | 432 } |
| OLD | NEW |