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

Unified Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm

Issue 2396893002: Enable the MD User Menu by default on trunk. (Closed)
Patch Set: Address feedback on cocoa tests. Created 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm
index 22630a8db093e11f48ea28c9df72b31ce8a5611d..2e1bc65b9041b3bda18f1fb77df02a0ec93d5c02 100644
--- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm
@@ -105,6 +105,11 @@ class ProfileChooserControllerTest : public CocoaProfileTest {
}
void AssertRightClickTutorialShown() {
+ // The right click menu doesn't exist in the MD user menu, so it doesn't
+ // show the tutorial.
+ if (switches::IsMaterialDesignUserMenu())
+ return;
+
NSArray* subviews = [[[controller() window] contentView] subviews];
ASSERT_EQ(2U, [subviews count]);
subviews = [[subviews objectAtIndex:0] subviews];
@@ -183,7 +188,8 @@ TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) {
NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
NSButton* userSwitcherButton;
if (switches::IsMaterialDesignUserMenu()) {
- ASSERT_EQ(1U, [buttonSubviews count]);
+ // There are 2 buttons in the initial layout: "Manage People" and "Guest".
+ ASSERT_EQ(2U, [buttonSubviews count]);
// There should be a user switcher button.
userSwitcherButton =
base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
@@ -209,24 +215,28 @@ TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) {
EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]);
EXPECT_EQ(controller(), [userSwitcherButton target]);
- // There should be a separator.
- EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
+ NSUInteger lastSubviewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2;
+ NSArray* activeCardSubviews =
+ [[subviews objectAtIndex:lastSubviewIndex] subviews];
// There should be the profile avatar, name and links container in the active
// card view. The links displayed in the container are checked separately.
- NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews];
- ASSERT_EQ(3U, [activeCardSubviews count]);
-
- // Profile icon.
- NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2];
- EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]);
+ // In the MD user menu, the profile avatar and name are in the same subview.
+ if (switches::IsMaterialDesignUserMenu()) {
+ ASSERT_EQ(2U, [activeCardSubviews count]);
+ } else {
+ ASSERT_EQ(3U, [activeCardSubviews count]);
- // Profile name.
- NSView* activeProfileName = [activeCardSubviews objectAtIndex:1];
- EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]);
- EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
- [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
+ // Profile icon.
+ NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2];
+ EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]);
+ // Profile name.
+ NSView* activeProfileName = [activeCardSubviews objectAtIndex:1];
+ EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]);
+ EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
+ [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
+ }
// Profile links. This is a local profile, so there should be a signin button
// and a signin promo.
NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
@@ -283,8 +293,10 @@ TEST_F(ProfileChooserControllerTest, RightClickTutorialNotShownAfterDismiss) {
ASSERT_EQ(2U, [subviews count]);
subviews = [[subviews objectAtIndex:0] subviews];
- // There should be 3 views since there's no tutorial
- ASSERT_EQ(3U, [subviews count]);
+ // There should be 3 views since there's no tutorial. There are 2 extra
+ // buttons in the MD user menu.
+ NSUInteger viewsCount = switches::IsMaterialDesignUserMenu() ? 5 : 3;
+ ASSERT_EQ(viewsCount, [subviews count]);
// Closing and reopening the menu shouldn't show the tutorial.
[controller() close];
@@ -294,11 +306,14 @@ TEST_F(ProfileChooserControllerTest, RightClickTutorialNotShownAfterDismiss) {
ASSERT_EQ(2U, [subviews count]);
subviews = [[subviews objectAtIndex:0] subviews];
- // There should be 3 views since there's no tutorial
- ASSERT_EQ(3U, [subviews count]);
+ ASSERT_EQ(viewsCount, [subviews count]);
}
TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) {
+ // This test is related to the fast user switcher, which doesn't exist under
+ // the MD user menu.
+ if (switches::IsMaterialDesignUserMenu())
+ return;
// Add two extra profiles, to make sure sorting is alphabetical and not
// by order of creation.
testing_profile_manager()->CreateTestingProfile(
@@ -341,7 +356,11 @@ TEST_F(ProfileChooserControllerTest,
NSArray* subviews = [[[controller() window] contentView] subviews];
ASSERT_EQ(2U, [subviews count]);
subviews = [[subviews objectAtIndex:0] subviews];
- NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews];
+ // The active card is the last subview and the MD User Menu has 2 extra
+ // buttons.
+ NSUInteger lastSubviewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2;
+ NSArray* activeCardSubviews =
+ [[subviews objectAtIndex:lastSubviewIndex] subviews];
NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews];
ASSERT_EQ(2U, [activeCardLinks count]);
@@ -369,7 +388,11 @@ TEST_F(ProfileChooserControllerTest,
NSArray* subviews = [[[controller() window] contentView] subviews];
ASSERT_EQ(2U, [subviews count]);
subviews = [[subviews objectAtIndex:0] subviews];
- NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews];
+ // The active card is the last subview and the MD User Menu has 2 extra
+ // buttons.
+ NSUInteger lastSubviewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2;
+ NSArray* activeCardSubviews =
+ [[subviews objectAtIndex:lastSubviewIndex] subviews];
NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews];
// There is one link: manage accounts.
@@ -388,16 +411,25 @@ TEST_F(ProfileChooserControllerTest,
NSArray* subviews = [[[controller() window] contentView] subviews];
ASSERT_EQ(2U, [subviews count]);
subviews = [[subviews objectAtIndex:0] subviews];
- NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews];
+ // The active card is the last subview and the MD User Menu has 2 extra
+ // buttons.
+ NSUInteger lastSubviewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2;
+ NSArray* activeCardSubviews =
+ [[subviews objectAtIndex:lastSubviewIndex] subviews];
NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews];
- // There is one disabled button with the user's email.
- ASSERT_EQ(1U, [activeCardLinks count]);
- NSButton* emailButton =
- base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]);
- EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title]));
- EXPECT_EQ(nil, [emailButton action]);
- EXPECT_FALSE([emailButton isEnabled]);
+ if (switches::IsMaterialDesignUserMenu()) {
+ // There is the profile avatar and the profile name.
+ ASSERT_EQ(2U, [activeCardLinks count]);
+ } else {
+ // There is one disabled button with the user's email.
+ ASSERT_EQ(1U, [activeCardLinks count]);
+ NSButton* emailButton =
+ base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]);
+ EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title]));
+ EXPECT_EQ(nil, [emailButton action]);
+ EXPECT_FALSE([emailButton isEnabled]);
+ }
}
TEST_F(ProfileChooserControllerTest, AccountManagementLayout) {
@@ -439,14 +471,15 @@ TEST_F(ProfileChooserControllerTest, AccountManagementLayout) {
subviews = [[subviews objectAtIndex:0] subviews];
// There should be one active card, one accounts container, two separators
- // and one option buttons view.
- ASSERT_EQ(5U, [subviews count]);
+ // and one option buttons view. In the MD User Menu, there are 2 more buttons.
+ NSUInteger viewsCount = switches::IsMaterialDesignUserMenu() ? 7 : 5;
+ ASSERT_EQ(viewsCount, [subviews count]);
NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
NSButton* userSwitcherButton;
if (switches::IsMaterialDesignUserMenu()) {
- // There should be one button in the option buttons view.
- ASSERT_EQ(1U, [buttonSubviews count]);
+ // There should be two buttons in the option buttons view.
+ ASSERT_EQ(2U, [buttonSubviews count]);
// There should be a user switcher button.
userSwitcherButton =
base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
@@ -472,12 +505,11 @@ TEST_F(ProfileChooserControllerTest, AccountManagementLayout) {
EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]);
EXPECT_EQ(controller(), [userSwitcherButton target]);
- // There should be a separator.
- EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
-
+ NSUInteger accountsViewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2;
// In the accounts view, there should be the account list container
// accounts and one "add accounts" button.
- NSArray* accountsSubviews = [[subviews objectAtIndex:2] subviews];
+ NSArray* accountsSubviews =
+ [[subviews objectAtIndex:accountsViewIndex] subviews];
ASSERT_EQ(2U, [accountsSubviews count]);
NSButton* addAccountsButton =
@@ -512,25 +544,31 @@ TEST_F(ProfileChooserControllerTest, AccountManagementLayout) {
// There should be the profile avatar, name and a "hide accounts" link
// container in the active card view.
NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews];
- ASSERT_EQ(3U, [activeCardSubviews count]);
-
- // Profile icon.
- NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2];
- EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]);
-
- // Profile name.
- NSView* activeProfileName = [activeCardSubviews objectAtIndex:1];
- EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]);
- EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
- [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
-
- // Profile links. This is a local profile, so there should be a signin button.
- NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
- ASSERT_EQ(1U, [linksSubviews count]);
- NSButton* link = base::mac::ObjCCast<NSButton>(
- [linksSubviews objectAtIndex:0]);
- EXPECT_EQ(@selector(hideAccountManagement:), [link action]);
- EXPECT_EQ(controller(), [link target]);
+ if (switches::IsMaterialDesignUserMenu()) {
+ // In the MD user menu, the profile name and avatar are in the same subview.
+ ASSERT_EQ(2U, [activeCardSubviews count]);
+ } else {
+ ASSERT_EQ(3U, [activeCardSubviews count]);
+
+ // Profile icon.
+ NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2];
+ EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]);
+
+ // Profile name.
+ NSView* activeProfileName = [activeCardSubviews objectAtIndex:1];
+ EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]);
+ EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
+ [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
+
+ // Profile links. This is a local profile, so there should be a signin
+ // button.
+ NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
+ ASSERT_EQ(1U, [linksSubviews count]);
+ NSButton* link = base::mac::ObjCCast<NSButton>(
+ [linksSubviews objectAtIndex:0]);
+ EXPECT_EQ(@selector(hideAccountManagement:), [link action]);
+ EXPECT_EQ(controller(), [link target]);
+ }
}
TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) {
@@ -550,8 +588,8 @@ TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) {
NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
if (switches::IsMaterialDesignUserMenu()) {
- // There will be one button in the option buttons view.
- ASSERT_EQ(1U, [buttonSubviews count]);
+ // There will be two buttons in the option buttons view.
+ ASSERT_EQ(2U, [buttonSubviews count]);
} else {
// For non-material-design user menu, there will be two buttons and one
// separators in the option buttons view.

Powered by Google App Engine
This is Rietveld 408576698