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

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

Issue 566933005: Do not display lock for hosted domains (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle a null in unit tests Created 6 years, 3 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 "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"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/prefs/pref_service_syncable.h" 13 #include "chrome/browser/prefs/pref_service_syncable.h"
14 #include "chrome/browser/profiles/avatar_menu.h" 14 #include "chrome/browser/profiles/avatar_menu.h"
15 #include "chrome/browser/profiles/profile_info_cache.h" 15 #include "chrome/browser/profiles/profile_info_cache.h"
16 #include "chrome/browser/signin/account_tracker_service_factory.h" 16 #include "chrome/browser/signin/account_tracker_service_factory.h"
17 #include "chrome/browser/signin/fake_account_tracker_service.h" 17 #include "chrome/browser/signin/fake_account_tracker_service.h"
18 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 18 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
19 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 19 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21 #include "chrome/browser/signin/signin_header_helper.h" 21 #include "chrome/browser/signin/signin_header_helper.h"
22 #include "chrome/browser/signin/signin_manager_factory.h" 22 #include "chrome/browser/signin/signin_manager_factory.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 24 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h"
26 #include "components/signin/core/browser/profile_oauth2_token_service.h" 27 #include "components/signin/core/browser/profile_oauth2_token_service.h"
27 #include "components/signin/core/browser/signin_manager.h" 28 #include "components/signin/core/browser/signin_manager.h"
28 #include "components/signin/core/common/profile_management_switches.h" 29 #include "components/signin/core/common/profile_management_switches.h"
29 30
30 const std::string kEmail = "user@gmail.com"; 31 const std::string kEmail = "user@gmail.com";
31 const std::string kSecondaryEmail = "user2@gmail.com"; 32 const std::string kSecondaryEmail = "user2@gmail.com";
32 const std::string kLoginToken = "oauth2_login_token"; 33 const std::string kLoginToken = "oauth2_login_token";
33 34
34 class ProfileChooserControllerTest : public CocoaProfileTest { 35 class ProfileChooserControllerTest : public CocoaProfileTest {
35 public: 36 public:
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 ASSERT_EQ(2U, [subviews count]); 370 ASSERT_EQ(2U, [subviews count]);
370 subviews = [[subviews objectAtIndex:0] subviews]; 371 subviews = [[subviews objectAtIndex:0] subviews];
371 372
372 // There should be one active card, one accounts container, two separators 373 // There should be one active card, one accounts container, two separators
373 // and one option buttons view. 374 // and one option buttons view.
374 ASSERT_EQ(5U, [subviews count]); 375 ASSERT_EQ(5U, [subviews count]);
375 376
376 // There should be three buttons and two separators in the option 377 // There should be three buttons and two separators in the option
377 // buttons view. 378 // buttons view.
378 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; 379 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
379 ASSERT_EQ(5U, [buttonSubviews count]); 380 ASSERT_EQ(3U, [buttonSubviews count]);
380
381 // There should be a lock button.
382 NSButton* lockButton =
383 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
384 EXPECT_EQ(@selector(lockProfile:), [lockButton action]);
385 EXPECT_EQ(controller(), [lockButton target]);
386 381
387 // There should be a separator. 382 // There should be a separator.
388 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]); 383 EXPECT_TRUE([[buttonSubviews objectAtIndex:1] isKindOfClass:[NSBox class]]);
389 384
390 // There should be an incognito button. 385 // There should be an incognito button.
391 NSButton* incognitoButton = 386 NSButton* incognitoButton =
392 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]); 387 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
393 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]); 388 EXPECT_EQ(@selector(goIncognito:), [incognitoButton action]);
394 EXPECT_EQ(controller(), [incognitoButton target]); 389 EXPECT_EQ(controller(), [incognitoButton target]);
395 390
396 // There should be a separator. 391 // There should be a separator.
397 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); 392 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]);
398 393
399 // There should be a user switcher button. 394 // There should be a user switcher button.
400 NSButton* userSwitcherButton = 395 NSButton* userSwitcherButton =
401 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:4]); 396 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:2]);
402 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]); 397 EXPECT_EQ(@selector(showUserManager:), [userSwitcherButton action]);
403 EXPECT_EQ(controller(), [userSwitcherButton target]); 398 EXPECT_EQ(controller(), [userSwitcherButton target]);
404 399
405 // In the accounts view, there should be the account list container 400 // In the accounts view, there should be the account list container
406 // accounts and one "add accounts" button. 401 // accounts and one "add accounts" button.
407 NSArray* accountsSubviews = [[subviews objectAtIndex:2] subviews]; 402 NSArray* accountsSubviews = [[subviews objectAtIndex:2] subviews];
408 ASSERT_EQ(2U, [accountsSubviews count]); 403 ASSERT_EQ(2U, [accountsSubviews count]);
409 404
410 NSButton* addAccountsButton = 405 NSButton* addAccountsButton =
411 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]); 406 base::mac::ObjCCast<NSButton>([accountsSubviews objectAtIndex:0]);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); 447 [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
453 448
454 // Profile links. This is a local profile, so there should be a signin button. 449 // Profile links. This is a local profile, so there should be a signin button.
455 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; 450 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
456 ASSERT_EQ(1U, [linksSubviews count]); 451 ASSERT_EQ(1U, [linksSubviews count]);
457 NSButton* link = base::mac::ObjCCast<NSButton>( 452 NSButton* link = base::mac::ObjCCast<NSButton>(
458 [linksSubviews objectAtIndex:0]); 453 [linksSubviews objectAtIndex:0]);
459 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); 454 EXPECT_EQ(@selector(hideAccountManagement:), [link action]);
460 EXPECT_EQ(controller(), [link target]); 455 EXPECT_EQ(controller(), [link target]);
461 } 456 }
457
458 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) {
459 switches::EnableNewProfileManagementForTesting(
460 CommandLine::ForCurrentProcess());
461 // Sign in the first profile.
462 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache();
463 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail));
464 // The preference, not the email, determines whether the profile can lock.
465 browser()->profile()->GetPrefs()->SetString(
466 prefs::kGoogleServicesHostedDomain, "chromium.org");
467
468 StartProfileChooserController();
469 NSArray* subviews = [[[controller() window] contentView] subviews];
470 ASSERT_EQ(2U, [subviews count]);
471 subviews = [[subviews objectAtIndex:0] subviews];
472
473 // Three profiles means we should have one active card, one separator, one
msw 2014/09/19 21:47:40 I see this comment is copied from elsewhere, but I
Mike Lerman 2014/09/21 00:19:36 I can agree with that - a test should test its own
474 // option buttons view and a lock view. We also have an update promo for the
475 // new avatar menu.
476 // TODO(noms): Enforcing 5U fails on the waterfall debug bots, but it's not
477 // reproducible anywhere else.
478 ASSERT_GE([subviews count], 4U);
479
480 // There will be two buttons and one separators in the option buttons view.
481 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
482 ASSERT_EQ(3U, [buttonSubviews count]);
483
484 // The last button should not be the lock button.
485 NSButton* lastButton =
486 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
487 ASSERT_TRUE(lastButton);
488 EXPECT_NE(@selector(lockProfile:), [lastButton action]);
489 }
490
491 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) {
492 switches::EnableNewProfileManagementForTesting(
493 CommandLine::ForCurrentProcess());
494 // Sign in the first profile.
495 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache();
496 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail));
497 // The preference, not the email, determines whether the profile can lock.
498 browser()->profile()->GetPrefs()->SetString(
499 prefs::kGoogleServicesHostedDomain, "google.com");
500 StartProfileChooserController();
msw 2014/09/19 21:47:40 nit: add a blank line above, or remove the corresp
Mike Lerman 2014/09/21 00:19:36 Done.
501 NSArray* subviews = [[[controller() window] contentView] subviews];
502 ASSERT_EQ(2U, [subviews count]);
503 subviews = [[subviews objectAtIndex:0] subviews];
504
505 // Three profiles means we should have one active card, one separator, one
msw 2014/09/19 21:47:40 Ditto.
Mike Lerman 2014/09/21 00:19:36 Done.
506 // option buttons view and a lock view. We also have an update promo for the
507 // new avatar menu.
508 // TODO(noms): Enforcing 5U fails on the waterfall debug bots, but it's not
509 // reproducible anywhere else.
510 ASSERT_GE([subviews count], 4U);
511
512 // There will be three buttons and two separators in the option buttons view.
513 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
514 ASSERT_EQ(5U, [buttonSubviews count]);
515
516 // There should be a lock button.
517 NSButton* lockButton =
518 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
519 ASSERT_TRUE(lockButton);
520 EXPECT_EQ(@selector(lockProfile:), [lockButton action]);
521 EXPECT_EQ(controller(), [lockButton target]);
522 EXPECT_TRUE([lockButton isEnabled]);
523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698