| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 private: | 143 private: |
| 144 base::scoped_nsobject<ProfileChooserController> controller_; | 144 base::scoped_nsobject<ProfileChooserController> controller_; |
| 145 | 145 |
| 146 // Weak; owned by |controller_|. | 146 // Weak; owned by |controller_|. |
| 147 AvatarMenu* menu_; | 147 AvatarMenu* menu_; |
| 148 | 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); | 149 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { | 152 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { |
| 153 switches::EnableNewAvatarMenuForTesting( | |
| 154 base::CommandLine::ForCurrentProcess()); | |
| 155 StartProfileChooserController(); | 153 StartProfileChooserController(); |
| 156 | 154 |
| 157 NSArray* subviews = [[[controller() window] contentView] subviews]; | 155 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 158 ASSERT_EQ(2U, [subviews count]); | 156 ASSERT_EQ(2U, [subviews count]); |
| 159 subviews = [[subviews objectAtIndex:0] subviews]; | 157 subviews = [[subviews objectAtIndex:0] subviews]; |
| 160 | 158 |
| 161 // Three profiles means we should have one active card, one separator and | 159 // Three profiles means we should have one active card, one separator and |
| 162 // one option buttons view. We also have an update promo for the new avatar | 160 // one option buttons view. We also have an update promo for the new avatar |
| 163 // menu. | 161 // menu. |
| 164 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not | 162 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 [linksSubviews objectAtIndex:0]); | 208 [linksSubviews objectAtIndex:0]); |
| 211 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); | 209 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
| 212 EXPECT_EQ(controller(), [link target]); | 210 EXPECT_EQ(controller(), [link target]); |
| 213 | 211 |
| 214 NSTextField* promo = base::mac::ObjCCast<NSTextField>( | 212 NSTextField* promo = base::mac::ObjCCast<NSTextField>( |
| 215 [linksSubviews objectAtIndex:1]); | 213 [linksSubviews objectAtIndex:1]); |
| 216 EXPECT_GT([[promo stringValue] length], 0U); | 214 EXPECT_GT([[promo stringValue] length], 0U); |
| 217 } | 215 } |
| 218 | 216 |
| 219 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterWelcome) { | 217 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterWelcome) { |
| 220 switches::EnableNewAvatarMenuForTesting( | |
| 221 base::CommandLine::ForCurrentProcess()); | |
| 222 // The welcome upgrade tutorial takes precedence so show it then dismiss it. | 218 // The welcome upgrade tutorial takes precedence so show it then dismiss it. |
| 223 // The right click tutorial should be shown right away. | 219 // The right click tutorial should be shown right away. |
| 224 StartProfileChooserControllerWithTutorialMode( | 220 StartProfileChooserControllerWithTutorialMode( |
| 225 profiles::TUTORIAL_MODE_WELCOME_UPGRADE); | 221 profiles::TUTORIAL_MODE_WELCOME_UPGRADE); |
| 226 | 222 |
| 227 [controller() dismissTutorial:nil]; | 223 [controller() dismissTutorial:nil]; |
| 228 AssertRightClickTutorialShown(); | 224 AssertRightClickTutorialShown(); |
| 229 } | 225 } |
| 230 | 226 |
| 231 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterReopen) { | 227 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterReopen) { |
| 232 switches::EnableNewAvatarMenuForTesting( | |
| 233 base::CommandLine::ForCurrentProcess()); | |
| 234 // The welcome upgrade tutorial takes precedence so show it then close the | 228 // The welcome upgrade tutorial takes precedence so show it then close the |
| 235 // menu. Reopening the menu should show the tutorial. | 229 // menu. Reopening the menu should show the tutorial. |
| 236 StartProfileChooserController(); | 230 StartProfileChooserController(); |
| 237 | 231 |
| 238 [controller() close]; | 232 [controller() close]; |
| 239 StartProfileChooserController(); | 233 StartProfileChooserController(); |
| 240 AssertRightClickTutorialShown(); | 234 AssertRightClickTutorialShown(); |
| 241 | 235 |
| 242 // The tutorial must be manually dismissed so it should still be shown after | 236 // The tutorial must be manually dismissed so it should still be shown after |
| 243 // closing and reopening the menu, | 237 // closing and reopening the menu, |
| 244 [controller() close]; | 238 [controller() close]; |
| 245 StartProfileChooserController(); | 239 StartProfileChooserController(); |
| 246 AssertRightClickTutorialShown(); | 240 AssertRightClickTutorialShown(); |
| 247 } | 241 } |
| 248 | 242 |
| 249 TEST_F(ProfileChooserControllerTest, RightClickTutorialNotShownAfterDismiss) { | 243 TEST_F(ProfileChooserControllerTest, RightClickTutorialNotShownAfterDismiss) { |
| 250 switches::EnableNewAvatarMenuForTesting( | |
| 251 base::CommandLine::ForCurrentProcess()); | |
| 252 // The welcome upgrade tutorial takes precedence so show it then close the | 244 // The welcome upgrade tutorial takes precedence so show it then close the |
| 253 // menu. Reopening the menu should show the tutorial. | 245 // menu. Reopening the menu should show the tutorial. |
| 254 StartProfileChooserController(); | 246 StartProfileChooserController(); |
| 255 | 247 |
| 256 [controller() close]; | 248 [controller() close]; |
| 257 StartProfileChooserControllerWithTutorialMode( | 249 StartProfileChooserControllerWithTutorialMode( |
| 258 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); | 250 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); |
| 259 AssertRightClickTutorialShown(); | 251 AssertRightClickTutorialShown(); |
| 260 | 252 |
| 261 // Dismissing the tutorial should prevent it from being shown forever. | 253 // Dismissing the tutorial should prevent it from being shown forever. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 273 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); | 265 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); |
| 274 subviews = [[[controller() window] contentView] subviews]; | 266 subviews = [[[controller() window] contentView] subviews]; |
| 275 ASSERT_EQ(2U, [subviews count]); | 267 ASSERT_EQ(2U, [subviews count]); |
| 276 subviews = [[subviews objectAtIndex:0] subviews]; | 268 subviews = [[subviews objectAtIndex:0] subviews]; |
| 277 | 269 |
| 278 // There should be 3 views since there's no tutorial | 270 // There should be 3 views since there's no tutorial |
| 279 ASSERT_EQ(3U, [subviews count]); | 271 ASSERT_EQ(3U, [subviews count]); |
| 280 } | 272 } |
| 281 | 273 |
| 282 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { | 274 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { |
| 283 switches::EnableNewAvatarMenuForTesting( | |
| 284 base::CommandLine::ForCurrentProcess()); | |
| 285 | |
| 286 // Add two extra profiles, to make sure sorting is alphabetical and not | 275 // Add two extra profiles, to make sure sorting is alphabetical and not |
| 287 // by order of creation. | 276 // by order of creation. |
| 288 testing_profile_manager()->CreateTestingProfile( | 277 testing_profile_manager()->CreateTestingProfile( |
| 289 "test3", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), | 278 "test3", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), |
| 290 base::ASCIIToUTF16("New Profile"), 1, std::string(), | 279 base::ASCIIToUTF16("New Profile"), 1, std::string(), |
| 291 TestingProfile::TestingFactories()); | 280 TestingProfile::TestingFactories()); |
| 292 testing_profile_manager()->CreateTestingProfile( | 281 testing_profile_manager()->CreateTestingProfile( |
| 293 "test4", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), | 282 "test4", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), |
| 294 base::ASCIIToUTF16("Another Test"), 1, std::string(), | 283 base::ASCIIToUTF16("Another Test"), 1, std::string(), |
| 295 TestingProfile::TestingFactories()); | 284 TestingProfile::TestingFactories()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 314 // The item at index i is the separator. | 303 // The item at index i is the separator. |
| 315 NSButton* button = base::mac::ObjCCast<NSButton>( | 304 NSButton* button = base::mac::ObjCCast<NSButton>( |
| 316 [subviews objectAtIndex:i-1]); | 305 [subviews objectAtIndex:i-1]); |
| 317 EXPECT_TRUE( | 306 EXPECT_TRUE( |
| 318 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); | 307 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); |
| 319 } | 308 } |
| 320 } | 309 } |
| 321 | 310 |
| 322 TEST_F(ProfileChooserControllerTest, | 311 TEST_F(ProfileChooserControllerTest, |
| 323 LocalProfileActiveCardLinksWithNewMenu) { | 312 LocalProfileActiveCardLinksWithNewMenu) { |
| 324 switches::EnableNewAvatarMenuForTesting( | |
| 325 base::CommandLine::ForCurrentProcess()); | |
| 326 StartProfileChooserController(); | 313 StartProfileChooserController(); |
| 327 NSArray* subviews = [[[controller() window] contentView] subviews]; | 314 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 328 ASSERT_EQ(2U, [subviews count]); | 315 ASSERT_EQ(2U, [subviews count]); |
| 329 subviews = [[subviews objectAtIndex:0] subviews]; | 316 subviews = [[subviews objectAtIndex:0] subviews]; |
| 330 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 317 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| 331 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 318 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 332 | 319 |
| 333 ASSERT_EQ(2U, [activeCardLinks count]); | 320 ASSERT_EQ(2U, [activeCardLinks count]); |
| 334 | 321 |
| 335 // There should be a sign in button. | 322 // There should be a sign in button. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 362 // There is one link: manage accounts. | 349 // There is one link: manage accounts. |
| 363 ASSERT_EQ(1U, [activeCardLinks count]); | 350 ASSERT_EQ(1U, [activeCardLinks count]); |
| 364 NSButton* manageAccountsLink = | 351 NSButton* manageAccountsLink = |
| 365 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); | 352 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); |
| 366 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); | 353 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); |
| 367 EXPECT_EQ(controller(), [manageAccountsLink target]); | 354 EXPECT_EQ(controller(), [manageAccountsLink target]); |
| 368 } | 355 } |
| 369 | 356 |
| 370 TEST_F(ProfileChooserControllerTest, | 357 TEST_F(ProfileChooserControllerTest, |
| 371 SignedInProfileActiveCardLinksWithNewMenu) { | 358 SignedInProfileActiveCardLinksWithNewMenu) { |
| 372 switches::EnableNewAvatarMenuForTesting( | |
| 373 base::CommandLine::ForCurrentProcess()); | |
| 374 // Sign in the first profile. | 359 // Sign in the first profile. |
| 375 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 360 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 376 cache->SetAuthInfoOfProfileAtIndex(0, kGaiaId, base::ASCIIToUTF16(kEmail)); | 361 cache->SetAuthInfoOfProfileAtIndex(0, kGaiaId, base::ASCIIToUTF16(kEmail)); |
| 377 | 362 |
| 378 StartProfileChooserController(); | 363 StartProfileChooserController(); |
| 379 NSArray* subviews = [[[controller() window] contentView] subviews]; | 364 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 380 ASSERT_EQ(2U, [subviews count]); | 365 ASSERT_EQ(2U, [subviews count]); |
| 381 subviews = [[subviews objectAtIndex:0] subviews]; | 366 subviews = [[subviews objectAtIndex:0] subviews]; |
| 382 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 367 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| 383 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 368 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 ASSERT_EQ(5U, [buttonSubviews count]); | 546 ASSERT_EQ(5U, [buttonSubviews count]); |
| 562 | 547 |
| 563 // There should be a lock button. | 548 // There should be a lock button. |
| 564 NSButton* lockButton = | 549 NSButton* lockButton = |
| 565 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 550 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
| 566 ASSERT_TRUE(lockButton); | 551 ASSERT_TRUE(lockButton); |
| 567 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | 552 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); |
| 568 EXPECT_EQ(controller(), [lockButton target]); | 553 EXPECT_EQ(controller(), [lockButton target]); |
| 569 EXPECT_TRUE([lockButton isEnabled]); | 554 EXPECT_TRUE([lockButton isEnabled]); |
| 570 } | 555 } |
| OLD | NEW |