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

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

Issue 2552423002: [Mac] Fix for avatar button active state (Closed)
Patch Set: Removed the Fast Chooser Profile Menu code in cocoa Created 4 years 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
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_button_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/avatar_button_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/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 11 matching lines...) Expand all
22 #include "components/signin/core/common/profile_management_switches.h" 22 #include "components/signin/core/common/profile_management_switches.h"
23 #import "testing/gtest_mac.h" 23 #import "testing/gtest_mac.h"
24 #include "ui/base/material_design/material_design_controller.h" 24 #include "ui/base/material_design/material_design_controller.h"
25 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
26 26
27 // Defined in the AvatarButtonController implementation. 27 // Defined in the AvatarButtonController implementation.
28 @interface AvatarButtonController (ExposedForTesting) 28 @interface AvatarButtonController (ExposedForTesting)
29 - (void)setErrorStatus:(BOOL)hasError; 29 - (void)setErrorStatus:(BOOL)hasError;
30 @end 30 @end
31 31
32 // Subclassing AvatarButtonController to be able to control the state of
33 // keyboard modifierFlags.
34 @interface AvatarButtonControllerForTesting : AvatarButtonController {
35 @private
36 bool isCtrlPressed_;
37 }
38 @end
39
40 @interface AvatarButtonControllerForTesting (ExposedForTesting)
41 - (void)setIsCtrlPressed:(BOOL)isPressed;
42 - (BOOL)isCtrlPressed;
43 @end
44
45 @implementation AvatarButtonControllerForTesting
46 - (void)setIsCtrlPressed:(BOOL)isPressed {
47 isCtrlPressed_ = isPressed;
48 }
49
50 - (BOOL)isCtrlPressed {
51 // Always report that Cmd is not pressed since that's the case we're testing
52 // and otherwise running the test while holding the Cmd key makes it fail.
53 return isCtrlPressed_;
54 }
55 @end
56
57 class AvatarButtonControllerTest : public CocoaProfileTest { 32 class AvatarButtonControllerTest : public CocoaProfileTest {
58 public: 33 public:
59 void SetUp() override { 34 void SetUp() override {
60 DCHECK(profiles::IsMultipleProfilesEnabled()); 35 DCHECK(profiles::IsMultipleProfilesEnabled());
61 36
62 CocoaProfileTest::SetUp(); 37 CocoaProfileTest::SetUp();
63 ASSERT_TRUE(browser()); 38 ASSERT_TRUE(browser());
64 39
65 controller_.reset( 40 controller_.reset(
66 [[AvatarButtonControllerForTesting alloc] initWithBrowser:browser()]); 41 [[AvatarButtonController alloc] initWithBrowser:browser()]);
67 [controller_ setIsCtrlPressed:false];
68 } 42 }
69 43
70 void TearDown() override { 44 void TearDown() override {
71 browser()->window()->Close(); 45 browser()->window()->Close();
72 CocoaProfileTest::TearDown(); 46 CocoaProfileTest::TearDown();
73 } 47 }
74 48
75 NSButton* button() { return [controller_ buttonView]; } 49 NSButton* button() { return [controller_ buttonView]; }
76 50
77 NSView* view() { return [controller_ view]; } 51 NSView* view() { return [controller_ view]; }
78 52
79 AvatarButtonControllerForTesting* controller() { return controller_.get(); } 53 AvatarButtonController* controller() { return controller_.get(); }
80 54
81 private: 55 private:
82 base::scoped_nsobject<AvatarButtonControllerForTesting> controller_; 56 base::scoped_nsobject<AvatarButtonController> controller_;
83 }; 57 };
84 58
85 TEST_F(AvatarButtonControllerTest, GenericButtonShown) { 59 TEST_F(AvatarButtonControllerTest, GenericButtonShown) {
86 ASSERT_FALSE([view() isHidden]); 60 ASSERT_FALSE([view() isHidden]);
87 // There is only one local profile, which means displaying the generic 61 // There is only one local profile, which means displaying the generic
88 // avatar button. 62 // avatar button.
89 EXPECT_NSEQ(@"", [button() title]); 63 EXPECT_NSEQ(@"", [button() title]);
90 } 64 }
91 65
92 TEST_F(AvatarButtonControllerTest, ProfileButtonShown) { 66 TEST_F(AvatarButtonControllerTest, ProfileButtonShown) {
(...skipping 30 matching lines...) Expand all
123 97
124 [button() performClick:button()]; 98 [button() performClick:button()];
125 EXPECT_EQ(menu, [controller() menuController]); 99 EXPECT_EQ(menu, [controller() menuController]);
126 100
127 // Do not animate out because that is hard to test around. 101 // Do not animate out because that is hard to test around.
128 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = 102 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations =
129 info_bubble::kAnimateNone; 103 info_bubble::kAnimateNone;
130 [menu close]; 104 [menu close];
131 EXPECT_FALSE([controller() menuController]); 105 EXPECT_FALSE([controller() menuController]);
132 } 106 }
133
134 TEST_F(AvatarButtonControllerTest, DontOpenFastSwitcherWithoutTarget) {
135 EXPECT_FALSE([controller() menuController]);
136
137 [controller() setIsCtrlPressed:YES];
138 [button() performClick:button()];
139
140 // If there's only one profile and the fast user switcher is requested,
141 // nothing should happen.
142 EXPECT_FALSE([controller() menuController]);
143 }
144
145 TEST_F(AvatarButtonControllerTest, OpenFastUserSwitcherWithTarget) {
146 testing_profile_manager()->CreateTestingProfile("batman");
147 EXPECT_FALSE([controller() menuController]);
148
149 [controller() setIsCtrlPressed:YES];
150 [button() performClick:button()];
151
152 BaseBubbleController* menu = [controller() menuController];
153 EXPECT_TRUE(menu);
154 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]);
155
156 // Do not animate out because that is hard to test around.
157 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations =
158 info_bubble::kAnimateNone;
159 [menu close];
160 EXPECT_FALSE([controller() menuController]);
161 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698