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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 28 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
29 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
31 #include "components/signin/core/browser/fake_account_fetcher_service.h" | 31 #include "components/signin/core/browser/fake_account_fetcher_service.h" |
32 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 32 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
33 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 33 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
34 #include "components/signin/core/browser/signin_manager.h" | 34 #include "components/signin/core/browser/signin_manager.h" |
35 #include "components/signin/core/common/profile_management_switches.h" | 35 #include "components/signin/core/common/profile_management_switches.h" |
36 #include "components/signin/core/common/signin_pref_names.h" | 36 #include "components/signin/core/common/signin_pref_names.h" |
37 #include "components/syncable_prefs/pref_service_syncable.h" | 37 #include "components/sync_preferences/pref_service_syncable.h" |
38 | 38 |
39 const std::string kGaiaId = "gaiaid-user@gmail.com"; | 39 const std::string kGaiaId = "gaiaid-user@gmail.com"; |
40 const std::string kEmail = "user@gmail.com"; | 40 const std::string kEmail = "user@gmail.com"; |
41 const std::string kSecondaryEmail = "user2@gmail.com"; | 41 const std::string kSecondaryEmail = "user2@gmail.com"; |
42 const std::string kSecondaryGaiaId = "gaiaid-user2@gmail.com"; | 42 const std::string kSecondaryGaiaId = "gaiaid-user2@gmail.com"; |
43 const std::string kLoginToken = "oauth2_login_token"; | 43 const std::string kLoginToken = "oauth2_login_token"; |
44 | 44 |
45 class ProfileChooserControllerTest : public CocoaProfileTest { | 45 class ProfileChooserControllerTest : public CocoaProfileTest { |
46 public: | 46 public: |
47 ProfileChooserControllerTest() { | 47 ProfileChooserControllerTest() { |
48 TestingProfile::TestingFactories factories; | 48 TestingProfile::TestingFactories factories; |
49 factories.push_back( | 49 factories.push_back( |
50 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), | 50 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), |
51 BuildFakeProfileOAuth2TokenService)); | 51 BuildFakeProfileOAuth2TokenService)); |
52 factories.push_back( | 52 factories.push_back( |
53 std::make_pair(AccountFetcherServiceFactory::GetInstance(), | 53 std::make_pair(AccountFetcherServiceFactory::GetInstance(), |
54 FakeAccountFetcherServiceBuilder::BuildForTests)); | 54 FakeAccountFetcherServiceBuilder::BuildForTests)); |
55 AddTestingFactories(factories); | 55 AddTestingFactories(factories); |
56 } | 56 } |
57 | 57 |
58 void SetUp() override { | 58 void SetUp() override { |
59 CocoaProfileTest::SetUp(); | 59 CocoaProfileTest::SetUp(); |
60 | 60 |
61 ASSERT_TRUE(browser()->profile()); | 61 ASSERT_TRUE(browser()->profile()); |
62 | 62 |
63 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( | 63 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory( |
64 browser()->profile(), gcm::FakeGCMProfileService::Build); | 64 browser()->profile(), gcm::FakeGCMProfileService::Build); |
65 | 65 |
66 testing_profile_manager()->CreateTestingProfile( | 66 testing_profile_manager()->CreateTestingProfile( |
67 "test1", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 67 "test1", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
68 base::ASCIIToUTF16("Test 1"), 0, std::string(), testing_factories()); | 68 base::ASCIIToUTF16("Test 1"), 0, std::string(), testing_factories()); |
69 testing_profile_manager()->CreateTestingProfile( | 69 testing_profile_manager()->CreateTestingProfile( |
70 "test2", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 70 "test2", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
71 base::ASCIIToUTF16("Test 2"), 1, std::string(), | 71 base::ASCIIToUTF16("Test 2"), 1, std::string(), |
72 TestingProfile::TestingFactories()); | 72 TestingProfile::TestingFactories()); |
73 | 73 |
74 menu_ = new AvatarMenu( | 74 menu_ = new AvatarMenu( |
75 testing_profile_manager()->profile_attributes_storage(), NULL, NULL); | 75 testing_profile_manager()->profile_attributes_storage(), NULL, NULL); |
76 menu_->RebuildMenu(); | 76 menu_->RebuildMenu(); |
77 | 77 |
78 // There should be the default profile + two profiles we created. | 78 // There should be the default profile + two profiles we created. |
79 EXPECT_EQ(3U, menu_->GetNumberOfItems()); | 79 EXPECT_EQ(3U, menu_->GetNumberOfItems()); |
80 } | 80 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 310 } |
311 | 311 |
312 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { | 312 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { |
313 // This test is related to the fast user switcher, which doesn't exist under | 313 // This test is related to the fast user switcher, which doesn't exist under |
314 // the MD user menu. | 314 // the MD user menu. |
315 if (switches::IsMaterialDesignUserMenu()) | 315 if (switches::IsMaterialDesignUserMenu()) |
316 return; | 316 return; |
317 // Add two extra profiles, to make sure sorting is alphabetical and not | 317 // Add two extra profiles, to make sure sorting is alphabetical and not |
318 // by order of creation. | 318 // by order of creation. |
319 testing_profile_manager()->CreateTestingProfile( | 319 testing_profile_manager()->CreateTestingProfile( |
320 "test3", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 320 "test3", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
321 base::ASCIIToUTF16("New Profile"), 1, std::string(), | 321 base::ASCIIToUTF16("New Profile"), 1, std::string(), |
322 TestingProfile::TestingFactories()); | 322 TestingProfile::TestingFactories()); |
323 testing_profile_manager()->CreateTestingProfile( | 323 testing_profile_manager()->CreateTestingProfile( |
324 "test4", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 324 "test4", std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
325 base::ASCIIToUTF16("Another Test"), 1, std::string(), | 325 base::ASCIIToUTF16("Another Test"), 1, std::string(), |
326 TestingProfile::TestingFactories()); | 326 TestingProfile::TestingFactories()); |
327 StartFastUserSwitcher(); | 327 StartFastUserSwitcher(); |
328 | 328 |
329 NSArray* subviews = [[[controller() window] contentView] subviews]; | 329 NSArray* subviews = [[[controller() window] contentView] subviews]; |
330 ASSERT_EQ(2U, [subviews count]); | 330 ASSERT_EQ(2U, [subviews count]); |
331 subviews = [[subviews objectAtIndex:0] subviews]; | 331 subviews = [[subviews objectAtIndex:0] subviews]; |
332 NSString* sortedNames[] = { @"Another Test", | 332 NSString* sortedNames[] = { @"Another Test", |
333 @"New Profile", | 333 @"New Profile", |
334 @"Test 1", | 334 @"Test 1", |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 } | 633 } |
634 | 634 |
635 // There should be a lock button. | 635 // There should be a lock button. |
636 NSButton* lockButton = | 636 NSButton* lockButton = |
637 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 637 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
638 ASSERT_TRUE(lockButton); | 638 ASSERT_TRUE(lockButton); |
639 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | 639 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); |
640 EXPECT_EQ(controller(), [lockButton target]); | 640 EXPECT_EQ(controller(), [lockButton target]); |
641 EXPECT_TRUE([lockButton isEnabled]); | 641 EXPECT_TRUE([lockButton isEnabled]); |
642 } | 642 } |
OLD | NEW |