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

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

Issue 8383036: Adding parameter to GetStatusLabels to indicate if links are acceptable. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix following try test. 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
14 using ::testing::Return; 15 using ::testing::Return;
16 using ::testing::ReturnRef;
15 using ::testing::NiceMock; 17 using ::testing::NiceMock;
16 18
19 // A number of distinct states of the ProfileSyncService can be generated for
20 // tests.
21 enum DistinctState {
22 STATUS_CASE_SETUP_IN_PROGRESS,
23 STATUS_CASE_SETUP_ERROR,
24 STATUS_CASE_AUTHENTICATING,
25 STATUS_CASE_AUTH_ERROR,
26 STATUS_CASE_PROTOCOL_ERROR,
27 STATUS_CASE_PASSPHRASE_ERROR,
28 STATUS_CASE_SYNCED,
29 NUMBER_OF_STATUS_CASES
30 };
31
17 namespace { 32 namespace {
18 33
19 // Utility function to test that GetStatusLabelsForSyncGlobalError returns 34 // Utility function to test that GetStatusLabelsForSyncGlobalError returns
20 // the correct results for the given states. 35 // the correct results for the given states.
21 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, 36 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service,
22 GoogleServiceAuthError::State error_state, 37 GoogleServiceAuthError::State error_state,
23 bool is_signed_in, 38 bool is_signed_in,
24 bool is_error) { 39 bool is_error) {
25 GoogleServiceAuthError auth_error(error_state); 40 GoogleServiceAuthError auth_error(error_state);
26 service->UpdateAuthErrorState(auth_error); 41 service->UpdateAuthErrorState(auth_error);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, 132 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true },
118 }; 133 };
119 134
120 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { 135 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) {
121 VerifySyncGlobalErrorResult( 136 VerifySyncGlobalErrorResult(
122 &service, table[i].error_state, true, table[i].is_error); 137 &service, table[i].error_state, true, table[i].is_error);
123 VerifySyncGlobalErrorResult( 138 VerifySyncGlobalErrorResult(
124 &service, table[i].error_state, false, false); 139 &service, table[i].error_state, false, false);
125 } 140 }
126 } 141 }
142 // Loads a ProfileSyncServiceMock to emulate one of a number of distinct cases
143 // in order to perform tests on the generated messages.
144 void GetDistinctCase(ProfileSyncServiceMock& service,
145 GoogleServiceAuthError** auth_error,
146 int caseNumber) {
147 // Auth Error object is returned by reference in mock and needs to stay in
148 // scope throughout test, so it is owned by calling method. However it is
149 // immutable so can only be allocated in this method.
150 switch (caseNumber) {
151 case STATUS_CASE_SETUP_IN_PROGRESS: {
152 EXPECT_CALL(service, HasSyncSetupCompleted())
153 .WillOnce(Return(false));
154 EXPECT_CALL(service, SetupInProgress())
155 .WillOnce(Return(true));
156 browser_sync::SyncBackendHost::Status status;
157 status.summary = browser_sync::SyncBackendHost::Status::READY;
158 EXPECT_CALL(service, QueryDetailedSyncStatus())
159 .WillOnce(Return(status));
160 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
161 EXPECT_CALL(service, GetAuthError())
162 .WillOnce(ReturnRef(**auth_error));
163 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
164 .WillOnce(Return(false));
165 return;
166 }
167 case STATUS_CASE_SETUP_ERROR: {
168 EXPECT_CALL(service, HasSyncSetupCompleted())
169 .WillOnce(Return(false));
170 EXPECT_CALL(service, SetupInProgress())
171 .WillOnce(Return(false));
172 EXPECT_CALL(service, unrecoverable_error_detected())
173 .WillOnce(Return(true));
174 browser_sync::SyncBackendHost::Status status;
175 status.summary = browser_sync::SyncBackendHost::Status::READY;
176 EXPECT_CALL(service, QueryDetailedSyncStatus())
177 .WillOnce(Return(status));
178 return;
179 }
180 case STATUS_CASE_AUTHENTICATING: {
181 EXPECT_CALL(service, HasSyncSetupCompleted())
182 .WillOnce(Return(true));
183 browser_sync::SyncBackendHost::Status status;
184 status.summary = browser_sync::SyncBackendHost::Status::READY;
185 EXPECT_CALL(service, QueryDetailedSyncStatus())
186 .WillOnce(Return(status));
187 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
188 .WillOnce(Return(true));
189 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
190 EXPECT_CALL(service, GetAuthError())
191 .WillOnce(ReturnRef(**auth_error));
192 return;
193 }
194 case STATUS_CASE_AUTH_ERROR: {
195 EXPECT_CALL(service, HasSyncSetupCompleted())
196 .WillOnce(Return(true));
197 browser_sync::SyncBackendHost::Status status;
198 status.summary = browser_sync::SyncBackendHost::Status::READY;
199 EXPECT_CALL(service, QueryDetailedSyncStatus())
200 .WillOnce(Return(status));
201 *auth_error = new GoogleServiceAuthError(
202 GoogleServiceAuthError::SERVICE_UNAVAILABLE);
203 EXPECT_CALL(service, GetAuthenticatedUsername())
204 .WillOnce(Return(ASCIIToUTF16("")));
205 EXPECT_CALL(service, GetAuthError())
206 .WillOnce(ReturnRef(**auth_error));
207 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
208 .WillOnce(Return(false));
209 return;
210 }
211 case STATUS_CASE_PROTOCOL_ERROR: {
212 EXPECT_CALL(service, HasSyncSetupCompleted())
213 .WillOnce(Return(true));
214 browser_sync::SyncProtocolError protocolError;
215 protocolError.action = browser_sync::STOP_AND_RESTART_SYNC;
216 browser_sync::SyncBackendHost::Status status;
217 status.summary = browser_sync::SyncBackendHost::Status::READY;
218 status.sync_protocol_error = protocolError;
219 EXPECT_CALL(service, QueryDetailedSyncStatus())
220 .WillOnce(Return(status));
221 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
222 EXPECT_CALL(service, GetAuthError())
223 .WillOnce(ReturnRef(**auth_error));
224 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
225 .WillOnce(Return(false));
226 return;
227 }
228 case STATUS_CASE_PASSPHRASE_ERROR: {
229 EXPECT_CALL(service, HasSyncSetupCompleted())
230 .WillOnce(Return(true));
231 browser_sync::SyncBackendHost::Status status;
232 status.summary = browser_sync::SyncBackendHost::Status::READY;
233 EXPECT_CALL(service, QueryDetailedSyncStatus())
234 .WillOnce(Return(status));
235 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
236 EXPECT_CALL(service, GetAuthError())
237 .WillOnce(ReturnRef(**auth_error));
238 EXPECT_CALL(service, GetAuthenticatedUsername())
239 .WillOnce(Return(ASCIIToUTF16("example@example.com")));
240 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
241 .WillOnce(Return(false));
242 EXPECT_CALL(service, IsPassphraseRequired())
243 .WillOnce(Return(true));
244 EXPECT_CALL(service, IsPassphraseRequiredForDecryption())
245 .WillOnce(Return(true));
246 return;
247 }
248 case STATUS_CASE_SYNCED: {
249 EXPECT_CALL(service, HasSyncSetupCompleted())
250 .WillOnce(Return(true));
251 browser_sync::SyncBackendHost::Status status;
252 status.summary = browser_sync::SyncBackendHost::Status::READY;
253 EXPECT_CALL(service, QueryDetailedSyncStatus())
254 .WillOnce(Return(status));
255 *auth_error = new GoogleServiceAuthError(GoogleServiceAuthError::NONE);
256 EXPECT_CALL(service, GetAuthError())
257 .WillOnce(ReturnRef(**auth_error));
258 EXPECT_CALL(service, GetAuthenticatedUsername())
259 .WillOnce(Return(ASCIIToUTF16("example@example.com")));
260 EXPECT_CALL(service, UIShouldDepictAuthInProgress())
261 .WillOnce(Return(false));
262 EXPECT_CALL(service, IsPassphraseRequired())
263 .WillOnce(Return(false));
264 return;
265 }
266 default:
267 NOTREACHED();
268 }
269 }
270
271 // This test ensures that a each distinctive ProfileSyncService statuses
272 // will return a unique combination of status and link messages from
273 // GetStatusLabels().
274 TEST(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
275 ProfileSyncServiceMock service;
276
277 std::set<string16> messages;
278 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) {
279 ProfileSyncServiceMock service;
280 GoogleServiceAuthError* auth_error = NULL;
281 GetDistinctCase(service, &auth_error, idx);
282 string16 status_label;
283 string16 link_label;
284 sync_ui_util::GetStatusLabels(&service,
285 &status_label,
286 &link_label,
287 true);
288 // If the status and link message combination is already present in the set
289 // of messages already seen, this is a duplicate rather than a unique
290 // message, and the test has failed.
291 string16 combined_label =
292 status_label + string16(ASCIIToUTF16("#")) + link_label;
293 EXPECT_EQ(messages.find(combined_label), messages.end());
294 messages.insert(combined_label);
295 if (auth_error)
296 delete auth_error;
297 }
298 }
299
300 // This test ensures that the html_links parameter on GetStatusLabels() is
301 // honored.
302 TEST(SyncUIUtilTest, HtmlNotIncludedInStatusIfNotRequested) {
303 ProfileSyncServiceMock service;
304 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) {
305 ProfileSyncServiceMock service;
306 GoogleServiceAuthError* auth_error = NULL;
307 GetDistinctCase(service, &auth_error, idx);
308 string16 status_label;
309 string16 link_label;
310 sync_ui_util::GetStatusLabels(&service,
311 &status_label,
312 &link_label,
313 false);
314 // Ensures a search for string 'href' (found in links, not a string to be
315 // found in an English language message) fails when links are excluded from
316 // the status label.
317 EXPECT_EQ(status_label.find(string16(ASCIIToUTF16("href"))),
318 string16::npos);
319 if (auth_error) {
320 delete auth_error;
321 }
322 }
323 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698