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

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

Issue 1116353004: Remove the #enable-fast-user-switcher flag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bad merge Created 5 years, 7 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/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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 NSTextField* tutorialContent = base::mac::ObjCCastStrict<NSTextField>( 117 NSTextField* tutorialContent = base::mac::ObjCCastStrict<NSTextField>(
118 [tutorialSubviews objectAtIndex:1]); 118 [tutorialSubviews objectAtIndex:1]);
119 EXPECT_GT([[tutorialContent stringValue] length], 0U); 119 EXPECT_GT([[tutorialContent stringValue] length], 0U);
120 120
121 NSButton* tutorialOKButton = base::mac::ObjCCastStrict<NSButton>( 121 NSButton* tutorialOKButton = base::mac::ObjCCastStrict<NSButton>(
122 [tutorialSubviews objectAtIndex:0]); 122 [tutorialSubviews objectAtIndex:0]);
123 EXPECT_GT([[tutorialOKButton title] length], 0U); 123 EXPECT_GT([[tutorialOKButton title] length], 0U);
124 } 124 }
125 125
126 void EnableFastUserSwitching() { 126 void StartFastUserSwitcher() {
127 base::CommandLine::ForCurrentProcess()->AppendSwitch( 127 NSRect frame = [test_window() frame];
128 switches::kFastUserSwitching); 128 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame));
129 controller_.reset([[ProfileChooserController alloc]
130 initWithBrowser:browser()
131 anchoredAt:point
132 viewMode:profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER
133 tutorialMode:profiles::TUTORIAL_MODE_NONE
134 serviceType:signin::GAIA_SERVICE_TYPE_NONE]);
135 [controller_ showWindow:nil];
129 } 136 }
130 137
131 ProfileChooserController* controller() { return controller_; } 138 ProfileChooserController* controller() { return controller_; }
132 AvatarMenu* menu() { return menu_; } 139 AvatarMenu* menu() { return menu_; }
133 140
134 private: 141 private:
135 base::scoped_nsobject<ProfileChooserController> controller_; 142 base::scoped_nsobject<ProfileChooserController> controller_;
136 143
137 // Weak; owned by |controller_|. 144 // Weak; owned by |controller_|.
138 AvatarMenu* menu_; 145 AvatarMenu* menu_;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 StartProfileChooserControllerWithTutorialMode( 270 StartProfileChooserControllerWithTutorialMode(
264 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); 271 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING);
265 subviews = [[[controller() window] contentView] subviews]; 272 subviews = [[[controller() window] contentView] subviews];
266 ASSERT_EQ(2U, [subviews count]); 273 ASSERT_EQ(2U, [subviews count]);
267 subviews = [[subviews objectAtIndex:0] subviews]; 274 subviews = [[subviews objectAtIndex:0] subviews];
268 275
269 // There should be 3 views since there's no tutorial 276 // There should be 3 views since there's no tutorial
270 ASSERT_EQ(3U, [subviews count]); 277 ASSERT_EQ(3U, [subviews count]);
271 } 278 }
272 279
273 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) {
274 switches::EnableNewAvatarMenuForTesting(
275 base::CommandLine::ForCurrentProcess());
276 EnableFastUserSwitching();
277 StartProfileChooserController();
278
279 NSArray* subviews = [[[controller() window] contentView] subviews];
280 ASSERT_EQ(2U, [subviews count]);
281 subviews = [[subviews objectAtIndex:0] subviews];
282
283 // Three profiles means we should have one active card and a
284 // fast user switcher which has two "other" profiles and 2 separators, and
285 // an option buttons view with its separator. We also have a promo for
286 // the new avatar menu.
287 // TODO(noms): Enforcing 8U fails on the waterfall debug bots, but it's not
288 // reproducible anywhere else.
289 ASSERT_GE([subviews count], 7U);
290
291 // There should be two buttons and a separator in the option buttons view.
292 // These buttons are tested in InitialLayoutWithNewMenu.
293 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
294 ASSERT_EQ(3U, [buttonSubviews count]);
295
296 // There should be a separator.
297 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
298
299 // There should be two "other profiles" items. The items are drawn from the
300 // bottom up, so in the opposite order of those in the AvatarMenu.
301 int profileIndex = 1;
302 for (int i = 5; i >= 2; i -= 2) {
303 // Each profile button has a separator.
304 EXPECT_TRUE([[subviews objectAtIndex:i] isKindOfClass:[NSBox class]]);
305
306 NSButton* button = base::mac::ObjCCast<NSButton>(
307 [subviews objectAtIndex:i-1]);
308 EXPECT_EQ(menu()->GetItemAt(profileIndex).name,
309 base::SysNSStringToUTF16([button title]));
310 EXPECT_EQ(profileIndex, [button tag]);
311 EXPECT_EQ(@selector(switchToProfile:), [button action]);
312 EXPECT_EQ(controller(), [button target]);
313 profileIndex++;
314 }
315
316 // There should be the profile avatar, name and links container in the active
317 // card view. The links displayed in the container are checked separately.
318 NSArray* activeCardSubviews = [[subviews objectAtIndex:6] subviews];
319 ASSERT_EQ(3U, [activeCardSubviews count]);
320
321 // Profile icon.
322 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2];
323 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]);
324
325 // Profile name.
326 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1];
327 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]);
328 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
329 [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
330
331 // Profile links. This is a local profile, so there should be a signin button
332 // and a signin promo. These are also tested in InitialLayoutWithNewMenu.
333 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
334 EXPECT_EQ(2U, [linksSubviews count]);
335 }
336
337 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { 280 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) {
338 switches::EnableNewAvatarMenuForTesting( 281 switches::EnableNewAvatarMenuForTesting(
339 base::CommandLine::ForCurrentProcess()); 282 base::CommandLine::ForCurrentProcess());
340 EnableFastUserSwitching();
341 283
342 // Add two extra profiles, to make sure sorting is alphabetical and not 284 // Add two extra profiles, to make sure sorting is alphabetical and not
343 // by order of creation. 285 // by order of creation.
344 testing_profile_manager()-> 286 testing_profile_manager()->
345 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), 287 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(),
346 base::ASCIIToUTF16("New Profile"), 1, std::string(), 288 base::ASCIIToUTF16("New Profile"), 1, std::string(),
347 TestingProfile::TestingFactories()); 289 TestingProfile::TestingFactories());
348 testing_profile_manager()-> 290 testing_profile_manager()->
349 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), 291 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(),
350 base::ASCIIToUTF16("Another Test"), 1, std::string(), 292 base::ASCIIToUTF16("Another Test"), 1, std::string(),
351 TestingProfile::TestingFactories()); 293 TestingProfile::TestingFactories());
352 StartProfileChooserController(); 294 StartFastUserSwitcher();
353 295
354 NSArray* subviews = [[[controller() window] contentView] subviews]; 296 NSArray* subviews = [[[controller() window] contentView] subviews];
355 ASSERT_EQ(2U, [subviews count]); 297 ASSERT_EQ(2U, [subviews count]);
356 subviews = [[subviews objectAtIndex:0] subviews]; 298 subviews = [[subviews objectAtIndex:0] subviews];
357 NSString* sortedNames[] = { @"Another Test", 299 NSString* sortedNames[] = { @"Another Test",
358 @"New Profile", 300 @"New Profile",
359 @"Test 1", 301 @"Test 1",
360 @"Test 2" }; 302 @"Test 2" };
361 // There are four "other" profiles, each with a button and a separator, an 303 // There are four "other" profiles, each with a button and a separator.
362 // active profile card, and an option buttons view with a separator. We 304 ASSERT_EQ([subviews count], 8U);
363 // also have an update promo for the new avatar menu.
364 // TODO(noms): Enforcing 12U fails on the waterfall debug bots, but it's not
365 // reproducible anywhere else.
366 ASSERT_GE([subviews count], 11U);
367 // There should be four "other profiles" items, sorted alphabetically. The 305 // There should be four "other profiles" items, sorted alphabetically. The
368 // "other profiles" start at index 2 (after the option buttons view and its 306 // "other profiles" start at index 2 (after the option buttons view and its
369 // separator), and each have a separator. We need to iterate through the 307 // separator), and each have a separator. We need to iterate through the
370 // profiles in the order displayed in the bubble, which is opposite from the 308 // profiles in the order displayed in the bubble, which is opposite from the
371 // drawn order. 309 // drawn order.
372 int sortedNameIndex = 0; 310 int sortedNameIndex = 0;
373 for (int i = 9; i >= 2; i -= 2) { 311 for (int i = 7; i > 0; i -= 2) {
374 // The item at index i is the separator. 312 // The item at index i is the separator.
375 NSButton* button = base::mac::ObjCCast<NSButton>( 313 NSButton* button = base::mac::ObjCCast<NSButton>(
376 [subviews objectAtIndex:i-1]); 314 [subviews objectAtIndex:i-1]);
377 EXPECT_TRUE( 315 EXPECT_TRUE(
378 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); 316 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]);
379 } 317 }
380 } 318 }
381 319
382 TEST_F(ProfileChooserControllerTest, 320 TEST_F(ProfileChooserControllerTest,
383 LocalProfileActiveCardLinksWithNewMenu) { 321 LocalProfileActiveCardLinksWithNewMenu) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 ASSERT_EQ(5U, [buttonSubviews count]); 551 ASSERT_EQ(5U, [buttonSubviews count]);
614 552
615 // There should be a lock button. 553 // There should be a lock button.
616 NSButton* lockButton = 554 NSButton* lockButton =
617 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); 555 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
618 ASSERT_TRUE(lockButton); 556 ASSERT_TRUE(lockButton);
619 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); 557 EXPECT_EQ(@selector(lockProfile:), [lockButton action]);
620 EXPECT_EQ(controller(), [lockButton target]); 558 EXPECT_EQ(controller(), [lockButton target]);
621 EXPECT_TRUE([lockButton isEnabled]); 559 EXPECT_TRUE([lockButton isEnabled]);
622 } 560 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698