| 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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/fake_auth_status_provider.h" |
| 9 #include "chrome/browser/signin/signin_manager.h" | 10 #include "chrome/browser/signin/signin_manager.h" |
| 10 #include "chrome/browser/signin/signin_manager_fake.h" | 11 #include "chrome/browser/signin/signin_manager_fake.h" |
| 11 #include "chrome/browser/sync/profile_sync_service_mock.h" | 12 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 12 #include "chrome/browser/sync/sync_ui_util.h" | 13 #include "chrome/browser/sync/sync_ui_util.h" |
| 13 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 15 #include "testing/gmock/include/gmock/gmock-actions.h" | 16 #include "testing/gmock/include/gmock/gmock-actions.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 | 20 |
| 20 using ::testing::AtMost; | 21 using ::testing::AtMost; |
| 21 using ::testing::NiceMock; | 22 using ::testing::NiceMock; |
| 22 using ::testing::Return; | 23 using ::testing::Return; |
| 23 using ::testing::ReturnRef; | 24 using ::testing::ReturnRef; |
| 24 using ::testing::SetArgPointee; | 25 using ::testing::SetArgPointee; |
| 25 using ::testing::_; | 26 using ::testing::_; |
| 26 using content::BrowserThread; | 27 using content::BrowserThread; |
| 27 | 28 |
| 28 // A number of distinct states of the ProfileSyncService can be generated for | 29 // A number of distinct states of the ProfileSyncService can be generated for |
| 29 // tests. | 30 // tests. |
| 30 enum DistinctState { | 31 enum DistinctState { |
| 31 STATUS_CASE_SETUP_IN_PROGRESS, | 32 STATUS_CASE_SETUP_IN_PROGRESS, |
| 32 STATUS_CASE_SETUP_ERROR, | 33 STATUS_CASE_SETUP_ERROR, |
| 33 STATUS_CASE_AUTHENTICATING, | 34 STATUS_CASE_AUTHENTICATING, |
| 34 STATUS_CASE_AUTH_ERROR, | 35 STATUS_CASE_AUTH_ERROR, |
| 35 STATUS_CASE_PROTOCOL_ERROR, | 36 STATUS_CASE_PROTOCOL_ERROR, |
| 36 STATUS_CASE_PASSPHRASE_ERROR, | 37 STATUS_CASE_PASSPHRASE_ERROR, |
| 37 STATUS_CASE_SYNCED, | 38 STATUS_CASE_SYNCED, |
| 39 STATUS_CASE_SYNC_DISABLED_BY_POLICY, |
| 38 NUMBER_OF_STATUS_CASES | 40 NUMBER_OF_STATUS_CASES |
| 39 }; | 41 }; |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 // Mock that allows us to mock a SigninManager that is authenticating. | |
| 44 class SigninManagerMock : public SigninManager { | |
| 45 public: | |
| 46 MOCK_CONST_METHOD0(AuthInProgress, bool()); | |
| 47 }; | |
| 48 | |
| 49 // Utility function to test that GetStatusLabelsForSyncGlobalError returns | 45 // Utility function to test that GetStatusLabelsForSyncGlobalError returns |
| 50 // the correct results for the given states. | 46 // the correct results for the given states. |
| 51 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, | 47 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
| 52 const SigninManager& signin, | 48 const SigninManager& signin, |
| 53 GoogleServiceAuthError::State error_state, | 49 GoogleServiceAuthError::State error_state, |
| 54 bool is_signed_in, | 50 bool is_signed_in, |
| 55 bool is_error) { | 51 bool is_error) { |
| 56 EXPECT_CALL(*service, HasSyncSetupCompleted()) | 52 EXPECT_CALL(*service, HasSyncSetupCompleted()) |
| 57 .WillRepeatedly(Return(is_signed_in)); | 53 .WillRepeatedly(Return(is_signed_in)); |
| 58 | 54 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 75 TEST(SyncUIUtilTest, PassphraseGlobalError) { | 71 TEST(SyncUIUtilTest, PassphraseGlobalError) { |
| 76 MessageLoopForUI message_loop; | 72 MessageLoopForUI message_loop; |
| 77 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 73 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 78 scoped_ptr<Profile> profile( | 74 scoped_ptr<Profile> profile( |
| 79 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 75 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 80 NiceMock<ProfileSyncServiceMock> service(profile.get()); | 76 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
| 81 FakeSigninManager signin(profile.get()); | 77 FakeSigninManager signin(profile.get()); |
| 82 browser_sync::SyncBackendHost::Status status; | 78 browser_sync::SyncBackendHost::Status status; |
| 83 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 79 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 84 .WillRepeatedly(Return(false)); | 80 .WillRepeatedly(Return(false)); |
| 85 | |
| 86 EXPECT_CALL(service, IsPassphraseRequired()) | 81 EXPECT_CALL(service, IsPassphraseRequired()) |
| 87 .WillRepeatedly(Return(true)); | 82 .WillRepeatedly(Return(true)); |
| 88 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 83 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
| 89 .WillRepeatedly(Return(true)); | 84 .WillRepeatedly(Return(true)); |
| 90 VerifySyncGlobalErrorResult( | 85 VerifySyncGlobalErrorResult( |
| 91 &service, signin, GoogleServiceAuthError::NONE, true, true); | 86 &service, signin, GoogleServiceAuthError::NONE, true, true); |
| 92 } | 87 } |
| 93 | 88 |
| 94 // Test that GetStatusLabelsForSyncGlobalError returns an error if a | 89 // Test that GetStatusLabelsForSyncGlobalError returns an error if a |
| 95 // passphrase is required and not for auth errors. | 90 // passphrase is required and not for auth errors. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 147 |
| 153 FakeSigninManager signin(profile.get()); | 148 FakeSigninManager signin(profile.get()); |
| 154 for (size_t i = 0; i < arraysize(table); ++i) { | 149 for (size_t i = 0; i < arraysize(table); ++i) { |
| 155 VerifySyncGlobalErrorResult(&service, signin, table[i], true, false); | 150 VerifySyncGlobalErrorResult(&service, signin, table[i], true, false); |
| 156 VerifySyncGlobalErrorResult(&service, signin, table[i], false, false); | 151 VerifySyncGlobalErrorResult(&service, signin, table[i], false, false); |
| 157 } | 152 } |
| 158 } | 153 } |
| 159 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases | 154 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases |
| 160 // in order to perform tests on the generated messages. | 155 // in order to perform tests on the generated messages. |
| 161 void GetDistinctCase(ProfileSyncServiceMock& service, | 156 void GetDistinctCase(ProfileSyncServiceMock& service, |
| 162 SigninManagerMock& signin, | 157 FakeSigninManager* signin, |
| 163 GoogleServiceAuthError** auth_error, | 158 FakeAuthStatusProvider* provider, |
| 164 int caseNumber) { | 159 int caseNumber) { |
| 165 // Auth Error object is returned by reference in mock and needs to stay in | 160 // Auth Error object is returned by reference in mock and needs to stay in |
| 166 // scope throughout test, so it is owned by calling method. However it is | 161 // scope throughout test, so it is owned by calling method. However it is |
| 167 // immutable so can only be allocated in this method. | 162 // immutable so can only be allocated in this method. |
| 168 switch (caseNumber) { | 163 switch (caseNumber) { |
| 169 case STATUS_CASE_SETUP_IN_PROGRESS: { | 164 case STATUS_CASE_SETUP_IN_PROGRESS: { |
| 170 EXPECT_CALL(service, HasSyncSetupCompleted()) | 165 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 171 .WillOnce(Return(false)); | 166 .WillRepeatedly(Return(false)); |
| 172 EXPECT_CALL(service, FirstSetupInProgress()) | 167 EXPECT_CALL(service, FirstSetupInProgress()) |
| 173 .WillOnce(Return(true)); | 168 .WillRepeatedly(Return(true)); |
| 174 browser_sync::SyncBackendHost::Status status; | 169 browser_sync::SyncBackendHost::Status status; |
| 175 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 170 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 176 .WillOnce(DoAll(SetArgPointee<0>(status), | 171 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
| 177 Return(false))); | 172 Return(false))); |
| 178 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | |
| 179 EXPECT_CALL(service, GetAuthError()) | |
| 180 .WillOnce(ReturnRef(**auth_error)); | |
| 181 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); | |
| 182 return; | 173 return; |
| 183 } | 174 } |
| 184 case STATUS_CASE_SETUP_ERROR: { | 175 case STATUS_CASE_SETUP_ERROR: { |
| 185 EXPECT_CALL(service, HasSyncSetupCompleted()) | 176 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 186 .WillOnce(Return(false)); | 177 .WillRepeatedly(Return(false)); |
| 187 EXPECT_CALL(service, FirstSetupInProgress()) | 178 EXPECT_CALL(service, FirstSetupInProgress()) |
| 188 .WillOnce(Return(false)); | 179 .WillRepeatedly(Return(false)); |
| 189 EXPECT_CALL(service, HasUnrecoverableError()) | 180 EXPECT_CALL(service, HasUnrecoverableError()) |
| 190 .WillOnce(Return(true)); | 181 .WillRepeatedly(Return(true)); |
| 191 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); | |
| 192 browser_sync::SyncBackendHost::Status status; | 182 browser_sync::SyncBackendHost::Status status; |
| 193 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 183 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 194 .WillOnce(DoAll(SetArgPointee<0>(status), | 184 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
| 195 Return(false))); | 185 Return(false))); |
| 196 return; | 186 return; |
| 197 } | 187 } |
| 198 case STATUS_CASE_AUTHENTICATING: { | 188 case STATUS_CASE_AUTHENTICATING: { |
| 199 EXPECT_CALL(service, HasSyncSetupCompleted()) | 189 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 200 .WillOnce(Return(true)); | 190 .WillRepeatedly(Return(true)); |
| 191 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); |
| 192 EXPECT_CALL(service, IsPassphraseRequired()) |
| 193 .WillRepeatedly(Return(false)); |
| 201 browser_sync::SyncBackendHost::Status status; | 194 browser_sync::SyncBackendHost::Status status; |
| 202 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 195 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 203 .WillOnce(DoAll(SetArgPointee<0>(status), | 196 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
| 204 Return(false))); | 197 Return(false))); |
| 205 EXPECT_CALL(service, HasUnrecoverableError()) | 198 EXPECT_CALL(service, HasUnrecoverableError()) |
| 206 .WillOnce(Return(false)); | 199 .WillRepeatedly(Return(false)); |
| 207 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(true)); | 200 signin->set_auth_in_progress(true); |
| 208 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | |
| 209 EXPECT_CALL(service, GetAuthError()) | |
| 210 .WillOnce(ReturnRef(**auth_error)); | |
| 211 return; | 201 return; |
| 212 } | 202 } |
| 213 case STATUS_CASE_AUTH_ERROR: { | 203 case STATUS_CASE_AUTH_ERROR: { |
| 214 EXPECT_CALL(service, HasSyncSetupCompleted()) | 204 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 215 .WillOnce(Return(true)); | 205 .WillRepeatedly(Return(true)); |
| 206 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); |
| 207 EXPECT_CALL(service, IsPassphraseRequired()) |
| 208 .WillRepeatedly(Return(false)); |
| 216 browser_sync::SyncBackendHost::Status status; | 209 browser_sync::SyncBackendHost::Status status; |
| 217 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 210 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 218 .WillOnce(DoAll(SetArgPointee<0>(status), | 211 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
| 219 Return(false))); | 212 Return(false))); |
| 220 *auth_error = new GoogleServiceAuthError( | 213 provider->set_auth_error(GoogleServiceAuthError( |
| 221 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 214 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 222 EXPECT_CALL(service, HasUnrecoverableError()) | 215 EXPECT_CALL(service, HasUnrecoverableError()) |
| 223 .WillOnce(Return(false)); | 216 .WillRepeatedly(Return(false)); |
| 224 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); | |
| 225 EXPECT_CALL(service, GetAuthError()) | |
| 226 .WillOnce(ReturnRef(**auth_error)); | |
| 227 return; | 217 return; |
| 228 } | 218 } |
| 229 case STATUS_CASE_PROTOCOL_ERROR: { | 219 case STATUS_CASE_PROTOCOL_ERROR: { |
| 230 EXPECT_CALL(service, HasSyncSetupCompleted()) | 220 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 231 .WillOnce(Return(true)); | 221 .WillRepeatedly(Return(true)); |
| 222 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); |
| 223 EXPECT_CALL(service, IsPassphraseRequired()) |
| 224 .WillRepeatedly(Return(false)); |
| 232 syncer::SyncProtocolError protocolError; | 225 syncer::SyncProtocolError protocolError; |
| 233 protocolError.action = syncer::STOP_AND_RESTART_SYNC; | 226 protocolError.action = syncer::STOP_AND_RESTART_SYNC; |
| 234 browser_sync::SyncBackendHost::Status status; | 227 browser_sync::SyncBackendHost::Status status; |
| 235 status.sync_protocol_error = protocolError; | 228 status.sync_protocol_error = protocolError; |
| 236 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 229 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 237 .WillOnce(DoAll(SetArgPointee<0>(status), | 230 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
| 238 Return(false))); | 231 Return(false))); |
| 239 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | |
| 240 EXPECT_CALL(service, GetAuthError()) | |
| 241 .WillOnce(ReturnRef(**auth_error)); | |
| 242 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); | |
| 243 EXPECT_CALL(service, HasUnrecoverableError()) | 232 EXPECT_CALL(service, HasUnrecoverableError()) |
| 244 .WillOnce(Return(false)); | 233 .WillRepeatedly(Return(false)); |
| 245 return; | 234 return; |
| 246 } | 235 } |
| 247 case STATUS_CASE_PASSPHRASE_ERROR: { | 236 case STATUS_CASE_PASSPHRASE_ERROR: { |
| 248 EXPECT_CALL(service, HasSyncSetupCompleted()) | 237 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 249 .WillOnce(Return(true)); | 238 .WillRepeatedly(Return(true)); |
| 239 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); |
| 250 browser_sync::SyncBackendHost::Status status; | 240 browser_sync::SyncBackendHost::Status status; |
| 251 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 241 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 252 .WillOnce(DoAll(SetArgPointee<0>(status), | 242 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
| 253 Return(false))); | 243 Return(false))); |
| 254 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | |
| 255 EXPECT_CALL(service, GetAuthError()) | |
| 256 .WillOnce(ReturnRef(**auth_error)); | |
| 257 EXPECT_CALL(service, HasUnrecoverableError()) | 244 EXPECT_CALL(service, HasUnrecoverableError()) |
| 258 .WillOnce(Return(false)); | 245 .WillRepeatedly(Return(false)); |
| 259 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); | |
| 260 EXPECT_CALL(service, IsPassphraseRequired()) | 246 EXPECT_CALL(service, IsPassphraseRequired()) |
| 261 .WillOnce(Return(true)); | 247 .WillRepeatedly(Return(true)); |
| 262 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 248 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
| 263 .WillOnce(Return(true)); | 249 .WillRepeatedly(Return(true)); |
| 264 return; | 250 return; |
| 265 } | 251 } |
| 266 case STATUS_CASE_SYNCED: { | 252 case STATUS_CASE_SYNCED: { |
| 267 EXPECT_CALL(service, HasSyncSetupCompleted()) | 253 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 268 .WillOnce(Return(true)); | 254 .WillRepeatedly(Return(true)); |
| 255 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); |
| 256 EXPECT_CALL(service, IsPassphraseRequired()) |
| 257 .WillRepeatedly(Return(false)); |
| 269 browser_sync::SyncBackendHost::Status status; | 258 browser_sync::SyncBackendHost::Status status; |
| 270 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 259 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 271 .WillOnce(DoAll(SetArgPointee<0>(status), | 260 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
| 272 Return(false))); | 261 Return(false))); |
| 273 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | |
| 274 EXPECT_CALL(service, GetAuthError()) | |
| 275 .WillOnce(ReturnRef(**auth_error)); | |
| 276 EXPECT_CALL(signin, AuthInProgress()).WillRepeatedly(Return(false)); | |
| 277 EXPECT_CALL(service, HasUnrecoverableError()) | 262 EXPECT_CALL(service, HasUnrecoverableError()) |
| 278 .WillOnce(Return(false)); | 263 .WillRepeatedly(Return(false)); |
| 279 EXPECT_CALL(service, IsPassphraseRequired()) | 264 EXPECT_CALL(service, IsPassphraseRequired()) |
| 280 .WillOnce(Return(false)); | 265 .WillRepeatedly(Return(false)); |
| 266 return; |
| 267 } |
| 268 case STATUS_CASE_SYNC_DISABLED_BY_POLICY: { |
| 269 EXPECT_CALL(service, IsManaged()).WillRepeatedly(Return(true)); |
| 270 EXPECT_CALL(service, HasSyncSetupCompleted()) |
| 271 .WillRepeatedly(Return(false)); |
| 272 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(false)); |
| 273 EXPECT_CALL(service, IsPassphraseRequired()) |
| 274 .WillRepeatedly(Return(false)); |
| 275 browser_sync::SyncBackendHost::Status status; |
| 276 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 277 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
| 278 Return(false))); |
| 279 EXPECT_CALL(service, HasUnrecoverableError()) |
| 280 .WillRepeatedly(Return(false)); |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 default: | 283 default: |
| 284 NOTREACHED(); | 284 NOTREACHED(); |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 // This test ensures that a each distinctive ProfileSyncService statuses | 288 // This test ensures that a each distinctive ProfileSyncService statuses |
| 289 // will return a unique combination of status and link messages from | 289 // will return a unique combination of status and link messages from |
| 290 // GetStatusLabels(). | 290 // GetStatusLabels(). |
| 291 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { | 291 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { |
| 292 std::set<string16> messages; | 292 std::set<string16> messages; |
| 293 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 293 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
| 294 scoped_ptr<Profile> profile( | 294 scoped_ptr<Profile> profile( |
| 295 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 295 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 296 ProfileSyncServiceMock service(profile.get()); | 296 ProfileSyncServiceMock service(profile.get()); |
| 297 NiceMock<SigninManagerMock> signin; | 297 FakeSigninManager signin(profile.get()); |
| 298 GoogleServiceAuthError* auth_error = NULL; | 298 signin.SetAuthenticatedUsername("test_user@test.com"); |
| 299 GetDistinctCase(service, signin, &auth_error, idx); | 299 FakeAuthStatusProvider provider(signin.signin_global_error()); |
| 300 GetDistinctCase(service, &signin, &provider, idx); |
| 300 string16 status_label; | 301 string16 status_label; |
| 301 string16 link_label; | 302 string16 link_label; |
| 302 sync_ui_util::GetStatusLabels(&service, | 303 sync_ui_util::GetStatusLabels(&service, |
| 303 signin, | 304 signin, |
| 304 sync_ui_util::WITH_HTML, | 305 sync_ui_util::WITH_HTML, |
| 305 &status_label, | 306 &status_label, |
| 306 &link_label); | 307 &link_label); |
| 307 // If the status and link message combination is already present in the set | 308 // If the status and link message combination is already present in the set |
| 308 // of messages already seen, this is a duplicate rather than a unique | 309 // of messages already seen, this is a duplicate rather than a unique |
| 309 // message, and the test has failed. | 310 // message, and the test has failed. |
| 311 EXPECT_FALSE(status_label.empty()) << |
| 312 "Empty status label returned for case #" << idx; |
| 310 string16 combined_label = | 313 string16 combined_label = |
| 311 status_label + string16(ASCIIToUTF16("#")) + link_label; | 314 status_label + string16(ASCIIToUTF16("#")) + link_label; |
| 312 EXPECT_TRUE(messages.find(combined_label) == messages.end()); | 315 EXPECT_TRUE(messages.find(combined_label) == messages.end()) << |
| 316 "Duplicate message for case #" << idx << ": " << combined_label; |
| 313 messages.insert(combined_label); | 317 messages.insert(combined_label); |
| 314 if (auth_error) | 318 testing::Mock::VerifyAndClearExpectations(&service); |
| 315 delete auth_error; | 319 testing::Mock::VerifyAndClearExpectations(&signin); |
| 316 } | 320 } |
| 317 } | 321 } |
| 318 | 322 |
| 319 // This test ensures that the html_links parameter on GetStatusLabels() is | 323 // This test ensures that the html_links parameter on GetStatusLabels() is |
| 320 // honored. | 324 // honored. |
| 321 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { | 325 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { |
| 322 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 326 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
| 323 scoped_ptr<Profile> profile( | 327 scoped_ptr<Profile> profile( |
| 324 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 328 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 325 ProfileSyncServiceMock service(profile.get()); | 329 ProfileSyncServiceMock service(profile.get()); |
| 326 NiceMock<SigninManagerMock> signin; | 330 FakeSigninManager signin(profile.get()); |
| 327 GoogleServiceAuthError* auth_error = NULL; | 331 signin.SetAuthenticatedUsername("test_user@test.com"); |
| 328 GetDistinctCase(service, signin, &auth_error, idx); | 332 FakeAuthStatusProvider provider(signin.signin_global_error()); |
| 333 GetDistinctCase(service, &signin, &provider, idx); |
| 329 string16 status_label; | 334 string16 status_label; |
| 330 string16 link_label; | 335 string16 link_label; |
| 331 sync_ui_util::GetStatusLabels(&service, | 336 sync_ui_util::GetStatusLabels(&service, |
| 332 signin, | 337 signin, |
| 333 sync_ui_util::PLAIN_TEXT, | 338 sync_ui_util::PLAIN_TEXT, |
| 334 &status_label, | 339 &status_label, |
| 335 &link_label); | 340 &link_label); |
| 341 |
| 336 // Ensures a search for string 'href' (found in links, not a string to be | 342 // Ensures a search for string 'href' (found in links, not a string to be |
| 337 // found in an English language message) fails when links are excluded from | 343 // found in an English language message) fails when links are excluded from |
| 338 // the status label. | 344 // the status label. |
| 345 EXPECT_FALSE(status_label.empty()); |
| 339 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), | 346 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
| 340 string16::npos); | 347 string16::npos); |
| 341 if (auth_error) { | 348 testing::Mock::VerifyAndClearExpectations(&service); |
| 342 delete auth_error; | 349 testing::Mock::VerifyAndClearExpectations(&signin); |
| 343 } | |
| 344 } | 350 } |
| 345 } | 351 } |
| OLD | NEW |