Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 anchoredAt:point | 98 anchoredAt:point |
| 99 viewMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER | 99 viewMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER |
| 100 tutorialMode:mode | 100 tutorialMode:mode |
| 101 serviceType:signin::GAIA_SERVICE_TYPE_NONE | 101 serviceType:signin::GAIA_SERVICE_TYPE_NONE |
| 102 accessPoint:signin_metrics::AccessPoint:: | 102 accessPoint:signin_metrics::AccessPoint:: |
| 103 ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN]); | 103 ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN]); |
| 104 [controller_ showWindow:nil]; | 104 [controller_ showWindow:nil]; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void AssertRightClickTutorialShown() { | 107 void AssertRightClickTutorialShown() { |
| 108 // The right click menu doesn't exist in the MD user menu, so it doesn't | |
| 109 // show the tutorial. | |
| 110 if (switches::IsMaterialDesignUserMenu()) | |
| 111 return; | |
| 112 | |
| 108 NSArray* subviews = [[[controller() window] contentView] subviews]; | 113 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 109 ASSERT_EQ(2U, [subviews count]); | 114 ASSERT_EQ(2U, [subviews count]); |
| 110 subviews = [[subviews objectAtIndex:0] subviews]; | 115 subviews = [[subviews objectAtIndex:0] subviews]; |
| 111 | 116 |
| 112 // There should be 4 views: the tutorial, the active profile card, a | 117 // There should be 4 views: the tutorial, the active profile card, a |
| 113 // separator and the options view. | 118 // separator and the options view. |
| 114 ASSERT_EQ(4U, [subviews count]); | 119 ASSERT_EQ(4U, [subviews count]); |
| 115 | 120 |
| 116 // The tutorial is the topmost view, so the last in the array. It should | 121 // The tutorial is the topmost view, so the last in the array. It should |
| 117 // contain 3 views: the title, the content text and the OK button. | 122 // contain 3 views: the title, the content text and the OK button. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 // one option buttons view. We also have an update promo for the new avatar | 181 // one option buttons view. We also have an update promo for the new avatar |
| 177 // menu. | 182 // menu. |
| 178 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not | 183 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not |
| 179 // reproducible anywhere else. | 184 // reproducible anywhere else. |
| 180 ASSERT_GE([subviews count], 3U); | 185 ASSERT_GE([subviews count], 3U); |
| 181 | 186 |
| 182 // There should be one button in the option buttons view. | 187 // There should be one button in the option buttons view. |
| 183 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 188 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
| 184 NSButton* userSwitcherButton; | 189 NSButton* userSwitcherButton; |
| 185 if (switches::IsMaterialDesignUserMenu()) { | 190 if (switches::IsMaterialDesignUserMenu()) { |
| 186 ASSERT_EQ(1U, [buttonSubviews count]); | 191 // There are 2 buttons in the initial layout: "Manage People" and "Guest". |
| 192 ASSERT_EQ(2U, [buttonSubviews count]); | |
| 187 // There should be a user switcher button. | 193 // There should be a user switcher button. |
| 188 userSwitcherButton = | 194 userSwitcherButton = |
| 189 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 195 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 190 } else { | 196 } else { |
| 191 // For non-material-design user menu, there should be two buttons and a | 197 // For non-material-design user menu, there should be two buttons and a |
| 192 // separator in the option buttons view. | 198 // separator in the option buttons view. |
| 193 ASSERT_EQ(3U, [buttonSubviews count]); | 199 ASSERT_EQ(3U, [buttonSubviews count]); |
| 194 | 200 |
| 195 // There should be an incognito button. | 201 // There should be an incognito button. |
| 196 NSButton* incognitoButton = | 202 NSButton* incognitoButton = |
| 197 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 203 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 198 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); | 204 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); |
| 199 EXPECT_EQ(controller(), [incognitoButton target]); | 205 EXPECT_EQ(controller(), [incognitoButton target]); |
| 200 | 206 |
| 201 // There should be a separator. | 207 // There should be a separator. |
| 202 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | 208 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); |
| 203 | 209 |
| 204 // There should be a user switcher button. | 210 // There should be a user switcher button. |
| 205 userSwitcherButton = | 211 userSwitcherButton = |
| 206 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); | 212 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); |
| 207 } | 213 } |
| 208 | 214 |
| 209 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); | 215 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); |
| 210 EXPECT_EQ(controller(), [userSwitcherButton target]); | 216 EXPECT_EQ(controller(), [userSwitcherButton target]); |
| 211 | 217 |
| 212 // There should be a separator. | 218 NSUInteger last_subview_index = switches::IsMaterialDesignUserMenu() ? 4 : 2; |
|
Robert Sesek
2016/10/06 18:49:35
These tests are incorrectly using camelCase for va
anthonyvd
2016/10/06 19:06:15
Ahh, makes sense! Done everywhere.
| |
| 213 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | 219 NSArray* activeCardSubviews = |
| 220 [[subviews objectAtIndex:last_subview_index] subviews]; | |
| 214 | 221 |
| 215 // There should be the profile avatar, name and links container in the active | 222 // There should be the profile avatar, name and links container in the active |
| 216 // card view. The links displayed in the container are checked separately. | 223 // card view. The links displayed in the container are checked separately. |
| 217 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 224 // In the MD user menu, the profile avatar and name are in the same subview. |
| 218 ASSERT_EQ(3U, [activeCardSubviews count]); | 225 if (switches::IsMaterialDesignUserMenu()) { |
| 226 ASSERT_EQ(2U, [activeCardSubviews count]); | |
| 227 } else { | |
| 228 ASSERT_EQ(3U, [activeCardSubviews count]); | |
| 219 | 229 |
| 220 // Profile icon. | 230 // Profile icon. |
| 221 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; | 231 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; |
| 222 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]); | 232 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]); |
| 223 | 233 |
| 224 // Profile name. | 234 // Profile name. |
| 225 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; | 235 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; |
| 226 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | 236 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
| 227 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 237 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 228 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); | 238 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); |
| 229 | 239 } |
| 230 // Profile links. This is a local profile, so there should be a signin button | 240 // Profile links. This is a local profile, so there should be a signin button |
| 231 // and a signin promo. | 241 // and a signin promo. |
| 232 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 242 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 233 ASSERT_EQ(2U, [linksSubviews count]); | 243 ASSERT_EQ(2U, [linksSubviews count]); |
| 234 NSButton* link = base::mac::ObjCCast<NSButton>( | 244 NSButton* link = base::mac::ObjCCast<NSButton>( |
| 235 [linksSubviews objectAtIndex:0]); | 245 [linksSubviews objectAtIndex:0]); |
| 236 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); | 246 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
| 237 EXPECT_EQ(controller(), [link target]); | 247 EXPECT_EQ(controller(), [link target]); |
| 238 | 248 |
| 239 NSTextField* promo = base::mac::ObjCCast<NSTextField>( | 249 NSTextField* promo = base::mac::ObjCCast<NSTextField>( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 StartProfileChooserControllerWithTutorialMode( | 286 StartProfileChooserControllerWithTutorialMode( |
| 277 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); | 287 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); |
| 278 AssertRightClickTutorialShown(); | 288 AssertRightClickTutorialShown(); |
| 279 | 289 |
| 280 // Dismissing the tutorial should prevent it from being shown forever. | 290 // Dismissing the tutorial should prevent it from being shown forever. |
| 281 [controller() dismissTutorial:nil]; | 291 [controller() dismissTutorial:nil]; |
| 282 NSArray* subviews = [[[controller() window] contentView] subviews]; | 292 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 283 ASSERT_EQ(2U, [subviews count]); | 293 ASSERT_EQ(2U, [subviews count]); |
| 284 subviews = [[subviews objectAtIndex:0] subviews]; | 294 subviews = [[subviews objectAtIndex:0] subviews]; |
| 285 | 295 |
| 286 // There should be 3 views since there's no tutorial | 296 // There should be 3 views since there's no tutorial. There are 2 extra |
| 287 ASSERT_EQ(3U, [subviews count]); | 297 // buttons in the MD user menu. |
| 298 auto views_count = switches::IsMaterialDesignUserMenu() ? 5U : 3U; | |
|
Robert Sesek
2016/10/06 18:49:35
Use NSUInteger instead of auto and drop the 'U's?
anthonyvd
2016/10/06 19:06:15
Done.
| |
| 299 ASSERT_EQ(views_count, [subviews count]); | |
| 288 | 300 |
| 289 // Closing and reopening the menu shouldn't show the tutorial. | 301 // Closing and reopening the menu shouldn't show the tutorial. |
| 290 [controller() close]; | 302 [controller() close]; |
| 291 StartProfileChooserControllerWithTutorialMode( | 303 StartProfileChooserControllerWithTutorialMode( |
| 292 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); | 304 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); |
| 293 subviews = [[[controller() window] contentView] subviews]; | 305 subviews = [[[controller() window] contentView] subviews]; |
| 294 ASSERT_EQ(2U, [subviews count]); | 306 ASSERT_EQ(2U, [subviews count]); |
| 295 subviews = [[subviews objectAtIndex:0] subviews]; | 307 subviews = [[subviews objectAtIndex:0] subviews]; |
| 296 | 308 |
| 297 // There should be 3 views since there's no tutorial | 309 ASSERT_EQ(views_count, [subviews count]); |
| 298 ASSERT_EQ(3U, [subviews count]); | |
| 299 } | 310 } |
| 300 | 311 |
| 301 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { | 312 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { |
| 313 // This test is related to the fast user switcher, which doesn't exist under | |
| 314 // the MD user menu. | |
| 315 if (switches::IsMaterialDesignUserMenu()) | |
| 316 return; | |
| 302 // Add two extra profiles, to make sure sorting is alphabetical and not | 317 // Add two extra profiles, to make sure sorting is alphabetical and not |
| 303 // by order of creation. | 318 // by order of creation. |
| 304 testing_profile_manager()->CreateTestingProfile( | 319 testing_profile_manager()->CreateTestingProfile( |
| 305 "test3", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 320 "test3", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), |
| 306 base::ASCIIToUTF16("New Profile"), 1, std::string(), | 321 base::ASCIIToUTF16("New Profile"), 1, std::string(), |
| 307 TestingProfile::TestingFactories()); | 322 TestingProfile::TestingFactories()); |
| 308 testing_profile_manager()->CreateTestingProfile( | 323 testing_profile_manager()->CreateTestingProfile( |
| 309 "test4", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 324 "test4", std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), |
| 310 base::ASCIIToUTF16("Another Test"), 1, std::string(), | 325 base::ASCIIToUTF16("Another Test"), 1, std::string(), |
| 311 TestingProfile::TestingFactories()); | 326 TestingProfile::TestingFactories()); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 334 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); | 349 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); |
| 335 } | 350 } |
| 336 } | 351 } |
| 337 | 352 |
| 338 TEST_F(ProfileChooserControllerTest, | 353 TEST_F(ProfileChooserControllerTest, |
| 339 LocalProfileActiveCardLinksWithNewMenu) { | 354 LocalProfileActiveCardLinksWithNewMenu) { |
| 340 StartProfileChooserController(); | 355 StartProfileChooserController(); |
| 341 NSArray* subviews = [[[controller() window] contentView] subviews]; | 356 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 342 ASSERT_EQ(2U, [subviews count]); | 357 ASSERT_EQ(2U, [subviews count]); |
| 343 subviews = [[subviews objectAtIndex:0] subviews]; | 358 subviews = [[subviews objectAtIndex:0] subviews]; |
| 344 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 359 // The active card is the last subview and the MD User Menu has 2 extra |
| 360 // buttons. | |
| 361 NSUInteger last_subview_index = switches::IsMaterialDesignUserMenu() ? 4 : 2; | |
| 362 NSArray* activeCardSubviews = | |
| 363 [[subviews objectAtIndex:last_subview_index] subviews]; | |
| 345 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 364 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 346 | 365 |
| 347 ASSERT_EQ(2U, [activeCardLinks count]); | 366 ASSERT_EQ(2U, [activeCardLinks count]); |
| 348 | 367 |
| 349 // There should be a sign in button. | 368 // There should be a sign in button. |
| 350 NSButton* link = base::mac::ObjCCast<NSButton>( | 369 NSButton* link = base::mac::ObjCCast<NSButton>( |
| 351 [activeCardLinks objectAtIndex:0]); | 370 [activeCardLinks objectAtIndex:0]); |
| 352 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); | 371 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
| 353 EXPECT_EQ(controller(), [link target]); | 372 EXPECT_EQ(controller(), [link target]); |
| 354 | 373 |
| 355 // Local profiles have a signin promo. | 374 // Local profiles have a signin promo. |
| 356 NSTextField* promo = base::mac::ObjCCast<NSTextField>( | 375 NSTextField* promo = base::mac::ObjCCast<NSTextField>( |
| 357 [activeCardLinks objectAtIndex:1]); | 376 [activeCardLinks objectAtIndex:1]); |
| 358 EXPECT_GT([[promo stringValue] length], 0U); | 377 EXPECT_GT([[promo stringValue] length], 0U); |
| 359 } | 378 } |
| 360 | 379 |
| 361 TEST_F(ProfileChooserControllerTest, | 380 TEST_F(ProfileChooserControllerTest, |
| 362 SignedInProfileActiveCardLinksWithAccountConsistency) { | 381 SignedInProfileActiveCardLinksWithAccountConsistency) { |
| 363 switches::EnableAccountConsistencyForTesting( | 382 switches::EnableAccountConsistencyForTesting( |
| 364 base::CommandLine::ForCurrentProcess()); | 383 base::CommandLine::ForCurrentProcess()); |
| 365 | 384 |
| 366 SignInFirstProfile(); | 385 SignInFirstProfile(); |
| 367 | 386 |
| 368 StartProfileChooserController(); | 387 StartProfileChooserController(); |
| 369 NSArray* subviews = [[[controller() window] contentView] subviews]; | 388 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 370 ASSERT_EQ(2U, [subviews count]); | 389 ASSERT_EQ(2U, [subviews count]); |
| 371 subviews = [[subviews objectAtIndex:0] subviews]; | 390 subviews = [[subviews objectAtIndex:0] subviews]; |
| 372 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 391 // The active card is the last subview and the MD User Menu has 2 extra |
| 392 // buttons. | |
| 393 NSUInteger last_subview_index = switches::IsMaterialDesignUserMenu() ? 4 : 2; | |
| 394 NSArray* activeCardSubviews = | |
| 395 [[subviews objectAtIndex:last_subview_index] subviews]; | |
| 373 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 396 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 374 | 397 |
| 375 // There is one link: manage accounts. | 398 // There is one link: manage accounts. |
| 376 ASSERT_EQ(1U, [activeCardLinks count]); | 399 ASSERT_EQ(1U, [activeCardLinks count]); |
| 377 NSButton* manageAccountsLink = | 400 NSButton* manageAccountsLink = |
| 378 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); | 401 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); |
| 379 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); | 402 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); |
| 380 EXPECT_EQ(controller(), [manageAccountsLink target]); | 403 EXPECT_EQ(controller(), [manageAccountsLink target]); |
| 381 } | 404 } |
| 382 | 405 |
| 383 TEST_F(ProfileChooserControllerTest, | 406 TEST_F(ProfileChooserControllerTest, |
| 384 SignedInProfileActiveCardLinksWithNewMenu) { | 407 SignedInProfileActiveCardLinksWithNewMenu) { |
| 385 SignInFirstProfile(); | 408 SignInFirstProfile(); |
| 386 | 409 |
| 387 StartProfileChooserController(); | 410 StartProfileChooserController(); |
| 388 NSArray* subviews = [[[controller() window] contentView] subviews]; | 411 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 389 ASSERT_EQ(2U, [subviews count]); | 412 ASSERT_EQ(2U, [subviews count]); |
| 390 subviews = [[subviews objectAtIndex:0] subviews]; | 413 subviews = [[subviews objectAtIndex:0] subviews]; |
| 391 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 414 // The active card is the last subview and the MD User Menu has 2 extra |
| 415 // buttons. | |
| 416 NSUInteger last_subview_index = switches::IsMaterialDesignUserMenu() ? 4 : 2; | |
| 417 NSArray* activeCardSubviews = | |
| 418 [[subviews objectAtIndex:last_subview_index] subviews]; | |
| 392 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 419 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 393 | 420 |
| 394 // There is one disabled button with the user's email. | 421 if (switches::IsMaterialDesignUserMenu()) { |
| 395 ASSERT_EQ(1U, [activeCardLinks count]); | 422 // There is the profile avatar and the profile name. |
| 396 NSButton* emailButton = | 423 ASSERT_EQ(2U, [activeCardLinks count]); |
| 397 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); | 424 } else { |
| 398 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title])); | 425 // There is one disabled button with the user's email. |
| 399 EXPECT_EQ(nil, [emailButton action]); | 426 ASSERT_EQ(1U, [activeCardLinks count]); |
| 400 EXPECT_FALSE([emailButton isEnabled]); | 427 NSButton* emailButton = |
| 428 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); | |
| 429 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title])); | |
| 430 EXPECT_EQ(nil, [emailButton action]); | |
| 431 EXPECT_FALSE([emailButton isEnabled]); | |
| 432 } | |
| 401 } | 433 } |
| 402 | 434 |
| 403 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { | 435 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { |
| 404 switches::EnableAccountConsistencyForTesting( | 436 switches::EnableAccountConsistencyForTesting( |
| 405 base::CommandLine::ForCurrentProcess()); | 437 base::CommandLine::ForCurrentProcess()); |
| 406 | 438 |
| 407 SignInFirstProfile(); | 439 SignInFirstProfile(); |
| 408 | 440 |
| 409 // Mark that we are using the profile name on purpose, so that we don't | 441 // Mark that we are using the profile name on purpose, so that we don't |
| 410 // fallback to testing the algorithm that chooses which default name | 442 // fallback to testing the algorithm that chooses which default name |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 432 | 464 |
| 433 StartProfileChooserController(); | 465 StartProfileChooserController(); |
| 434 [controller() initMenuContentsWithView: | 466 [controller() initMenuContentsWithView: |
| 435 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 467 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
| 436 | 468 |
| 437 NSArray* subviews = [[[controller() window] contentView] subviews]; | 469 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 438 ASSERT_EQ(2U, [subviews count]); | 470 ASSERT_EQ(2U, [subviews count]); |
| 439 subviews = [[subviews objectAtIndex:0] subviews]; | 471 subviews = [[subviews objectAtIndex:0] subviews]; |
| 440 | 472 |
| 441 // There should be one active card, one accounts container, two separators | 473 // There should be one active card, one accounts container, two separators |
| 442 // and one option buttons view. | 474 // and one option buttons view. In the MD User Menu, there are 2 more buttons. |
| 443 ASSERT_EQ(5U, [subviews count]); | 475 auto views_count = switches::IsMaterialDesignUserMenu() ? 7U : 5U; |
| 476 ASSERT_EQ(views_count, [subviews count]); | |
| 444 | 477 |
| 445 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 478 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
| 446 NSButton* userSwitcherButton; | 479 NSButton* userSwitcherButton; |
| 447 if (switches::IsMaterialDesignUserMenu()) { | 480 if (switches::IsMaterialDesignUserMenu()) { |
| 448 // There should be one button in the option buttons view. | 481 // There should be two buttons in the option buttons view. |
| 449 ASSERT_EQ(1U, [buttonSubviews count]); | 482 ASSERT_EQ(2U, [buttonSubviews count]); |
| 450 // There should be a user switcher button. | 483 // There should be a user switcher button. |
| 451 userSwitcherButton = | 484 userSwitcherButton = |
| 452 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 485 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 453 } else { | 486 } else { |
| 454 // For non-material-design user menu, there should be two buttons and one | 487 // For non-material-design user menu, there should be two buttons and one |
| 455 // separator in the option buttons view. | 488 // separator in the option buttons view. |
| 456 ASSERT_EQ(3U, [buttonSubviews count]); | 489 ASSERT_EQ(3U, [buttonSubviews count]); |
| 457 | 490 |
| 458 // There should be an incognito button. | 491 // There should be an incognito button. |
| 459 NSButton* incognitoButton = | 492 NSButton* incognitoButton = |
| 460 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 493 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 461 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); | 494 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); |
| 462 EXPECT_EQ(controller(), [incognitoButton target]); | 495 EXPECT_EQ(controller(), [incognitoButton target]); |
| 463 | 496 |
| 464 // There should be a separator. | 497 // There should be a separator. |
| 465 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | 498 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]); |
| 466 | 499 |
| 467 // There should be a user switcher button. | 500 // There should be a user switcher button. |
| 468 userSwitcherButton = | 501 userSwitcherButton = |
| 469 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); | 502 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); |
| 470 } | 503 } |
| 471 | 504 |
| 472 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); | 505 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); |
| 473 EXPECT_EQ(controller(), [userSwitcherButton target]); | 506 EXPECT_EQ(controller(), [userSwitcherButton target]); |
| 474 | 507 |
| 475 // There should be a separator. | 508 NSUInteger accounts_view_index = switches::IsMaterialDesignUserMenu() ? 4 : 2; |
| 476 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | |
| 477 | |
| 478 // In the accounts view, there should be the account list container | 509 // In the accounts view, there should be the account list container |
| 479 // accounts and one "add accounts" button. | 510 // accounts and one "add accounts" button. |
| 480 NSArray* accountsSubviews = [[subviews objectAtIndex:2] subviews]; | 511 NSArray* accountsSubviews = |
| 512 [[subviews objectAtIndex:accounts_view_index] subviews]; | |
| 481 ASSERT_EQ(2U, [accountsSubviews count]); | 513 ASSERT_EQ(2U, [accountsSubviews count]); |
| 482 | 514 |
| 483 NSButton* addAccountsButton = | 515 NSButton* addAccountsButton = |
| 484 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]); | 516 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]); |
| 485 EXPECT_EQ(@selector(addAccount:), [addAccountsButton action]); | 517 EXPECT_EQ(@selector(addAccount:), [addAccountsButton action]); |
| 486 EXPECT_EQ(controller(), [addAccountsButton target]); | 518 EXPECT_EQ(controller(), [addAccountsButton target]); |
| 487 | 519 |
| 488 // There should be two accounts in the account list container. | 520 // There should be two accounts in the account list container. |
| 489 NSArray* accountsListSubviews = [[accountsSubviews objectAtIndex:1] subviews]; | 521 NSArray* accountsListSubviews = [[accountsSubviews objectAtIndex:1] subviews]; |
| 490 ASSERT_EQ(2U, [accountsListSubviews count]); | 522 ASSERT_EQ(2U, [accountsListSubviews count]); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 505 EXPECT_EQ(@selector(showAccountRemovalView:), [primaryAccountDelete action]); | 537 EXPECT_EQ(@selector(showAccountRemovalView:), [primaryAccountDelete action]); |
| 506 EXPECT_EQ(controller(), [primaryAccountDelete target]); | 538 EXPECT_EQ(controller(), [primaryAccountDelete target]); |
| 507 EXPECT_EQ(-1, [primaryAccountDelete tag]); | 539 EXPECT_EQ(-1, [primaryAccountDelete tag]); |
| 508 | 540 |
| 509 // There should be another separator. | 541 // There should be another separator. |
| 510 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); | 542 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); |
| 511 | 543 |
| 512 // There should be the profile avatar, name and a "hide accounts" link | 544 // There should be the profile avatar, name and a "hide accounts" link |
| 513 // container in the active card view. | 545 // container in the active card view. |
| 514 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; | 546 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; |
| 515 ASSERT_EQ(3U, [activeCardSubviews count]); | 547 if (switches::IsMaterialDesignUserMenu()) { |
| 548 // In the MD user menu, the profile name and avatar are in the same subview. | |
| 549 ASSERT_EQ(2U, [activeCardSubviews count]); | |
| 550 } else { | |
| 551 ASSERT_EQ(3U, [activeCardSubviews count]); | |
| 516 | 552 |
| 517 // Profile icon. | 553 // Profile icon. |
| 518 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; | 554 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; |
| 519 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]); | 555 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]); |
| 520 | 556 |
| 521 // Profile name. | 557 // Profile name. |
| 522 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; | 558 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; |
| 523 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | 559 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
| 524 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 560 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 525 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); | 561 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); |
| 526 | 562 |
| 527 // Profile links. This is a local profile, so there should be a signin button. | 563 // Profile links. This is a local profile, so there should be a signin |
| 528 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 564 // button. |
| 529 ASSERT_EQ(1U, [linksSubviews count]); | 565 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 530 NSButton* link = base::mac::ObjCCast<NSButton>( | 566 ASSERT_EQ(1U, [linksSubviews count]); |
| 531 [linksSubviews objectAtIndex:0]); | 567 NSButton* link = base::mac::ObjCCast<NSButton>( |
| 532 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); | 568 [linksSubviews objectAtIndex:0]); |
| 533 EXPECT_EQ(controller(), [link target]); | 569 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); |
| 570 EXPECT_EQ(controller(), [link target]); | |
| 571 } | |
| 534 } | 572 } |
| 535 | 573 |
| 536 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) { | 574 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) { |
| 537 switches::EnableNewProfileManagementForTesting( | 575 switches::EnableNewProfileManagementForTesting( |
| 538 base::CommandLine::ForCurrentProcess()); | 576 base::CommandLine::ForCurrentProcess()); |
| 539 | 577 |
| 540 SignInFirstProfile(); | 578 SignInFirstProfile(); |
| 541 | 579 |
| 542 // The preference, not the email, determines whether the profile can lock. | 580 // The preference, not the email, determines whether the profile can lock. |
| 543 browser()->profile()->GetPrefs()->SetString( | 581 browser()->profile()->GetPrefs()->SetString( |
| 544 prefs::kGoogleServicesHostedDomain, "chromium.org"); | 582 prefs::kGoogleServicesHostedDomain, "chromium.org"); |
| 545 | 583 |
| 546 StartProfileChooserController(); | 584 StartProfileChooserController(); |
| 547 NSArray* subviews = [[[controller() window] contentView] subviews]; | 585 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 548 ASSERT_EQ(2U, [subviews count]); | 586 ASSERT_EQ(2U, [subviews count]); |
| 549 subviews = [[subviews objectAtIndex:0] subviews]; | 587 subviews = [[subviews objectAtIndex:0] subviews]; |
| 550 | 588 |
| 551 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 589 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
| 552 if (switches::IsMaterialDesignUserMenu()) { | 590 if (switches::IsMaterialDesignUserMenu()) { |
| 553 // There will be one button in the option buttons view. | 591 // There will be two buttons in the option buttons view. |
| 554 ASSERT_EQ(1U, [buttonSubviews count]); | 592 ASSERT_EQ(2U, [buttonSubviews count]); |
| 555 } else { | 593 } else { |
| 556 // For non-material-design user menu, there will be two buttons and one | 594 // For non-material-design user menu, there will be two buttons and one |
| 557 // separators in the option buttons view. | 595 // separators in the option buttons view. |
| 558 ASSERT_EQ(3U, [buttonSubviews count]); | 596 ASSERT_EQ(3U, [buttonSubviews count]); |
| 559 } | 597 } |
| 560 | 598 |
| 561 // The last button should not be the lock button. | 599 // The last button should not be the lock button. |
| 562 NSButton* lastButton = | 600 NSButton* lastButton = |
| 563 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 601 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 564 ASSERT_TRUE(lastButton); | 602 ASSERT_TRUE(lastButton); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 595 } | 633 } |
| 596 | 634 |
| 597 // There should be a lock button. | 635 // There should be a lock button. |
| 598 NSButton* lockButton = | 636 NSButton* lockButton = |
| 599 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 637 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 600 ASSERT_TRUE(lockButton); | 638 ASSERT_TRUE(lockButton); |
| 601 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | 639 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); |
| 602 EXPECT_EQ(controller(), [lockButton target]); | 640 EXPECT_EQ(controller(), [lockButton target]); |
| 603 EXPECT_TRUE([lockButton isEnabled]); | 641 EXPECT_TRUE([lockButton isEnabled]); |
| 604 } | 642 } |
| OLD | NEW |