| 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 "chrome/browser/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/signin/fake_auth_status_provider.h" | 16 #include "chrome/browser/signin/fake_auth_status_provider.h" |
| 17 #include "chrome/browser/signin/fake_signin_manager.h" | 17 #include "chrome/browser/signin/fake_signin_manager.h" |
| 18 #include "chrome/browser/signin/signin_manager.h" | 18 #include "chrome/browser/signin/signin_manager.h" |
| 19 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_mock.h" | 21 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 22 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 22 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
| 27 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
| 28 #include "chrome/test/base/scoped_testing_local_state.h" | 28 #include "chrome/test/base/scoped_testing_local_state.h" |
| 29 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
| 30 #include "content/public/test/test_browser_thread.h" |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/layout.h" | 34 #include "ui/base/layout.h" |
| 34 | 35 |
| 35 using ::testing::_; | 36 using ::testing::_; |
| 36 using ::testing::Mock; | 37 using ::testing::Mock; |
| 37 using ::testing::Return; | 38 using ::testing::Return; |
| 38 using ::testing::ReturnRef; | 39 using ::testing::ReturnRef; |
| 39 using ::testing::Values; | 40 using ::testing::Values; |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 void SetupInitializedProfileSyncService() { | 373 void SetupInitializedProfileSyncService() { |
| 373 // An initialized ProfileSyncService will have already completed sync setup | 374 // An initialized ProfileSyncService will have already completed sync setup |
| 374 // and will have an initialized sync backend. | 375 // and will have an initialized sync backend. |
| 375 if (!mock_signin_->IsInitialized()) { | 376 if (!mock_signin_->IsInitialized()) { |
| 376 profile_->GetPrefs()->SetString( | 377 profile_->GetPrefs()->SetString( |
| 377 prefs::kGoogleServicesUsername, kTestUser); | 378 prefs::kGoogleServicesUsername, kTestUser); |
| 378 mock_signin_->Initialize(profile_.get(), NULL); | 379 mock_signin_->Initialize(profile_.get(), NULL); |
| 379 } | 380 } |
| 380 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 381 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 381 .WillRepeatedly(Return(true)); | 382 .WillRepeatedly(Return(true)); |
| 382 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 383 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 383 .WillRepeatedly(Return(true)); | 384 .WillRepeatedly(Return(true)); |
| 384 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 385 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 385 .WillRepeatedly(Return(true)); | 386 .WillRepeatedly(Return(true)); |
| 386 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 387 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 387 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); | 388 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); |
| 388 } | 389 } |
| 389 | 390 |
| 390 void ExpectConfig() { | 391 void ExpectConfig() { |
| 391 ASSERT_EQ(1U, web_ui_.call_data().size()); | 392 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 392 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 393 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 scoped_ptr<TestingSyncSetupHandler> handler_; | 442 scoped_ptr<TestingSyncSetupHandler> handler_; |
| 442 }; | 443 }; |
| 443 | 444 |
| 444 TEST_F(SyncSetupHandlerTest, Basic) { | 445 TEST_F(SyncSetupHandlerTest, Basic) { |
| 445 } | 446 } |
| 446 | 447 |
| 447 #if !defined(OS_CHROMEOS) | 448 #if !defined(OS_CHROMEOS) |
| 448 TEST_F(SyncSetupHandlerTest, DisplayBasicLogin) { | 449 TEST_F(SyncSetupHandlerTest, DisplayBasicLogin) { |
| 449 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 450 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 450 .WillRepeatedly(Return(false)); | 451 .WillRepeatedly(Return(false)); |
| 451 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 452 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 452 .WillRepeatedly(Return(false)); | 453 .WillRepeatedly(Return(false)); |
| 453 const GoogleServiceAuthError error(GoogleServiceAuthError::NONE); | 454 const GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| 454 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 455 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
| 455 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 456 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 456 .WillRepeatedly(Return(false)); | 457 .WillRepeatedly(Return(false)); |
| 457 handler_->HandleStartSignin(NULL); | 458 handler_->HandleStartSignin(NULL); |
| 458 EXPECT_EQ(handler_.get(), | 459 EXPECT_EQ(handler_.get(), |
| 459 LoginUIServiceFactory::GetForProfile( | 460 LoginUIServiceFactory::GetForProfile( |
| 460 profile_.get())->current_login_ui()); | 461 profile_.get())->current_login_ui()); |
| 461 | 462 |
| 462 ASSERT_FALSE(handler_->is_configuring_sync()); | 463 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 463 ASSERT_TRUE(handler_->have_signin_tracker()); | 464 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 464 | 465 |
| 465 handler_->CloseSyncSetup(); | 466 handler_->CloseSyncSetup(); |
| 466 EXPECT_EQ(NULL, | 467 EXPECT_EQ(NULL, |
| 467 LoginUIServiceFactory::GetForProfile( | 468 LoginUIServiceFactory::GetForProfile( |
| 468 profile_.get())->current_login_ui()); | 469 profile_.get())->current_login_ui()); |
| 469 } | 470 } |
| 470 | 471 |
| 471 TEST_F(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn) { | 472 TEST_F(SyncSetupHandlerTest, ShowSyncSetupWhenNotSignedIn) { |
| 472 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 473 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 473 .WillRepeatedly(Return(false)); | 474 .WillRepeatedly(Return(false)); |
| 474 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 475 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 475 .WillRepeatedly(Return(false)); | 476 .WillRepeatedly(Return(false)); |
| 476 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 477 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 477 .WillRepeatedly(Return(false)); | 478 .WillRepeatedly(Return(false)); |
| 478 handler_->HandleShowSetupUI(NULL); | 479 handler_->HandleShowSetupUI(NULL); |
| 479 | 480 |
| 480 ASSERT_EQ(1U, web_ui_.call_data().size()); | 481 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 481 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 482 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 482 EXPECT_EQ("OptionsPage.closeOverlay", data.function_name); | 483 EXPECT_EQ("OptionsPage.closeOverlay", data.function_name); |
| 483 ASSERT_FALSE(handler_->is_configuring_sync()); | 484 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 484 EXPECT_EQ(NULL, | 485 EXPECT_EQ(NULL, |
| 485 LoginUIServiceFactory::GetForProfile( | 486 LoginUIServiceFactory::GetForProfile( |
| 486 profile_.get())->current_login_ui()); | 487 profile_.get())->current_login_ui()); |
| 487 } | 488 } |
| 488 #endif | 489 #endif |
| 489 | 490 |
| 490 // Verifies that the handler correctly handles a cancellation when | 491 // Verifies that the handler correctly handles a cancellation when |
| 491 // it is displaying the spinner to the user. | 492 // it is displaying the spinner to the user. |
| 492 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { | 493 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { |
| 493 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 494 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 494 .WillRepeatedly(Return(true)); | 495 .WillRepeatedly(Return(true)); |
| 495 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); | 496 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 496 mock_signin_->Initialize(profile_.get(), NULL); | 497 mock_signin_->Initialize(profile_.get(), NULL); |
| 497 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 498 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 498 .WillRepeatedly(Return(true)); | 499 .WillRepeatedly(Return(true)); |
| 499 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 500 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 500 .WillRepeatedly(Return(false)); | 501 .WillRepeatedly(Return(false)); |
| 501 error_ = GoogleServiceAuthError::AuthErrorNone(); | 502 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 502 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 503 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 503 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); | 504 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); |
| 504 | 505 |
| 505 // We're simulating a user setting up sync, which would cause the backend to | 506 // We're simulating a user setting up sync, which would cause the backend to |
| 506 // kick off initialization, but not download user data types. The sync | 507 // kick off initialization, but not download user data types. The sync |
| 507 // backend will try to download control data types (e.g encryption info), but | 508 // backend will try to download control data types (e.g encryption info), but |
| 508 // that won't finish for this test as we're simulating cancelling while the | 509 // that won't finish for this test as we're simulating cancelling while the |
| 509 // spinner is showing. | 510 // spinner is showing. |
| 510 handler_->HandleShowSetupUI(NULL); | 511 handler_->HandleShowSetupUI(NULL); |
| 511 | 512 |
| 512 EXPECT_EQ(handler_.get(), | 513 EXPECT_EQ(handler_.get(), |
| 513 LoginUIServiceFactory::GetForProfile( | 514 LoginUIServiceFactory::GetForProfile( |
| 514 profile_.get())->current_login_ui()); | 515 profile_.get())->current_login_ui()); |
| 515 | 516 |
| 516 ExpectSpinnerAndClose(); | 517 ExpectSpinnerAndClose(); |
| 517 } | 518 } |
| 518 | 519 |
| 519 // Verifies that the handler correctly transitions from showing the spinner | 520 // Verifies that the handler correctly transitions from showing the spinner |
| 520 // to showing a configuration page when sync setup completes successfully. | 521 // to showing a configuration page when sync setup completes successfully. |
| 521 TEST_F(SyncSetupHandlerTest, | 522 TEST_F(SyncSetupHandlerTest, |
| 522 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { | 523 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { |
| 523 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 524 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 524 .WillRepeatedly(Return(true)); | 525 .WillRepeatedly(Return(true)); |
| 525 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); | 526 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 526 mock_signin_->Initialize(profile_.get(), NULL); | 527 mock_signin_->Initialize(profile_.get(), NULL); |
| 527 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 528 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 528 .WillRepeatedly(Return(true)); | 529 .WillRepeatedly(Return(true)); |
| 529 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 530 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 530 .WillRepeatedly(Return(false)); | 531 .WillRepeatedly(Return(false)); |
| 531 error_ = GoogleServiceAuthError::AuthErrorNone(); | 532 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 532 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 533 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 533 // Sync backend is stopped initially, and will start up. | 534 // Sync backend is stopped initially, and will start up. |
| 534 EXPECT_CALL(*mock_pss_, sync_initialized()) | 535 EXPECT_CALL(*mock_pss_, sync_initialized()) |
| 535 .WillRepeatedly(Return(false)); | 536 .WillRepeatedly(Return(false)); |
| 536 SetDefaultExpectationsForConfigPage(); | 537 SetDefaultExpectationsForConfigPage(); |
| 537 | 538 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 // initialized (meaning it already transitioned from the spinner to a proper | 578 // initialized (meaning it already transitioned from the spinner to a proper |
| 578 // configuration page, tested by | 579 // configuration page, tested by |
| 579 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user | 580 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user |
| 580 // before the user has continued on. | 581 // before the user has continued on. |
| 581 TEST_F(SyncSetupHandlerTest, | 582 TEST_F(SyncSetupHandlerTest, |
| 582 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { | 583 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { |
| 583 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 584 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 584 .WillRepeatedly(Return(true)); | 585 .WillRepeatedly(Return(true)); |
| 585 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); | 586 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 586 mock_signin_->Initialize(profile_.get(), NULL); | 587 mock_signin_->Initialize(profile_.get(), NULL); |
| 587 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 588 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 588 .WillRepeatedly(Return(true)); | 589 .WillRepeatedly(Return(true)); |
| 589 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 590 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 590 .WillRepeatedly(Return(false)); | 591 .WillRepeatedly(Return(false)); |
| 591 error_ = GoogleServiceAuthError::AuthErrorNone(); | 592 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 592 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 593 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 593 EXPECT_CALL(*mock_pss_, sync_initialized()) | 594 EXPECT_CALL(*mock_pss_, sync_initialized()) |
| 594 .WillOnce(Return(false)) | 595 .WillOnce(Return(false)) |
| 595 .WillRepeatedly(Return(true)); | 596 .WillRepeatedly(Return(true)); |
| 596 SetDefaultExpectationsForConfigPage(); | 597 SetDefaultExpectationsForConfigPage(); |
| 597 handler_->OpenSyncSetup(); | 598 handler_->OpenSyncSetup(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 608 LoginUIServiceFactory::GetForProfile( | 609 LoginUIServiceFactory::GetForProfile( |
| 609 profile_.get())->current_login_ui()); | 610 profile_.get())->current_login_ui()); |
| 610 } | 611 } |
| 611 | 612 |
| 612 TEST_F(SyncSetupHandlerTest, | 613 TEST_F(SyncSetupHandlerTest, |
| 613 DisplayConfigureWithBackendDisabledAndSigninFailed) { | 614 DisplayConfigureWithBackendDisabledAndSigninFailed) { |
| 614 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 615 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 615 .WillRepeatedly(Return(true)); | 616 .WillRepeatedly(Return(true)); |
| 616 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); | 617 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 617 mock_signin_->Initialize(profile_.get(), NULL); | 618 mock_signin_->Initialize(profile_.get(), NULL); |
| 618 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 619 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 619 .WillRepeatedly(Return(true)); | 620 .WillRepeatedly(Return(true)); |
| 620 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 621 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 621 .WillRepeatedly(Return(false)); | 622 .WillRepeatedly(Return(false)); |
| 622 error_ = GoogleServiceAuthError::AuthErrorNone(); | 623 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 623 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 624 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 624 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); | 625 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); |
| 625 | 626 |
| 626 handler_->OpenSyncSetup(); | 627 handler_->OpenSyncSetup(); |
| 627 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 628 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 628 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 629 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 650 SyncSetupHandlerTest::SetUp(); | 651 SyncSetupHandlerTest::SetUp(); |
| 651 mock_signin_ = static_cast<SigninManagerBase*>( | 652 mock_signin_ = static_cast<SigninManagerBase*>( |
| 652 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | 653 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 653 profile_.get(), FakeSigninManager::Build)); | 654 profile_.get(), FakeSigninManager::Build)); |
| 654 } | 655 } |
| 655 }; | 656 }; |
| 656 | 657 |
| 657 TEST_F(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure) { | 658 TEST_F(SyncSetupHandlerNonCrosTest, HandleGaiaAuthFailure) { |
| 658 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 659 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 659 .WillRepeatedly(Return(false)); | 660 .WillRepeatedly(Return(false)); |
| 660 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 661 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 661 .WillRepeatedly(Return(false)); | 662 .WillRepeatedly(Return(false)); |
| 662 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 663 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 663 .WillRepeatedly(Return(false)); | 664 .WillRepeatedly(Return(false)); |
| 664 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 665 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 665 .WillRepeatedly(Return(false)); | 666 .WillRepeatedly(Return(false)); |
| 666 // Open the web UI. | 667 // Open the web UI. |
| 667 handler_->OpenSyncSetup(); | 668 handler_->OpenSyncSetup(); |
| 668 | 669 |
| 669 ASSERT_FALSE(handler_->is_configuring_sync()); | 670 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 670 ASSERT_TRUE(handler_->have_signin_tracker()); | 671 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 671 } | 672 } |
| 672 | 673 |
| 673 // TODO(kochi): We need equivalent tests for ChromeOS. | 674 // TODO(kochi): We need equivalent tests for ChromeOS. |
| 674 TEST_F(SyncSetupHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { | 675 TEST_F(SyncSetupHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { |
| 675 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 676 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 676 .WillRepeatedly(Return(false)); | 677 .WillRepeatedly(Return(false)); |
| 677 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 678 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 678 .WillRepeatedly(Return(false)); | 679 .WillRepeatedly(Return(false)); |
| 679 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 680 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 680 .WillRepeatedly(Return(false)); | 681 .WillRepeatedly(Return(false)); |
| 681 // Open the web UI. | 682 // Open the web UI. |
| 682 handler_->OpenSyncSetup(); | 683 handler_->OpenSyncSetup(); |
| 683 | 684 |
| 684 ASSERT_FALSE(handler_->is_configuring_sync()); | 685 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 685 ASSERT_TRUE(handler_->have_signin_tracker()); | 686 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 686 } | 687 } |
| 687 | 688 |
| 688 TEST_F(SyncSetupHandlerNonCrosTest, GaiaErrorInitializingSync) { | 689 TEST_F(SyncSetupHandlerNonCrosTest, GaiaErrorInitializingSync) { |
| 689 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 690 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 690 .WillRepeatedly(Return(false)); | 691 .WillRepeatedly(Return(false)); |
| 691 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 692 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 692 .WillRepeatedly(Return(false)); | 693 .WillRepeatedly(Return(false)); |
| 693 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 694 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 694 .WillRepeatedly(Return(false)); | 695 .WillRepeatedly(Return(false)); |
| 695 // Open the web UI. | 696 // Open the web UI. |
| 696 handler_->OpenSyncSetup(); | 697 handler_->OpenSyncSetup(); |
| 697 | 698 |
| 698 ASSERT_FALSE(handler_->is_configuring_sync()); | 699 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 699 ASSERT_TRUE(handler_->have_signin_tracker()); | 700 ASSERT_TRUE(handler_->have_signin_tracker()); |
| 700 } | 701 } |
| 701 | 702 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 // Initialize the system to a signed in state, but with an auth error. | 931 // Initialize the system to a signed in state, but with an auth error. |
| 931 error_ = GoogleServiceAuthError( | 932 error_ = GoogleServiceAuthError( |
| 932 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 933 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 933 | 934 |
| 934 SetupInitializedProfileSyncService(); | 935 SetupInitializedProfileSyncService(); |
| 935 mock_signin_->SetAuthenticatedUsername(kTestUser); | 936 mock_signin_->SetAuthenticatedUsername(kTestUser); |
| 936 FakeAuthStatusProvider provider(mock_signin_->signin_global_error()); | 937 FakeAuthStatusProvider provider(mock_signin_->signin_global_error()); |
| 937 provider.SetAuthError(error_); | 938 provider.SetAuthError(error_); |
| 938 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 939 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 939 .WillRepeatedly(Return(true)); | 940 .WillRepeatedly(Return(true)); |
| 940 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 941 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 941 .WillRepeatedly(Return(true)); | 942 .WillRepeatedly(Return(true)); |
| 942 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 943 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 943 .WillRepeatedly(Return(false)); | 944 .WillRepeatedly(Return(false)); |
| 944 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 945 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 945 .WillRepeatedly(Return(false)); | 946 .WillRepeatedly(Return(false)); |
| 946 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 947 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 947 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); | 948 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); |
| 948 | 949 |
| 949 #if defined(OS_CHROMEOS) | 950 #if defined(OS_CHROMEOS) |
| 950 // On ChromeOS, auth errors are ignored - instead we just try to start the | 951 // On ChromeOS, auth errors are ignored - instead we just try to start the |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 | 1109 |
| 1109 // This should display the sync setup dialog (not login). | 1110 // This should display the sync setup dialog (not login). |
| 1110 handler_->OpenSyncSetup(); | 1111 handler_->OpenSyncSetup(); |
| 1111 | 1112 |
| 1112 ExpectConfig(); | 1113 ExpectConfig(); |
| 1113 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1114 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 1114 DictionaryValue* dictionary; | 1115 DictionaryValue* dictionary; |
| 1115 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1116 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 1116 CheckBool(dictionary, "encryptAllData", true); | 1117 CheckBool(dictionary, "encryptAllData", true); |
| 1117 } | 1118 } |
| OLD | NEW |