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 <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 Loading... |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 .WillRepeatedly(DoAll(SetArgPointee<0>(status), Return(false))); | 325 .WillRepeatedly(DoAll(SetArgPointee<0>(status), Return(false))); |
326 EXPECT_CALL(*service, HasUnrecoverableError()) | 326 EXPECT_CALL(*service, HasUnrecoverableError()) |
327 .WillRepeatedly(Return(false)); | 327 .WillRepeatedly(Return(false)); |
328 return; | 328 return; |
329 } | 329 } |
330 default: | 330 default: |
331 NOTREACHED(); | 331 NOTREACHED(); |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
| 335 // Returns the expected value for the output argument |action_type| for each |
| 336 // of the distinct cases. |
| 337 sync_ui_util::ActionType GetActionTypeforDistinctCase(int case_number) { |
| 338 switch (case_number) { |
| 339 case STATUS_CASE_SETUP_IN_PROGRESS: |
| 340 return sync_ui_util::NO_ACTION; |
| 341 case STATUS_CASE_SETUP_ERROR: |
| 342 return sync_ui_util::REAUTHENTICATE; |
| 343 case STATUS_CASE_AUTHENTICATING: |
| 344 return sync_ui_util::NO_ACTION; |
| 345 case STATUS_CASE_AUTH_ERROR: |
| 346 return sync_ui_util::NO_ACTION; |
| 347 case STATUS_CASE_PROTOCOL_ERROR: |
| 348 return sync_ui_util::UPGRADE_CLIENT; |
| 349 case STATUS_CASE_PASSPHRASE_ERROR: |
| 350 return sync_ui_util::ENTER_PASSPHRASE; |
| 351 case STATUS_CASE_SYNCED: |
| 352 return sync_ui_util::NO_ACTION; |
| 353 case STATUS_CASE_SYNC_DISABLED_BY_POLICY: |
| 354 return sync_ui_util::NO_ACTION; |
| 355 default: |
| 356 NOTREACHED(); |
| 357 return sync_ui_util::NO_ACTION; |
| 358 } |
| 359 } |
| 360 |
335 // This test ensures that a each distinctive ProfileSyncService statuses | 361 // This test ensures that a each distinctive ProfileSyncService statuses |
336 // will return a unique combination of status and link messages from | 362 // will return a unique combination of status and link messages from |
337 // GetStatusLabels(). | 363 // GetStatusLabels(). |
338 TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { | 364 TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) { |
339 std::set<base::string16> messages; | 365 std::set<base::string16> messages; |
340 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { | 366 for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) { |
341 std::unique_ptr<Profile> profile(new TestingProfile()); | 367 std::unique_ptr<Profile> profile(new TestingProfile()); |
342 ProfileSyncService::InitParams init_params = | 368 ProfileSyncService::InitParams init_params = |
343 CreateProfileSyncServiceParamsForTest(profile.get()); | 369 CreateProfileSyncServiceParamsForTest(profile.get()); |
344 NiceMock<ProfileSyncServiceMock> service(&init_params); | 370 NiceMock<ProfileSyncServiceMock> service(&init_params); |
345 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); | 371 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); |
346 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 372 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
347 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); | 373 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); |
348 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); | 374 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
349 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( | 375 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( |
350 SigninErrorControllerFactory::GetForProfile(profile.get()))); | 376 SigninErrorControllerFactory::GetForProfile(profile.get()))); |
351 GetDistinctCase(&service, &signin, provider.get(), idx); | 377 GetDistinctCase(&service, &signin, provider.get(), idx); |
352 base::string16 status_label; | 378 base::string16 status_label; |
353 base::string16 link_label; | 379 base::string16 link_label; |
| 380 sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; |
354 sync_ui_util::GetStatusLabels(profile.get(), &service, signin, | 381 sync_ui_util::GetStatusLabels(profile.get(), &service, signin, |
355 sync_ui_util::WITH_HTML, &status_label, | 382 sync_ui_util::WITH_HTML, &status_label, |
356 &link_label); | 383 &link_label, &action_type); |
| 384 |
| 385 EXPECT_EQ(GetActionTypeforDistinctCase(idx), action_type); |
357 // If the status and link message combination is already present in the set | 386 // 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 | 387 // of messages already seen, this is a duplicate rather than a unique |
359 // message, and the test has failed. | 388 // message, and the test has failed. |
360 EXPECT_FALSE(status_label.empty()) << | 389 EXPECT_FALSE(status_label.empty()) << |
361 "Empty status label returned for case #" << idx; | 390 "Empty status label returned for case #" << idx; |
362 base::string16 combined_label = | 391 base::string16 combined_label = |
363 status_label + base::ASCIIToUTF16("#") + link_label; | 392 status_label + base::ASCIIToUTF16("#") + link_label; |
364 EXPECT_TRUE(messages.find(combined_label) == messages.end()) << | 393 EXPECT_TRUE(messages.find(combined_label) == messages.end()) << |
365 "Duplicate message for case #" << idx << ": " << combined_label; | 394 "Duplicate message for case #" << idx << ": " << combined_label; |
366 messages.insert(combined_label); | 395 messages.insert(combined_label); |
(...skipping 15 matching lines...) Expand all Loading... |
382 NiceMock<ProfileSyncServiceMock> service(&init_params); | 411 NiceMock<ProfileSyncServiceMock> service(&init_params); |
383 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); | 412 GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone(); |
384 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 413 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
385 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); | 414 FakeSigninManagerForSyncUIUtilTest signin(profile.get()); |
386 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); | 415 signin.SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser); |
387 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( | 416 std::unique_ptr<FakeAuthStatusProvider> provider(new FakeAuthStatusProvider( |
388 SigninErrorControllerFactory::GetForProfile(profile.get()))); | 417 SigninErrorControllerFactory::GetForProfile(profile.get()))); |
389 GetDistinctCase(&service, &signin, provider.get(), idx); | 418 GetDistinctCase(&service, &signin, provider.get(), idx); |
390 base::string16 status_label; | 419 base::string16 status_label; |
391 base::string16 link_label; | 420 base::string16 link_label; |
| 421 sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; |
392 sync_ui_util::GetStatusLabels(profile.get(), &service, signin, | 422 sync_ui_util::GetStatusLabels(profile.get(), &service, signin, |
393 sync_ui_util::PLAIN_TEXT, &status_label, | 423 sync_ui_util::PLAIN_TEXT, &status_label, |
394 &link_label); | 424 &link_label, &action_type); |
395 | 425 |
| 426 EXPECT_EQ(GetActionTypeforDistinctCase(idx), action_type); |
396 // Ensures a search for string 'href' (found in links, not a string to be | 427 // 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 | 428 // found in an English language message) fails when links are excluded from |
398 // the status label. | 429 // the status label. |
399 EXPECT_FALSE(status_label.empty()); | 430 EXPECT_FALSE(status_label.empty()); |
400 EXPECT_EQ(status_label.find(base::ASCIIToUTF16("href")), | 431 EXPECT_EQ(status_label.find(base::ASCIIToUTF16("href")), |
401 base::string16::npos); | 432 base::string16::npos); |
402 testing::Mock::VerifyAndClearExpectations(&service); | 433 testing::Mock::VerifyAndClearExpectations(&service); |
403 testing::Mock::VerifyAndClearExpectations(&signin); | 434 testing::Mock::VerifyAndClearExpectations(&signin); |
404 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 435 EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
405 provider.reset(); | 436 provider.reset(); |
(...skipping 11 matching lines...) Expand all Loading... |
417 EXPECT_CALL(service, IsFirstSetupComplete()).WillRepeatedly(Return(true)); | 448 EXPECT_CALL(service, IsFirstSetupComplete()).WillRepeatedly(Return(true)); |
418 EXPECT_CALL(service, HasUnrecoverableError()).WillRepeatedly(Return(true)); | 449 EXPECT_CALL(service, HasUnrecoverableError()).WillRepeatedly(Return(true)); |
419 | 450 |
420 // First time action is not set. We should get unrecoverable error. | 451 // First time action is not set. We should get unrecoverable error. |
421 syncer::SyncStatus status; | 452 syncer::SyncStatus status; |
422 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 453 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
423 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true))); | 454 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true))); |
424 | 455 |
425 base::string16 link_label; | 456 base::string16 link_label; |
426 base::string16 unrecoverable_error_status_label; | 457 base::string16 unrecoverable_error_status_label; |
| 458 sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; |
427 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin, | 459 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin, |
428 sync_ui_util::PLAIN_TEXT, | 460 sync_ui_util::PLAIN_TEXT, |
429 &unrecoverable_error_status_label, &link_label); | 461 &unrecoverable_error_status_label, &link_label, |
| 462 &action_type); |
| 463 |
| 464 // Expect the generic unrecoverable error action which is to reauthenticate. |
| 465 EXPECT_EQ(sync_ui_util::REAUTHENTICATE, action_type); |
430 | 466 |
431 // This time set action to UPGRADE_CLIENT. Ensure that status label differs | 467 // This time set action to UPGRADE_CLIENT. Ensure that status label differs |
432 // from previous one. | 468 // from previous one. |
433 status.sync_protocol_error.action = syncer::UPGRADE_CLIENT; | 469 status.sync_protocol_error.action = syncer::UPGRADE_CLIENT; |
434 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) | 470 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
435 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true))); | 471 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true))); |
436 base::string16 upgrade_client_status_label; | 472 base::string16 upgrade_client_status_label; |
437 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin, | 473 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin, |
438 sync_ui_util::PLAIN_TEXT, | 474 sync_ui_util::PLAIN_TEXT, |
439 &upgrade_client_status_label, &link_label); | 475 &upgrade_client_status_label, &link_label, |
| 476 &action_type); |
| 477 // Expect an explicit 'client upgrade' action. |
| 478 EXPECT_EQ(sync_ui_util::UPGRADE_CLIENT, action_type); |
| 479 |
440 EXPECT_NE(unrecoverable_error_status_label, upgrade_client_status_label); | 480 EXPECT_NE(unrecoverable_error_status_label, upgrade_client_status_label); |
441 } | 481 } |
| 482 |
| 483 TEST_F(SyncUIUtilTest, ActionableErrorWithPassiveMessage) { |
| 484 std::unique_ptr<Profile> profile(MakeSignedInTestingProfile()); |
| 485 SigninManagerBase* signin = |
| 486 SigninManagerFactory::GetForProfile(profile.get()); |
| 487 |
| 488 ProfileSyncServiceMock service( |
| 489 CreateProfileSyncServiceParamsForTest(profile.get())); |
| 490 EXPECT_CALL(service, IsFirstSetupComplete()).WillRepeatedly(Return(true)); |
| 491 EXPECT_CALL(service, HasUnrecoverableError()).WillRepeatedly(Return(true)); |
| 492 |
| 493 // Set action to UPGRADE_CLIENT. |
| 494 syncer::SyncStatus status; |
| 495 status.sync_protocol_error.action = syncer::UPGRADE_CLIENT; |
| 496 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 497 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true))); |
| 498 |
| 499 base::string16 first_actionable_error_status_label; |
| 500 base::string16 link_label; |
| 501 sync_ui_util::ActionType action_type = sync_ui_util::NO_ACTION; |
| 502 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin, |
| 503 sync_ui_util::PLAIN_TEXT, |
| 504 &first_actionable_error_status_label, |
| 505 &link_label, &action_type); |
| 506 // Expect a 'client upgrade' call to action. |
| 507 EXPECT_EQ(sync_ui_util::UPGRADE_CLIENT, action_type); |
| 508 |
| 509 // This time set action to ENABLE_SYNC_ON_ACCOUNT. |
| 510 status.sync_protocol_error.action = syncer::ENABLE_SYNC_ON_ACCOUNT; |
| 511 EXPECT_CALL(service, QueryDetailedSyncStatus(_)) |
| 512 .WillOnce(DoAll(SetArgPointee<0>(status), Return(true))); |
| 513 |
| 514 base::string16 second_actionable_error_status_label; |
| 515 action_type = sync_ui_util::NO_ACTION; |
| 516 sync_ui_util::GetStatusLabels(profile.get(), &service, *signin, |
| 517 sync_ui_util::PLAIN_TEXT, |
| 518 &second_actionable_error_status_label, |
| 519 &link_label, &action_type); |
| 520 // Expect a passive message instead of a call to action. |
| 521 EXPECT_EQ(sync_ui_util::NO_ACTION, action_type); |
| 522 |
| 523 EXPECT_NE(first_actionable_error_status_label, |
| 524 second_actionable_error_status_label); |
| 525 } |
OLD | NEW |