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/fake_auth_status_provider.h" |
10 #include "chrome/browser/signin/fake_signin_manager.h" | 10 #include "chrome/browser/signin/fake_signin_manager.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 | 68 |
69 // Test that GetStatusLabelsForSyncGlobalError returns an error if a | 69 // Test that GetStatusLabelsForSyncGlobalError returns an error if a |
70 // passphrase is required. | 70 // passphrase is required. |
71 TEST(SyncUIUtilTest, PassphraseGlobalError) { | 71 TEST(SyncUIUtilTest, PassphraseGlobalError) { |
72 MessageLoopForUI message_loop; | 72 MessageLoopForUI message_loop; |
73 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 73 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
74 scoped_ptr<Profile> profile( | 74 scoped_ptr<Profile> profile( |
75 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 75 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
76 NiceMock<ProfileSyncServiceMock> service(profile.get()); | 76 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
77 FakeSigninManagerBase signin(profile.get()); | 77 FakeSigninManagerBase signin; |
78 browser_sync::SyncBackendHost::Status status; | 78 browser_sync::SyncBackendHost::Status status; |
79 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 79 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
80 .WillRepeatedly(Return(false)); | 80 .WillRepeatedly(Return(false)); |
81 EXPECT_CALL(service, IsPassphraseRequired()) | 81 EXPECT_CALL(service, IsPassphraseRequired()) |
82 .WillRepeatedly(Return(true)); | 82 .WillRepeatedly(Return(true)); |
83 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 83 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
84 .WillRepeatedly(Return(true)); | 84 .WillRepeatedly(Return(true)); |
85 VerifySyncGlobalErrorResult( | 85 VerifySyncGlobalErrorResult( |
86 &service, signin, GoogleServiceAuthError::NONE, true, true); | 86 &service, signin, GoogleServiceAuthError::NONE, true, true); |
87 } | 87 } |
88 | 88 |
89 // Test that GetStatusLabelsForSyncGlobalError returns an error if a | 89 // Test that GetStatusLabelsForSyncGlobalError returns an error if a |
90 // passphrase is required and not for auth errors. | 90 // passphrase is required and not for auth errors. |
91 TEST(SyncUIUtilTest, AuthAndPassphraseGlobalError) { | 91 TEST(SyncUIUtilTest, AuthAndPassphraseGlobalError) { |
92 MessageLoopForUI message_loop; | 92 MessageLoopForUI message_loop; |
93 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 93 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
94 scoped_ptr<Profile> profile( | 94 scoped_ptr<Profile> profile( |
95 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 95 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
96 NiceMock<ProfileSyncServiceMock> service(profile.get()); | 96 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
97 FakeSigninManagerBase signin(profile.get()); | 97 FakeSigninManagerBase signin; |
98 browser_sync::SyncBackendHost::Status status; | 98 browser_sync::SyncBackendHost::Status status; |
99 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 99 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
100 .WillRepeatedly(Return(false)); | 100 .WillRepeatedly(Return(false)); |
101 | 101 |
102 EXPECT_CALL(service, IsPassphraseRequired()) | 102 EXPECT_CALL(service, IsPassphraseRequired()) |
103 .WillRepeatedly(Return(true)); | 103 .WillRepeatedly(Return(true)); |
104 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 104 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
105 .WillRepeatedly(Return(true)); | 105 .WillRepeatedly(Return(true)); |
106 EXPECT_CALL(service, HasSyncSetupCompleted()) | 106 EXPECT_CALL(service, HasSyncSetupCompleted()) |
107 .WillRepeatedly(Return(true)); | 107 .WillRepeatedly(Return(true)); |
(...skipping 30 matching lines...) Expand all Loading... |
138 GoogleServiceAuthError::CONNECTION_FAILED, | 138 GoogleServiceAuthError::CONNECTION_FAILED, |
139 GoogleServiceAuthError::CAPTCHA_REQUIRED, | 139 GoogleServiceAuthError::CAPTCHA_REQUIRED, |
140 GoogleServiceAuthError::ACCOUNT_DELETED, | 140 GoogleServiceAuthError::ACCOUNT_DELETED, |
141 GoogleServiceAuthError::ACCOUNT_DISABLED, | 141 GoogleServiceAuthError::ACCOUNT_DISABLED, |
142 GoogleServiceAuthError::SERVICE_UNAVAILABLE, | 142 GoogleServiceAuthError::SERVICE_UNAVAILABLE, |
143 GoogleServiceAuthError::TWO_FACTOR, | 143 GoogleServiceAuthError::TWO_FACTOR, |
144 GoogleServiceAuthError::REQUEST_CANCELED, | 144 GoogleServiceAuthError::REQUEST_CANCELED, |
145 GoogleServiceAuthError::HOSTED_NOT_ALLOWED | 145 GoogleServiceAuthError::HOSTED_NOT_ALLOWED |
146 }; | 146 }; |
147 | 147 |
148 FakeSigninManagerBase signin(profile.get()); | 148 FakeSigninManagerBase signin; |
149 for (size_t i = 0; i < arraysize(table); ++i) { | 149 for (size_t i = 0; i < arraysize(table); ++i) { |
150 VerifySyncGlobalErrorResult(&service, signin, table[i], true, false); | 150 VerifySyncGlobalErrorResult(&service, signin, table[i], true, false); |
151 VerifySyncGlobalErrorResult(&service, signin, table[i], false, false); | 151 VerifySyncGlobalErrorResult(&service, signin, table[i], false, false); |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 // TODO(tim): This shouldn't be required. r194857 removed the | 155 // TODO(tim): This shouldn't be required. r194857 removed the |
156 // AuthInProgress override from FakeSigninManager, which meant this test started | 156 // AuthInProgress override from FakeSigninManager, which meant this test started |
157 // using the "real" SigninManager AuthInProgress logic. Without that override, | 157 // using the "real" SigninManager AuthInProgress logic. Without that override, |
158 // it's no longer possible to test both chrome os + desktop flows as part of the | 158 // it's no longer possible to test both chrome os + desktop flows as part of the |
159 // same test, because AuthInProgress is always false on chrome os. Most of the | 159 // same test, because AuthInProgress is always false on chrome os. Most of the |
160 // tests are unaffected, but STATUS_CASE_AUTHENTICATING can't exist in both | 160 // tests are unaffected, but STATUS_CASE_AUTHENTICATING can't exist in both |
161 // versions, so it we will require two separate tests, one using SigninManager | 161 // versions, so it we will require two separate tests, one using SigninManager |
162 // and one using SigninManagerBase (which require different setup procedures. | 162 // and one using SigninManagerBase (which require different setup procedures. |
163 class FakeSigninManagerForSyncUIUtilTest : public FakeSigninManagerBase { | 163 class FakeSigninManagerForSyncUIUtilTest : public FakeSigninManagerBase { |
164 public: | 164 public: |
165 explicit FakeSigninManagerForSyncUIUtilTest(Profile* profile) | 165 explicit FakeSigninManagerForSyncUIUtilTest(Profile* profile) |
166 : FakeSigninManagerBase(profile), auth_in_progress_(false) { | 166 : auth_in_progress_(false) { |
| 167 Initialize(profile); |
167 } | 168 } |
168 | 169 |
169 virtual ~FakeSigninManagerForSyncUIUtilTest() { | 170 virtual ~FakeSigninManagerForSyncUIUtilTest() { |
170 } | 171 } |
171 | 172 |
172 virtual bool AuthInProgress() const OVERRIDE { | 173 virtual bool AuthInProgress() const OVERRIDE { |
173 return auth_in_progress_; | 174 return auth_in_progress_; |
174 } | 175 } |
175 | 176 |
176 void set_auth_in_progress() { | 177 void set_auth_in_progress() { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 NOTREACHED(); | 315 NOTREACHED(); |
315 } | 316 } |
316 } | 317 } |
317 | 318 |
318 // This test ensures that a each distinctive ProfileSyncService statuses | 319 // This test ensures that a each distinctive ProfileSyncService statuses |
319 // will return a unique combination of status and link messages from | 320 // will return a unique combination of status and link messages from |
320 // GetStatusLabels(). | 321 // GetStatusLabels(). |
321 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { | 322 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { |
322 std::set<string16> messages; | 323 std::set<string16> messages; |
323 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 324 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
324 scoped_ptr<Profile> profile( | 325 scoped_ptr<Profile> profile(new TestingProfile()); |
325 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | |
326 ProfileSyncServiceMock service(profile.get()); | 326 ProfileSyncServiceMock service(profile.get()); |
327 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); | 327 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); |
328 signin.SetAuthenticatedUsername("test_user@test.com"); | 328 signin.SetAuthenticatedUsername("test_user@test.com"); |
329 FakeAuthStatusProvider provider(signin.signin_global_error()); | 329 scoped_ptr<FakeAuthStatusProvider> provider( |
330 GetDistinctCase(service, &signin, &provider, idx); | 330 new FakeAuthStatusProvider(signin.signin_global_error())); |
| 331 GetDistinctCase(service, &signin, provider.get(), idx); |
331 string16 status_label; | 332 string16 status_label; |
332 string16 link_label; | 333 string16 link_label; |
333 sync_ui_util::GetStatusLabels(&service, | 334 sync_ui_util::GetStatusLabels(&service, |
334 signin, | 335 signin, |
335 sync_ui_util::WITH_HTML, | 336 sync_ui_util::WITH_HTML, |
336 &status_label, | 337 &status_label, |
337 &link_label); | 338 &link_label); |
338 // If the status and link message combination is already present in the set | 339 // If the status and link message combination is already present in the set |
339 // of messages already seen, this is a duplicate rather than a unique | 340 // of messages already seen, this is a duplicate rather than a unique |
340 // message, and the test has failed. | 341 // message, and the test has failed. |
341 EXPECT_FALSE(status_label.empty()) << | 342 EXPECT_FALSE(status_label.empty()) << |
342 "Empty status label returned for case #" << idx; | 343 "Empty status label returned for case #" << idx; |
343 string16 combined_label = | 344 string16 combined_label = |
344 status_label + string16(ASCIIToUTF16("#")) + link_label; | 345 status_label + string16(ASCIIToUTF16("#")) + link_label; |
345 EXPECT_TRUE(messages.find(combined_label) == messages.end()) << | 346 EXPECT_TRUE(messages.find(combined_label) == messages.end()) << |
346 "Duplicate message for case #" << idx << ": " << combined_label; | 347 "Duplicate message for case #" << idx << ": " << combined_label; |
347 messages.insert(combined_label); | 348 messages.insert(combined_label); |
348 testing::Mock::VerifyAndClearExpectations(&service); | 349 testing::Mock::VerifyAndClearExpectations(&service); |
349 testing::Mock::VerifyAndClearExpectations(&signin); | 350 testing::Mock::VerifyAndClearExpectations(&signin); |
| 351 provider.reset(); |
| 352 signin.Shutdown(); |
350 } | 353 } |
351 } | 354 } |
352 | 355 |
353 // This test ensures that the html_links parameter on GetStatusLabels() is | 356 // This test ensures that the html_links parameter on GetStatusLabels() is |
354 // honored. | 357 // honored. |
355 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { | 358 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { |
356 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 359 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
357 scoped_ptr<Profile> profile( | 360 scoped_ptr<Profile> profile( |
358 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 361 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
359 ProfileSyncServiceMock service(profile.get()); | 362 ProfileSyncServiceMock service(profile.get()); |
360 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); | 363 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); |
361 signin.SetAuthenticatedUsername("test_user@test.com"); | 364 signin.SetAuthenticatedUsername("test_user@test.com"); |
362 FakeAuthStatusProvider provider(signin.signin_global_error()); | 365 scoped_ptr<FakeAuthStatusProvider> provider( |
363 GetDistinctCase(service, &signin, &provider, idx); | 366 new FakeAuthStatusProvider(signin.signin_global_error())); |
| 367 GetDistinctCase(service, &signin, provider.get(), idx); |
364 string16 status_label; | 368 string16 status_label; |
365 string16 link_label; | 369 string16 link_label; |
366 sync_ui_util::GetStatusLabels(&service, | 370 sync_ui_util::GetStatusLabels(&service, |
367 signin, | 371 signin, |
368 sync_ui_util::PLAIN_TEXT, | 372 sync_ui_util::PLAIN_TEXT, |
369 &status_label, | 373 &status_label, |
370 &link_label); | 374 &link_label); |
371 | 375 |
372 // Ensures a search for string 'href' (found in links, not a string to be | 376 // Ensures a search for string 'href' (found in links, not a string to be |
373 // found in an English language message) fails when links are excluded from | 377 // found in an English language message) fails when links are excluded from |
374 // the status label. | 378 // the status label. |
375 EXPECT_FALSE(status_label.empty()); | 379 EXPECT_FALSE(status_label.empty()); |
376 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), | 380 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
377 string16::npos); | 381 string16::npos); |
378 testing::Mock::VerifyAndClearExpectations(&service); | 382 testing::Mock::VerifyAndClearExpectations(&service); |
379 testing::Mock::VerifyAndClearExpectations(&signin); | 383 testing::Mock::VerifyAndClearExpectations(&signin); |
| 384 provider.reset(); |
| 385 signin.Shutdown(); |
380 } | 386 } |
381 } | 387 } |
OLD | NEW |