From 7529916efbda5763f6b5ddd9256ea46e29065281 Mon Sep 17 00:00:00 2001 From: ricea Date: Wed, 19 Aug 2015 02:32:03 -0700 Subject: Revert of Delete dead signin code (SigninGlobalError) (patchset #8 id:140001 of https://codereview.chromium.org/1299543002/ ) Reason for revert: Broke the Mac10.9 Tests (dbg) bot: http://build.chromium.org/p/chromium.mac/builders/Mac10.9%20Tests%20%28dbg%29/builds/10278 See the stack trace in the logs. Original issue's description: > Delete dead signin code (SigninGlobalError) > > BUG=none > > Committed: https://crrev.com/c91b178b07b0d9fb0c7a437df3a1da3db1887160 > Cr-Commit-Position: refs/heads/master@{#344176} TBR=anthonyvd@chromium.org,sky@chromium.org,rogerta@chromium.org,estade@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=none Review URL: https://codereview.chromium.org/1301583004 Cr-Commit-Position: refs/heads/master@{#344188} --- chrome/browser/app_controller_mac_unittest.mm | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) (limited to 'chrome/browser/app_controller_mac_unittest.mm') diff --git a/chrome/browser/app_controller_mac_unittest.mm b/chrome/browser/app_controller_mac_unittest.mm index eb04619..5cf952c 100644 --- a/chrome/browser/app_controller_mac_unittest.mm +++ b/chrome/browser/app_controller_mac_unittest.mm @@ -91,3 +91,135 @@ TEST_F(AppControllerTest, LastProfile) { EXPECT_EQ(dest_path2, [ac lastProfile]->GetPath()); } + +TEST_F(AppControllerTest, TestSigninMenuItemNoErrors) { + base::scoped_nsobject syncMenuItem( + [[NSMenuItem alloc] initWithTitle:@"" + action:@selector(commandDispatch) + keyEquivalent:@""]); + [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; + + NSString* startSignin = l10n_util::GetNSStringFWithFixup( + IDS_SYNC_MENU_PRE_SYNCED_LABEL, + l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); + + // Make sure shouldShow parameter is obeyed, and we get the default + // label if not signed in. + [AppController updateSigninItem:syncMenuItem + shouldShow:YES + currentProfile:profile_]; + + EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSignin]); + EXPECT_FALSE([syncMenuItem isHidden]); + + [AppController updateSigninItem:syncMenuItem + shouldShow:NO + currentProfile:profile_]; + EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSignin]); + EXPECT_TRUE([syncMenuItem isHidden]); + + // Now sign in. + std::string username = "foo@example.com"; + NSString* alreadySignedIn = l10n_util::GetNSStringFWithFixup( + IDS_SYNC_MENU_SYNCED_LABEL, base::UTF8ToUTF16(username)); + SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); + signin->SetAuthenticatedAccountInfo(username, username); + ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(profile_); + sync->SetSyncSetupCompleted(); + [AppController updateSigninItem:syncMenuItem + shouldShow:YES + currentProfile:profile_]; + EXPECT_TRUE([[syncMenuItem title] isEqualTo:alreadySignedIn]); + EXPECT_FALSE([syncMenuItem isHidden]); +} + +TEST_F(AppControllerTest, TestSigninMenuItemAuthError) { + base::scoped_nsobject syncMenuItem( + [[NSMenuItem alloc] initWithTitle:@"" + action:@selector(commandDispatch) + keyEquivalent:@""]); + [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP]; + + // Now sign in. + std::string username = "foo@example.com"; + SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); + signin->SetAuthenticatedAccountInfo(username, username); + ProfileSyncService* sync = ProfileSyncServiceFactory::GetForProfile(profile_); + sync->SetSyncSetupCompleted(); + // Force an auth error. + FakeAuthStatusProvider provider( + SigninErrorControllerFactory::GetForProfile(profile_)); + GoogleServiceAuthError error( + GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); + provider.SetAuthError("user@gmail.com", error); + [AppController updateSigninItem:syncMenuItem + shouldShow:YES + currentProfile:profile_]; + NSString* authError = + l10n_util::GetNSStringWithFixup(IDS_SYNC_SIGN_IN_ERROR_WRENCH_MENU_ITEM); + EXPECT_TRUE([[syncMenuItem title] isEqualTo:authError]); + EXPECT_FALSE([syncMenuItem isHidden]); +} + +// If there's a separator after the signin menu item, make sure it is hidden/ +// shown when the signin menu item is. +TEST_F(AppControllerTest, TestSigninMenuItemWithSeparator) { + base::scoped_nsobject menu([[NSMenu alloc] initWithTitle:@""]); + NSMenuItem* signinMenuItem = [menu addItemWithTitle:@"" + action:@selector(commandDispatch) + keyEquivalent:@""]; + [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; + NSMenuItem* followingSeparator = [NSMenuItem separatorItem]; + [menu addItem:followingSeparator]; + [signinMenuItem setHidden:NO]; + [followingSeparator setHidden:NO]; + + [AppController updateSigninItem:signinMenuItem + shouldShow:NO + currentProfile:profile_]; + + EXPECT_FALSE([followingSeparator isEnabled]); + EXPECT_TRUE([signinMenuItem isHidden]); + EXPECT_TRUE([followingSeparator isHidden]); + + [AppController updateSigninItem:signinMenuItem + shouldShow:YES + currentProfile:profile_]; + + EXPECT_FALSE([followingSeparator isEnabled]); + EXPECT_FALSE([signinMenuItem isHidden]); + EXPECT_FALSE([followingSeparator isHidden]); +} + +// If there's a non-separator item after the signin menu item, it should not +// change state when the signin menu item is hidden/shown. +TEST_F(AppControllerTest, TestSigninMenuItemWithNonSeparator) { + base::scoped_nsobject menu([[NSMenu alloc] initWithTitle:@""]); + NSMenuItem* signinMenuItem = [menu addItemWithTitle:@"" + action:@selector(commandDispatch) + keyEquivalent:@""]; + [signinMenuItem setTag:IDC_SHOW_SYNC_SETUP]; + NSMenuItem* followingNonSeparator = + [menu addItemWithTitle:@"" + action:@selector(commandDispatch) + keyEquivalent:@""]; + [signinMenuItem setHidden:NO]; + [followingNonSeparator setHidden:NO]; + + [AppController updateSigninItem:signinMenuItem + shouldShow:NO + currentProfile:profile_]; + + EXPECT_TRUE([followingNonSeparator isEnabled]); + EXPECT_TRUE([signinMenuItem isHidden]); + EXPECT_FALSE([followingNonSeparator isHidden]); + + [followingNonSeparator setHidden:YES]; + [AppController updateSigninItem:signinMenuItem + shouldShow:YES + currentProfile:profile_]; + + EXPECT_TRUE([followingNonSeparator isEnabled]); + EXPECT_FALSE([signinMenuItem isHidden]); + EXPECT_TRUE([followingNonSeparator isHidden]); +} -- cgit v1.1