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" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); | 83 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
84 controller_.reset([[ProfileChooserController alloc] | 84 controller_.reset([[ProfileChooserController alloc] |
85 initWithBrowser:browser() | 85 initWithBrowser:browser() |
86 anchoredAt:point | 86 anchoredAt:point |
87 viewMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER | 87 viewMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER |
88 tutorialMode:profiles::TUTORIAL_MODE_NONE | 88 tutorialMode:profiles::TUTORIAL_MODE_NONE |
89 serviceType:signin::GAIA_SERVICE_TYPE_NONE]); | 89 serviceType:signin::GAIA_SERVICE_TYPE_NONE]); |
90 [controller_ showWindow:nil]; | 90 [controller_ showWindow:nil]; |
91 } | 91 } |
92 | 92 |
93 void EnableFastUserSwitching() { | 93 void StartFastUserSwitcher() { |
94 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 94 NSRect frame = [test_window() frame]; |
95 switches::kFastUserSwitching); | 95 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
| 96 controller_.reset([[ProfileChooserController alloc] |
| 97 initWithBrowser:browser() |
| 98 anchoredAt:point |
| 99 viewMode:profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER |
| 100 tutorialMode:profiles::TUTORIAL_MODE_NONE |
| 101 serviceType:signin::GAIA_SERVICE_TYPE_NONE]); |
| 102 [controller_ showWindow:nil]; |
96 } | 103 } |
97 | 104 |
98 ProfileChooserController* controller() { return controller_; } | 105 ProfileChooserController* controller() { return controller_; } |
99 AvatarMenu* menu() { return menu_; } | 106 AvatarMenu* menu() { return menu_; } |
100 | 107 |
101 private: | 108 private: |
102 base::scoped_nsobject<ProfileChooserController> controller_; | 109 base::scoped_nsobject<ProfileChooserController> controller_; |
103 | 110 |
104 // Weak; owned by |controller_|. | 111 // Weak; owned by |controller_|. |
105 AvatarMenu* menu_; | 112 AvatarMenu* menu_; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 NSButton* link = base::mac::ObjCCast<NSButton>( | 174 NSButton* link = base::mac::ObjCCast<NSButton>( |
168 [linksSubviews objectAtIndex:0]); | 175 [linksSubviews objectAtIndex:0]); |
169 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); | 176 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
170 EXPECT_EQ(controller(), [link target]); | 177 EXPECT_EQ(controller(), [link target]); |
171 | 178 |
172 NSTextField* promo = base::mac::ObjCCast<NSTextField>( | 179 NSTextField* promo = base::mac::ObjCCast<NSTextField>( |
173 [linksSubviews objectAtIndex:1]); | 180 [linksSubviews objectAtIndex:1]); |
174 EXPECT_GT([[promo stringValue] length], 0U); | 181 EXPECT_GT([[promo stringValue] length], 0U); |
175 } | 182 } |
176 | 183 |
177 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { | |
178 switches::EnableNewAvatarMenuForTesting( | |
179 base::CommandLine::ForCurrentProcess()); | |
180 EnableFastUserSwitching(); | |
181 StartProfileChooserController(); | |
182 | |
183 NSArray* subviews = [[[controller() window] contentView] subviews]; | |
184 ASSERT_EQ(2U, [subviews count]); | |
185 subviews = [[subviews objectAtIndex:0] subviews]; | |
186 | |
187 // Three profiles means we should have one active card and a | |
188 // fast user switcher which has two "other" profiles and 2 separators, and | |
189 // an option buttons view with its separator. We also have a promo for | |
190 // the new avatar menu. | |
191 // TODO(noms): Enforcing 8U fails on the waterfall debug bots, but it's not | |
192 // reproducible anywhere else. | |
193 ASSERT_GE([subviews count], 7U); | |
194 | |
195 // There should be two buttons and a separator in the option buttons view. | |
196 // These buttons are tested in InitialLayoutWithNewMenu. | |
197 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | |
198 ASSERT_EQ(3U, [buttonSubviews count]); | |
199 | |
200 // There should be a separator. | |
201 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | |
202 | |
203 // There should be two "other profiles" items. The items are drawn from the | |
204 // bottom up, so in the opposite order of those in the AvatarMenu. | |
205 int profileIndex = 1; | |
206 for (int i = 5; i >= 2; i -= 2) { | |
207 // Each profile button has a separator. | |
208 EXPECT_TRUE([[subviews objectAtIndex:i] isKindOfClass:[NSBox class]]); | |
209 | |
210 NSButton* button = base::mac::ObjCCast<NSButton>( | |
211 [subviews objectAtIndex:i-1]); | |
212 EXPECT_EQ(menu()->GetItemAt(profileIndex).name, | |
213 base::SysNSStringToUTF16([button title])); | |
214 EXPECT_EQ(profileIndex, [button tag]); | |
215 EXPECT_EQ(@selector(switchToProfile:), [button action]); | |
216 EXPECT_EQ(controller(), [button target]); | |
217 profileIndex++; | |
218 } | |
219 | |
220 // There should be the profile avatar, name and links container in the active | |
221 // card view. The links displayed in the container are checked separately. | |
222 NSArray* activeCardSubviews = [[subviews objectAtIndex:6] subviews]; | |
223 ASSERT_EQ(3U, [activeCardSubviews count]); | |
224 | |
225 // Profile icon. | |
226 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; | |
227 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]); | |
228 | |
229 // Profile name. | |
230 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; | |
231 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | |
232 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | |
233 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); | |
234 | |
235 // Profile links. This is a local profile, so there should be a signin button | |
236 // and a signin promo. These are also tested in InitialLayoutWithNewMenu. | |
237 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | |
238 EXPECT_EQ(2U, [linksSubviews count]); | |
239 } | |
240 | |
241 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { | 184 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { |
242 switches::EnableNewAvatarMenuForTesting( | 185 switches::EnableNewAvatarMenuForTesting( |
243 base::CommandLine::ForCurrentProcess()); | 186 base::CommandLine::ForCurrentProcess()); |
244 EnableFastUserSwitching(); | |
245 | 187 |
246 // Add two extra profiles, to make sure sorting is alphabetical and not | 188 // Add two extra profiles, to make sure sorting is alphabetical and not |
247 // by order of creation. | 189 // by order of creation. |
248 testing_profile_manager()-> | 190 testing_profile_manager()-> |
249 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), | 191 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), |
250 base::ASCIIToUTF16("New Profile"), 1, std::string(), | 192 base::ASCIIToUTF16("New Profile"), 1, std::string(), |
251 TestingProfile::TestingFactories()); | 193 TestingProfile::TestingFactories()); |
252 testing_profile_manager()-> | 194 testing_profile_manager()-> |
253 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), | 195 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), |
254 base::ASCIIToUTF16("Another Test"), 1, std::string(), | 196 base::ASCIIToUTF16("Another Test"), 1, std::string(), |
255 TestingProfile::TestingFactories()); | 197 TestingProfile::TestingFactories()); |
256 StartProfileChooserController(); | 198 StartFastUserSwitcher(); |
257 | 199 |
258 NSArray* subviews = [[[controller() window] contentView] subviews]; | 200 NSArray* subviews = [[[controller() window] contentView] subviews]; |
259 ASSERT_EQ(2U, [subviews count]); | 201 ASSERT_EQ(2U, [subviews count]); |
260 subviews = [[subviews objectAtIndex:0] subviews]; | 202 subviews = [[subviews objectAtIndex:0] subviews]; |
261 NSString* sortedNames[] = { @"Another Test", | 203 NSString* sortedNames[] = { @"Another Test", |
262 @"New Profile", | 204 @"New Profile", |
263 @"Test 1", | 205 @"Test 1", |
264 @"Test 2" }; | 206 @"Test 2" }; |
265 // There are four "other" profiles, each with a button and a separator, an | 207 // There are four "other" profiles, each with a button and a separator. |
266 // active profile card, and an option buttons view with a separator. We | 208 ASSERT_EQ([subviews count], 8U); |
267 // also have an update promo for the new avatar menu. | |
268 // TODO(noms): Enforcing 12U fails on the waterfall debug bots, but it's not | |
269 // reproducible anywhere else. | |
270 ASSERT_GE([subviews count], 11U); | |
271 // There should be four "other profiles" items, sorted alphabetically. The | 209 // There should be four "other profiles" items, sorted alphabetically. The |
272 // "other profiles" start at index 2 (after the option buttons view and its | 210 // "other profiles" start at index 2 (after the option buttons view and its |
273 // separator), and each have a separator. We need to iterate through the | 211 // separator), and each have a separator. We need to iterate through the |
274 // profiles in the order displayed in the bubble, which is opposite from the | 212 // profiles in the order displayed in the bubble, which is opposite from the |
275 // drawn order. | 213 // drawn order. |
276 int sortedNameIndex = 0; | 214 int sortedNameIndex = 0; |
277 for (int i = 9; i >= 2; i -= 2) { | 215 for (int i = 7; i > 0; i -= 2) { |
278 // The item at index i is the separator. | 216 // The item at index i is the separator. |
279 NSButton* button = base::mac::ObjCCast<NSButton>( | 217 NSButton* button = base::mac::ObjCCast<NSButton>( |
280 [subviews objectAtIndex:i-1]); | 218 [subviews objectAtIndex:i-1]); |
281 EXPECT_TRUE( | 219 EXPECT_TRUE( |
282 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); | 220 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); |
283 } | 221 } |
284 } | 222 } |
285 | 223 |
286 TEST_F(ProfileChooserControllerTest, | 224 TEST_F(ProfileChooserControllerTest, |
287 LocalProfileActiveCardLinksWithNewMenu) { | 225 LocalProfileActiveCardLinksWithNewMenu) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 ASSERT_EQ(5U, [buttonSubviews count]); | 455 ASSERT_EQ(5U, [buttonSubviews count]); |
518 | 456 |
519 // There should be a lock button. | 457 // There should be a lock button. |
520 NSButton* lockButton = | 458 NSButton* lockButton = |
521 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 459 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
522 ASSERT_TRUE(lockButton); | 460 ASSERT_TRUE(lockButton); |
523 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | 461 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); |
524 EXPECT_EQ(controller(), [lockButton target]); | 462 EXPECT_EQ(controller(), [lockButton target]); |
525 EXPECT_TRUE([lockButton isEnabled]); | 463 EXPECT_TRUE([lockButton isEnabled]); |
526 } | 464 } |
OLD | NEW |