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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm

Issue 2708073002: Removing pre-material design menu setting. (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 initWithBrowser:browser() 100 initWithBrowser:browser()
101 anchoredAt:point 101 anchoredAt:point
102 viewMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER 102 viewMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER
103 tutorialMode:mode 103 tutorialMode:mode
104 serviceType:signin::GAIA_SERVICE_TYPE_NONE 104 serviceType:signin::GAIA_SERVICE_TYPE_NONE
105 accessPoint:signin_metrics::AccessPoint:: 105 accessPoint:signin_metrics::AccessPoint::
106 ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN]); 106 ACCESS_POINT_AVATAR_BUBBLE_SIGN_IN]);
107 [controller_ showWindow:nil]; 107 [controller_ showWindow:nil];
108 } 108 }
109 109
110 void AssertRightClickTutorialShown() {
111 // The right click menu doesn't exist in the MD user menu, so it doesn't
112 // show the tutorial.
113 if (switches::IsMaterialDesignUserMenu())
114 return;
115
116 NSArray* subviews = [[[controller() window] contentView] subviews];
117 ASSERT_EQ(2U, [subviews count]);
118 subviews = [[subviews objectAtIndex:0] subviews];
119
120 // There should be 4 views: the tutorial, the active profile card, a
121 // separator and the options view.
122 ASSERT_EQ(4U, [subviews count]);
123
124 // The tutorial is the topmost view, so the last in the array. It should
125 // contain 3 views: the title, the content text and the OK button.
126 NSArray* tutorialSubviews = [[subviews objectAtIndex:3] subviews];
127 ASSERT_EQ(3U, [tutorialSubviews count]);
128
129 NSTextField* tutorialTitle = base::mac::ObjCCastStrict<NSTextField>(
130 [tutorialSubviews objectAtIndex:2]);
131 EXPECT_GT([[tutorialTitle stringValue] length], 0U);
132
133 NSTextField* tutorialContent = base::mac::ObjCCastStrict<NSTextField>(
134 [tutorialSubviews objectAtIndex:1]);
135 EXPECT_GT([[tutorialContent stringValue] length], 0U);
136
137 NSButton* tutorialOKButton = base::mac::ObjCCastStrict<NSButton>(
138 [tutorialSubviews objectAtIndex:0]);
139 EXPECT_GT([[tutorialOKButton title] length], 0U);
140 }
141
142 void StartFastUserSwitcher() { 110 void StartFastUserSwitcher() {
143 NSRect frame = [test_window() frame]; 111 NSRect frame = [test_window() frame];
144 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); 112 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame));
145 controller_.reset([[ProfileChooserController alloc] 113 controller_.reset([[ProfileChooserController alloc]
146 initWithBrowser:browser() 114 initWithBrowser:browser()
147 anchoredAt:point 115 anchoredAt:point
148 viewMode:profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER 116 viewMode:profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER
149 tutorialMode:profiles::TUTORIAL_MODE_NONE 117 tutorialMode:profiles::TUTORIAL_MODE_NONE
150 serviceType:signin::GAIA_SERVICE_TYPE_NONE 118 serviceType:signin::GAIA_SERVICE_TYPE_NONE
151 accessPoint:signin_metrics::AccessPoint:: 119 accessPoint:signin_metrics::AccessPoint::
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // Three profiles means we should have one active card, one separator and 151 // Three profiles means we should have one active card, one separator and
184 // one option buttons view. We also have an update promo for the new avatar 152 // one option buttons view. We also have an update promo for the new avatar
185 // menu. 153 // menu.
186 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not 154 // TODO(noms): Enforcing 4U fails on the waterfall debug bots, but it's not
187 // reproducible anywhere else. 155 // reproducible anywhere else.
188 ASSERT_GE([subviews count], 3U); 156 ASSERT_GE([subviews count], 3U);
189 157
190 // There should be one button in the option buttons view. 158 // There should be one button in the option buttons view.
191 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 159 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
192 NSButton* userSwitcherButton; 160 NSButton* userSwitcherButton;
193 if (switches::IsMaterialDesignUserMenu()) { 161 // There are 2 buttons in the initial layout: "Manage People" and "Guest".
194 // There are 2 buttons in the initial layout: "Manage People" and "Guest". 162 ASSERT_EQ(2U, [buttonSubviews count]);
195 ASSERT_EQ(2U, [buttonSubviews count]); 163 // There should be a user switcher button.
196 // There should be a user switcher button. 164 userSwitcherButton =
197 userSwitcherButton =
198 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); 165 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
199 } else {
200 // For non-material-design user menu, there should be two buttons and a
201 // separator in the option buttons view.
202 ASSERT_EQ(3U, [buttonSubviews count]);
203
204 // There should be an incognito button.
205 NSButton* incognitoButton =
206 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
207 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]);
208 EXPECT_EQ(controller(), [incognitoButton target]);
209
210 // There should be a separator.
211 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
212
213 // There should be a user switcher button.
214 userSwitcherButton =
215 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]);
216 }
217 166
218 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); 167 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]);
219 EXPECT_EQ(controller(), [userSwitcherButton target]); 168 EXPECT_EQ(controller(), [userSwitcherButton target]);
220 169
221 NSUInteger lastSubviewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2; 170 NSUInteger lastSubviewIndex = 4;
222 NSArray* activeCardSubviews = 171 NSArray* activeCardSubviews =
223 [[subviews objectAtIndex:lastSubviewIndex] subviews]; 172 [[subviews objectAtIndex:lastSubviewIndex] subviews];
224 173
225 // There should be the profile avatar, name and links container in the active 174 // There should be the profile avatar, name and links container in the active
226 // card view. The links displayed in the container are checked separately. 175 // card view. The links displayed in the container are checked separately.
227 // In the MD user menu, the profile avatar and name are in the same subview. 176 // In the MD user menu, the profile avatar and name are in the same subview.
228 if (switches::IsMaterialDesignUserMenu()) { 177 ASSERT_EQ(2U, [activeCardSubviews count]);
229 ASSERT_EQ(2U, [activeCardSubviews count]);
230 } else {
231 ASSERT_EQ(3U, [activeCardSubviews count]);
232
233 // Profile icon.
234 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2];
235 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]);
236
237 // Profile name.
238 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1];
239 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]);
240 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
241 [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
242 }
243 // Profile links. This is a local profile, so there should be a signin button 178 // Profile links. This is a local profile, so there should be a signin button
244 // and a signin promo. 179 // and a signin promo.
245 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; 180 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
246 ASSERT_EQ(2U, [linksSubviews count]); 181 ASSERT_EQ(2U, [linksSubviews count]);
247 NSButton* link = base::mac::ObjCCast<NSButton>( 182 NSButton* link = base::mac::ObjCCast<NSButton>(
248 [linksSubviews objectAtIndex:0]); 183 [linksSubviews objectAtIndex:0]);
249 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); 184 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]);
250 EXPECT_EQ(controller(), [link target]); 185 EXPECT_EQ(controller(), [link target]);
251 186
252 NSTextField* promo = base::mac::ObjCCast<NSTextField>( 187 NSTextField* promo = base::mac::ObjCCast<NSTextField>(
(...skipping 20 matching lines...) Expand all
273 [controller() close]; 208 [controller() close];
274 } 209 }
275 210
276 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterWelcome) { 211 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterWelcome) {
277 // The welcome upgrade tutorial takes precedence so show it then dismiss it. 212 // The welcome upgrade tutorial takes precedence so show it then dismiss it.
278 // The right click tutorial should be shown right away. 213 // The right click tutorial should be shown right away.
279 StartProfileChooserControllerWithTutorialMode( 214 StartProfileChooserControllerWithTutorialMode(
280 profiles::TUTORIAL_MODE_WELCOME_UPGRADE); 215 profiles::TUTORIAL_MODE_WELCOME_UPGRADE);
281 216
282 [controller() dismissTutorial:nil]; 217 [controller() dismissTutorial:nil];
283 AssertRightClickTutorialShown();
284 } 218 }
285 219
286 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterReopen) { 220 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterReopen) {
287 // The welcome upgrade tutorial takes precedence so show it then close the 221 // The welcome upgrade tutorial takes precedence so show it then close the
288 // menu. Reopening the menu should show the tutorial. 222 // menu. Reopening the menu should show the tutorial.
289 StartProfileChooserController(); 223 StartProfileChooserController();
290 224
291 [controller() close]; 225 [controller() close];
292 StartProfileChooserController(); 226 StartProfileChooserController();
293 AssertRightClickTutorialShown();
294 227
295 // The tutorial must be manually dismissed so it should still be shown after 228 // The tutorial must be manually dismissed so it should still be shown after
296 // closing and reopening the menu, 229 // closing and reopening the menu,
297 [controller() close]; 230 [controller() close];
298 StartProfileChooserController(); 231 StartProfileChooserController();
299 AssertRightClickTutorialShown();
300 } 232 }
301 233
302 TEST_F(ProfileChooserControllerTest, RightClickTutorialNotShownAfterDismiss) { 234 TEST_F(ProfileChooserControllerTest, RightClickTutorialNotShownAfterDismiss) {
303 // The welcome upgrade tutorial takes precedence so show it then close the 235 // The welcome upgrade tutorial takes precedence so show it then close the
304 // menu. Reopening the menu should show the tutorial. 236 // menu. Reopening the menu should show the tutorial.
305 StartProfileChooserController(); 237 StartProfileChooserController();
306 238
307 [controller() close]; 239 [controller() close];
308 StartProfileChooserControllerWithTutorialMode( 240 StartProfileChooserControllerWithTutorialMode(
309 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); 241 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING);
310 AssertRightClickTutorialShown();
311 242
312 // Dismissing the tutorial should prevent it from being shown forever. 243 // Dismissing the tutorial should prevent it from being shown forever.
313 [controller() dismissTutorial:nil]; 244 [controller() dismissTutorial:nil];
314 NSArray* subviews = [[[controller() window] contentView] subviews]; 245 NSArray* subviews = [[[controller() window] contentView] subviews];
315 ASSERT_EQ(2U, [subviews count]); 246 ASSERT_EQ(2U, [subviews count]);
316 subviews = [[subviews objectAtIndex:0] subviews]; 247 subviews = [[subviews objectAtIndex:0] subviews];
317 248
318 // There should be 3 views since there's no tutorial. There are 2 extra 249 // There should be 3 views since there's no tutorial. There are 2 extra
319 // buttons in the MD user menu. 250 // buttons in the MD user menu.
320 NSUInteger viewsCount = switches::IsMaterialDesignUserMenu() ? 5 : 3; 251 NSUInteger viewsCount = 5;
321 ASSERT_EQ(viewsCount, [subviews count]); 252 ASSERT_EQ(viewsCount, [subviews count]);
322 253
323 // Closing and reopening the menu shouldn't show the tutorial. 254 // Closing and reopening the menu shouldn't show the tutorial.
324 [controller() close]; 255 [controller() close];
325 StartProfileChooserControllerWithTutorialMode( 256 StartProfileChooserControllerWithTutorialMode(
326 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); 257 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING);
327 subviews = [[[controller() window] contentView] subviews]; 258 subviews = [[[controller() window] contentView] subviews];
328 ASSERT_EQ(2U, [subviews count]); 259 ASSERT_EQ(2U, [subviews count]);
329 subviews = [[subviews objectAtIndex:0] subviews]; 260 subviews = [[subviews objectAtIndex:0] subviews];
330 261
331 ASSERT_EQ(viewsCount, [subviews count]); 262 ASSERT_EQ(viewsCount, [subviews count]);
332 } 263 }
333 264
334 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) {
335 // This test is related to the fast user switcher, which doesn't exist under
336 // the MD user menu.
337 if (switches::IsMaterialDesignUserMenu())
338 return;
339 // Add two extra profiles, to make sure sorting is alphabetical and not
340 // by order of creation.
341 testing_profile_manager()->CreateTestingProfile(
342 "test3", std::unique_ptr<sync_preferences::PrefServiceSyncable>(),
343 base::ASCIIToUTF16("New Profile"), 1, std::string(),
344 TestingProfile::TestingFactories());
345 testing_profile_manager()->CreateTestingProfile(
346 "test4", std::unique_ptr<sync_preferences::PrefServiceSyncable>(),
347 base::ASCIIToUTF16("Another Test"), 1, std::string(),
348 TestingProfile::TestingFactories());
349 StartFastUserSwitcher();
350
351 NSArray* subviews = [[[controller() window] contentView] subviews];
352 ASSERT_EQ(2U, [subviews count]);
353 subviews = [[subviews objectAtIndex:0] subviews];
354 NSString* sortedNames[] = { @"Another Test",
355 @"New Profile",
356 @"Test 1",
357 @"Test 2" };
358 // There are four "other" profiles, each with a button and a separator.
359 ASSERT_EQ([subviews count], 8U);
360 // There should be four "other profiles" items, sorted alphabetically. The
361 // "other profiles" start at index 2 (after the option buttons view and its
362 // separator), and each have a separator. We need to iterate through the
363 // profiles in the order displayed in the bubble, which is opposite from the
364 // drawn order.
365 int sortedNameIndex = 0;
366 for (int i = 7; i > 0; i -= 2) {
367 // The item at index i is the separator.
368 NSButton* button = base::mac::ObjCCast<NSButton>(
369 [subviews objectAtIndex:i-1]);
370 EXPECT_TRUE(
371 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]);
372 }
373 }
374
375 TEST_F(ProfileChooserControllerTest, 265 TEST_F(ProfileChooserControllerTest,
376 LocalProfileActiveCardLinksWithNewMenu) { 266 LocalProfileActiveCardLinksWithNewMenu) {
377 StartProfileChooserController(); 267 StartProfileChooserController();
378 NSArray* subviews = [[[controller() window] contentView] subviews]; 268 NSArray* subviews = [[[controller() window] contentView] subviews];
379 ASSERT_EQ(2U, [subviews count]); 269 ASSERT_EQ(2U, [subviews count]);
380 subviews = [[subviews objectAtIndex:0] subviews]; 270 subviews = [[subviews objectAtIndex:0] subviews];
381 // The active card is the last subview and the MD User Menu has 2 extra 271 // The active card is the last subview and the MD User Menu has 2 extra
382 // buttons. 272 // buttons.
383 NSUInteger lastSubviewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2; 273 NSUInteger lastSubviewIndex = 4;
384 NSArray* activeCardSubviews = 274 NSArray* activeCardSubviews =
385 [[subviews objectAtIndex:lastSubviewIndex] subviews]; 275 [[subviews objectAtIndex:lastSubviewIndex] subviews];
386 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; 276 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews];
387 277
388 ASSERT_EQ(2U, [activeCardLinks count]); 278 ASSERT_EQ(2U, [activeCardLinks count]);
389 279
390 // There should be a sign in button. 280 // There should be a sign in button.
391 NSButton* link = base::mac::ObjCCast<NSButton>( 281 NSButton* link = base::mac::ObjCCast<NSButton>(
392 [activeCardLinks objectAtIndex:0]); 282 [activeCardLinks objectAtIndex:0]);
393 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); 283 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]);
(...skipping 11 matching lines...) Expand all
405 base::CommandLine::ForCurrentProcess()); 295 base::CommandLine::ForCurrentProcess());
406 296
407 SignInFirstProfile(); 297 SignInFirstProfile();
408 298
409 StartProfileChooserController(); 299 StartProfileChooserController();
410 NSArray* subviews = [[[controller() window] contentView] subviews]; 300 NSArray* subviews = [[[controller() window] contentView] subviews];
411 ASSERT_EQ(2U, [subviews count]); 301 ASSERT_EQ(2U, [subviews count]);
412 subviews = [[subviews objectAtIndex:0] subviews]; 302 subviews = [[subviews objectAtIndex:0] subviews];
413 // The active card is the last subview and the MD User Menu has 2 extra 303 // The active card is the last subview and the MD User Menu has 2 extra
414 // buttons. 304 // buttons.
415 NSUInteger lastSubviewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2; 305 NSUInteger lastSubviewIndex = 4;
416 NSArray* activeCardSubviews = 306 NSArray* activeCardSubviews =
417 [[subviews objectAtIndex:lastSubviewIndex] subviews]; 307 [[subviews objectAtIndex:lastSubviewIndex] subviews];
418 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; 308 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews];
419 309
420 // There is one link: manage accounts. 310 // There is one link: manage accounts.
421 ASSERT_EQ(1U, [activeCardLinks count]); 311 ASSERT_EQ(1U, [activeCardLinks count]);
422 NSButton* manageAccountsLink = 312 NSButton* manageAccountsLink =
423 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]); 313 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]);
424 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); 314 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]);
425 EXPECT_EQ(controller(), [manageAccountsLink target]); 315 EXPECT_EQ(controller(), [manageAccountsLink target]);
426 } 316 }
427 317
428 TEST_F(ProfileChooserControllerTest, 318 TEST_F(ProfileChooserControllerTest,
429 SignedInProfileActiveCardLinksWithNewMenu) { 319 SignedInProfileActiveCardLinksWithNewMenu) {
430 SignInFirstProfile(); 320 SignInFirstProfile();
431 321
432 StartProfileChooserController(); 322 StartProfileChooserController();
433 NSArray* subviews = [[[controller() window] contentView] subviews]; 323 NSArray* subviews = [[[controller() window] contentView] subviews];
434 ASSERT_EQ(2U, [subviews count]); 324 ASSERT_EQ(2U, [subviews count]);
435 subviews = [[subviews objectAtIndex:0] subviews]; 325 subviews = [[subviews objectAtIndex:0] subviews];
436 // The active card is the last subview and the MD User Menu has 2 extra 326 // The active card is the last subview and the MD User Menu has 2 extra
437 // buttons. 327 // buttons.
438 NSUInteger lastSubviewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2; 328 NSUInteger lastSubviewIndex = 4;
439 NSArray* activeCardSubviews = 329 NSArray* activeCardSubviews =
440 [[subviews objectAtIndex:lastSubviewIndex] subviews]; 330 [[subviews objectAtIndex:lastSubviewIndex] subviews];
441 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; 331 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews];
442 332
443 if (switches::IsMaterialDesignUserMenu()) { 333 // There is the profile avatar and the profile name.
444 // There is the profile avatar and the profile name. 334 ASSERT_EQ(2U, [activeCardLinks count]);
445 ASSERT_EQ(2U, [activeCardLinks count]);
446 } else {
447 // There is one disabled button with the user's email.
448 ASSERT_EQ(1U, [activeCardLinks count]);
449 NSButton* emailButton =
450 base::mac::ObjCCast<NSButton>([activeCardLinks objectAtIndex:0]);
451 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailButton title]));
452 EXPECT_EQ(nil, [emailButton action]);
453 EXPECT_FALSE([emailButton isEnabled]);
454 }
455 } 335 }
456 336
457 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { 337 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) {
458 switches::EnableAccountConsistencyForTesting( 338 switches::EnableAccountConsistencyForTesting(
459 base::CommandLine::ForCurrentProcess()); 339 base::CommandLine::ForCurrentProcess());
460 340
461 SignInFirstProfile(); 341 SignInFirstProfile();
462 342
463 // Mark that we are using the profile name on purpose, so that we don't 343 // Mark that we are using the profile name on purpose, so that we don't
464 // fallback to testing the algorithm that chooses which default name 344 // fallback to testing the algorithm that chooses which default name
(...skipping 22 matching lines...) Expand all
487 StartProfileChooserController(); 367 StartProfileChooserController();
488 [controller() initMenuContentsWithView: 368 [controller() initMenuContentsWithView:
489 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; 369 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT];
490 370
491 NSArray* subviews = [[[controller() window] contentView] subviews]; 371 NSArray* subviews = [[[controller() window] contentView] subviews];
492 ASSERT_EQ(2U, [subviews count]); 372 ASSERT_EQ(2U, [subviews count]);
493 subviews = [[subviews objectAtIndex:0] subviews]; 373 subviews = [[subviews objectAtIndex:0] subviews];
494 374
495 // There should be one active card, one accounts container, two separators 375 // There should be one active card, one accounts container, two separators
496 // and one option buttons view. In the MD User Menu, there are 2 more buttons. 376 // and one option buttons view. In the MD User Menu, there are 2 more buttons.
497 NSUInteger viewsCount = switches::IsMaterialDesignUserMenu() ? 7 : 5; 377 NSUInteger viewsCount = 7;
498 ASSERT_EQ(viewsCount, [subviews count]); 378 ASSERT_EQ(viewsCount, [subviews count]);
499 379
500 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 380 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
501 NSButton* userSwitcherButton; 381 NSButton* userSwitcherButton;
502 if (switches::IsMaterialDesignUserMenu()) { 382 // There should be two buttons in the option buttons view.
503 // There should be two buttons in the option buttons view. 383 ASSERT_EQ(2U, [buttonSubviews count]);
504 ASSERT_EQ(2U, [buttonSubviews count]); 384 // There should be a user switcher button.
505 // There should be a user switcher button. 385 userSwitcherButton =
506 userSwitcherButton = 386 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
507 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
508 } else {
509 // For non-material-design user menu, there should be two buttons and one
510 // separator in the option buttons view.
511 ASSERT_EQ(3U, [buttonSubviews count]);
512
513 // There should be an incognito button.
514 NSButton* incognitoButton =
515 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
516 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]);
517 EXPECT_EQ(controller(), [incognitoButton target]);
518
519 // There should be a separator.
520 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
521
522 // There should be a user switcher button.
523 userSwitcherButton =
524 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]);
525 }
526 387
527 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); 388 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]);
528 EXPECT_EQ(controller(), [userSwitcherButton target]); 389 EXPECT_EQ(controller(), [userSwitcherButton target]);
529 390
530 NSUInteger accountsViewIndex = switches::IsMaterialDesignUserMenu() ? 4 : 2; 391 NSUInteger accountsViewIndex = 4;
531 // In the accounts view, there should be the account list container 392 // In the accounts view, there should be the account list container
532 // accounts and one "add accounts" button. 393 // accounts and one "add accounts" button.
533 NSArray* accountsSubviews = 394 NSArray* accountsSubviews =
534 [[subviews objectAtIndex:accountsViewIndex] subviews]; 395 [[subviews objectAtIndex:accountsViewIndex] subviews];
535 ASSERT_EQ(2U, [accountsSubviews count]); 396 ASSERT_EQ(2U, [accountsSubviews count]);
536 397
537 NSButton* addAccountsButton = 398 NSButton* addAccountsButton =
538 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]); 399 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]);
539 EXPECT_EQ(@selector(addAccount:), [addAccountsButton action]); 400 EXPECT_EQ(@selector(addAccount:), [addAccountsButton action]);
540 EXPECT_EQ(controller(), [addAccountsButton target]); 401 EXPECT_EQ(controller(), [addAccountsButton target]);
(...skipping 18 matching lines...) Expand all
559 EXPECT_EQ(@selector(showAccountRemovalView:), [primaryAccountDelete action]); 420 EXPECT_EQ(@selector(showAccountRemovalView:), [primaryAccountDelete action]);
560 EXPECT_EQ(controller(), [primaryAccountDelete target]); 421 EXPECT_EQ(controller(), [primaryAccountDelete target]);
561 EXPECT_EQ(-1, [primaryAccountDelete tag]); 422 EXPECT_EQ(-1, [primaryAccountDelete tag]);
562 423
563 // There should be another separator. 424 // There should be another separator.
564 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); 425 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]);
565 426
566 // There should be the profile avatar, name and a "hide accounts" link 427 // There should be the profile avatar, name and a "hide accounts" link
567 // container in the active card view. 428 // container in the active card view.
568 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; 429 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews];
569 if (switches::IsMaterialDesignUserMenu()) { 430 // In the MD user menu, the profile name and avatar are in the same subview.
570 // In the MD user menu, the profile name and avatar are in the same subview. 431 ASSERT_EQ(2U, [activeCardSubviews count]);
571 ASSERT_EQ(2U, [activeCardSubviews count]);
572 } else {
573 ASSERT_EQ(3U, [activeCardSubviews count]);
574
575 // Profile icon.
576 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2];
577 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSButton class]]);
578
579 // Profile name.
580 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1];
581 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]);
582 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
583 [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
584
585 // Profile links. This is a local profile, so there should be a signin
586 // button.
587 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
588 ASSERT_EQ(1U, [linksSubviews count]);
589 NSButton* link = base::mac::ObjCCast<NSButton>(
590 [linksSubviews objectAtIndex:0]);
591 EXPECT_EQ(@selector(hideAccountManagement:), [link action]);
592 EXPECT_EQ(controller(), [link target]);
593 }
594 } 432 }
595 433
596 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) { 434 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) {
597 switches::EnableNewProfileManagementForTesting( 435 switches::EnableNewProfileManagementForTesting(
598 base::CommandLine::ForCurrentProcess()); 436 base::CommandLine::ForCurrentProcess());
599 437
600 SignInFirstProfile(); 438 SignInFirstProfile();
601 439
602 // The preference, not the email, determines whether the profile can lock. 440 // The preference, not the email, determines whether the profile can lock.
603 browser()->profile()->GetPrefs()->SetString( 441 browser()->profile()->GetPrefs()->SetString(
604 prefs::kGoogleServicesHostedDomain, "chromium.org"); 442 prefs::kGoogleServicesHostedDomain, "chromium.org");
605 443
606 StartProfileChooserController(); 444 StartProfileChooserController();
607 NSArray* subviews = [[[controller() window] contentView] subviews]; 445 NSArray* subviews = [[[controller() window] contentView] subviews];
608 ASSERT_EQ(2U, [subviews count]); 446 ASSERT_EQ(2U, [subviews count]);
609 subviews = [[subviews objectAtIndex:0] subviews]; 447 subviews = [[subviews objectAtIndex:0] subviews];
610 448
611 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 449 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
612 if (switches::IsMaterialDesignUserMenu()) { 450 // There will be two buttons in the option buttons view.
613 // There will be two buttons in the option buttons view. 451 ASSERT_EQ(2U, [buttonSubviews count]);
614 ASSERT_EQ(2U, [buttonSubviews count]);
615 } else {
616 // For non-material-design user menu, there will be two buttons and one
617 // separators in the option buttons view.
618 ASSERT_EQ(3U, [buttonSubviews count]);
619 }
620 452
621 // The last button should not be the lock button. 453 // The last button should not be the lock button.
622 NSButton* lastButton = 454 NSButton* lastButton =
623 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); 455 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
624 ASSERT_TRUE(lastButton); 456 ASSERT_TRUE(lastButton);
625 EXPECT_NE(@selector(lockProfile:), [lastButton action]); 457 EXPECT_NE(@selector(lockProfile:), [lastButton action]);
626 } 458 }
627 459
628 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) { 460 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) {
629 switches::EnableNewProfileManagementForTesting( 461 switches::EnableNewProfileManagementForTesting(
630 base::CommandLine::ForCurrentProcess()); 462 base::CommandLine::ForCurrentProcess());
631 463
632 SignInFirstProfile(); 464 SignInFirstProfile();
633 465
634 // The preference, not the email, determines whether the profile can lock. 466 // The preference, not the email, determines whether the profile can lock.
635 browser()->profile()->GetPrefs()->SetString( 467 browser()->profile()->GetPrefs()->SetString(
636 prefs::kGoogleServicesHostedDomain, "google.com"); 468 prefs::kGoogleServicesHostedDomain, "google.com");
637 // Lock is only available where a supervised user is present. 469 // Lock is only available where a supervised user is present.
638 ProfileAttributesEntry* entry = testing_profile_manager()-> 470 ProfileAttributesEntry* entry = testing_profile_manager()->
639 profile_attributes_storage()->GetAllProfilesAttributes().front(); 471 profile_attributes_storage()->GetAllProfilesAttributes().front();
640 entry->SetSupervisedUserId(kEmail); 472 entry->SetSupervisedUserId(kEmail);
641 473
642 StartProfileChooserController(); 474 StartProfileChooserController();
643 NSArray* subviews = [[[controller() window] contentView] subviews]; 475 NSArray* subviews = [[[controller() window] contentView] subviews];
644 ASSERT_EQ(2U, [subviews count]); 476 ASSERT_EQ(2U, [subviews count]);
645 subviews = [[subviews objectAtIndex:0] subviews]; 477 subviews = [[subviews objectAtIndex:0] subviews];
646 478
647 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 479 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
648 if (switches::IsMaterialDesignUserMenu()) { 480 // There will be two buttons and one separator in the option buttons view.
649 // There will be two buttons and one separator in the option buttons view. 481 ASSERT_EQ(3U, [buttonSubviews count]);
650 ASSERT_EQ(3U, [buttonSubviews count]);
651 } else {
652 // FOr non-material-design user menu, There will be three buttons and two
653 // separators in the option buttons view.
654 ASSERT_EQ(5U, [buttonSubviews count]);
655 }
656 482
657 // There should be a lock button. 483 // There should be a lock button.
658 NSButton* lockButton = 484 NSButton* lockButton =
659 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); 485 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
660 ASSERT_TRUE(lockButton); 486 ASSERT_TRUE(lockButton);
661 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); 487 EXPECT_EQ(@selector(lockProfile:), [lockButton action]);
662 EXPECT_EQ(controller(), [lockButton target]); 488 EXPECT_EQ(controller(), [lockButton target]);
663 EXPECT_TRUE([lockButton isEnabled]); 489 EXPECT_TRUE([lockButton isEnabled]);
664 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698