| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 AvatarMenu* menu_; | 100 AvatarMenu* menu_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); | 102 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { | 105 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { |
| 106 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 106 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 107 StartProfileChooserController(); | 107 StartProfileChooserController(); |
| 108 | 108 |
| 109 NSArray* subviews = [[[controller() window] contentView] subviews]; | 109 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 110 ASSERT_EQ(2U, [subviews count]); | 110 ASSERT_EQ(1U, [subviews count]); |
| 111 subviews = [[subviews objectAtIndex:0] subviews]; | 111 subviews = [[subviews objectAtIndex:0] subviews]; |
| 112 | 112 |
| 113 // Three profiles means we should have one active card, one separator and | 113 // Three profiles means we should have one active card, one separator and |
| 114 // one option buttons view. We also have an update promo for the new avatar | 114 // one option buttons view. We also have an update promo for the new avatar |
| 115 // menu. | 115 // menu. |
| 116 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not | 116 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not |
| 117 // reproducible anywhere else. | 117 // reproducible anywhere else. |
| 118 ASSERT_GE([subviews count], 3U); | 118 ASSERT_GE([subviews count], 3U); |
| 119 | 119 |
| 120 // There should be two buttons and a separator in the option buttons view. | 120 // There should be two buttons and a separator in the option buttons view. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 139 // There should be a separator. | 139 // There should be a separator. |
| 140 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | 140 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); |
| 141 | 141 |
| 142 // There should be the profile avatar, name and links container in the active | 142 // There should be the profile avatar, name and links container in the active |
| 143 // card view. The links displayed in the container are checked separately. | 143 // card view. The links displayed in the container are checked separately. |
| 144 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 144 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| 145 ASSERT_EQ(3U, [activeCardSubviews count]); | 145 ASSERT_EQ(3U, [activeCardSubviews count]); |
| 146 | 146 |
| 147 // Profile icon. | 147 // Profile icon. |
| 148 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; | 148 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; |
| 149 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]); | 149 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); |
| 150 | 150 |
| 151 // Profile name. | 151 // Profile name. |
| 152 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; | 152 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; |
| 153 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | 153 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
| 154 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 154 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 155 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); | 155 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); |
| 156 | 156 |
| 157 // Profile links. This is a local profile, so there should be a signin button | 157 // Profile links. This is a local profile, so there should be a signin button |
| 158 // and a signin promo. | 158 // and a signin promo. |
| 159 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 159 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 160 ASSERT_EQ(2U, [linksSubviews count]); | 160 ASSERT_EQ(2U, [linksSubviews count]); |
| 161 NSButton* link = base::mac::ObjCCast<NSButton>( | 161 NSButton* link = base::mac::ObjCCast<NSButton>( |
| 162 [linksSubviews objectAtIndex:0]); | 162 [linksSubviews objectAtIndex:0]); |
| 163 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); | 163 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
| 164 EXPECT_EQ(controller(), [link target]); | 164 EXPECT_EQ(controller(), [link target]); |
| 165 | 165 |
| 166 NSTextField* promo = base::mac::ObjCCast<NSTextField>( | 166 NSTextField* promo = base::mac::ObjCCast<NSTextField>( |
| 167 [linksSubviews objectAtIndex:1]); | 167 [linksSubviews objectAtIndex:1]); |
| 168 EXPECT_GT([[promo stringValue] length], 0U); | 168 EXPECT_GT([[promo stringValue] length], 0U); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { | 171 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { |
| 172 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 172 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 173 EnableFastUserSwitching(); | 173 EnableFastUserSwitching(); |
| 174 StartProfileChooserController(); | 174 StartProfileChooserController(); |
| 175 | 175 |
| 176 NSArray* subviews = [[[controller() window] contentView] subviews]; | 176 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 177 ASSERT_EQ(2U, [subviews count]); | 177 ASSERT_EQ(1U, [subviews count]); |
| 178 subviews = [[subviews objectAtIndex:0] subviews]; | 178 subviews = [[subviews objectAtIndex:0] subviews]; |
| 179 | 179 |
| 180 // Three profiles means we should have one active card and a | 180 // Three profiles means we should have one active card and a |
| 181 // fast user switcher which has two "other" profiles and 2 separators, and | 181 // fast user switcher which has two "other" profiles and 2 separators, and |
| 182 // an option buttons view with its separator. We also have a promo for | 182 // an option buttons view with its separator. We also have a promo for |
| 183 // the new avatar menu. | 183 // the new avatar menu. |
| 184 // TODO(noms): Enforcing 8U fails on the waterfall debug bots, but it's not | 184 // TODO(noms): Enforcing 8U fails on the waterfall debug bots, but it's not |
| 185 // reproducible anywhere else. | 185 // reproducible anywhere else. |
| 186 ASSERT_GE([subviews count], 7U); | 186 ASSERT_GE([subviews count], 7U); |
| 187 | 187 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 210 profileIndex++; | 210 profileIndex++; |
| 211 } | 211 } |
| 212 | 212 |
| 213 // There should be the profile avatar, name and links container in the active | 213 // There should be the profile avatar, name and links container in the active |
| 214 // card view. The links displayed in the container are checked separately. | 214 // card view. The links displayed in the container are checked separately. |
| 215 NSArray* activeCardSubviews = [[subviews objectAtIndex:6] subviews]; | 215 NSArray* activeCardSubviews = [[subviews objectAtIndex:6] subviews]; |
| 216 ASSERT_EQ(3U, [activeCardSubviews count]); | 216 ASSERT_EQ(3U, [activeCardSubviews count]); |
| 217 | 217 |
| 218 // Profile icon. | 218 // Profile icon. |
| 219 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; | 219 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; |
| 220 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]); | 220 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); |
| 221 | 221 |
| 222 // Profile name. | 222 // Profile name. |
| 223 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; | 223 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; |
| 224 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | 224 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
| 225 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 225 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 226 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); | 226 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); |
| 227 | 227 |
| 228 // Profile links. This is a local profile, so there should be a signin button | 228 // Profile links. This is a local profile, so there should be a signin button |
| 229 // and a signin promo. These are also tested in InitialLayoutWithNewMenu. | 229 // and a signin promo. These are also tested in InitialLayoutWithNewMenu. |
| 230 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 230 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 241 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), | 241 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), |
| 242 base::ASCIIToUTF16("New Profile"), 1, std::string(), | 242 base::ASCIIToUTF16("New Profile"), 1, std::string(), |
| 243 TestingProfile::TestingFactories()); | 243 TestingProfile::TestingFactories()); |
| 244 testing_profile_manager()-> | 244 testing_profile_manager()-> |
| 245 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), | 245 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), |
| 246 base::ASCIIToUTF16("Another Test"), 1, std::string(), | 246 base::ASCIIToUTF16("Another Test"), 1, std::string(), |
| 247 TestingProfile::TestingFactories()); | 247 TestingProfile::TestingFactories()); |
| 248 StartProfileChooserController(); | 248 StartProfileChooserController(); |
| 249 | 249 |
| 250 NSArray* subviews = [[[controller() window] contentView] subviews]; | 250 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 251 ASSERT_EQ(2U, [subviews count]); | 251 ASSERT_EQ(1U, [subviews count]); |
| 252 subviews = [[subviews objectAtIndex:0] subviews]; | 252 subviews = [[subviews objectAtIndex:0] subviews]; |
| 253 NSString* sortedNames[] = { @"Another Test", | 253 NSString* sortedNames[] = { @"Another Test", |
| 254 @"New Profile", | 254 @"New Profile", |
| 255 @"Test 1", | 255 @"Test 1", |
| 256 @"Test 2" }; | 256 @"Test 2" }; |
| 257 // There are four "other" profiles, each with a button and a separator, an | 257 // There are four "other" profiles, each with a button and a separator, an |
| 258 // active profile card, and an option buttons view with a separator. We | 258 // active profile card, and an option buttons view with a separator. We |
| 259 // also have an update promo for the new avatar menu. | 259 // also have an update promo for the new avatar menu. |
| 260 // TODO(noms): Enforcing 12U fails on the waterfall debug bots, but it's not | 260 // TODO(noms): Enforcing 12U fails on the waterfall debug bots, but it's not |
| 261 // reproducible anywhere else. | 261 // reproducible anywhere else. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 273 EXPECT_TRUE( | 273 EXPECT_TRUE( |
| 274 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); | 274 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_F(ProfileChooserControllerTest, | 278 TEST_F(ProfileChooserControllerTest, |
| 279 LocalProfileActiveCardLinksWithNewMenu) { | 279 LocalProfileActiveCardLinksWithNewMenu) { |
| 280 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 280 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 281 StartProfileChooserController(); | 281 StartProfileChooserController(); |
| 282 NSArray* subviews = [[[controller() window] contentView] subviews]; | 282 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 283 ASSERT_EQ(2U, [subviews count]); | 283 ASSERT_EQ(1U, [subviews count]); |
| 284 subviews = [[subviews objectAtIndex:0] subviews]; | 284 subviews = [[subviews objectAtIndex:0] subviews]; |
| 285 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 285 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| 286 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 286 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 287 | 287 |
| 288 ASSERT_EQ(2U, [activeCardLinks count]); | 288 ASSERT_EQ(2U, [activeCardLinks count]); |
| 289 | 289 |
| 290 // There should be a sign in button. | 290 // There should be a sign in button. |
| 291 NSButton* link = base::mac::ObjCCast<NSButton>( | 291 NSButton* link = base::mac::ObjCCast<NSButton>( |
| 292 [activeCardLinks objectAtIndex:0]); | 292 [activeCardLinks objectAtIndex:0]); |
| 293 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); | 293 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
| 294 EXPECT_EQ(controller(), [link target]); | 294 EXPECT_EQ(controller(), [link target]); |
| 295 | 295 |
| 296 // Local profiles have a signin promo. | 296 // Local profiles have a signin promo. |
| 297 NSTextField* promo = base::mac::ObjCCast<NSTextField>( | 297 NSTextField* promo = base::mac::ObjCCast<NSTextField>( |
| 298 [activeCardLinks objectAtIndex:1]); | 298 [activeCardLinks objectAtIndex:1]); |
| 299 EXPECT_GT([[promo stringValue] length], 0U); | 299 EXPECT_GT([[promo stringValue] length], 0U); |
| 300 } | 300 } |
| 301 | 301 |
| 302 TEST_F(ProfileChooserControllerTest, | 302 TEST_F(ProfileChooserControllerTest, |
| 303 SignedInProfileActiveCardLinksWithAccountConsistency) { | 303 SignedInProfileActiveCardLinksWithAccountConsistency) { |
| 304 switches::EnableAccountConsistencyForTesting( | 304 switches::EnableAccountConsistencyForTesting( |
| 305 CommandLine::ForCurrentProcess()); | 305 CommandLine::ForCurrentProcess()); |
| 306 // Sign in the first profile. | 306 // Sign in the first profile. |
| 307 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 307 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 308 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 308 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
| 309 | 309 |
| 310 StartProfileChooserController(); | 310 StartProfileChooserController(); |
| 311 NSArray* subviews = [[[controller() window] contentView] subviews]; | 311 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 312 ASSERT_EQ(2U, [subviews count]); | 312 ASSERT_EQ(1U, [subviews count]); |
| 313 subviews = [[subviews objectAtIndex:0] subviews]; | 313 subviews = [[subviews objectAtIndex:0] subviews]; |
| 314 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 314 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| 315 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 315 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 316 | 316 |
| 317 // There is one link: manage accounts. | 317 // There is one link: manage accounts. |
| 318 ASSERT_EQ(1U, [activeCardLinks count]); | 318 ASSERT_EQ(1U, [activeCardLinks count]); |
| 319 NSButton* manageAccountsLink = | 319 NSButton* manageAccountsLink = |
| 320 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); | 320 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); |
| 321 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); | 321 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); |
| 322 EXPECT_EQ(controller(), [manageAccountsLink target]); | 322 EXPECT_EQ(controller(), [manageAccountsLink target]); |
| 323 } | 323 } |
| 324 | 324 |
| 325 TEST_F(ProfileChooserControllerTest, | 325 TEST_F(ProfileChooserControllerTest, |
| 326 SignedInProfileActiveCardLinksWithNewMenu) { | 326 SignedInProfileActiveCardLinksWithNewMenu) { |
| 327 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 327 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 328 // Sign in the first profile. | 328 // Sign in the first profile. |
| 329 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 329 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 330 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 330 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
| 331 | 331 |
| 332 StartProfileChooserController(); | 332 StartProfileChooserController(); |
| 333 NSArray* subviews = [[[controller() window] contentView] subviews]; | 333 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 334 ASSERT_EQ(2U, [subviews count]); | 334 ASSERT_EQ(1U, [subviews count]); |
| 335 subviews = [[subviews objectAtIndex:0] subviews]; | 335 subviews = [[subviews objectAtIndex:0] subviews]; |
| 336 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 336 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| 337 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 337 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 338 | 338 |
| 339 // There is one disabled button with the user's email. | 339 // There is one disabled button with the user's email. |
| 340 ASSERT_EQ(1U, [activeCardLinks count]); | 340 ASSERT_EQ(1U, [activeCardLinks count]); |
| 341 NSButton* emailButton = | 341 NSButton* emailButton = |
| 342 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); | 342 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); |
| 343 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title])); | 343 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title])); |
| 344 EXPECT_EQ(nil, [emailButton action]); | 344 EXPECT_EQ(nil, [emailButton action]); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 359 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | 359 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
| 360 UpdateCredentials(kEmail, kLoginToken); | 360 UpdateCredentials(kEmail, kLoginToken); |
| 361 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | 361 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
| 362 UpdateCredentials(kSecondaryEmail, kLoginToken); | 362 UpdateCredentials(kSecondaryEmail, kLoginToken); |
| 363 | 363 |
| 364 StartProfileChooserController(); | 364 StartProfileChooserController(); |
| 365 [controller() initMenuContentsWithView: | 365 [controller() initMenuContentsWithView: |
| 366 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 366 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
| 367 | 367 |
| 368 NSArray* subviews = [[[controller() window] contentView] subviews]; | 368 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 369 ASSERT_EQ(2U, [subviews count]); | 369 ASSERT_EQ(1U, [subviews count]); |
| 370 subviews = [[subviews objectAtIndex:0] subviews]; | 370 subviews = [[subviews objectAtIndex:0] subviews]; |
| 371 | 371 |
| 372 // There should be one active card, one accounts container, two separators | 372 // There should be one active card, one accounts container, two separators |
| 373 // and one option buttons view. | 373 // and one option buttons view. |
| 374 ASSERT_EQ(5U, [subviews count]); | 374 ASSERT_EQ(5U, [subviews count]); |
| 375 | 375 |
| 376 // There should be three buttons and two separators in the option | 376 // There should be three buttons and two separators in the option |
| 377 // buttons view. | 377 // buttons view. |
| 378 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 378 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
| 379 ASSERT_EQ(5U, [buttonSubviews count]); | 379 ASSERT_EQ(5U, [buttonSubviews count]); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 // There should be another separator. | 436 // There should be another separator. |
| 437 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); | 437 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); |
| 438 | 438 |
| 439 // There should be the profile avatar, name and a "hide accounts" link | 439 // There should be the profile avatar, name and a "hide accounts" link |
| 440 // container in the active card view. | 440 // container in the active card view. |
| 441 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; | 441 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; |
| 442 ASSERT_EQ(3U, [activeCardSubviews count]); | 442 ASSERT_EQ(3U, [activeCardSubviews count]); |
| 443 | 443 |
| 444 // Profile icon. | 444 // Profile icon. |
| 445 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; | 445 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; |
| 446 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]); | 446 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); |
| 447 | 447 |
| 448 // Profile name. | 448 // Profile name. |
| 449 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; | 449 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; |
| 450 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | 450 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
| 451 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 451 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 452 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); | 452 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); |
| 453 | 453 |
| 454 // Profile links. This is a local profile, so there should be a signin button. | 454 // Profile links. This is a local profile, so there should be a signin button. |
| 455 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 455 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 456 ASSERT_EQ(1U, [linksSubviews count]); | 456 ASSERT_EQ(1U, [linksSubviews count]); |
| 457 NSButton* link = base::mac::ObjCCast<NSButton>( | 457 NSButton* link = base::mac::ObjCCast<NSButton>( |
| 458 [linksSubviews objectAtIndex:0]); | 458 [linksSubviews objectAtIndex:0]); |
| 459 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); | 459 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); |
| 460 EXPECT_EQ(controller(), [link target]); | 460 EXPECT_EQ(controller(), [link target]); |
| 461 } | 461 } |
| 462 | |
| 463 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) { | |
| 464 switches::EnableNewProfileManagementForTesting( | |
| 465 CommandLine::ForCurrentProcess()); | |
| 466 // Sign in the first profile. | |
| 467 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | |
| 468 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | |
| 469 cache->SetLocalAuthCredentialsOfProfileAtIndex(0, std::string()); | |
| 470 | |
| 471 StartProfileChooserController(); | |
| 472 NSArray* subviews = [[[controller() window] contentView] subviews]; | |
| 473 ASSERT_EQ(2U, [subviews count]); | |
| 474 subviews = [[subviews objectAtIndex:0] subviews]; | |
| 475 | |
| 476 // Three profiles means we should have one active card, one separator, one | |
| 477 // option buttons view and a lock view. We also have an update promo for the | |
| 478 // new avatar menu. | |
| 479 // TODO(noms): Enforcing 5U fails on the waterfall debug bots, but it's not | |
| 480 // reproducible anywhere else. | |
| 481 ASSERT_GE([subviews count], 4U); | |
| 482 | |
| 483 // There will be three buttons and two separators in the option buttons view. | |
| 484 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | |
| 485 ASSERT_EQ(5U, [buttonSubviews count]); | |
| 486 | |
| 487 // There should be a lock button. | |
| 488 NSButton* lockButton = | |
| 489 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | |
| 490 ASSERT_TRUE(lockButton); | |
| 491 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | |
| 492 EXPECT_EQ(controller(), [lockButton target]); | |
| 493 EXPECT_FALSE([lockButton isEnabled]); | |
| 494 } | |
| 495 | |
| 496 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) { | |
| 497 switches::EnableNewProfileManagementForTesting( | |
| 498 CommandLine::ForCurrentProcess()); | |
| 499 // Sign in the first profile. | |
| 500 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | |
| 501 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | |
| 502 cache->SetLocalAuthCredentialsOfProfileAtIndex(0, "YourHashHere"); | |
| 503 | |
| 504 StartProfileChooserController(); | |
| 505 NSArray* subviews = [[[controller() window] contentView] subviews]; | |
| 506 ASSERT_EQ(2U, [subviews count]); | |
| 507 subviews = [[subviews objectAtIndex:0] subviews]; | |
| 508 | |
| 509 // Three profiles means we should have one active card, one separator, one | |
| 510 // option buttons view and a lock view. We also have an update promo for the | |
| 511 // new avatar menu. | |
| 512 // TODO(noms): Enforcing 5U fails on the waterfall debug bots, but it's not | |
| 513 // reproducible anywhere else. | |
| 514 ASSERT_GE([subviews count], 4U); | |
| 515 | |
| 516 // There will be three buttons and two separators in the option buttons view. | |
| 517 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | |
| 518 ASSERT_EQ(5U, [buttonSubviews count]); | |
| 519 | |
| 520 // There should be a lock button. | |
| 521 NSButton* lockButton = | |
| 522 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | |
| 523 ASSERT_TRUE(lockButton); | |
| 524 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | |
| 525 EXPECT_EQ(controller(), [lockButton target]); | |
| 526 EXPECT_TRUE([lockButton isEnabled]); | |
| 527 } | |
| OLD | NEW |