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

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

Issue 2457483002: [MD Settings][Sync Settings] Updates sync status messages (Closed)
Patch Set: Addressed tommycli's comments Created 4 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) 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include <set> 9 #include <set>
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 .WillRepeatedly(Return(false)); 267 .WillRepeatedly(Return(false));
268 return; 268 return;
269 } 269 }
270 case STATUS_CASE_PROTOCOL_ERROR: { 270 case STATUS_CASE_PROTOCOL_ERROR: {
271 EXPECT_CALL(*service, IsFirstSetupComplete()) 271 EXPECT_CALL(*service, IsFirstSetupComplete())
272 .WillRepeatedly(Return(true)); 272 .WillRepeatedly(Return(true));
273 EXPECT_CALL(*service, IsSyncActive()).WillRepeatedly(Return(true)); 273 EXPECT_CALL(*service, IsSyncActive()).WillRepeatedly(Return(true));
274 EXPECT_CALL(*service, IsPassphraseRequired()) 274 EXPECT_CALL(*service, IsPassphraseRequired())
275 .WillRepeatedly(Return(false)); 275 .WillRepeatedly(Return(false));
276 syncer::SyncProtocolError protocolError; 276 syncer::SyncProtocolError protocolError;
277 protocolError.action = syncer::STOP_AND_RESTART_SYNC; 277 protocolError.action = syncer::UPGRADE_CLIENT;
278 syncer::SyncBackendHost::Status status; 278 syncer::SyncBackendHost::Status status;
279 status.sync_protocol_error = protocolError; 279 status.sync_protocol_error = protocolError;
280 EXPECT_CALL(*service, QueryDetailedSyncStatus(_)) 280 EXPECT_CALL(*service, QueryDetailedSyncStatus(_))
281 .WillRepeatedly(DoAll(SetArgPointee<0>(status), Return(false))); 281 .WillRepeatedly(DoAll(SetArgPointee<0>(status), Return(false)));
282 EXPECT_CALL(*service, HasUnrecoverableError()) 282 EXPECT_CALL(*service, HasUnrecoverableError())
283 .WillRepeatedly(Return(false)); 283 .WillRepeatedly(Return(false));
284 return; 284 return;
285 } 285 }
286 case STATUS_CASE_PASSPHRASE_ERROR: { 286 case STATUS_CASE_PASSPHRASE_ERROR: {
287 EXPECT_CALL(*service, IsFirstSetupComplete()) 287 EXPECT_CALL(*service, IsFirstSetupComplete())
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 NiceMock<ProfileSyncServiceMock> service(&init_params); 344 NiceMock<ProfileSyncServiceMock> service(&init_params);
345 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); 345 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone();
346 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); 346 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
347 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); 347 FakeSigninManagerForSyncUIUtilTest signin(profile.get());
348 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 348 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
349 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( 349 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider(
350 SigninErrorControllerFactory::GetForProfile(profile.get()))); 350 SigninErrorControllerFactory::GetForProfile(profile.get())));
351 GetDistinctCase(&service, &signin, provider.get(), idx); 351 GetDistinctCase(&service, &signin, provider.get(), idx);
352 base::string16 status_label; 352 base::string16 status_label;
353 base::string16 link_label; 353 base::string16 link_label;
354 sync_ui_util::ActionType action_type(sync_ui_util::NO_ACTION);
354 sync_ui_util::GetStatusLabels(profile.get(), &service, signin, 355 sync_ui_util::GetStatusLabels(profile.get(), &service, signin,
355 sync_ui_util::WITH_HTML, &status_label, 356 sync_ui_util::WITH_HTML, &status_label,
356 &link_label); 357 &link_label, &action_type);
357 // If the status and link message combination is already present in the set 358 // If the status and link message combination is already present in the set
358 // of messages already seen, this is a duplicate rather than a unique 359 // of messages already seen, this is a duplicate rather than a unique
359 // message, and the test has failed. 360 // message, and the test has failed.
360 EXPECT_FALSE(status_label.empty()) << 361 EXPECT_FALSE(status_label.empty()) <<
361 "Empty status label returned for case #" << idx; 362 "Empty status label returned for case #" << idx;
362 base::string16 combined_label = 363 base::string16 combined_label =
363 status_label + base::ASCIIToUTF16("#") + link_label; 364 status_label + base::ASCIIToUTF16("#") + link_label;
364 EXPECT_TRUE(messages.find(combined_label) == messages.end()) << 365 EXPECT_TRUE(messages.find(combined_label) == messages.end()) <<
365 "Duplicate message for case #" << idx << ": " << combined_label; 366 "Duplicate message for case #" << idx << ": " << combined_label;
366 messages.insert(combined_label); 367 messages.insert(combined_label);
(...skipping 15 matching lines...) Expand all
382 NiceMock<ProfileSyncServiceMock> service(&init_params); 383 NiceMock<ProfileSyncServiceMock> service(&init_params);
383 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); 384 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone();
384 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); 385 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
385 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); 386 FakeSigninManagerForSyncUIUtilTest signin(profile.get());
386 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); 387 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
387 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( 388 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider(
388 SigninErrorControllerFactory::GetForProfile(profile.get()))); 389 SigninErrorControllerFactory::GetForProfile(profile.get())));
389 GetDistinctCase(&service, &signin, provider.get(), idx); 390 GetDistinctCase(&service, &signin, provider.get(), idx);
390 base::string16 status_label; 391 base::string16 status_label;
391 base::string16 link_label; 392 base::string16 link_label;
393 sync_ui_util::ActionType action_type(sync_ui_util::NO_ACTION);
392 sync_ui_util::GetStatusLabels(profile.get(), &service, signin, 394 sync_ui_util::GetStatusLabels(profile.get(), &service, signin,
393 sync_ui_util::PLAIN_TEXT, &status_label, 395 sync_ui_util::PLAIN_TEXT, &status_label,
394 &link_label); 396 &link_label, &action_type);
395 397
396 // Ensures a search for string 'href' (found in links, not a string to be 398 // Ensures a search for string 'href' (found in links, not a string to be
397 // found in an English language message) fails when links are excluded from 399 // found in an English language message) fails when links are excluded from
398 // the status label. 400 // the status label.
399 EXPECT_FALSE(status_label.empty()); 401 EXPECT_FALSE(status_label.empty());
400 EXPECT_EQ(status_label.find(base::ASCIIToUTF16("href")), 402 EXPECT_EQ(status_label.find(base::ASCIIToUTF16("href")),
401 base::string16::npos); 403 base::string16::npos);
402 testing::Mock::VerifyAndClearExpectations(&service); 404 testing::Mock::VerifyAndClearExpectations(&service);
403 testing::Mock::VerifyAndClearExpectations(&signin); 405 testing::Mock::VerifyAndClearExpectations(&signin);
404 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); 406 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
(...skipping 12 matching lines...) Expand all
417 EXPECT_CALL(service, IsFirstSetupComplete()).WillRepeatedly(Return(true)); 419 EXPECT_CALL(service, IsFirstSetupComplete()).WillRepeatedly(Return(true));
418 EXPECT_CALL(service, HasUnrecoverableError()).WillRepeatedly(Return(true)); 420 EXPECT_CALL(service, HasUnrecoverableError()).WillRepeatedly(Return(true));
419 421
420 // First time action is not set. We should get unrecoverable error. 422 // First time action is not set. We should get unrecoverable error.
421 syncer::SyncStatus status; 423 syncer::SyncStatus status;
422 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) 424 EXPECT_CALL(service, QueryDetailedSyncStatus(_))
423 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true))); 425 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true)));
424 426
425 base::string16 link_label; 427 base::string16 link_label;
426 base::string16 unrecoverable_error_status_label; 428 base::string16 unrecoverable_error_status_label;
429 sync_ui_util::ActionType action_type(sync_ui_util::NO_ACTION);
427 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin, 430 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin,
428 sync_ui_util::PLAIN_TEXT, 431 sync_ui_util::PLAIN_TEXT,
429 &unrecoverable_error_status_label, &link_label); 432 &unrecoverable_error_status_label, &link_label,
433 &action_type);
434 // Expect the generic unrecoverable error action which is to reauthenticate.
435 EXPECT_EQ(action_type, sync_ui_util::REAUTHENTICATE);
430 436
431 // This time set action to UPGRADE_CLIENT. Ensure that status label differs 437 // This time set action to UPGRADE_CLIENT. Ensure that status label differs
432 // from previous one. 438 // from previous one.
433 status.sync_protocol_error.action = syncer::UPGRADE_CLIENT; 439 status.sync_protocol_error.action = syncer::UPGRADE_CLIENT;
434 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) 440 EXPECT_CALL(service, QueryDetailedSyncStatus(_))
435 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true))); 441 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true)));
436 base::string16 upgrade_client_status_label; 442 base::string16 upgrade_client_status_label;
437 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin, 443 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin,
438 sync_ui_util::PLAIN_TEXT, 444 sync_ui_util::PLAIN_TEXT,
439 &upgrade_client_status_label, &link_label); 445 &upgrade_client_status_label, &link_label,
446 &action_type);
447 // Expect an explicit 'client upgrade' action.
448 EXPECT_EQ(action_type, sync_ui_util::UPGRADE_CLIENT);
449
440 EXPECT_NE(unrecoverable_error_status_label, upgrade_client_status_label); 450 EXPECT_NE(unrecoverable_error_status_label, upgrade_client_status_label);
441 } 451 }
452
453 TEST_F(SyncUIUtilTest, ActionableErrorWithPassiveMessage) {
454 std::unique_ptr<Profile> profile(MakeSignedInTestingProfile());
455 SigninManagerBase* signin =
456 SigninManagerFactory::GetForProfile(profile.get());
457
458 ProfileSyncServiceMock service(
459 CreateProfileSyncServiceParamsForTest(profile.get()));
460 EXPECT_CALL(service, IsFirstSetupComplete()).WillRepeatedly(Return(true));
461 EXPECT_CALL(service, HasUnrecoverableError()).WillRepeatedly(Return(true));
462
463 // Set action to UPGRADE_CLIENT.
464 syncer::SyncStatus status;
465 status.sync_protocol_error.action = syncer::UPGRADE_CLIENT;
466 EXPECT_CALL(service, QueryDetailedSyncStatus(_))
467 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true)));
468
469 base::string16 first_actionable_error_status_label;
470 base::string16 link_label;
471 sync_ui_util::ActionType action_type(sync_ui_util::NO_ACTION);
472 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin,
473 sync_ui_util::PLAIN_TEXT,
474 &first_actionable_error_status_label,
475 &link_label, &action_type);
476 // Expect a 'client upgrade' call to action.
477 EXPECT_EQ(action_type, sync_ui_util::UPGRADE_CLIENT);
478
479 // This time set action to ENABLE_SYNC_ON_ACCOUNT.
480 status.sync_protocol_error.action = syncer::ENABLE_SYNC_ON_ACCOUNT;
481 EXPECT_CALL(service, QueryDetailedSyncStatus(_))
482 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true)));
483
484 base::string16 second_actionable_error_status_label;
485 action_type = sync_ui_util::NO_ACTION;
486 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin,
487 sync_ui_util::PLAIN_TEXT,
488 &second_actionable_error_status_label,
489 &link_label, &action_type);
490 // Expect a passive message instead of a call to action.
491 EXPECT_EQ(action_type, sync_ui_util::NO_ACTION);
492
493 EXPECT_NE(first_actionable_error_status_label,
494 second_actionable_error_status_label);
495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698