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

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: Improved tests, more comments 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 [base::mac::ObjCCast<NSButton>(activeProfileName) title])); 453 [base::mac::ObjCCast<NSButton>(activeProfileName) title]));
453 454
454 // Profile links. This is a local profile, so there should be a signin button. 455 // Profile links. This is a local profile, so there should be a signin button.
455 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; 456 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
456 ASSERT_EQ(1U, [linksSubviews count]); 457 ASSERT_EQ(1U, [linksSubviews count]);
457 NSButton* link = base::mac::ObjCCast<NSButton>( 458 NSButton* link = base::mac::ObjCCast<NSButton>(
458 [linksSubviews objectAtIndex:0]); 459 [linksSubviews objectAtIndex:0]);
459 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); 460 EXPECT_EQ(@selector(hideAccountManagement:), [link action]);
460 EXPECT_EQ(controller(), [link target]); 461 EXPECT_EQ(controller(), [link target]);
461 } 462 }
463
464 TEST_F(ProfileChooserControllerTest, SignedInProfileLockDisabled) {
465 switches::EnableNewProfileManagementForTesting(
466 CommandLine::ForCurrentProcess());
467 // Sign in the first profile.
468 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache();
469 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail));
470 // The preference, not the email, determines whether the profile can lock.
471 browser()->profile()->GetPrefs()->SetBoolean(
472 prefs::kProfileIsLockable, false);
473
474 StartProfileChooserController();
475 NSArray* subviews = [[[controller() window] contentView] subviews];
476 ASSERT_EQ(2U, [subviews count]);
477 subviews = [[subviews objectAtIndex:0] subviews];
478
479 // Three profiles means we should have one active card, one separator, one
480 // option buttons view and a lock view. We also have an update promo for the
481 // new avatar menu.
482 // TODO(noms): Enforcing 5U fails on the waterfall debug bots, but it's not
483 // reproducible anywhere else.
484 ASSERT_GE([subviews count], 4U);
485
486 // There will be three buttons and two separators in the option buttons view.
487 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
488 ASSERT_EQ(5U, [buttonSubviews count]);
489
490 // There should be a lock button.
491 NSButton* lockButton =
492 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
493 ASSERT_TRUE(lockButton);
494 EXPECT_EQ(@selector(lockProfile:), [lockButton action]);
495 EXPECT_EQ(controller(), [lockButton target]);
496 EXPECT_FALSE([lockButton isEnabled]);
497 }
498
499 TEST_F(ProfileChooserControllerTest, SignedInProfileLockEnabled) {
500 switches::EnableNewProfileManagementForTesting(
501 CommandLine::ForCurrentProcess());
502 // Sign in the first profile.
503 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache();
504 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail));
505 // The preference, not the email, determines whether the profile can lock.
506 browser()->profile()->GetPrefs()->SetBoolean(prefs::kProfileIsLockable, true);
507
508 StartProfileChooserController();
509 NSArray* subviews = [[[controller() window] contentView] subviews];
510 ASSERT_EQ(2U, [subviews count]);
511 subviews = [[subviews objectAtIndex:0] subviews];
512
513 // Three profiles means we should have one active card, one separator, one
514 // option buttons view and a lock view. We also have an update promo for the
515 // new avatar menu.
516 // TODO(noms): Enforcing 5U fails on the waterfall debug bots, but it's not
517 // reproducible anywhere else.
518 ASSERT_GE([subviews count], 4U);
519
520 // There will be three buttons and two separators in the option buttons view.
521 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews];
522 ASSERT_EQ(5U, [buttonSubviews count]);
523
524 // There should be a lock button.
525 NSButton* lockButton =
526 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]);
527 ASSERT_TRUE(lockButton);
528 EXPECT_EQ(@selector(lockProfile:), [lockButton action]);
529 EXPECT_EQ(controller(), [lockButton target]);
530 EXPECT_TRUE([lockButton isEnabled]);
531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698