OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" |
7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/sync/profile_sync_service_mock.h" | 10 #include "chrome/browser/sync/profile_sync_service_mock.h" |
9 #include "chrome/browser/sync/sync_ui_util.h" | 11 #include "chrome/browser/sync/sync_ui_util.h" |
10 #include "content/test/test_browser_thread.h" | 12 #include "content/test/test_browser_thread.h" |
11 #include "testing/gmock/include/gmock/gmock-actions.h" | 13 #include "testing/gmock/include/gmock/gmock-actions.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 | 16 |
15 using ::testing::AtMost; | 17 using ::testing::AtMost; |
16 using ::testing::Return; | 18 using ::testing::Return; |
17 using ::testing::ReturnRef; | 19 using ::testing::ReturnRef; |
(...skipping 17 matching lines...) Expand all Loading... |
35 | 37 |
36 // Utility function to test that GetStatusLabelsForSyncGlobalError returns | 38 // Utility function to test that GetStatusLabelsForSyncGlobalError returns |
37 // the correct results for the given states. | 39 // the correct results for the given states. |
38 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, | 40 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
39 GoogleServiceAuthError::State error_state, | 41 GoogleServiceAuthError::State error_state, |
40 bool is_signed_in, | 42 bool is_signed_in, |
41 bool is_error) { | 43 bool is_error) { |
42 EXPECT_CALL(*service, HasSyncSetupCompleted()) | 44 EXPECT_CALL(*service, HasSyncSetupCompleted()) |
43 .WillRepeatedly(Return(is_signed_in)); | 45 .WillRepeatedly(Return(is_signed_in)); |
44 | 46 |
45 if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { | |
46 EXPECT_CALL(*service, GetAuthenticatedUsername()) | |
47 .WillRepeatedly(Return(UTF8ToUTF16(""))); | |
48 } else { | |
49 EXPECT_CALL(*service, GetAuthenticatedUsername()) | |
50 .WillRepeatedly(Return(UTF8ToUTF16("foo"))); | |
51 } | |
52 | |
53 GoogleServiceAuthError auth_error(error_state); | 47 GoogleServiceAuthError auth_error(error_state); |
54 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); | 48 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error)); |
55 | 49 |
56 string16 label1, label2, label3; | 50 string16 label1, label2, label3; |
57 sync_ui_util::GetStatusLabelsForSyncGlobalError( | 51 sync_ui_util::GetStatusLabelsForSyncGlobalError( |
58 service, &label1, &label2, &label3); | 52 service, &label1, &label2, &label3); |
59 EXPECT_EQ(label1.empty(), !is_error); | 53 EXPECT_EQ(label1.empty(), !is_error); |
60 EXPECT_EQ(label2.empty(), !is_error); | 54 EXPECT_EQ(label2.empty(), !is_error); |
61 EXPECT_EQ(label3.empty(), !is_error); | 55 EXPECT_EQ(label3.empty(), !is_error); |
62 } | 56 } |
63 | 57 |
64 } // namespace | 58 } // namespace |
65 | 59 |
66 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { | 60 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { |
67 MessageLoopForUI message_loop; | 61 MessageLoopForUI message_loop; |
68 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 62 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
69 NiceMock<ProfileSyncServiceMock> service; | 63 scoped_ptr<Profile> profile( |
| 64 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 65 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
70 DictionaryValue strings; | 66 DictionaryValue strings; |
71 | 67 |
72 // Will be released when the dictionary is destroyed | 68 // Will be released when the dictionary is destroyed |
73 string16 str(ASCIIToUTF16("none")); | 69 string16 str(ASCIIToUTF16("none")); |
74 | 70 |
75 browser_sync::SyncBackendHost::Status status; | 71 browser_sync::SyncBackendHost::Status status; |
76 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE; | 72 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE; |
77 | 73 |
78 EXPECT_CALL(service, HasSyncSetupCompleted()) | 74 EXPECT_CALL(service, HasSyncSetupCompleted()) |
79 .WillOnce(Return(true)); | 75 .WillOnce(Return(true)); |
(...skipping 12 matching lines...) Expand all Loading... |
92 sync_ui_util::ConstructAboutInformation(&service, &strings); | 88 sync_ui_util::ConstructAboutInformation(&service, &strings); |
93 | 89 |
94 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); | 90 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); |
95 } | 91 } |
96 | 92 |
97 // Test that GetStatusLabelsForSyncGlobalError returns an error if a | 93 // Test that GetStatusLabelsForSyncGlobalError returns an error if a |
98 // passphrase is required. | 94 // passphrase is required. |
99 TEST(SyncUIUtilTest, PassphraseGlobalError) { | 95 TEST(SyncUIUtilTest, PassphraseGlobalError) { |
100 MessageLoopForUI message_loop; | 96 MessageLoopForUI message_loop; |
101 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 97 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
102 NiceMock<ProfileSyncServiceMock> service; | 98 scoped_ptr<Profile> profile( |
| 99 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 100 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
103 | 101 |
104 EXPECT_CALL(service, IsPassphraseRequired()) | 102 EXPECT_CALL(service, IsPassphraseRequired()) |
105 .WillOnce(Return(true)); | 103 .WillOnce(Return(true)); |
106 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 104 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
107 .WillOnce(Return(true)); | 105 .WillOnce(Return(true)); |
108 VerifySyncGlobalErrorResult( | 106 VerifySyncGlobalErrorResult( |
109 &service, GoogleServiceAuthError::NONE, true, true); | 107 &service, GoogleServiceAuthError::NONE, true, true); |
110 } | 108 } |
111 | 109 |
112 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions | 110 // Test that GetStatusLabelsForSyncGlobalError indicates errors for conditions |
113 // that can be resolved by the user and suppresses errors for conditions that | 111 // that can be resolved by the user and suppresses errors for conditions that |
114 // cannot be resolved by the user. | 112 // cannot be resolved by the user. |
115 TEST(SyncUIUtilTest, AuthStateGlobalError) { | 113 TEST(SyncUIUtilTest, AuthStateGlobalError) { |
116 MessageLoopForUI message_loop; | 114 MessageLoopForUI message_loop; |
117 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 115 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
118 NiceMock<ProfileSyncServiceMock> service; | 116 scoped_ptr<Profile> profile( |
| 117 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 118 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
119 | 119 |
120 browser_sync::SyncBackendHost::Status status; | 120 browser_sync::SyncBackendHost::Status status; |
121 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 121 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
122 .WillRepeatedly(Return(status)); | 122 .WillRepeatedly(Return(status)); |
123 | 123 |
124 struct { | 124 struct { |
125 GoogleServiceAuthError::State error_state; | 125 GoogleServiceAuthError::State error_state; |
126 bool is_error; | 126 bool is_error; |
127 } table[] = { | 127 } table[] = { |
128 { GoogleServiceAuthError::NONE, false }, | 128 { GoogleServiceAuthError::NONE, false }, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 EXPECT_CALL(service, HasSyncSetupCompleted()) | 203 EXPECT_CALL(service, HasSyncSetupCompleted()) |
204 .WillOnce(Return(true)); | 204 .WillOnce(Return(true)); |
205 browser_sync::SyncBackendHost::Status status; | 205 browser_sync::SyncBackendHost::Status status; |
206 status.summary = browser_sync::SyncBackendHost::Status::READY; | 206 status.summary = browser_sync::SyncBackendHost::Status::READY; |
207 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 207 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
208 .WillOnce(Return(status)); | 208 .WillOnce(Return(status)); |
209 *auth_error = new GoogleServiceAuthError( | 209 *auth_error = new GoogleServiceAuthError( |
210 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 210 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
211 EXPECT_CALL(service, unrecoverable_error_detected()) | 211 EXPECT_CALL(service, unrecoverable_error_detected()) |
212 .WillOnce(Return(false)); | 212 .WillOnce(Return(false)); |
213 EXPECT_CALL(service, GetAuthenticatedUsername()) | |
214 .Times(AtMost(1)).WillRepeatedly(Return(ASCIIToUTF16(""))); | |
215 EXPECT_CALL(service, GetAuthError()) | 213 EXPECT_CALL(service, GetAuthError()) |
216 .WillOnce(ReturnRef(**auth_error)); | 214 .WillOnce(ReturnRef(**auth_error)); |
217 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | 215 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
218 .WillOnce(Return(false)); | 216 .WillOnce(Return(false)); |
219 return; | 217 return; |
220 } | 218 } |
221 case STATUS_CASE_PROTOCOL_ERROR: { | 219 case STATUS_CASE_PROTOCOL_ERROR: { |
222 EXPECT_CALL(service, HasSyncSetupCompleted()) | 220 EXPECT_CALL(service, HasSyncSetupCompleted()) |
223 .WillOnce(Return(true)); | 221 .WillOnce(Return(true)); |
224 browser_sync::SyncProtocolError protocolError; | 222 browser_sync::SyncProtocolError protocolError; |
(...skipping 17 matching lines...) Expand all Loading... |
242 .WillOnce(Return(true)); | 240 .WillOnce(Return(true)); |
243 browser_sync::SyncBackendHost::Status status; | 241 browser_sync::SyncBackendHost::Status status; |
244 status.summary = browser_sync::SyncBackendHost::Status::READY; | 242 status.summary = browser_sync::SyncBackendHost::Status::READY; |
245 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 243 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
246 .WillOnce(Return(status)); | 244 .WillOnce(Return(status)); |
247 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | 245 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
248 EXPECT_CALL(service, GetAuthError()) | 246 EXPECT_CALL(service, GetAuthError()) |
249 .WillOnce(ReturnRef(**auth_error)); | 247 .WillOnce(ReturnRef(**auth_error)); |
250 EXPECT_CALL(service, unrecoverable_error_detected()) | 248 EXPECT_CALL(service, unrecoverable_error_detected()) |
251 .WillOnce(Return(false)); | 249 .WillOnce(Return(false)); |
252 EXPECT_CALL(service, GetAuthenticatedUsername()) | |
253 .WillOnce(Return(ASCIIToUTF16("example@example.com"))); | |
254 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | 250 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
255 .WillOnce(Return(false)); | 251 .WillOnce(Return(false)); |
256 EXPECT_CALL(service, IsPassphraseRequired()) | 252 EXPECT_CALL(service, IsPassphraseRequired()) |
257 .WillOnce(Return(true)); | 253 .WillOnce(Return(true)); |
258 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 254 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
259 .WillOnce(Return(true)); | 255 .WillOnce(Return(true)); |
260 return; | 256 return; |
261 } | 257 } |
262 case STATUS_CASE_SYNCED: { | 258 case STATUS_CASE_SYNCED: { |
263 EXPECT_CALL(service, HasSyncSetupCompleted()) | 259 EXPECT_CALL(service, HasSyncSetupCompleted()) |
264 .WillOnce(Return(true)); | 260 .WillOnce(Return(true)); |
265 browser_sync::SyncBackendHost::Status status; | 261 browser_sync::SyncBackendHost::Status status; |
266 status.summary = browser_sync::SyncBackendHost::Status::READY; | 262 status.summary = browser_sync::SyncBackendHost::Status::READY; |
267 EXPECT_CALL(service, QueryDetailedSyncStatus()) | 263 EXPECT_CALL(service, QueryDetailedSyncStatus()) |
268 .WillOnce(Return(status)); | 264 .WillOnce(Return(status)); |
269 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); | 265 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE); |
270 EXPECT_CALL(service, GetAuthError()) | 266 EXPECT_CALL(service, GetAuthError()) |
271 .WillOnce(ReturnRef(**auth_error)); | 267 .WillOnce(ReturnRef(**auth_error)); |
272 EXPECT_CALL(service, unrecoverable_error_detected()) | 268 EXPECT_CALL(service, unrecoverable_error_detected()) |
273 .WillOnce(Return(false)); | 269 .WillOnce(Return(false)); |
274 EXPECT_CALL(service, GetAuthenticatedUsername()) | |
275 .WillOnce(Return(ASCIIToUTF16("example@example.com"))); | |
276 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) | 270 EXPECT_CALL(service, UIShouldDepictAuthInProgress()) |
277 .WillOnce(Return(false)); | 271 .WillOnce(Return(false)); |
278 EXPECT_CALL(service, IsPassphraseRequired()) | 272 EXPECT_CALL(service, IsPassphraseRequired()) |
279 .WillOnce(Return(false)); | 273 .WillOnce(Return(false)); |
280 return; | 274 return; |
281 } | 275 } |
282 default: | 276 default: |
283 NOTREACHED(); | 277 NOTREACHED(); |
284 } | 278 } |
285 } | 279 } |
286 | 280 |
287 // This test ensures that a each distinctive ProfileSyncService statuses | 281 // This test ensures that a each distinctive ProfileSyncService statuses |
288 // will return a unique combination of status and link messages from | 282 // will return a unique combination of status and link messages from |
289 // GetStatusLabels(). | 283 // GetStatusLabels(). |
290 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { | 284 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { |
291 ProfileSyncServiceMock service; | |
292 | |
293 std::set<string16> messages; | 285 std::set<string16> messages; |
294 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 286 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
295 ProfileSyncServiceMock service; | 287 scoped_ptr<Profile> profile( |
| 288 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 289 ProfileSyncServiceMock service(profile.get()); |
296 GoogleServiceAuthError* auth_error = NULL; | 290 GoogleServiceAuthError* auth_error = NULL; |
297 GetDistinctCase(service, &auth_error, idx); | 291 GetDistinctCase(service, &auth_error, idx); |
298 string16 status_label; | 292 string16 status_label; |
299 string16 link_label; | 293 string16 link_label; |
300 sync_ui_util::GetStatusLabels(&service, | 294 sync_ui_util::GetStatusLabels(&service, |
301 sync_ui_util::WITH_HTML, | 295 sync_ui_util::WITH_HTML, |
302 &status_label, | 296 &status_label, |
303 &link_label); | 297 &link_label); |
304 // If the status and link message combination is already present in the set | 298 // If the status and link message combination is already present in the set |
305 // of messages already seen, this is a duplicate rather than a unique | 299 // of messages already seen, this is a duplicate rather than a unique |
306 // message, and the test has failed. | 300 // message, and the test has failed. |
307 string16 combined_label = | 301 string16 combined_label = |
308 status_label + string16(ASCIIToUTF16("#")) + link_label; | 302 status_label + string16(ASCIIToUTF16("#")) + link_label; |
309 EXPECT_TRUE(messages.find(combined_label) == messages.end()); | 303 EXPECT_TRUE(messages.find(combined_label) == messages.end()); |
310 messages.insert(combined_label); | 304 messages.insert(combined_label); |
311 if (auth_error) | 305 if (auth_error) |
312 delete auth_error; | 306 delete auth_error; |
313 } | 307 } |
314 } | 308 } |
315 | 309 |
316 // This test ensures that the html_links parameter on GetStatusLabels() is | 310 // This test ensures that the html_links parameter on GetStatusLabels() is |
317 // honored. | 311 // honored. |
318 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { | 312 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) { |
319 ProfileSyncServiceMock service; | |
320 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 313 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
321 ProfileSyncServiceMock service; | 314 scoped_ptr<Profile> profile( |
| 315 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 316 ProfileSyncServiceMock service(profile.get()); |
322 GoogleServiceAuthError* auth_error = NULL; | 317 GoogleServiceAuthError* auth_error = NULL; |
323 GetDistinctCase(service, &auth_error, idx); | 318 GetDistinctCase(service, &auth_error, idx); |
324 string16 status_label; | 319 string16 status_label; |
325 string16 link_label; | 320 string16 link_label; |
326 sync_ui_util::GetStatusLabels(&service, | 321 sync_ui_util::GetStatusLabels(&service, |
327 sync_ui_util::PLAIN_TEXT, | 322 sync_ui_util::PLAIN_TEXT, |
328 &status_label, | 323 &status_label, |
329 &link_label); | 324 &link_label); |
330 // Ensures a search for string 'href' (found in links, not a string to be | 325 // Ensures a search for string 'href' (found in links, not a string to be |
331 // found in an English language message) fails when links are excluded from | 326 // found in an English language message) fails when links are excluded from |
332 // the status label. | 327 // the status label. |
333 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), | 328 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))), |
334 string16::npos); | 329 string16::npos); |
335 if (auth_error) { | 330 if (auth_error) { |
336 delete auth_error; | 331 delete auth_error; |
337 } | 332 } |
338 } | 333 } |
339 } | 334 } |
OLD | NEW |