Index: chrome/browser/sync/sync_ui_util_unittest.cc |
diff --git a/chrome/browser/sync/sync_ui_util_unittest.cc b/chrome/browser/sync/sync_ui_util_unittest.cc |
index 17f2f18e3884fa830585a294d38be3302ca3503c..5e580fc50d020aaf87470e399cb1c8719c2f8231 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); |
+ } |
} |