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 ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(profile_); |
| 128 sync->SetSyncSetupCompleted(); |
| 129 [AppController updateSigninItem:syncMenuItem |
| 130 shouldShow:YES |
| 131 currentProfile:profile_]; |
| 132 EXPECT_TRUE([[syncMenuItem title] isEqualTo:alreadySignedIn]); |
| 133 EXPECT_FALSE([syncMenuItem isHidden]); |
| 134 } |
| 135 |
| 136 TEST_F(AppControllerTest, TestSigninMenuItemAuthError) { |
| 137 base::scoped_nsobject<NSMenuItem> syncMenuItem( |
| 138 [[NSMenuItem alloc] initWithTitle:@"" |
| 139 action:@selector(commandDispatch) |
| 140 keyEquivalent:@""]); |
| 141 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
| 142 |
| 143 // Now sign in. |
| 144 std::string username = "foo@example.com"; |
| 145 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 146 signin->SetAuthenticatedAccountInfo(username, username); |
| 147 ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(profile_); |
| 148 sync->SetSyncSetupCompleted(); |
| 149 // Force an auth error. |
| 150 FakeAuthStatusProvider provider( |
| 151 SigninErrorControllerFactory::GetForProfile(profile_)); |
| 152 GoogleServiceAuthError error( |
| 153 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 154 provider.SetAuthError("user@gmail.com", error); |
| 155 [AppController updateSigninItem:syncMenuItem |
| 156 shouldShow:YES |
| 157 currentProfile:profile_]; |
| 158 NSString* authError = |
| 159 l10n_util::GetNSStringWithFixup(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM); |
| 160 EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); |
| 161 EXPECT_FALSE([syncMenuItem isHidden]); |
| 162 } |
| 163 |
| 164 // If there's a separator after the signin menu item, make sure it is hidden/ |
| 165 // shown when the signin menu item is. |
| 166 TEST_F(AppControllerTest, TestSigninMenuItemWithSeparator) { |
| 167 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
| 168 NSMenuItem* signinMenuItem = [menu addItemWithTitle:@"" |
| 169 action:@selector(commandDispatch) |
| 170 keyEquivalent:@""]; |
| 171 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
| 172 NSMenuItem* followingSeparator = [NSMenuItem separatorItem]; |
| 173 [menu addItem:followingSeparator]; |
| 174 [signinMenuItem setHidden:NO]; |
| 175 [followingSeparator setHidden:NO]; |
| 176 |
| 177 [AppController updateSigninItem:signinMenuItem |
| 178 shouldShow:NO |
| 179 currentProfile:profile_]; |
| 180 |
| 181 EXPECT_FALSE([followingSeparator isEnabled]); |
| 182 EXPECT_TRUE([signinMenuItem isHidden]); |
| 183 EXPECT_TRUE([followingSeparator isHidden]); |
| 184 |
| 185 [AppController updateSigninItem:signinMenuItem |
| 186 shouldShow:YES |
| 187 currentProfile:profile_]; |
| 188 |
| 189 EXPECT_FALSE([followingSeparator isEnabled]); |
| 190 EXPECT_FALSE([signinMenuItem isHidden]); |
| 191 EXPECT_FALSE([followingSeparator isHidden]); |
| 192 } |
| 193 |
| 194 // If there's a non-separator item after the signin menu item, it should not |
| 195 // change state when the signin menu item is hidden/shown. |
| 196 TEST_F(AppControllerTest, TestSigninMenuItemWithNonSeparator) { |
| 197 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
| 198 NSMenuItem* signinMenuItem = [menu addItemWithTitle:@"" |
| 199 action:@selector(commandDispatch) |
| 200 keyEquivalent:@""]; |
| 201 [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; |
| 202 NSMenuItem* followingNonSeparator = |
| 203 [menu addItemWithTitle:@"" |
| 204 action:@selector(commandDispatch) |
| 205 keyEquivalent:@""]; |
| 206 [signinMenuItem setHidden:NO]; |
| 207 [followingNonSeparator setHidden:NO]; |
| 208 |
| 209 [AppController updateSigninItem:signinMenuItem |
| 210 shouldShow:NO |
| 211 currentProfile:profile_]; |
| 212 |
| 213 EXPECT_TRUE([followingNonSeparator isEnabled]); |
| 214 EXPECT_TRUE([signinMenuItem isHidden]); |
| 215 EXPECT_FALSE([followingNonSeparator isHidden]); |
| 216 |
| 217 [followingNonSeparator setHidden:YES]; |
| 218 [AppController updateSigninItem:signinMenuItem |
| 219 shouldShow:YES |
| 220 currentProfile:profile_]; |
| 221 |
| 222 EXPECT_TRUE([followingNonSeparator isEnabled]); |
| 223 EXPECT_FALSE([signinMenuItem isHidden]); |
| 224 EXPECT_TRUE([followingNonSeparator isHidden]); |
| 225 } |
OLD | NEW |