OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); | 84 base::scoped_nsobject<AppController> ac([[AppController alloc] init]); |
85 | 85 |
86 // Delete the active profile. | 86 // Delete the active profile. |
87 profile_manager_.profile_manager()->ScheduleProfileForDeletion( | 87 profile_manager_.profile_manager()->ScheduleProfileForDeletion( |
88 dest_path1, ProfileManager::CreateCallback()); | 88 dest_path1, ProfileManager::CreateCallback()); |
89 | 89 |
90 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
91 | 91 |
92 EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath()); | 92 EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath()); |
93 } | 93 } |
94 | |
95 TEST_F(AppControllerTest, TestSigninMenuItemNoErrors) { | |
96 base::scoped_nsobject<NSMenuItem> syncMenuItem( | |
97 [[NSMenuItem alloc] initWithTitle:@"" | |
98 action:@selector(commandDispatch) | |
99 keyEquivalent:@""]); | |
100 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | |
101 | |
102 NSString* startSignin = l10n_util::GetNSStringFWithFixup( | |
103 IDS_SYNC_MENU_PRE_SYNCED_LABEL, | |
104 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | |
105 | |
106 // Make sure shouldShow parameter is obeyed, and we get the default | |
107 // label if not signed in. | |
108 [AppController updateSigninItem:syncMenuItem | |
109 shouldShow:YES | |
110 currentProfile:profile_]; | |
111 | |
112 EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSignin]); | |
113 EXPECT_FALSE([syncMenuItem isHidden]); | |
114 | |
115 [AppController updateSigninItem:syncMenuItem | |
116 shouldShow:NO | |
117 currentProfile:profile_]; | |
118 EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSignin]); | |
119 EXPECT_TRUE([syncMenuItem isHidden]); | |
120 | |
121 // Now sign in. | |
122 std::string username = "foo@example.com"; | |
123 NSString* alreadySignedIn = l10n_util::GetNSStringFWithFixup( | |
124 IDS_SYNC_MENU_SYNCED_LABEL, base::UTF8ToUTF16(username)); | |
125 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | |
126 signin->SetAuthenticatedAccountInfo(username, username); | |
127 browser_sync::ProfileSyncService* sync = | |
128 ProfileSyncServiceFactory::GetForProfile(profile_); | |
129 sync->SetFirstSetupComplete(); | |
130 [AppController updateSigninItem:syncMenuItem | |
131 shouldShow:YES | |
132 currentProfile:profile_]; | |
133 EXPECT_TRUE([[syncMenuItem title] isEqualTo:alreadySignedIn]); | |
134 EXPECT_FALSE([syncMenuItem isHidden]); | |
135 } | |
136 | |
137 TEST_F(AppControllerTest, TestSigninMenuItemAuthError) { | |
138 base::scoped_nsobject<NSMenuItem> syncMenuItem( | |
139 [[NSMenuItem alloc] initWithTitle:@"" | |
140 action:@selector(commandDispatch) | |
141 keyEquivalent:@""]); | |
142 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | |
143 | |
144 // Now sign in. | |
145 std::string username = "foo@example.com"; | |
146 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | |
147 signin->SetAuthenticatedAccountInfo(username, username); | |
148 browser_sync::ProfileSyncService* sync = | |
149 ProfileSyncServiceFactory::GetForProfile(profile_); | |
150 sync->SetFirstSetupComplete(); | |
151 // Force an auth error. | |
152 FakeAuthStatusProvider provider( | |
153 SigninErrorControllerFactory::GetForProfile(profile_)); | |
154 GoogleServiceAuthError error( | |
155 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | |
156 provider.SetAuthError("user@gmail.com", error); | |
157 [AppController updateSigninItem:syncMenuItem | |
158 shouldShow:YES | |
159 currentProfile:profile_]; | |
160 NSString* authError = | |
161 l10n_util::GetNSStringWithFixup(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM); | |
162 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); | |
163 EXPECT_FALSE([syncMenuItem isHidden]); | |
164 } | |
165 | |
166 // If there's a separator after the signin menu item, make sure it is hidden/ | |
167 // shown when the signin menu item is. | |
168 TEST_F(AppControllerTest, TestSigninMenuItemWithSeparator) { | |
169 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); | |
170 NSMenuItem* signinMenuItem = [menu addItemWithTitle:@"" | |
171 action:@selector(commandDispatch) | |
172 keyEquivalent:@""]; | |
173 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | |
174 NSMenuItem* followingSeparator = [NSMenuItem separatorItem]; | |
175 [menu addItem:followingSeparator]; | |
176 [signinMenuItem setHidden:NO]; | |
177 [followingSeparator setHidden:NO]; | |
178 | |
179 [AppController updateSigninItem:signinMenuItem | |
180 shouldShow:NO | |
181 currentProfile:profile_]; | |
182 | |
183 EXPECT_FALSE([followingSeparator isEnabled]); | |
184 EXPECT_TRUE([signinMenuItem isHidden]); | |
185 EXPECT_TRUE([followingSeparator isHidden]); | |
186 | |
187 [AppController updateSigninItem:signinMenuItem | |
188 shouldShow:YES | |
189 currentProfile:profile_]; | |
190 | |
191 EXPECT_FALSE([followingSeparator isEnabled]); | |
192 EXPECT_FALSE([signinMenuItem isHidden]); | |
193 EXPECT_FALSE([followingSeparator isHidden]); | |
194 } | |
195 | |
196 // If there's a non-separator item after the signin menu item, it should not | |
197 // change state when the signin menu item is hidden/shown. | |
198 TEST_F(AppControllerTest, TestSigninMenuItemWithNonSeparator) { | |
199 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); | |
200 NSMenuItem* signinMenuItem = [menu addItemWithTitle:@"" | |
201 action:@selector(commandDispatch) | |
202 keyEquivalent:@""]; | |
203 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; | |
204 NSMenuItem* followingNonSeparator = | |
205 [menu addItemWithTitle:@"" | |
206 action:@selector(commandDispatch) | |
207 keyEquivalent:@""]; | |
208 [signinMenuItem setHidden:NO]; | |
209 [followingNonSeparator setHidden:NO]; | |
210 | |
211 [AppController updateSigninItem:signinMenuItem | |
212 shouldShow:NO | |
213 currentProfile:profile_]; | |
214 | |
215 EXPECT_TRUE([followingNonSeparator isEnabled]); | |
216 EXPECT_TRUE([signinMenuItem isHidden]); | |
217 EXPECT_FALSE([followingNonSeparator isHidden]); | |
218 | |
219 [followingNonSeparator setHidden:YES]; | |
220 [AppController updateSigninItem:signinMenuItem | |
221 shouldShow:YES | |
222 currentProfile:profile_]; | |
223 | |
224 EXPECT_TRUE([followingNonSeparator isEnabled]); | |
225 EXPECT_FALSE([signinMenuItem isHidden]); | |
226 EXPECT_TRUE([followingNonSeparator isHidden]); | |
227 } | |
OLD | NEW |