diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-17 22:38:50 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-17 22:38:50 +0000 |
commit | 9c60fa405d17f9a11a31afec943993629d25a741 (patch) | |
tree | 2b3a95b022ffd14ed7dc6b65533a2fb38d10e4b7 /chrome/browser/sync/sync_ui_util_unittest.cc | |
parent | 60eb6b080fabe616f2103ef23e8ac2a6ccf20d44 (diff) | |
download | chromium_src-9c60fa405d17f9a11a31afec943993629d25a741.zip chromium_src-9c60fa405d17f9a11a31afec943993629d25a741.tar.gz chromium_src-9c60fa405d17f9a11a31afec943993629d25a741.tar.bz2 |
Suppress bubble view for CONNECTION_FAILED error
If there was a connection failed error then we woud display an error bubble view and wrench menu item.
We're not supposed to display error messages for CONNECTION_FAILED errors so all the labels in the bubble view and wrench menu error item were blank.
The problem was that we would decide when to show the error UI based on the auth error state.
To fix this I simplified the code so that we show the error UI based directly on the presence of the error labels. This makes the code significantly simpler.
I also added unit tests to make sure that we're returning labels when we should not not returning them when we shouldn't.
BUG=100451
TEST=
Review URL: http://codereview.chromium.org/8308005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/sync_ui_util_unittest.cc')
-rw-r--r-- | chrome/browser/sync/sync_ui_util_unittest.cc | 76 |
1 files changed, 70 insertions, 6 deletions
diff --git a/chrome/browser/sync/sync_ui_util_unittest.cc b/chrome/browser/sync/sync_ui_util_unittest.cc index 17f2f18..5e580fc 100644 --- a/chrome/browser/sync/sync_ui_util_unittest.cc +++ b/chrome/browser/sync/sync_ui_util_unittest.cc @@ -13,6 +13,38 @@ using ::testing::Return; using ::testing::NiceMock; + +namespace { + +// Utility function to test that GetStatusLabelsForSyncGlobalError returns +// the correct results for the given states. +void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, + GoogleServiceAuthError::State error_state, + bool is_signed_in, + bool is_error) { + GoogleServiceAuthError auth_error(error_state); + service->UpdateAuthErrorState(auth_error); + + EXPECT_CALL(*service, HasSyncSetupCompleted()) + .WillRepeatedly(Return(is_signed_in)); + if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { + EXPECT_CALL(*service, GetAuthenticatedUsername()) + .WillRepeatedly(Return(UTF8ToUTF16(""))); + } else { + EXPECT_CALL(*service, GetAuthenticatedUsername()) + .WillRepeatedly(Return(UTF8ToUTF16("foo"))); + } + + string16 label1, label2, label3; + sync_ui_util::GetStatusLabelsForSyncGlobalError( + service, &label1, &label2, &label3); + EXPECT_EQ(label1.empty(), !is_error); + EXPECT_EQ(label2.empty(), !is_error); + EXPECT_EQ(label3.empty(), !is_error); +} + +} // namespace + TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { MessageLoopForUI message_loop; BrowserThread ui_thread(BrowserThread::UI, &message_loop); @@ -48,15 +80,47 @@ TEST(SyncUIUtilTest, PassphraseGlobalError) { BrowserThread ui_thread(BrowserThread::UI, &message_loop); NiceMock<ProfileSyncServiceMock> service; - EXPECT_CALL(service, HasSyncSetupCompleted()) - .WillOnce(Return(true)); EXPECT_CALL(service, IsPassphraseRequired()) .WillOnce(Return(true)); EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) .WillOnce(Return(true)); + VerifySyncGlobalErrorResult( + &service, GoogleServiceAuthError::NONE, true, true); +} + +// Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions +// that can be resolved by the user and suppresses errors for conditions that +// cannot be resolved by the user. +TEST(SyncUIUtilTest, AuthStateGlobalError) { + MessageLoopForUI message_loop; + BrowserThread ui_thread(BrowserThread::UI, &message_loop); + NiceMock<ProfileSyncServiceMock> service; + + browser_sync::SyncBackendHost::Status status; + EXPECT_CALL(service, QueryDetailedSyncStatus()) + .WillRepeatedly(Return(status)); + + struct { + GoogleServiceAuthError::State error_state; + bool is_error; + } table[] = { + { GoogleServiceAuthError::NONE, false }, + { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true }, + { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true }, + { GoogleServiceAuthError::CONNECTION_FAILED, false }, + { GoogleServiceAuthError::CAPTCHA_REQUIRED, true }, + { GoogleServiceAuthError::ACCOUNT_DELETED, true }, + { GoogleServiceAuthError::ACCOUNT_DISABLED, true }, + { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true }, + { GoogleServiceAuthError::TWO_FACTOR, true }, + { GoogleServiceAuthError::REQUEST_CANCELED, true }, + { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, + }; - sync_ui_util::MessageType type = - sync_ui_util::GetStatusLabelsForSyncGlobalError( - &service, NULL, NULL, NULL); - EXPECT_EQ(type, sync_ui_util::SYNC_ERROR); + for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { + VerifySyncGlobalErrorResult( + &service, table[i].error_state, true, table[i].is_error); + VerifySyncGlobalErrorResult( + &service, table[i].error_state, false, false); + } } |