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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/signin/fake_signin_manager.h" | 9 #include "chrome/browser/signin/fake_signin_manager.h" |
10 #include "chrome/browser/signin/signin_error_controller_factory.h" | 10 #include "chrome/browser/signin/signin_error_controller_factory.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 STATUS_CASE_AUTH_ERROR, | 37 STATUS_CASE_AUTH_ERROR, |
38 STATUS_CASE_PROTOCOL_ERROR, | 38 STATUS_CASE_PROTOCOL_ERROR, |
39 STATUS_CASE_PASSPHRASE_ERROR, | 39 STATUS_CASE_PASSPHRASE_ERROR, |
40 STATUS_CASE_SYNCED, | 40 STATUS_CASE_SYNCED, |
41 STATUS_CASE_SYNC_DISABLED_BY_POLICY, | 41 STATUS_CASE_SYNC_DISABLED_BY_POLICY, |
42 NUMBER_OF_STATUS_CASES | 42 NUMBER_OF_STATUS_CASES |
43 }; | 43 }; |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
| 47 const char kTestGaiaId[] = "gaia-id-test_user@test.com"; |
47 const char kTestUser[] = "test_user@test.com"; | 48 const char kTestUser[] = "test_user@test.com"; |
48 | 49 |
49 #if !defined(OS_CHROMEOS) | 50 #if !defined(OS_CHROMEOS) |
50 // Utility function to test that GetStatusLabelsForSyncGlobalError returns | 51 // Utility function to test that GetStatusLabelsForSyncGlobalError returns |
51 // the correct results for the given states. | 52 // the correct results for the given states. |
52 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, | 53 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
53 GoogleServiceAuthError::State error_state, | 54 GoogleServiceAuthError::State error_state, |
54 bool is_signed_in, | 55 bool is_signed_in, |
55 bool is_error) { | 56 bool is_error) { |
56 EXPECT_CALL(*service, HasSyncSetupCompleted()) | 57 EXPECT_CALL(*service, HasSyncSetupCompleted()) |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 EXPECT_CALL(service, HasSyncSetupCompleted()) | 246 EXPECT_CALL(service, HasSyncSetupCompleted()) |
246 .WillRepeatedly(Return(true)); | 247 .WillRepeatedly(Return(true)); |
247 EXPECT_CALL(service, SyncActive()).WillRepeatedly(Return(true)); | 248 EXPECT_CALL(service, SyncActive()).WillRepeatedly(Return(true)); |
248 EXPECT_CALL(service, IsPassphraseRequired()) | 249 EXPECT_CALL(service, IsPassphraseRequired()) |
249 .WillRepeatedly(Return(false)); | 250 .WillRepeatedly(Return(false)); |
250 browser_sync::SyncBackendHost::Status status; | 251 browser_sync::SyncBackendHost::Status status; |
251 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 252 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
252 .WillRepeatedly(DoAll(SetArgPointee<0>(status), | 253 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
253 Return(false))); | 254 Return(false))); |
254 provider->SetAuthError( | 255 provider->SetAuthError( |
255 kTestUser, | 256 signin->GetAuthenticatedAccountId(), |
256 kTestUser, | 257 kTestUser, |
257 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | 258 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
258 EXPECT_CALL(service, HasUnrecoverableError()) | 259 EXPECT_CALL(service, HasUnrecoverableError()) |
259 .WillRepeatedly(Return(false)); | 260 .WillRepeatedly(Return(false)); |
260 return; | 261 return; |
261 } | 262 } |
262 case STATUS_CASE_PROTOCOL_ERROR: { | 263 case STATUS_CASE_PROTOCOL_ERROR: { |
263 EXPECT_CALL(service, HasSyncSetupCompleted()) | 264 EXPECT_CALL(service, HasSyncSetupCompleted()) |
264 .WillRepeatedly(Return(true)); | 265 .WillRepeatedly(Return(true)); |
265 EXPECT_CALL(service, SyncActive()).WillRepeatedly(Return(true)); | 266 EXPECT_CALL(service, SyncActive()).WillRepeatedly(Return(true)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // will return a unique combination of status and link messages from | 333 // will return a unique combination of status and link messages from |
333 // GetStatusLabels(). | 334 // GetStatusLabels(). |
334 TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { | 335 TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { |
335 std::set<base::string16> messages; | 336 std::set<base::string16> messages; |
336 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 337 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
337 scoped_ptr<Profile> profile(new TestingProfile()); | 338 scoped_ptr<Profile> profile(new TestingProfile()); |
338 ProfileSyncServiceMock service(profile.get()); | 339 ProfileSyncServiceMock service(profile.get()); |
339 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); | 340 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); |
340 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 341 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
341 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); | 342 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); |
342 signin.SetAuthenticatedUsername(kTestUser); | 343 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
343 scoped_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( | 344 scoped_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( |
344 SigninErrorControllerFactory::GetForProfile(profile.get()))); | 345 SigninErrorControllerFactory::GetForProfile(profile.get()))); |
345 GetDistinctCase(service, &signin, provider.get(), idx); | 346 GetDistinctCase(service, &signin, provider.get(), idx); |
346 base::string16 status_label; | 347 base::string16 status_label; |
347 base::string16 link_label; | 348 base::string16 link_label; |
348 sync_ui_util::GetStatusLabels(&service, | 349 sync_ui_util::GetStatusLabels(&service, |
349 signin, | 350 signin, |
350 sync_ui_util::WITH_HTML, | 351 sync_ui_util::WITH_HTML, |
351 &status_label, | 352 &status_label, |
352 &link_label); | 353 &link_label); |
(...skipping 18 matching lines...) Expand all Loading... |
371 // This test ensures that the html_links parameter on GetStatusLabels() is | 372 // This test ensures that the html_links parameter on GetStatusLabels() is |
372 // honored. | 373 // honored. |
373 TEST_F(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { | 374 TEST_F(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { |
374 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 375 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
375 scoped_ptr<Profile> profile( | 376 scoped_ptr<Profile> profile( |
376 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 377 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
377 ProfileSyncServiceMock service(profile.get()); | 378 ProfileSyncServiceMock service(profile.get()); |
378 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); | 379 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); |
379 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 380 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
380 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); | 381 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); |
381 signin.SetAuthenticatedUsername(kTestUser); | 382 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
382 scoped_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( | 383 scoped_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( |
383 SigninErrorControllerFactory::GetForProfile(profile.get()))); | 384 SigninErrorControllerFactory::GetForProfile(profile.get()))); |
384 GetDistinctCase(service, &signin, provider.get(), idx); | 385 GetDistinctCase(service, &signin, provider.get(), idx); |
385 base::string16 status_label; | 386 base::string16 status_label; |
386 base::string16 link_label; | 387 base::string16 link_label; |
387 sync_ui_util::GetStatusLabels(&service, | 388 sync_ui_util::GetStatusLabels(&service, |
388 signin, | 389 signin, |
389 sync_ui_util::PLAIN_TEXT, | 390 sync_ui_util::PLAIN_TEXT, |
390 &status_label, | 391 &status_label, |
391 &link_label); | 392 &link_label); |
392 | 393 |
393 // Ensures a search for string 'href' (found in links, not a string to be | 394 // Ensures a search for string 'href' (found in links, not a string to be |
394 // found in an English language message) fails when links are excluded from | 395 // found in an English language message) fails when links are excluded from |
395 // the status label. | 396 // the status label. |
396 EXPECT_FALSE(status_label.empty()); | 397 EXPECT_FALSE(status_label.empty()); |
397 EXPECT_EQ(status_label.find(base::ASCIIToUTF16("href")), | 398 EXPECT_EQ(status_label.find(base::ASCIIToUTF16("href")), |
398 base::string16::npos); | 399 base::string16::npos); |
399 testing::Mock::VerifyAndClearExpectations(&service); | 400 testing::Mock::VerifyAndClearExpectations(&service); |
400 testing::Mock::VerifyAndClearExpectations(&signin); | 401 testing::Mock::VerifyAndClearExpectations(&signin); |
401 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 402 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
402 provider.reset(); | 403 provider.reset(); |
403 signin.Shutdown(); | 404 signin.Shutdown(); |
404 } | 405 } |
405 } | 406 } |
OLD | NEW |