| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <set> | 5 #include <set> |
| 6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/signin/signin_manager.h" |
| 11 #include "chrome/browser/signin/signin_manager_fake.h" |
| 10 #include "chrome/browser/sync/profile_sync_service_mock.h" | 12 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 11 #include "chrome/browser/sync/sync_ui_util.h" | 13 #include "chrome/browser/sync/sync_ui_util.h" |
| 12 #include "content/test/test_browser_thread.h" | 14 #include "content/test/test_browser_thread.h" |
| 13 #include "testing/gmock/include/gmock/gmock-actions.h" | 15 #include "testing/gmock/include/gmock/gmock-actions.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 using ::testing::AtMost; | 19 using ::testing::AtMost; |
| 18 using ::testing::Return; | 20 using ::testing::Return; |
| 19 using ::testing::ReturnRef; | 21 using ::testing::ReturnRef; |
| 20 using ::testing::NiceMock; | 22 using ::testing::NiceMock; |
| 21 using content::BrowserThread; | 23 using content::BrowserThread; |
| 22 | 24 |
| 23 // A number of distinct states of the ProfileSyncService can be generated for | 25 // A number of distinct states of the ProfileSyncService can be generated for |
| 24 // tests. | 26 // tests. |
| 25 enum DistinctState { | 27 enum DistinctState { |
| 26 STATUS_CASE_SETUP_IN_PROGRESS, | 28 STATUS_CASE_SETUP_IN_PROGRESS, |
| 27 STATUS_CASE_SETUP_ERROR, | 29 STATUS_CASE_SETUP_ERROR, |
| 28 STATUS_CASE_AUTHENTICATING, | 30 STATUS_CASE_AUTHENTICATING, |
| 29 STATUS_CASE_AUTH_ERROR, | 31 STATUS_CASE_AUTH_ERROR, |
| 30 STATUS_CASE_PROTOCOL_ERROR, | 32 STATUS_CASE_PROTOCOL_ERROR, |
| 31 STATUS_CASE_PASSPHRASE_ERROR, | 33 STATUS_CASE_PASSPHRASE_ERROR, |
| 32 STATUS_CASE_SYNCED, | 34 STATUS_CASE_SYNCED, |
| 33 NUMBER_OF_STATUS_CASES | 35 NUMBER_OF_STATUS_CASES |
| 34 }; | 36 }; |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 40 // Mock that allows us to mock a SigninManager that is authenticating. |
| 41 class SigninManagerMock : public SigninManager { |
| 42 public: |
| 43 MOCK_CONST_METHOD0(AuthInProgress, bool()); |
| 44 }; |
| 45 |
| 38 // Utility function to test that GetStatusLabelsForSyncGlobalError returns | 46 // Utility function to test that GetStatusLabelsForSyncGlobalError returns |
| 39 // the correct results for the given states. | 47 // the correct results for the given states. |
| 40 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, | 48 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
| 49 const SigninManager& signin, |
| 41 GoogleServiceAuthError::State error_state, | 50 GoogleServiceAuthError::State error_state, |
| 42 bool is_signed_in, | 51 bool is_signed_in, |
| 43 bool is_error) { | 52 bool is_error) { |
| 44 EXPECT_CALL(*service, HasSyncSetupCompleted()) | 53 EXPECT_CALL(*service, HasSyncSetupCompleted()) |
| 45 .WillRepeatedly(Return(is_signed_in)); | 54 .WillRepeatedly(Return(is_signed_in)); |
| 46 | 55 |
| 47 GoogleServiceAuthError auth_error(error_state); | 56 GoogleServiceAuthError auth_error(error_state); |
| 48 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); | 57 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); |
| 49 | 58 |
| 50 string16 label1, label2, label3; | 59 string16 label1, label2, label3; |
| 51 sync_ui_util::GetStatusLabelsForSyncGlobalError( | 60 sync_ui_util::GetStatusLabelsForSyncGlobalError( |
| 52 service, &label1, &label2, &label3); | 61 service, signin, &label1, &label2, &label3); |
| 53 EXPECT_EQ(label1.empty(), !is_error); | 62 EXPECT_EQ(label1.empty(), !is_error); |
| 54 EXPECT_EQ(label2.empty(), !is_error); | 63 EXPECT_EQ(label2.empty(), !is_error); |
| 55 EXPECT_EQ(label3.empty(), !is_error); | 64 EXPECT_EQ(label3.empty(), !is_error); |
| 56 } | 65 } |
| 57 | 66 |
| 58 } // namespace | 67 } // namespace |
| 59 | 68 |
| 60 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { | 69 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { |
| 61 MessageLoopForUI message_loop; | 70 MessageLoopForUI message_loop; |
| 62 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 71 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 90 } | 99 } |
| 91 | 100 |
| 92 // Test that GetStatusLabelsForSyncGlobalError returns an error if a | 101 // Test that GetStatusLabelsForSyncGlobalError returns an error if a |
| 93 // passphrase is required. | 102 // passphrase is required. |
| 94 TEST(SyncUIUtilTest, PassphraseGlobalError) { | 103 TEST(SyncUIUtilTest, PassphraseGlobalError) { |
| 95 MessageLoopForUI message_loop; | 104 MessageLoopForUI message_loop; |
| 96 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 105 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 97 scoped_ptr<Profile> profile( | 106 scoped_ptr<Profile> profile( |
| 98 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 107 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 99 NiceMock<ProfileSyncServiceMock> service(profile.get()); | 108 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
| 109 FakeSigninManager signin; |
| 100 | 110 |
| 101 EXPECT_CALL(service, IsPassphraseRequired()) | 111 EXPECT_CALL(service, IsPassphraseRequired()) |
| 102 .WillOnce(Return(true)); | 112 .WillOnce(Return(true)); |
| 103 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 113 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
| 104 .WillOnce(Return(true)); | 114 .WillOnce(Return(true)); |
| 105 VerifySyncGlobalErrorResult( | 115 VerifySyncGlobalErrorResult( |
| 106 &service, GoogleServiceAuthError::NONE, true, true); | 116 &service, signin, GoogleServiceAuthError::NONE, true, true); |
| 107 } | 117 } |
| 108 | 118 |
| 109 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions | 119 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions |
| 110 // that can be resolved by the user and suppresses errors for conditions that | 120 // that can be resolved by the user and suppresses errors for conditions that |
| 111 // cannot be resolved by the user. | 121 // cannot be resolved by the user. |
| 112 TEST(SyncUIUtilTest, AuthStateGlobalError) { | 122 TEST(SyncUIUtilTest, AuthStateGlobalError) { |
| 113 MessageLoopForUI message_loop; | 123 MessageLoopForUI message_loop; |
| 114 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 124 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 115 scoped_ptr<Profile> profile( | 125 scoped_ptr<Profile> profile( |
| 116 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 126 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 130 { GoogleServiceAuthError::CONNECTION_FAILED, false }, | 140 { GoogleServiceAuthError::CONNECTION_FAILED, false }, |
| 131 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true }, | 141 { GoogleServiceAuthError::CAPTCHA_REQUIRED, true }, |
| 132 { GoogleServiceAuthError::ACCOUNT_DELETED, true }, | 142 { GoogleServiceAuthError::ACCOUNT_DELETED, true }, |
| 133 { GoogleServiceAuthError::ACCOUNT_DISABLED, true }, | 143 { GoogleServiceAuthError::ACCOUNT_DISABLED, true }, |
| 134 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true }, | 144 { GoogleServiceAuthError::SERVICE_UNAVAILABLE, true }, |
| 135 { GoogleServiceAuthError::TWO_FACTOR, true }, | 145 { GoogleServiceAuthError::TWO_FACTOR, true }, |
| 136 { GoogleServiceAuthError::REQUEST_CANCELED, true }, | 146 { GoogleServiceAuthError::REQUEST_CANCELED, true }, |
| 137 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, | 147 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, |
| 138 }; | 148 }; |
| 139 | 149 |
| 150 FakeSigninManager signin; |
| 140 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { | 151 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { |
| 141 VerifySyncGlobalErrorResult( | 152 VerifySyncGlobalErrorResult( |
| 142 &service, table[i].error_state, true, table[i].is_error); | 153 &service, signin, table[i].error_state, true, table[i].is_error); |
| 143 VerifySyncGlobalErrorResult( | 154 VerifySyncGlobalErrorResult( |
| 144 &service, table[i].error_state, false, false); | 155 &service, signin, table[i].error_state, false, false); |
| 145 } | 156 } |
| 146 } | 157 } |
| 147 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases | 158 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases |
| 148 // in order to perform tests on the generated messages. | 159 // in order to perform tests on the generated messages. |
| 149 void GetDistinctCase(ProfileSyncServiceMock& service, | 160 void GetDistinctCase(ProfileSyncServiceMock& service, |
| 161 SigninManagerMock& signin, |
| 150 GoogleServiceAuthError** auth_error, | 162 GoogleServiceAuthError** auth_error, |
| 151 int caseNumber) { | 163 int caseNumber) { |
| 152 // Auth Error object is returned by reference in mock and needs to stay in | 164 // Auth Error object is returned by reference in mock and needs to stay in |
| 153 // scope throughout test, so it is owned by calling method. However it is | 165 // scope throughout test, so it is owned by calling method. However it is |
| 154 // immutable so can only be allocated in this method. | 166 // immutable so can only be allocated in this method. |
| 155 switch (caseNumber) { | 167 switch (caseNumber) { |
| 156 case STATUS_CASE_SETUP_IN_PROGRESS: { | 168 case STATUS_CASE_SETUP_IN_PROGRESS: { |
| 157 EXPECT_CALL(service, HasSyncSetupCompleted()) | 169 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 158 .WillOnce(Return(false)); | 170 .WillOnce(Return(false)); |
| 159 EXPECT_CALL(service, FirstSetupInProgress()) | 171 EXPECT_CALL(service, FirstSetupInProgress()) |
| 160 .WillOnce(Return(true)); | 172 .WillOnce(Return(true)); |
| 161 browser_sync::SyncBackendHost::Status status; | 173 browser_sync::SyncBackendHost::Status status; |
| 162 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 174 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
| 163 .WillOnce(Return(status)); | 175 .WillOnce(Return(status)); |
| 164 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | 176 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
| 165 EXPECT_CALL(service, GetAuthError()) | 177 EXPECT_CALL(service, GetAuthError()) |
| 166 .WillOnce(ReturnRef(**auth_error)); | 178 .WillOnce(ReturnRef(**auth_error)); |
| 167 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | 179 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); |
| 168 .WillOnce(Return(false)); | |
| 169 return; | 180 return; |
| 170 } | 181 } |
| 171 case STATUS_CASE_SETUP_ERROR: { | 182 case STATUS_CASE_SETUP_ERROR: { |
| 172 EXPECT_CALL(service, HasSyncSetupCompleted()) | 183 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 173 .WillOnce(Return(false)); | 184 .WillOnce(Return(false)); |
| 174 EXPECT_CALL(service, FirstSetupInProgress()) | 185 EXPECT_CALL(service, FirstSetupInProgress()) |
| 175 .WillOnce(Return(false)); | 186 .WillOnce(Return(false)); |
| 176 EXPECT_CALL(service, unrecoverable_error_detected()) | 187 EXPECT_CALL(service, unrecoverable_error_detected()) |
| 177 .WillOnce(Return(true)); | 188 .WillOnce(Return(true)); |
| 189 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); |
| 178 browser_sync::SyncBackendHost::Status status; | 190 browser_sync::SyncBackendHost::Status status; |
| 179 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 191 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
| 180 .WillOnce(Return(status)); | 192 .WillOnce(Return(status)); |
| 181 return; | 193 return; |
| 182 } | 194 } |
| 183 case STATUS_CASE_AUTHENTICATING: { | 195 case STATUS_CASE_AUTHENTICATING: { |
| 184 EXPECT_CALL(service, HasSyncSetupCompleted()) | 196 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 185 .WillOnce(Return(true)); | 197 .WillOnce(Return(true)); |
| 186 browser_sync::SyncBackendHost::Status status; | 198 browser_sync::SyncBackendHost::Status status; |
| 187 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 199 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
| 188 .WillOnce(Return(status)); | 200 .WillOnce(Return(status)); |
| 189 EXPECT_CALL(service, unrecoverable_error_detected()) | 201 EXPECT_CALL(service, unrecoverable_error_detected()) |
| 190 .WillOnce(Return(false)); | 202 .WillOnce(Return(false)); |
| 191 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | 203 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(true)); |
| 192 .WillOnce(Return(true)); | |
| 193 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | 204 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
| 194 EXPECT_CALL(service, GetAuthError()) | 205 EXPECT_CALL(service, GetAuthError()) |
| 195 .WillOnce(ReturnRef(**auth_error)); | 206 .WillOnce(ReturnRef(**auth_error)); |
| 196 return; | 207 return; |
| 197 } | 208 } |
| 198 case STATUS_CASE_AUTH_ERROR: { | 209 case STATUS_CASE_AUTH_ERROR: { |
| 199 EXPECT_CALL(service, HasSyncSetupCompleted()) | 210 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 200 .WillOnce(Return(true)); | 211 .WillOnce(Return(true)); |
| 201 browser_sync::SyncBackendHost::Status status; | 212 browser_sync::SyncBackendHost::Status status; |
| 202 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 213 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
| 203 .WillOnce(Return(status)); | 214 .WillOnce(Return(status)); |
| 204 *auth_error = new GoogleServiceAuthError( | 215 *auth_error = new GoogleServiceAuthError( |
| 205 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 216 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 206 EXPECT_CALL(service, unrecoverable_error_detected()) | 217 EXPECT_CALL(service, unrecoverable_error_detected()) |
| 207 .WillOnce(Return(false)); | 218 .WillOnce(Return(false)); |
| 219 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); |
| 208 EXPECT_CALL(service, GetAuthError()) | 220 EXPECT_CALL(service, GetAuthError()) |
| 209 .WillOnce(ReturnRef(**auth_error)); | 221 .WillOnce(ReturnRef(**auth_error)); |
| 210 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | |
| 211 .WillOnce(Return(false)); | |
| 212 return; | 222 return; |
| 213 } | 223 } |
| 214 case STATUS_CASE_PROTOCOL_ERROR: { | 224 case STATUS_CASE_PROTOCOL_ERROR: { |
| 215 EXPECT_CALL(service, HasSyncSetupCompleted()) | 225 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 216 .WillOnce(Return(true)); | 226 .WillOnce(Return(true)); |
| 217 browser_sync::SyncProtocolError protocolError; | 227 browser_sync::SyncProtocolError protocolError; |
| 218 protocolError.action = browser_sync::STOP_AND_RESTART_SYNC; | 228 protocolError.action = browser_sync::STOP_AND_RESTART_SYNC; |
| 219 browser_sync::SyncBackendHost::Status status; | 229 browser_sync::SyncBackendHost::Status status; |
| 220 status.sync_protocol_error = protocolError; | 230 status.sync_protocol_error = protocolError; |
| 221 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 231 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
| 222 .WillOnce(Return(status)); | 232 .WillOnce(Return(status)); |
| 223 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | 233 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
| 224 EXPECT_CALL(service, GetAuthError()) | 234 EXPECT_CALL(service, GetAuthError()) |
| 225 .WillOnce(ReturnRef(**auth_error)); | 235 .WillOnce(ReturnRef(**auth_error)); |
| 236 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); |
| 226 EXPECT_CALL(service, unrecoverable_error_detected()) | 237 EXPECT_CALL(service, unrecoverable_error_detected()) |
| 227 .WillOnce(Return(false)); | 238 .WillOnce(Return(false)); |
| 228 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | |
| 229 .WillOnce(Return(false)); | |
| 230 return; | 239 return; |
| 231 } | 240 } |
| 232 case STATUS_CASE_PASSPHRASE_ERROR: { | 241 case STATUS_CASE_PASSPHRASE_ERROR: { |
| 233 EXPECT_CALL(service, HasSyncSetupCompleted()) | 242 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 234 .WillOnce(Return(true)); | 243 .WillOnce(Return(true)); |
| 235 browser_sync::SyncBackendHost::Status status; | 244 browser_sync::SyncBackendHost::Status status; |
| 236 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 245 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
| 237 .WillOnce(Return(status)); | 246 .WillOnce(Return(status)); |
| 238 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | 247 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
| 239 EXPECT_CALL(service, GetAuthError()) | 248 EXPECT_CALL(service, GetAuthError()) |
| 240 .WillOnce(ReturnRef(**auth_error)); | 249 .WillOnce(ReturnRef(**auth_error)); |
| 241 EXPECT_CALL(service, unrecoverable_error_detected()) | 250 EXPECT_CALL(service, unrecoverable_error_detected()) |
| 242 .WillOnce(Return(false)); | 251 .WillOnce(Return(false)); |
| 243 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | 252 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); |
| 244 .WillOnce(Return(false)); | |
| 245 EXPECT_CALL(service, IsPassphraseRequired()) | 253 EXPECT_CALL(service, IsPassphraseRequired()) |
| 246 .WillOnce(Return(true)); | 254 .WillOnce(Return(true)); |
| 247 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 255 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
| 248 .WillOnce(Return(true)); | 256 .WillOnce(Return(true)); |
| 249 return; | 257 return; |
| 250 } | 258 } |
| 251 case STATUS_CASE_SYNCED: { | 259 case STATUS_CASE_SYNCED: { |
| 252 EXPECT_CALL(service, HasSyncSetupCompleted()) | 260 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 253 .WillOnce(Return(true)); | 261 .WillOnce(Return(true)); |
| 254 browser_sync::SyncBackendHost::Status status; | 262 browser_sync::SyncBackendHost::Status status; |
| 255 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 263 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
| 256 .WillOnce(Return(status)); | 264 .WillOnce(Return(status)); |
| 257 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | 265 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
| 258 EXPECT_CALL(service, GetAuthError()) | 266 EXPECT_CALL(service, GetAuthError()) |
| 259 .WillOnce(ReturnRef(**auth_error)); | 267 .WillOnce(ReturnRef(**auth_error)); |
| 268 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); |
| 260 EXPECT_CALL(service, unrecoverable_error_detected()) | 269 EXPECT_CALL(service, unrecoverable_error_detected()) |
| 261 .WillOnce(Return(false)); | 270 .WillOnce(Return(false)); |
| 262 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | |
| 263 .WillOnce(Return(false)); | |
| 264 EXPECT_CALL(service, IsPassphraseRequired()) | 271 EXPECT_CALL(service, IsPassphraseRequired()) |
| 265 .WillOnce(Return(false)); | 272 .WillOnce(Return(false)); |
| 266 return; | 273 return; |
| 267 } | 274 } |
| 268 default: | 275 default: |
| 269 NOTREACHED(); | 276 NOTREACHED(); |
| 270 } | 277 } |
| 271 } | 278 } |
| 272 | 279 |
| 273 // This test ensures that a each distinctive ProfileSyncService statuses | 280 // This test ensures that a each distinctive ProfileSyncService statuses |
| 274 // will return a unique combination of status and link messages from | 281 // will return a unique combination of status and link messages from |
| 275 // GetStatusLabels(). | 282 // GetStatusLabels(). |
| 276 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { | 283 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { |
| 277 std::set<string16> messages; | 284 std::set<string16> messages; |
| 278 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 285 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
| 279 scoped_ptr<Profile> profile( | 286 scoped_ptr<Profile> profile( |
| 280 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 287 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 281 ProfileSyncServiceMock service(profile.get()); | 288 ProfileSyncServiceMock service(profile.get()); |
| 289 NiceMock<SigninManagerMock> signin; |
| 282 GoogleServiceAuthError* auth_error = NULL; | 290 GoogleServiceAuthError* auth_error = NULL; |
| 283 GetDistinctCase(service, &auth_error, idx); | 291 GetDistinctCase(service, signin, &auth_error, idx); |
| 284 string16 status_label; | 292 string16 status_label; |
| 285 string16 link_label; | 293 string16 link_label; |
| 286 sync_ui_util::GetStatusLabels(&service, | 294 sync_ui_util::GetStatusLabels(&service, |
| 295 signin, |
| 287 sync_ui_util::WITH_HTML, | 296 sync_ui_util::WITH_HTML, |
| 288 &status_label, | 297 &status_label, |
| 289 &link_label); | 298 &link_label); |
| 290 // If the status and link message combination is already present in the set | 299 // If the status and link message combination is already present in the set |
| 291 // of messages already seen, this is a duplicate rather than a unique | 300 // of messages already seen, this is a duplicate rather than a unique |
| 292 // message, and the test has failed. | 301 // message, and the test has failed. |
| 293 string16 combined_label = | 302 string16 combined_label = |
| 294 status_label + string16(ASCIIToUTF16("#")) + link_label; | 303 status_label + string16(ASCIIToUTF16("#")) + link_label; |
| 295 EXPECT_TRUE(messages.find(combined_label) == messages.end()); | 304 EXPECT_TRUE(messages.find(combined_label) == messages.end()); |
| 296 messages.insert(combined_label); | 305 messages.insert(combined_label); |
| 297 if (auth_error) | 306 if (auth_error) |
| 298 delete auth_error; | 307 delete auth_error; |
| 299 } | 308 } |
| 300 } | 309 } |
| 301 | 310 |
| 302 // This test ensures that the html_links parameter on GetStatusLabels() is | 311 // This test ensures that the html_links parameter on GetStatusLabels() is |
| 303 // honored. | 312 // honored. |
| 304 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { | 313 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { |
| 305 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 314 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
| 306 scoped_ptr<Profile> profile( | 315 scoped_ptr<Profile> profile( |
| 307 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 316 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 308 ProfileSyncServiceMock service(profile.get()); | 317 ProfileSyncServiceMock service(profile.get()); |
| 318 NiceMock<SigninManagerMock> signin; |
| 309 GoogleServiceAuthError* auth_error = NULL; | 319 GoogleServiceAuthError* auth_error = NULL; |
| 310 GetDistinctCase(service, &auth_error, idx); | 320 GetDistinctCase(service, signin, &auth_error, idx); |
| 311 string16 status_label; | 321 string16 status_label; |
| 312 string16 link_label; | 322 string16 link_label; |
| 313 sync_ui_util::GetStatusLabels(&service, | 323 sync_ui_util::GetStatusLabels(&service, |
| 324 signin, |
| 314 sync_ui_util::PLAIN_TEXT, | 325 sync_ui_util::PLAIN_TEXT, |
| 315 &status_label, | 326 &status_label, |
| 316 &link_label); | 327 &link_label); |
| 317 // Ensures a search for string 'href' (found in links, not a string to be | 328 // Ensures a search for string 'href' (found in links, not a string to be |
| 318 // found in an English language message) fails when links are excluded from | 329 // found in an English language message) fails when links are excluded from |
| 319 // the status label. | 330 // the status label. |
| 320 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), | 331 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
| 321 string16::npos); | 332 string16::npos); |
| 322 if (auth_error) { | 333 if (auth_error) { |
| 323 delete auth_error; | 334 delete auth_error; |
| 324 } | 335 } |
| 325 } | 336 } |
| 326 } | 337 } |
| OLD | NEW |