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 27 matching lines...) Expand all Loading... |
38 STATUS_CASE_SYNCED, | 38 STATUS_CASE_SYNCED, |
39 STATUS_CASE_SYNC_DISABLED_BY_POLICY, | 39 STATUS_CASE_SYNC_DISABLED_BY_POLICY, |
40 NUMBER_OF_STATUS_CASES | 40 NUMBER_OF_STATUS_CASES |
41 }; | 41 }; |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 // Utility function to test that GetStatusLabelsForSyncGlobalError returns | 45 // Utility function to test that GetStatusLabelsForSyncGlobalError returns |
46 // the correct results for the given states. | 46 // the correct results for the given states. |
47 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, | 47 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
48 const SigninManager& signin, | 48 const SigninManagerBase& signin, |
49 GoogleServiceAuthError::State error_state, | 49 GoogleServiceAuthError::State error_state, |
50 bool is_signed_in, | 50 bool is_signed_in, |
51 bool is_error) { | 51 bool is_error) { |
52 EXPECT_CALL(*service, HasSyncSetupCompleted()) | 52 EXPECT_CALL(*service, HasSyncSetupCompleted()) |
53 .WillRepeatedly(Return(is_signed_in)); | 53 .WillRepeatedly(Return(is_signed_in)); |
54 | 54 |
55 GoogleServiceAuthError auth_error(error_state); | 55 GoogleServiceAuthError auth_error(error_state); |
56 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); | 56 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); |
57 | 57 |
58 string16 label1, label2, label3; | 58 string16 label1, label2, label3; |
59 sync_ui_util::GetStatusLabelsForSyncGlobalError( | 59 sync_ui_util::GetStatusLabelsForSyncGlobalError( |
60 service, signin, &label1, &label2, &label3); | 60 service, signin, &label1, &label2, &label3); |
61 EXPECT_EQ(label1.empty(), !is_error); | 61 EXPECT_EQ(label1.empty(), !is_error); |
62 EXPECT_EQ(label2.empty(), !is_error); | 62 EXPECT_EQ(label2.empty(), !is_error); |
63 EXPECT_EQ(label3.empty(), !is_error); | 63 EXPECT_EQ(label3.empty(), !is_error); |
64 } | 64 } |
65 | 65 |
66 } // namespace | 66 } // namespace |
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 FakeSigninManager signin(profile.get()); | 77 FakeSigninManagerBase signin(profile.get()); |
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 FakeSigninManager signin(profile.get()); | 97 FakeSigninManagerBase signin(profile.get()); |
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 FakeSigninManager signin(profile.get()); | 148 FakeSigninManagerBase signin(profile.get()); |
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 |
| 155 // TODO(tim): This shouldn't be required. r194857 removed the |
| 156 // AuthInProgress override from FakeSigninManager, which meant this test started |
| 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 |
| 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 |
| 161 // versions, so it we will require two separate tests, one using SigninManager |
| 162 // and one using SigninManagerBase (which require different setup procedures. |
| 163 class FakeSigninManagerForSyncUIUtilTest : public FakeSigninManagerBase { |
| 164 public: |
| 165 explicit FakeSigninManagerForSyncUIUtilTest(Profile* profile) |
| 166 : FakeSigninManagerBase(profile), auth_in_progress_(false) { |
| 167 } |
| 168 |
| 169 virtual ~FakeSigninManagerForSyncUIUtilTest() { |
| 170 } |
| 171 |
| 172 virtual bool AuthInProgress() const OVERRIDE { |
| 173 return auth_in_progress_; |
| 174 } |
| 175 |
| 176 void set_auth_in_progress() { |
| 177 auth_in_progress_ = true; |
| 178 } |
| 179 |
| 180 private: |
| 181 bool auth_in_progress_; |
| 182 }; |
| 183 |
154 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases | 184 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases |
155 // in order to perform tests on the generated messages. | 185 // in order to perform tests on the generated messages. |
156 void GetDistinctCase(ProfileSyncServiceMock& service, | 186 void GetDistinctCase(ProfileSyncServiceMock& service, |
157 FakeSigninManager* signin, | 187 FakeSigninManagerForSyncUIUtilTest* signin, |
158 FakeAuthStatusProvider* provider, | 188 FakeAuthStatusProvider* provider, |
159 int caseNumber) { | 189 int caseNumber) { |
160 // Auth Error object is returned by reference in mock and needs to stay in | 190 // Auth Error object is returned by reference in mock and needs to stay in |
161 // scope throughout test, so it is owned by calling method. However it is | 191 // scope throughout test, so it is owned by calling method. However it is |
162 // immutable so can only be allocated in this method. | 192 // immutable so can only be allocated in this method. |
163 switch (caseNumber) { | 193 switch (caseNumber) { |
164 case STATUS_CASE_SETUP_IN_PROGRESS: { | 194 case STATUS_CASE_SETUP_IN_PROGRESS: { |
165 EXPECT_CALL(service, HasSyncSetupCompleted()) | 195 EXPECT_CALL(service, HasSyncSetupCompleted()) |
166 .WillRepeatedly(Return(false)); | 196 .WillRepeatedly(Return(false)); |
167 EXPECT_CALL(service, FirstSetupInProgress()) | 197 EXPECT_CALL(service, FirstSetupInProgress()) |
(...skipping 22 matching lines...) Expand all Loading... |
190 .WillRepeatedly(Return(true)); | 220 .WillRepeatedly(Return(true)); |
191 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); | 221 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); |
192 EXPECT_CALL(service, IsPassphraseRequired()) | 222 EXPECT_CALL(service, IsPassphraseRequired()) |
193 .WillRepeatedly(Return(false)); | 223 .WillRepeatedly(Return(false)); |
194 browser_sync::SyncBackendHost::Status status; | 224 browser_sync::SyncBackendHost::Status status; |
195 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 225 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
196 .WillRepeatedly(DoAll(SetArgPointee<0>(status), | 226 .WillRepeatedly(DoAll(SetArgPointee<0>(status), |
197 Return(false))); | 227 Return(false))); |
198 EXPECT_CALL(service, HasUnrecoverableError()) | 228 EXPECT_CALL(service, HasUnrecoverableError()) |
199 .WillRepeatedly(Return(false)); | 229 .WillRepeatedly(Return(false)); |
200 signin->set_auth_in_progress("test_user@test.com"); | 230 signin->set_auth_in_progress(); |
201 return; | 231 return; |
202 } | 232 } |
203 case STATUS_CASE_AUTH_ERROR: { | 233 case STATUS_CASE_AUTH_ERROR: { |
204 EXPECT_CALL(service, HasSyncSetupCompleted()) | 234 EXPECT_CALL(service, HasSyncSetupCompleted()) |
205 .WillRepeatedly(Return(true)); | 235 .WillRepeatedly(Return(true)); |
206 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); | 236 EXPECT_CALL(service, sync_initialized()).WillRepeatedly(Return(true)); |
207 EXPECT_CALL(service, IsPassphraseRequired()) | 237 EXPECT_CALL(service, IsPassphraseRequired()) |
208 .WillRepeatedly(Return(false)); | 238 .WillRepeatedly(Return(false)); |
209 browser_sync::SyncBackendHost::Status status; | 239 browser_sync::SyncBackendHost::Status status; |
210 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 240 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 317 |
288 // This test ensures that a each distinctive ProfileSyncService statuses | 318 // This test ensures that a each distinctive ProfileSyncService statuses |
289 // will return a unique combination of status and link messages from | 319 // will return a unique combination of status and link messages from |
290 // GetStatusLabels(). | 320 // GetStatusLabels(). |
291 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { | 321 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { |
292 std::set<string16> messages; | 322 std::set<string16> messages; |
293 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 323 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
294 scoped_ptr<Profile> profile( | 324 scoped_ptr<Profile> profile( |
295 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 325 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
296 ProfileSyncServiceMock service(profile.get()); | 326 ProfileSyncServiceMock service(profile.get()); |
297 FakeSigninManager signin(profile.get()); | 327 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); |
298 signin.SetAuthenticatedUsername("test_user@test.com"); | 328 signin.SetAuthenticatedUsername("test_user@test.com"); |
299 FakeAuthStatusProvider provider(signin.signin_global_error()); | 329 FakeAuthStatusProvider provider(signin.signin_global_error()); |
300 GetDistinctCase(service, &signin, &provider, idx); | 330 GetDistinctCase(service, &signin, &provider, idx); |
301 string16 status_label; | 331 string16 status_label; |
302 string16 link_label; | 332 string16 link_label; |
303 sync_ui_util::GetStatusLabels(&service, | 333 sync_ui_util::GetStatusLabels(&service, |
304 signin, | 334 signin, |
305 sync_ui_util::WITH_HTML, | 335 sync_ui_util::WITH_HTML, |
306 &status_label, | 336 &status_label, |
307 &link_label); | 337 &link_label); |
(...skipping 12 matching lines...) Expand all Loading... |
320 } | 350 } |
321 } | 351 } |
322 | 352 |
323 // This test ensures that the html_links parameter on GetStatusLabels() is | 353 // This test ensures that the html_links parameter on GetStatusLabels() is |
324 // honored. | 354 // honored. |
325 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { | 355 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { |
326 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 356 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
327 scoped_ptr<Profile> profile( | 357 scoped_ptr<Profile> profile( |
328 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 358 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
329 ProfileSyncServiceMock service(profile.get()); | 359 ProfileSyncServiceMock service(profile.get()); |
330 FakeSigninManager signin(profile.get()); | 360 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); |
331 signin.SetAuthenticatedUsername("test_user@test.com"); | 361 signin.SetAuthenticatedUsername("test_user@test.com"); |
332 FakeAuthStatusProvider provider(signin.signin_global_error()); | 362 FakeAuthStatusProvider provider(signin.signin_global_error()); |
333 GetDistinctCase(service, &signin, &provider, idx); | 363 GetDistinctCase(service, &signin, &provider, idx); |
334 string16 status_label; | 364 string16 status_label; |
335 string16 link_label; | 365 string16 link_label; |
336 sync_ui_util::GetStatusLabels(&service, | 366 sync_ui_util::GetStatusLabels(&service, |
337 signin, | 367 signin, |
338 sync_ui_util::PLAIN_TEXT, | 368 sync_ui_util::PLAIN_TEXT, |
339 &status_label, | 369 &status_label, |
340 &link_label); | 370 &link_label); |
341 | 371 |
342 // Ensures a search for string 'href' (found in links, not a string to be | 372 // Ensures a search for string 'href' (found in links, not a string to be |
343 // found in an English language message) fails when links are excluded from | 373 // found in an English language message) fails when links are excluded from |
344 // the status label. | 374 // the status label. |
345 EXPECT_FALSE(status_label.empty()); | 375 EXPECT_FALSE(status_label.empty()); |
346 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), | 376 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
347 string16::npos); | 377 string16::npos); |
348 testing::Mock::VerifyAndClearExpectations(&service); | 378 testing::Mock::VerifyAndClearExpectations(&service); |
349 testing::Mock::VerifyAndClearExpectations(&signin); | 379 testing::Mock::VerifyAndClearExpectations(&signin); |
350 } | 380 } |
351 } | 381 } |
OLD | NEW |