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