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

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

Issue 890143005: [Mac] Allow "Enter" to activate the buttons in the new avatar bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unbreak tests Created 5 years, 10 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 EnableFastUserSwitching() {
94 base::CommandLine::ForCurrentProcess()->AppendSwitch( 94 base::CommandLine::ForCurrentProcess()->AppendSwitch(
95 switches::kFastUserSwitching); 95 switches::kFastUserSwitching);
96 } 96 }
97 97
98 NSButton* GetButtonFromButtonContainer(NSView* container) {
99 return base::mac::ObjCCast<NSButton>(
100 [[container subviews] objectAtIndex:0]);
101 }
102
98 ProfileChooserController* controller() { return controller_; } 103 ProfileChooserController* controller() { return controller_; }
99 AvatarMenu* menu() { return menu_; } 104 AvatarMenu* menu() { return menu_; }
100 105
101 private: 106 private:
102 base::scoped_nsobject<ProfileChooserController> controller_; 107 base::scoped_nsobject<ProfileChooserController> controller_;
103 108
104 // Weak; owned by |controller_|. 109 // Weak; owned by |controller_|.
105 AvatarMenu* menu_; 110 AvatarMenu* menu_;
106 111
107 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); 112 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest);
(...skipping 14 matching lines...) Expand all
122 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not 127 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not
123 // reproducible anywhere else. 128 // reproducible anywhere else.
124 ASSERT_GE([subviews count], 3U); 129 ASSERT_GE([subviews count], 3U);
125 130
126 // There should be two buttons and a separator in the option buttons view. 131 // There should be two buttons and a separator in the option buttons view.
127 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 132 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
128 ASSERT_EQ(3U, [buttonSubviews count]); 133 ASSERT_EQ(3U, [buttonSubviews count]);
129 134
130 // There should be an incognito button. 135 // There should be an incognito button.
131 NSButton* incognitoButton = 136 NSButton* incognitoButton =
132 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); 137 GetButtonFromButtonContainer([buttonSubviews objectAtIndex:0]);
133 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); 138 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]);
134 EXPECT_EQ(controller(), [incognitoButton target]); 139 EXPECT_EQ(controller(), [incognitoButton target]);
135 140
136 // There should be a separator. 141 // There should be a separator.
137 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); 142 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
138 143
139 // There should be a user switcher button. 144 // There should be a user switcher button.
140 NSButton* userSwitcherButton = 145 NSButton* userSwitcherButton =
141 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); 146 GetButtonFromButtonContainer([buttonSubviews objectAtIndex:2]);
142 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); 147 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]);
143 EXPECT_EQ(controller(), [userSwitcherButton target]); 148 EXPECT_EQ(controller(), [userSwitcherButton target]);
144 149
145 // There should be a separator. 150 // There should be a separator.
146 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); 151 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
147 152
148 // There should be the profile avatar, name and links container in the active 153 // There should be the profile avatar, name and links container in the active
149 // card view. The links displayed in the container are checked separately. 154 // card view. The links displayed in the container are checked separately.
150 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; 155 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews];
151 ASSERT_EQ(3U, [activeCardSubviews count]); 156 ASSERT_EQ(3U, [activeCardSubviews count]);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // There should be a separator. 205 // There should be a separator.
201 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); 206 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
202 207
203 // There should be two "other profiles" items. The items are drawn from the 208 // 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. 209 // bottom up, so in the opposite order of those in the AvatarMenu.
205 int profileIndex = 1; 210 int profileIndex = 1;
206 for (int i = 5; i >= 2; i -= 2) { 211 for (int i = 5; i >= 2; i -= 2) {
207 // Each profile button has a separator. 212 // Each profile button has a separator.
208 EXPECT_TRUE([[subviews objectAtIndex:i] isKindOfClass:[NSBox class]]); 213 EXPECT_TRUE([[subviews objectAtIndex:i] isKindOfClass:[NSBox class]]);
209 214
210 NSButton* button = base::mac::ObjCCast<NSButton>( 215 NSButton* button = GetButtonFromButtonContainer(
211 [subviews objectAtIndex:i-1]); 216 [subviews objectAtIndex:i-1]);
212 EXPECT_EQ(menu()->GetItemAt(profileIndex).name, 217 EXPECT_EQ(menu()->GetItemAt(profileIndex).name,
213 base::SysNSStringToUTF16([button title])); 218 base::SysNSStringToUTF16([button title]));
214 EXPECT_EQ(profileIndex, [button tag]); 219 EXPECT_EQ(profileIndex, [button tag]);
215 EXPECT_EQ(@selector(switchToProfile:), [button action]); 220 EXPECT_EQ(@selector(switchToProfile:), [button action]);
216 EXPECT_EQ(controller(), [button target]); 221 EXPECT_EQ(controller(), [button target]);
217 profileIndex++; 222 profileIndex++;
218 } 223 }
219 224
220 // There should be the profile avatar, name and links container in the active 225 // There should be the profile avatar, name and links container in the active
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 // reproducible anywhere else. 274 // reproducible anywhere else.
270 ASSERT_GE([subviews count], 11U); 275 ASSERT_GE([subviews count], 11U);
271 // There should be four "other profiles" items, sorted alphabetically. The 276 // There should be four "other profiles" items, sorted alphabetically. The
272 // "other profiles" start at index 2 (after the option buttons view and its 277 // "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 278 // 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 279 // profiles in the order displayed in the bubble, which is opposite from the
275 // drawn order. 280 // drawn order.
276 int sortedNameIndex = 0; 281 int sortedNameIndex = 0;
277 for (int i = 9; i >= 2; i -= 2) { 282 for (int i = 9; i >= 2; i -= 2) {
278 // The item at index i is the separator. 283 // The item at index i is the separator.
279 NSButton* button = base::mac::ObjCCast<NSButton>( 284 NSButton* button = GetButtonFromButtonContainer(
280 [subviews objectAtIndex:i-1]); 285 [subviews objectAtIndex:i-1]);
281 EXPECT_TRUE( 286 EXPECT_TRUE(
282 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); 287 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]);
283 } 288 }
284 } 289 }
285 290
286 TEST_F(ProfileChooserControllerTest, 291 TEST_F(ProfileChooserControllerTest,
287 LocalProfileActiveCardLinksWithNewMenu) { 292 LocalProfileActiveCardLinksWithNewMenu) {
288 switches::EnableNewAvatarMenuForTesting( 293 switches::EnableNewAvatarMenuForTesting(
289 base::CommandLine::ForCurrentProcess()); 294 base::CommandLine::ForCurrentProcess());
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // There should be three buttons and two separators in the option 396 // There should be three buttons and two separators in the option
392 // buttons view. 397 // buttons view.
393 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 398 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
394 ASSERT_EQ(3U, [buttonSubviews count]); 399 ASSERT_EQ(3U, [buttonSubviews count]);
395 400
396 // There should be a separator. 401 // There should be a separator.
397 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]); 402 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
398 403
399 // There should be an incognito button. 404 // There should be an incognito button.
400 NSButton* incognitoButton = 405 NSButton* incognitoButton =
401 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); 406 GetButtonFromButtonContainer([buttonSubviews objectAtIndex:0]);
402 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); 407 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]);
403 EXPECT_EQ(controller(), [incognitoButton target]); 408 EXPECT_EQ(controller(), [incognitoButton target]);
404 409
405 // There should be a separator. 410 // There should be a separator.
406 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); 411 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]);
407 412
408 // There should be a user switcher button. 413 // There should be a user switcher button.
409 NSButton* userSwitcherButton = 414 NSButton* userSwitcherButton =
410 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); 415 GetButtonFromButtonContainer([buttonSubviews objectAtIndex:2]);
411 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); 416 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]);
412 EXPECT_EQ(controller(), [userSwitcherButton target]); 417 EXPECT_EQ(controller(), [userSwitcherButton target]);
413 418
414 // In the accounts view, there should be the account list container 419 // In the accounts view, there should be the account list container
415 // accounts and one "add accounts" button. 420 // accounts and one "add accounts" button.
416 NSArray* accountsSubviews = [[subviews objectAtIndex:2] subviews]; 421 NSArray* accountsSubviews = [[subviews objectAtIndex:2] subviews];
417 ASSERT_EQ(2U, [accountsSubviews count]); 422 ASSERT_EQ(2U, [accountsSubviews count]);
418 423
419 NSButton* addAccountsButton = 424 NSButton* addAccountsButton =
420 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]); 425 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]);
421 EXPECT_EQ(@selector(addAccount:), [addAccountsButton action]); 426 EXPECT_EQ(@selector(addAccount:), [addAccountsButton action]);
422 EXPECT_EQ(controller(), [addAccountsButton target]); 427 EXPECT_EQ(controller(), [addAccountsButton target]);
423 428
424 // There should be two accounts in the account list container. 429 // There should be two accounts in the account list container.
425 NSArray* accountsListSubviews = [[accountsSubviews objectAtIndex:1] subviews]; 430 NSArray* accountsListSubviews = [[accountsSubviews objectAtIndex:1] subviews];
426 ASSERT_EQ(2U, [accountsListSubviews count]); 431 ASSERT_EQ(2U, [accountsListSubviews count]);
427 432
428 NSButton* genericAccount = 433 NSButton* genericAccount =
429 base::mac::ObjCCast<NSButton>([accountsListSubviews objectAtIndex:0]); 434 base::mac::ObjCCast<NSButton>([accountsListSubviews objectAtIndex:0]);
430 NSButton* genericAccountDelete = base::mac::ObjCCast<NSButton>( 435 NSButton* genericAccountDelete = base::mac::ObjCCast<NSButton>(
431 [[genericAccount subviews] objectAtIndex:0]); 436 [[genericAccount subviews] objectAtIndex:0]);
432 EXPECT_EQ(@selector(showAccountRemovalView:), [genericAccountDelete action]); 437 EXPECT_EQ(@selector(showAccountRemovalView:), [genericAccountDelete action]);
433 EXPECT_EQ(controller(), [genericAccountDelete target]); 438 EXPECT_EQ(controller(), [genericAccountDelete target]);
434 EXPECT_NE(-1, [genericAccountDelete tag]); 439 EXPECT_NE(-1, [genericAccountDelete tag]);
435 440
436 // Primary accounts are always last. 441 // Primary accounts are always last.
437 NSButton* primaryAccount = 442 NSButton* primaryAccount =
438 base::mac::ObjCCast<NSButton>([accountsListSubviews objectAtIndex:1]); 443 base::mac::ObjCCast<NSButton>([accountsListSubviews objectAtIndex:1]);
439 NSButton* primaryAccountDelete = base::mac::ObjCCast<NSButton>( 444 NSButton* primaryAccountDelete = base::mac::ObjCCast<NSButton>(
440 [[primaryAccount subviews] objectAtIndex:0]); 445 [[primaryAccount subviews] objectAtIndex:0]);
441 EXPECT_EQ(@selector(showAccountRemovalView:), [primaryAccountDelete action]); 446 EXPECT_EQ(@selector(showAccountRemovalView:), [primaryAccountDelete action]);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 NSArray* subviews = [[[controller() window] contentView] subviews]; 488 NSArray* subviews = [[[controller() window] contentView] subviews];
484 ASSERT_EQ(2U, [subviews count]); 489 ASSERT_EQ(2U, [subviews count]);
485 subviews = [[subviews objectAtIndex:0] subviews]; 490 subviews = [[subviews objectAtIndex:0] subviews];
486 491
487 // There will be two buttons and one separators in the option buttons view. 492 // There will be two buttons and one separators in the option buttons view.
488 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 493 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
489 ASSERT_EQ(3U, [buttonSubviews count]); 494 ASSERT_EQ(3U, [buttonSubviews count]);
490 495
491 // The last button should not be the lock button. 496 // The last button should not be the lock button.
492 NSButton* lastButton = 497 NSButton* lastButton =
493 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); 498 GetButtonFromButtonContainer([buttonSubviews objectAtIndex:0]);
494 ASSERT_TRUE(lastButton); 499 ASSERT_TRUE(lastButton);
495 EXPECT_NE(@selector(lockProfile:), [lastButton action]); 500 EXPECT_NE(@selector(lockProfile:), [lastButton action]);
496 } 501 }
497 502
498 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) { 503 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) {
499 switches::EnableNewProfileManagementForTesting( 504 switches::EnableNewProfileManagementForTesting(
500 base::CommandLine::ForCurrentProcess()); 505 base::CommandLine::ForCurrentProcess());
501 // Sign in the first profile. 506 // Sign in the first profile.
502 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); 507 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache();
503 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); 508 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail));
504 // The preference, not the email, determines whether the profile can lock. 509 // The preference, not the email, determines whether the profile can lock.
505 browser()->profile()->GetPrefs()->SetString( 510 browser()->profile()->GetPrefs()->SetString(
506 prefs::kGoogleServicesHostedDomain, "google.com"); 511 prefs::kGoogleServicesHostedDomain, "google.com");
507 // Lock is only available where a supervised user is present. 512 // Lock is only available where a supervised user is present.
508 cache->SetSupervisedUserIdOfProfileAtIndex(1, kEmail); 513 cache->SetSupervisedUserIdOfProfileAtIndex(1, kEmail);
509 514
510 StartProfileChooserController(); 515 StartProfileChooserController();
511 NSArray* subviews = [[[controller() window] contentView] subviews]; 516 NSArray* subviews = [[[controller() window] contentView] subviews];
512 ASSERT_EQ(2U, [subviews count]); 517 ASSERT_EQ(2U, [subviews count]);
513 subviews = [[subviews objectAtIndex:0] subviews]; 518 subviews = [[subviews objectAtIndex:0] subviews];
514 519
515 // There will be three buttons and two separators in the option buttons view. 520 // There will be three buttons and two separators in the option buttons view.
516 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 521 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
517 ASSERT_EQ(5U, [buttonSubviews count]); 522 ASSERT_EQ(5U, [buttonSubviews count]);
518 523
519 // There should be a lock button. 524 // There should be a lock button.
520 NSButton* lockButton = 525 NSButton* lockButton =
521 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); 526 GetButtonFromButtonContainer([buttonSubviews objectAtIndex:0]);
522 ASSERT_TRUE(lockButton); 527 ASSERT_TRUE(lockButton);
523 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); 528 EXPECT_EQ(@selector(lockProfile:), [lockButton action]);
524 EXPECT_EQ(controller(), [lockButton target]); 529 EXPECT_EQ(controller(), [lockButton target]);
525 EXPECT_TRUE([lockButton isEnabled]); 530 EXPECT_TRUE([lockButton isEnabled]);
526 } 531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698