Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: chrome/browser/sync/sync_ui_util_unittest.cc

Issue 8634008: Adding parameter to GetStatusLabels to indicate if links are acceptable. (Re applied) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Test fix. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/basictypes.h" 6 #include "base/basictypes.h"
6 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/sync/profile_sync_service_mock.h" 8 #include "chrome/browser/sync/profile_sync_service_mock.h"
8 #include "chrome/browser/sync/sync_ui_util.h" 9 #include "chrome/browser/sync/sync_ui_util.h"
9 #include "content/test/test_browser_thread.h" 10 #include "content/test/test_browser_thread.h"
10 #include "testing/gmock/include/gmock/gmock-actions.h" 11 #include "testing/gmock/include/gmock/gmock-actions.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
15 using ::testing::AtMost;
14 using ::testing::Return; 16 using ::testing::Return;
17 using ::testing::ReturnRef;
15 using ::testing::NiceMock; 18 using ::testing::NiceMock;
16 using content::BrowserThread; 19 using content::BrowserThread;
17 20
21 // A number of distinct states of the ProfileSyncService can be generated for
22 // tests.
23 enum DistinctState {
24 STATUS_CASE_SETUP_IN_PROGRESS,
25 STATUS_CASE_SETUP_ERROR,
26 STATUS_CASE_AUTHENTICATING,
27 STATUS_CASE_AUTH_ERROR,
28 STATUS_CASE_PROTOCOL_ERROR,
29 STATUS_CASE_PASSPHRASE_ERROR,
30 STATUS_CASE_SYNCED,
31 NUMBER_OF_STATUS_CASES
32 };
33
18 namespace { 34 namespace {
19 35
20 // Utility function to test that GetStatusLabelsForSyncGlobalError returns 36 // Utility function to test that GetStatusLabelsForSyncGlobalError returns
21 // the correct results for the given states. 37 // the correct results for the given states.
22 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, 38 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
23 GoogleServiceAuthError::State error_state, 39 GoogleServiceAuthError::State error_state,
24 bool is_signed_in, 40 bool is_signed_in,
25 bool is_error) { 41 bool is_error) {
26 GoogleServiceAuthError auth_error(error_state);
27 service->UpdateAuthErrorState(auth_error);
28
29 EXPECT_CALL(*service, HasSyncSetupCompleted()) 42 EXPECT_CALL(*service, HasSyncSetupCompleted())
30 .WillRepeatedly(Return(is_signed_in)); 43 .WillRepeatedly(Return(is_signed_in));
44
31 if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { 45 if (error_state == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
32 EXPECT_CALL(*service, GetAuthenticatedUsername()) 46 EXPECT_CALL(*service, GetAuthenticatedUsername())
33 .WillRepeatedly(Return(UTF8ToUTF16(""))); 47 .WillRepeatedly(Return(UTF8ToUTF16("")));
34 } else { 48 } else {
35 EXPECT_CALL(*service, GetAuthenticatedUsername()) 49 EXPECT_CALL(*service, GetAuthenticatedUsername())
36 .WillRepeatedly(Return(UTF8ToUTF16("foo"))); 50 .WillRepeatedly(Return(UTF8ToUTF16("foo")));
37 } 51 }
38 52
53 GoogleServiceAuthError auth_error(error_state);
54 EXPECT_CALL(*service, GetAuthError()).WillRepeatedly(ReturnRef(auth_error));
55
39 string16 label1, label2, label3; 56 string16 label1, label2, label3;
40 sync_ui_util::GetStatusLabelsForSyncGlobalError( 57 sync_ui_util::GetStatusLabelsForSyncGlobalError(
41 service, &label1, &label2, &label3); 58 service, &label1, &label2, &label3);
42 EXPECT_EQ(label1.empty(), !is_error); 59 EXPECT_EQ(label1.empty(), !is_error);
43 EXPECT_EQ(label2.empty(), !is_error); 60 EXPECT_EQ(label2.empty(), !is_error);
44 EXPECT_EQ(label3.empty(), !is_error); 61 EXPECT_EQ(label3.empty(), !is_error);
45 } 62 }
46 63
47 } // namespace 64 } // namespace
48 65
49 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) { 66 TEST(SyncUIUtilTest, ConstructAboutInformationWithUnrecoverableErrorTest) {
50 MessageLoopForUI message_loop; 67 MessageLoopForUI message_loop;
51 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 68 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
52 NiceMock<ProfileSyncServiceMock> service; 69 NiceMock<ProfileSyncServiceMock> service;
53 DictionaryValue strings; 70 DictionaryValue strings;
54 71
55 // Will be released when the dictionary is destroyed 72 // Will be released when the dictionary is destroyed
56 string16 str(ASCIIToUTF16("none")); 73 string16 str(ASCIIToUTF16("none"));
57 74
58 browser_sync::SyncBackendHost::Status status; 75 browser_sync::SyncBackendHost::Status status;
59 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE; 76 status.summary = browser_sync::SyncBackendHost::Status::OFFLINE_UNUSABLE;
60 77
61 EXPECT_CALL(service, HasSyncSetupCompleted()) 78 EXPECT_CALL(service, HasSyncSetupCompleted())
62 .WillOnce(Return(true)); 79 .WillOnce(Return(true));
63 EXPECT_CALL(service, QueryDetailedSyncStatus()) 80 EXPECT_CALL(service, QueryDetailedSyncStatus())
64 .WillOnce(Return(status)); 81 .WillOnce(Return(status));
65 82
83 GoogleServiceAuthError auth_error(GoogleServiceAuthError::NONE);
84 EXPECT_CALL(service, GetAuthError()).WillOnce(ReturnRef(auth_error));
85
66 EXPECT_CALL(service, unrecoverable_error_detected()) 86 EXPECT_CALL(service, unrecoverable_error_detected())
67 .WillOnce(Return(true)); 87 .WillOnce(Return(true));
68 88
69 EXPECT_CALL(service, GetLastSyncedTimeString()) 89 EXPECT_CALL(service, GetLastSyncedTimeString())
70 .WillOnce(Return(str)); 90 .WillOnce(Return(str));
71 91
72 sync_ui_util::ConstructAboutInformation(&service, &strings); 92 sync_ui_util::ConstructAboutInformation(&service, &strings);
73 93
74 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected")); 94 EXPECT_TRUE(strings.HasKey("unrecoverable_error_detected"));
75 } 95 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, 138 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true },
119 }; 139 };
120 140
121 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { 141 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) {
122 VerifySyncGlobalErrorResult( 142 VerifySyncGlobalErrorResult(
123 &service, table[i].error_state, true, table[i].is_error); 143 &service, table[i].error_state, true, table[i].is_error);
124 VerifySyncGlobalErrorResult( 144 VerifySyncGlobalErrorResult(
125 &service, table[i].error_state, false, false); 145 &service, table[i].error_state, false, false);
126 } 146 }
127 } 147 }
148 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases
149 // in order to perform tests on the generated messages.
150 void GetDistinctCase(ProfileSyncServiceMock& service,
151 GoogleServiceAuthError** auth_error,
152 int caseNumber) {
153 // Auth Error object is returned by reference in mock and needs to stay in
154 // scope throughout test, so it is owned by calling method. However it is
155 // immutable so can only be allocated in this method.
156 switch (caseNumber) {
157 case STATUS_CASE_SETUP_IN_PROGRESS: {
158 EXPECT_CALL(service, HasSyncSetupCompleted())
159 .WillOnce(Return(false));
160 EXPECT_CALL(service, SetupInProgress())
161 .WillOnce(Return(true));
162 browser_sync::SyncBackendHost::Status status;
163 status.summary = browser_sync::SyncBackendHost::Status::READY;
164 EXPECT_CALL(service, QueryDetailedSyncStatus())
165 .WillOnce(Return(status));
166 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
167 EXPECT_CALL(service, GetAuthError())
168 .WillOnce(ReturnRef(**auth_error));
169 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
170 .WillOnce(Return(false));
171 return;
172 }
173 case STATUS_CASE_SETUP_ERROR: {
174 EXPECT_CALL(service, HasSyncSetupCompleted())
175 .WillOnce(Return(false));
176 EXPECT_CALL(service, SetupInProgress())
177 .WillOnce(Return(false));
178 EXPECT_CALL(service, unrecoverable_error_detected())
179 .WillOnce(Return(true));
180 browser_sync::SyncBackendHost::Status status;
181 status.summary = browser_sync::SyncBackendHost::Status::READY;
182 EXPECT_CALL(service, QueryDetailedSyncStatus())
183 .WillOnce(Return(status));
184 return;
185 }
186 case STATUS_CASE_AUTHENTICATING: {
187 EXPECT_CALL(service, HasSyncSetupCompleted())
188 .WillOnce(Return(true));
189 browser_sync::SyncBackendHost::Status status;
190 status.summary = browser_sync::SyncBackendHost::Status::READY;
191 EXPECT_CALL(service, QueryDetailedSyncStatus())
192 .WillOnce(Return(status));
193 EXPECT_CALL(service, unrecoverable_error_detected())
194 .WillOnce(Return(false));
195 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
196 .WillOnce(Return(true));
197 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
198 EXPECT_CALL(service, GetAuthError())
199 .WillOnce(ReturnRef(**auth_error));
200 return;
201 }
202 case STATUS_CASE_AUTH_ERROR: {
203 EXPECT_CALL(service, HasSyncSetupCompleted())
204 .WillOnce(Return(true));
205 browser_sync::SyncBackendHost::Status status;
206 status.summary = browser_sync::SyncBackendHost::Status::READY;
207 EXPECT_CALL(service, QueryDetailedSyncStatus())
208 .WillOnce(Return(status));
209 *auth_error = new GoogleServiceAuthError(
210 GoogleServiceAuthError::SERVICE_UNAVAILABLE);
211 EXPECT_CALL(service, unrecoverable_error_detected())
212 .WillOnce(Return(false));
213 EXPECT_CALL(service, GetAuthenticatedUsername())
214 .Times(AtMost(1)).WillRepeatedly(Return(ASCIIToUTF16("")));
215 EXPECT_CALL(service, GetAuthError())
216 .WillOnce(ReturnRef(**auth_error));
217 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
218 .WillOnce(Return(false));
219 return;
220 }
221 case STATUS_CASE_PROTOCOL_ERROR: {
222 EXPECT_CALL(service, HasSyncSetupCompleted())
223 .WillOnce(Return(true));
224 browser_sync::SyncProtocolError protocolError;
225 protocolError.action = browser_sync::STOP_AND_RESTART_SYNC;
226 browser_sync::SyncBackendHost::Status status;
227 status.summary = browser_sync::SyncBackendHost::Status::READY;
228 status.sync_protocol_error = protocolError;
229 EXPECT_CALL(service, QueryDetailedSyncStatus())
230 .WillOnce(Return(status));
231 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
232 EXPECT_CALL(service, GetAuthError())
233 .WillOnce(ReturnRef(**auth_error));
234 EXPECT_CALL(service, unrecoverable_error_detected())
235 .WillOnce(Return(false));
236 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
237 .WillOnce(Return(false));
238 return;
239 }
240 case STATUS_CASE_PASSPHRASE_ERROR: {
241 EXPECT_CALL(service, HasSyncSetupCompleted())
242 .WillOnce(Return(true));
243 browser_sync::SyncBackendHost::Status status;
244 status.summary = browser_sync::SyncBackendHost::Status::READY;
245 EXPECT_CALL(service, QueryDetailedSyncStatus())
246 .WillOnce(Return(status));
247 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
248 EXPECT_CALL(service, GetAuthError())
249 .WillOnce(ReturnRef(**auth_error));
250 EXPECT_CALL(service, unrecoverable_error_detected())
251 .WillOnce(Return(false));
252 EXPECT_CALL(service, GetAuthenticatedUsername())
253 .WillOnce(Return(ASCIIToUTF16("example@example.com")));
254 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
255 .WillOnce(Return(false));
256 EXPECT_CALL(service, IsPassphraseRequired())
257 .WillOnce(Return(true));
258 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
259 .WillOnce(Return(true));
260 return;
261 }
262 case STATUS_CASE_SYNCED: {
263 EXPECT_CALL(service, HasSyncSetupCompleted())
264 .WillOnce(Return(true));
265 browser_sync::SyncBackendHost::Status status;
266 status.summary = browser_sync::SyncBackendHost::Status::READY;
267 EXPECT_CALL(service, QueryDetailedSyncStatus())
268 .WillOnce(Return(status));
269 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
270 EXPECT_CALL(service, GetAuthError())
271 .WillOnce(ReturnRef(**auth_error));
272 EXPECT_CALL(service, unrecoverable_error_detected())
273 .WillOnce(Return(false));
274 EXPECT_CALL(service, GetAuthenticatedUsername())
275 .WillOnce(Return(ASCIIToUTF16("example@example.com")));
276 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
277 .WillOnce(Return(false));
278 EXPECT_CALL(service, IsPassphraseRequired())
279 .WillOnce(Return(false));
280 return;
281 }
282 default:
283 NOTREACHED();
284 }
285 }
286
287 // This test ensures that a each distinctive ProfileSyncService statuses
288 // will return a unique combination of status and link messages from
289 // GetStatusLabels().
290 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
291 ProfileSyncServiceMock service;
292
293 std::set<string16> messages;
294 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) {
295 ProfileSyncServiceMock service;
296 GoogleServiceAuthError* auth_error = NULL;
297 GetDistinctCase(service, &auth_error, idx);
298 string16 status_label;
299 string16 link_label;
300 sync_ui_util::GetStatusLabels(&service,
301 sync_ui_util::WITH_HTML,
302 &status_label,
303 &link_label);
304 // 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
306 // message, and the test has failed.
307 string16 combined_label =
308 status_label + string16(ASCIIToUTF16("#")) + link_label;
309 EXPECT_TRUE(messages.find(combined_label) == messages.end());
310 messages.insert(combined_label);
311 if (auth_error)
312 delete auth_error;
313 }
314 }
315
316 // This test ensures that the html_links parameter on GetStatusLabels() is
317 // honored.
318 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) {
319 ProfileSyncServiceMock service;
320 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) {
321 ProfileSyncServiceMock service;
322 GoogleServiceAuthError* auth_error = NULL;
323 GetDistinctCase(service, &auth_error, idx);
324 string16 status_label;
325 string16 link_label;
326 sync_ui_util::GetStatusLabels(&service,
327 sync_ui_util::PLAIN_TEXT,
328 &status_label,
329 &link_label);
330 // 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
332 // the status label.
333 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))),
334 string16::npos);
335 if (auth_error) {
336 delete auth_error;
337 }
338 }
339 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_ui_util.cc ('k') | chrome/browser/ui/webui/options/personal_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698