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

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

Issue 2920853004: [sync] Display an error when sync settings aren't confirmed (Closed)
Patch Set: Reformat, remove browser_options change Created 3 years, 6 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/avatar_button_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/profiles/profiles_state.h" 12 #include "chrome/browser/profiles/profiles_state.h"
13 #include "chrome/browser/sync/profile_sync_service_factory.h"
14 #include "chrome/browser/sync/profile_sync_test_util.h"
13 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
15 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 17 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
16 #include "chrome/browser/ui/cocoa/info_bubble_window.h" 18 #include "chrome/browser/ui/cocoa/info_bubble_window.h"
17 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 19 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
18 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" 20 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
19 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
20 #include "components/signin/core/common/profile_management_switches.h" 22 #include "components/signin/core/common/profile_management_switches.h"
23 #include "components/sync_preferences/pref_service_syncable.h"
21 #import "testing/gtest_mac.h" 24 #import "testing/gtest_mac.h"
22 #include "ui/base/material_design/material_design_controller.h" 25 #include "ui/base/material_design/material_design_controller.h"
23 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
24 27
28 using ::testing::Return;
29
25 // Defined in the AvatarButtonController implementation. 30 // Defined in the AvatarButtonController implementation.
26 @interface AvatarButtonController (ExposedForTesting) 31 @interface AvatarButtonController (ExposedForTesting)
27 - (void)setErrorStatus:(BOOL)hasError; 32 - (void)setErrorStatus:(BOOL)hasError;
28 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; 33 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent;
29 @end 34 @end
30 35
31 // Mocks the AvatarButtonController class so that we can mock its browser 36 // Mocks the AvatarButtonController class so that we can mock its browser
32 // window's frame color. 37 // window's frame color.
33 @interface MockAvatarButtonController : AvatarButtonController { 38 @interface MockAvatarButtonController : AvatarButtonController {
34 // True if the frame color is dark. 39 // True if the frame color is dark.
(...skipping 11 matching lines...) Expand all
46 } 51 }
47 52
48 - (BOOL)isFrameColorDark { 53 - (BOOL)isFrameColorDark {
49 return isFrameDark_; 54 return isFrameDark_;
50 } 55 }
51 56
52 @end 57 @end
53 58
54 class AvatarButtonControllerTest : public CocoaProfileTest { 59 class AvatarButtonControllerTest : public CocoaProfileTest {
55 public: 60 public:
61 AvatarButtonControllerTest() {
62 TestingProfile::TestingFactories factories;
63 factories.push_back(std::make_pair(ProfileSyncServiceFactory::GetInstance(),
64 BuildMockProfileSyncService));
65 AddTestingFactories(factories);
66 }
67
56 void SetUp() override { 68 void SetUp() override {
57 DCHECK(profiles::IsMultipleProfilesEnabled()); 69 DCHECK(profiles::IsMultipleProfilesEnabled());
58 70
59 CocoaProfileTest::SetUp(); 71 CocoaProfileTest::SetUp();
60 ASSERT_TRUE(browser()); 72 ASSERT_TRUE(browser());
73 ASSERT_TRUE(browser()->profile());
74
75 mock_sync_service_1_ = static_cast<browser_sync::ProfileSyncServiceMock*>(
76 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
77 browser()->profile()));
78 EXPECT_CALL(*mock_sync_service_1_, IsFirstSetupComplete())
79 .WillRepeatedly(Return(false));
80 EXPECT_CALL(*mock_sync_service_1_, IsFirstSetupInProgress())
81 .WillRepeatedly(Return(true));
82 EXPECT_CALL(*mock_sync_service_1_, IsSyncConfirmationNeeded())
83 .WillRepeatedly(Return(false));
61 84
62 controller_.reset([[MockAvatarButtonController alloc] 85 controller_.reset([[MockAvatarButtonController alloc]
63 initWithBrowser:browser() 86 initWithBrowser:browser()
64 window:nil]); 87 window:nil]);
65 } 88 }
66 89
67 void TearDown() override { 90 void TearDown() override {
68 browser()->window()->Close(); 91 browser()->window()->Close();
69 CocoaProfileTest::TearDown(); 92 CocoaProfileTest::TearDown();
70 } 93 }
71 94
95 void AddSecondProfile() {
96 TestingProfile::TestingFactories factories;
97 factories.push_back(std::make_pair(ProfileSyncServiceFactory::GetInstance(),
98 BuildMockProfileSyncService));
99
100 Profile* new_profile = testing_profile_manager()->CreateTestingProfile(
101 "batman", std::unique_ptr<sync_preferences::PrefServiceSyncable>(),
102 base::UTF8ToUTF16("Person 1"), 0, std::string(), factories);
103
104 mock_sync_service_2_ = static_cast<browser_sync::ProfileSyncServiceMock*>(
105 ProfileSyncServiceFactory::GetInstance()->GetForProfile(new_profile));
106
107 EXPECT_CALL(*mock_sync_service_2_, IsFirstSetupComplete())
108 .WillRepeatedly(Return(false));
109 EXPECT_CALL(*mock_sync_service_2_, IsFirstSetupInProgress())
110 .WillRepeatedly(Return(true));
111 EXPECT_CALL(*mock_sync_service_2_, IsSyncConfirmationNeeded())
112 .WillRepeatedly(Return(false));
113 }
114
72 NSButton* button() { return [controller_ buttonView]; } 115 NSButton* button() { return [controller_ buttonView]; }
73 116
74 NSView* view() { return [controller_ view]; } 117 NSView* view() { return [controller_ view]; }
75 118
76 MockAvatarButtonController* controller() { return controller_.get(); } 119 MockAvatarButtonController* controller() { return controller_.get(); }
77 120
78 private: 121 private:
79 base::scoped_nsobject<MockAvatarButtonController> controller_; 122 base::scoped_nsobject<MockAvatarButtonController> controller_;
123 browser_sync::ProfileSyncServiceMock* mock_sync_service_1_;
124 browser_sync::ProfileSyncServiceMock* mock_sync_service_2_;
80 }; 125 };
81 126
82 TEST_F(AvatarButtonControllerTest, GenericButtonShown) { 127 TEST_F(AvatarButtonControllerTest, GenericButtonShown) {
83 ASSERT_FALSE([view() isHidden]); 128 ASSERT_FALSE([view() isHidden]);
84 // There is only one local profile, which means displaying the generic 129 // There is only one local profile, which means displaying the generic
85 // avatar button. 130 // avatar button.
86 EXPECT_NSEQ(@"", [button() title]); 131 EXPECT_NSEQ(@"", [button() title]);
87 } 132 }
88 133
89 TEST_F(AvatarButtonControllerTest, ProfileButtonShown) { 134 TEST_F(AvatarButtonControllerTest, ProfileButtonShown) {
90 // Create a second profile, to force the button to display the profile name. 135 // Create a second profile, to force the button to display the profile name.
91 testing_profile_manager()->CreateTestingProfile("batman"); 136 testing_profile_manager()->CreateTestingProfile("batman");
92 137
93 ASSERT_FALSE([view() isHidden]); 138 ASSERT_FALSE([view() isHidden]);
94 EXPECT_NSEQ(@"Person 1", [button() title]); 139 EXPECT_NSEQ(@"Person 1", [button() title]);
95 } 140 }
96 141
97 TEST_F(AvatarButtonControllerTest, ProfileButtonWithErrorShown) { 142 TEST_F(AvatarButtonControllerTest, ProfileButtonWithErrorShown) {
98 // Create a second profile, to force the button to display the profile name. 143 // Create a second profile, to force the button to display the profile name.
99 testing_profile_manager()->CreateTestingProfile("batman"); 144 AddSecondProfile();
100 145
101 EXPECT_EQ(0, [button() image].size.width); 146 EXPECT_EQ(0, [button() image].size.width);
102 [controller() setErrorStatus:true]; 147 [controller() setErrorStatus:true];
103 148
104 ASSERT_FALSE([view() isHidden]); 149 ASSERT_FALSE([view() isHidden]);
105 EXPECT_NSEQ(@"Person 1", [button() title]); 150 EXPECT_NSEQ(@"Person 1", [button() title]);
106 151
107 // If the button has an authentication error, it should display an error 152 // If the button has an authentication error, it should display an error
108 // icon. 153 // icon.
109 EXPECT_EQ(16, [button() image].size.width); 154 EXPECT_EQ(16, [button() image].size.width);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 189
145 // Set the frame color to be dark. The button's title color should be white. 190 // Set the frame color to be dark. The button's title color should be white.
146 [controller() setIsFrameDark:YES]; 191 [controller() setIsFrameDark:YES];
147 [controller() updateAvatarButtonAndLayoutParent:NO]; 192 [controller() updateAvatarButtonAndLayoutParent:NO];
148 titleColor = 193 titleColor =
149 [[button() attributedTitle] attribute:NSForegroundColorAttributeName 194 [[button() attributedTitle] attribute:NSForegroundColorAttributeName
150 atIndex:0 195 atIndex:0
151 effectiveRange:nil]; 196 effectiveRange:nil];
152 DCHECK_EQ(titleColor, [NSColor whiteColor]); 197 DCHECK_EQ(titleColor, [NSColor whiteColor]);
153 } 198 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/avatar_button_error_controller.cc ('k') | chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698