OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/sync/sync_global_error.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 10 #include "content/browser/browser_thread.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gmock/include/gmock/gmock-actions.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 using ::testing::Return; |
| 16 using ::testing::NiceMock; |
| 17 |
| 18 namespace { |
| 19 |
| 20 // Utility function to test that SyncGlobalError behaves correct for the given |
| 21 // error condition. |
| 22 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
| 23 SyncGlobalError* error, |
| 24 GoogleServiceAuthError::State error_state, |
| 25 bool is_signed_in, |
| 26 bool is_error) { |
| 27 GoogleServiceAuthError auth_error(error_state); |
| 28 service->UpdateAuthErrorState(auth_error); |
| 29 |
| 30 EXPECT_CALL(*service, HasSyncSetupCompleted()) |
| 31 .WillRepeatedly(Return(is_signed_in)); |
| 32 if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { |
| 33 EXPECT_CALL(*service, GetAuthenticatedUsername()) |
| 34 .WillRepeatedly(Return(UTF8ToUTF16(""))); |
| 35 } else { |
| 36 EXPECT_CALL(*service, GetAuthenticatedUsername()) |
| 37 .WillRepeatedly(Return(UTF8ToUTF16("foo"))); |
| 38 } |
| 39 |
| 40 error->OnStateChanged(); |
| 41 |
| 42 // If there is an error then a wrench button badge, menu item, and bubble view |
| 43 // should be shown. |
| 44 EXPECT_EQ(error->HasBadge(), is_error); |
| 45 EXPECT_EQ(error->HasMenuItem() || error->HasCustomizedSyncMenuItem(), |
| 46 is_error); |
| 47 EXPECT_EQ(error->HasBubbleView(), is_error); |
| 48 |
| 49 // If there is an error then labels should not be empty. |
| 50 EXPECT_NE(error->MenuItemCommandID(), 0); |
| 51 EXPECT_NE(error->MenuItemLabel().empty(), is_error); |
| 52 EXPECT_NE(error->GetBubbleViewAcceptButtonLabel().empty(), is_error); |
| 53 |
| 54 // We never have a cancel button. |
| 55 EXPECT_TRUE(error->GetBubbleViewCancelButtonLabel().empty()); |
| 56 // We always return a hardcoded title. |
| 57 EXPECT_FALSE(error->GetBubbleViewTitle().empty()); |
| 58 |
| 59 // Test message handler. |
| 60 if (is_error) { |
| 61 EXPECT_CALL(*service, ShowErrorUI()); |
| 62 error->ExecuteMenuItem(NULL); |
| 63 EXPECT_CALL(*service, ShowErrorUI()); |
| 64 error->BubbleViewAcceptButtonPressed(); |
| 65 error->BubbleViewDidClose(); |
| 66 } |
| 67 } |
| 68 |
| 69 } // namespace |
| 70 |
| 71 // Test that SyncGlobalError shows an error if a passphrase is required. |
| 72 TEST(SyncGlobalErrorTest, PassphraseGlobalError) { |
| 73 MessageLoopForUI message_loop; |
| 74 BrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 75 NiceMock<ProfileSyncServiceMock> service; |
| 76 SyncGlobalError error(&service); |
| 77 |
| 78 EXPECT_CALL(service, IsPassphraseRequired()) |
| 79 .WillRepeatedly(Return(true)); |
| 80 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
| 81 .WillRepeatedly(Return(true)); |
| 82 VerifySyncGlobalErrorResult( |
| 83 &service, &error, GoogleServiceAuthError::NONE, true, true); |
| 84 } |
| 85 |
| 86 // Test that SyncGlobalError shows an error for conditions that can be resolved |
| 87 // by the user and suppresses errors for conditions that cannot be resolved by |
| 88 // the user. |
| 89 TEST(SyncGlobalErrorTest, AuthStateGlobalError) { |
| 90 MessageLoopForUI message_loop; |
| 91 BrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 92 NiceMock<ProfileSyncServiceMock> service; |
| 93 SyncGlobalError error(&service); |
| 94 |
| 95 browser_sync::SyncBackendHost::Status status; |
| 96 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
| 97 .WillRepeatedly(Return(status)); |
| 98 |
| 99 struct { |
| 100 GoogleServiceAuthError::State error_state; |
| 101 bool is_error; |
| 102 } table[] = { |
| 103 { GoogleServiceAuthError::NONE, false }, |
| 104 { GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, true }, |
| 105 { GoogleServiceAuthError::USER_NOT_SIGNED_UP, true }, |
| 106 { GoogleServiceAuthError::CONNECTION_FAILED, false }, |
| 107 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true }, |
| 108 { GoogleServiceAuthError::ACCOUNT_DELETED, true }, |
| 109 { GoogleServiceAuthError::ACCOUNT_DISABLED, true }, |
| 110 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true }, |
| 111 { GoogleServiceAuthError::TWO_FACTOR, true }, |
| 112 { GoogleServiceAuthError::REQUEST_CANCELED, true }, |
| 113 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, |
| 114 }; |
| 115 |
| 116 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { |
| 117 VerifySyncGlobalErrorResult( |
| 118 &service, &error, table[i].error_state, true, table[i].is_error); |
| 119 VerifySyncGlobalErrorResult( |
| 120 &service, &error, table[i].error_state, false, false); |
| 121 } |
| 122 } |
OLD | NEW |