Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1460)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/avatar_icon_controller_unittest.mm

Issue 1307093004: Remove references to IsNewAvatarMenu since the flag was removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Correctly close window at end of unit test. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/avatar_icon_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 10 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
12 #include "chrome/browser/search_engines/template_url_service_factory.h" 12 #include "chrome/browser/search_engines/template_url_service_factory.h"
13 #include "chrome/browser/supervised_user/supervised_user_service.h" 13 #include "chrome/browser/supervised_user/supervised_user_service.h"
14 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 14 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
19 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
20 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
19 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 21 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
20 #include "chrome/browser/ui/cocoa/info_bubble_window.h" 22 #include "chrome/browser/ui/cocoa/info_bubble_window.h"
23 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h"
21 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" 24 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
24 #include "components/bookmarks/test/bookmark_test_helpers.h" 27 #include "components/bookmarks/test/bookmark_test_helpers.h"
25 #include "components/signin/core/common/profile_management_switches.h" 28 #include "components/signin/core/common/profile_management_switches.h"
26 #include "components/syncable_prefs/pref_service_syncable.h" 29 #include "components/syncable_prefs/pref_service_syncable.h"
27 30
28 class AvatarIconControllerTest : public CocoaProfileTest { 31 class AvatarIconControllerTest : public CocoaProfileTest {
29 public: 32 public:
33 // Incognito, which is the only way to show the icon
Robert Sesek 2015/09/30 21:25:08 Is this comment still relevant?
anthonyvd 2015/10/01 14:16:54 Done.
34 AvatarIconControllerTest() {}
35
30 void SetUp() override { 36 void SetUp() override {
31 switches::DisableNewAvatarMenuForTesting(
32 base::CommandLine::ForCurrentProcess());
33 CocoaProfileTest::SetUp(); 37 CocoaProfileTest::SetUp();
34 ASSERT_TRUE(browser()); 38 ASSERT_TRUE(browser());
35
36 controller_.reset(
37 [[AvatarIconController alloc] initWithBrowser:browser()]);
38 [[controller_ view] setHidden:YES];
39 } 39 }
40 40
41 void TearDown() override { 41 void TearDown() override {
42 browser()->window()->Close(); 42 browser()->window()->Close();
43 CocoaProfileTest::TearDown(); 43 CocoaProfileTest::TearDown();
44 } 44 }
45 45
46 NSButton* button() { return [controller_ buttonView]; } 46 AvatarBaseController* icon_controller() {
47 47 BrowserWindowCocoa* window = (BrowserWindowCocoa*)browser()->window();
Robert Sesek 2015/09/30 21:25:08 nit: C-style casts are banned. static_cast<> inste
anthonyvd 2015/10/01 14:16:54 Done.
48 NSView* view() { return [controller_ view]; } 48 return [window->cocoa_controller() avatarButtonController];
49 49 }
50 AvatarIconController* controller() { return controller_.get(); }
51
52 private:
53 base::scoped_nsobject<AvatarIconController> controller_;
54 }; 50 };
55 51
56 TEST_F(AvatarIconControllerTest, AddRemoveProfiles) { 52 TEST_F(AvatarIconControllerTest, ShowingAvatarIconInIncognito) {
57 EXPECT_TRUE([view() isHidden]);
58
59 testing_profile_manager()->CreateTestingProfile("one");
60
61 EXPECT_FALSE([view() isHidden]);
62
63 testing_profile_manager()->CreateTestingProfile("two");
64 EXPECT_FALSE([view() isHidden]);
65
66 testing_profile_manager()->DeleteTestingProfile("one");
67 EXPECT_FALSE([view() isHidden]);
68
69 testing_profile_manager()->DeleteTestingProfile("two");
70 EXPECT_TRUE([view() isHidden]);
71 }
72
73 TEST_F(AvatarIconControllerTest, DoubleOpen) {
74 // Create a second profile to enable the avatar menu.
75 testing_profile_manager()->CreateTestingProfile("p2");
76
77 EXPECT_FALSE([controller() menuController]);
78
79 [button() performClick:button()];
80
81 BaseBubbleController* menu = [controller() menuController];
82 EXPECT_TRUE([menu isKindOfClass:[AvatarMenuBubbleController class]]);
83
84 EXPECT_TRUE(menu);
85
86 [button() performClick:button()];
87 EXPECT_EQ(menu, [controller() menuController]);
88
89 // Do not animate out because that is hard to test around.
90 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations =
91 info_bubble::kAnimateNone;
92 [menu close];
93 EXPECT_FALSE([controller() menuController]);
94
95 testing_profile_manager()->DeleteTestingProfile("p2");
96 }
97
98 TEST_F(AvatarIconControllerTest, SupervisedUserLabel) {
99 DCHECK(!profile()->IsSupervised());
100 EXPECT_FALSE([controller() labelButtonView]);
101
102 // Create a second, supervised profile to enable the avatar menu.
103 std::string name = "p2";
104 TestingProfile* profile = testing_profile_manager()->CreateTestingProfile(
105 name, scoped_ptr<syncable_prefs::PrefServiceSyncable>(),
106 base::ASCIIToUTF16(name), 0, "asdf", TestingProfile::TestingFactories());
107 EXPECT_TRUE(profile->IsSupervised());
108
109 // http://crbug.com/39725
110 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
111 profile, &TemplateURLServiceFactory::BuildInstanceFor);
112 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
113 profile, &AutocompleteClassifierFactory::BuildInstanceFor);
114 profile->CreateBookmarkModel(true);
115 bookmarks::test::WaitForBookmarkModelToLoad(
116 BookmarkModelFactory::GetForProfile(profile));
117
118 Browser* browser = 53 Browser* browser =
119 new Browser(Browser::CreateParams(profile, chrome::GetActiveDesktop())); 54 new Browser(Browser::CreateParams(profile()->GetOffTheRecordProfile(),
120 // Build a new controller to check if it is initialized correctly for a 55 chrome::GetActiveDesktop()));
121 // supervised user profile. 56 BrowserWindowCocoa* window = (BrowserWindowCocoa*)browser->window();
Robert Sesek 2015/09/30 21:25:08 No C-style casts.
anthonyvd 2015/10/01 14:16:54 Done.
122 base::scoped_nsobject<AvatarIconController> controller( 57 AvatarBaseController* icon_controller =
123 [[AvatarIconController alloc] initWithBrowser:browser]); 58 [window->cocoa_controller() avatarButtonController];
124 59 // In incognito, we should be using the AvatarIconController to show the
125 EXPECT_TRUE([controller labelButtonView]); 60 // incognito guy.
61 EXPECT_TRUE([icon_controller isKindOfClass:[AvatarIconController class]]);
126 62
127 browser->window()->Close(); 63 browser->window()->Close();
128 } 64 }
65
66 TEST_F(AvatarIconControllerTest, ShowingAvatarButtonInRegularSession) {
67 // In a regular session, we should be using the AvatarButtonController to show
68 // the profile name.
69 EXPECT_TRUE([icon_controller() isKindOfClass:[AvatarButtonController class]]);
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698