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/signin_manager.h" | 10 #include "chrome/browser/signin/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 // 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 |
155 // in order to perform tests on the generated messages. | 155 // in order to perform tests on the generated messages. |
156 void GetDistinctCase(ProfileSyncServiceMock& service, | 156 void GetDistinctCase(ProfileSyncServiceMock& service, |
157 FakeSigninManager* signin, | 157 FakeSigninManagerBase* signin, |
158 FakeAuthStatusProvider* provider, | 158 FakeAuthStatusProvider* provider, |
159 int caseNumber) { | 159 int caseNumber) { |
160 // 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 |
161 // 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 |
162 // immutable so can only be allocated in this method. | 162 // immutable so can only be allocated in this method. |
163 switch (caseNumber) { | 163 switch (caseNumber) { |
164 case STATUS_CASE_SETUP_IN_PROGRESS: { | 164 case STATUS_CASE_SETUP_IN_PROGRESS: { |
165 EXPECT_CALL(service, HasSyncSetupCompleted()) | 165 EXPECT_CALL(service, HasSyncSetupCompleted()) |
166 .WillRepeatedly(Return(false)); | 166 .WillRepeatedly(Return(false)); |
167 EXPECT_CALL(service, FirstSetupInProgress()) | 167 EXPECT_CALL(service, FirstSetupInProgress()) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 FakeSigninManager signin(profile.get()); | 297 FakeSigninManagerBase signin(profile.get()); |
298 signin.SetAuthenticatedUsername("test_user@test.com"); | 298 signin.SetAuthenticatedUsername("test_user@test.com"); |
299 FakeAuthStatusProvider provider(signin.signin_global_error()); | 299 FakeAuthStatusProvider provider(signin.signin_global_error()); |
300 GetDistinctCase(service, &signin, &provider, idx); | 300 GetDistinctCase(service, &signin, &provider, idx); |
301 string16 status_label; | 301 string16 status_label; |
302 string16 link_label; | 302 string16 link_label; |
303 sync_ui_util::GetStatusLabels(&service, | 303 sync_ui_util::GetStatusLabels(&service, |
304 signin, | 304 signin, |
305 sync_ui_util::WITH_HTML, | 305 sync_ui_util::WITH_HTML, |
306 &status_label, | 306 &status_label, |
307 &link_label); | 307 &link_label); |
(...skipping 12 matching lines...) Expand all Loading... |
320 } | 320 } |
321 } | 321 } |
322 | 322 |
323 // This test ensures that the html_links parameter on GetStatusLabels() is | 323 // This test ensures that the html_links parameter on GetStatusLabels() is |
324 // honored. | 324 // honored. |
325 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { | 325 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { |
326 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 326 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
327 scoped_ptr<Profile> profile( | 327 scoped_ptr<Profile> profile( |
328 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 328 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
329 ProfileSyncServiceMock service(profile.get()); | 329 ProfileSyncServiceMock service(profile.get()); |
330 FakeSigninManager signin(profile.get()); | 330 FakeSigninManagerBase signin(profile.get()); |
331 signin.SetAuthenticatedUsername("test_user@test.com"); | 331 signin.SetAuthenticatedUsername("test_user@test.com"); |
332 FakeAuthStatusProvider provider(signin.signin_global_error()); | 332 FakeAuthStatusProvider provider(signin.signin_global_error()); |
333 GetDistinctCase(service, &signin, &provider, idx); | 333 GetDistinctCase(service, &signin, &provider, idx); |
334 string16 status_label; | 334 string16 status_label; |
335 string16 link_label; | 335 string16 link_label; |
336 sync_ui_util::GetStatusLabels(&service, | 336 sync_ui_util::GetStatusLabels(&service, |
337 signin, | 337 signin, |
338 sync_ui_util::PLAIN_TEXT, | 338 sync_ui_util::PLAIN_TEXT, |
339 &status_label, | 339 &status_label, |
340 &link_label); | 340 &link_label); |
341 | 341 |
342 // 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 |
343 // 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 |
344 // the status label. | 344 // the status label. |
345 EXPECT_FALSE(status_label.empty()); | 345 EXPECT_FALSE(status_label.empty()); |
346 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), | 346 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
347 string16::npos); | 347 string16::npos); |
348 testing::Mock::VerifyAndClearExpectations(&service); | 348 testing::Mock::VerifyAndClearExpectations(&service); |
349 testing::Mock::VerifyAndClearExpectations(&signin); | 349 testing::Mock::VerifyAndClearExpectations(&signin); |
350 } | 350 } |
351 } | 351 } |
OLD | NEW |