| 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" |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). | 378 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). |
| 379 WillRepeatedly(Return(false)); | 379 WillRepeatedly(Return(false)); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void SetupInitializedProfileSyncService() { | 382 void SetupInitializedProfileSyncService() { |
| 383 // An initialized ProfileSyncService will have already completed sync setup | 383 // An initialized ProfileSyncService will have already completed sync setup |
| 384 // and will have an initialized sync backend. | 384 // and will have an initialized sync backend. |
| 385 if (!mock_signin_->IsInitialized()) { | 385 if (!mock_signin_->IsInitialized()) { |
| 386 profile_->GetPrefs()->SetString( | 386 profile_->GetPrefs()->SetString( |
| 387 prefs::kGoogleServicesUsername, kTestUser); | 387 prefs::kGoogleServicesUsername, kTestUser); |
| 388 mock_signin_->Initialize(profile_.get()); | 388 mock_signin_->Initialize(profile_.get(), NULL); |
| 389 } | 389 } |
| 390 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 390 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 391 .WillRepeatedly(Return(true)); | 391 .WillRepeatedly(Return(true)); |
| 392 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 392 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 393 .WillRepeatedly(Return(true)); | 393 .WillRepeatedly(Return(true)); |
| 394 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 394 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 395 .WillRepeatedly(Return(true)); | 395 .WillRepeatedly(Return(true)); |
| 396 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 396 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 397 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); | 397 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); |
| 398 } | 398 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 } | 513 } |
| 514 } | 514 } |
| 515 #endif | 515 #endif |
| 516 | 516 |
| 517 // Verifies that the handler correctly handles a cancellation when | 517 // Verifies that the handler correctly handles a cancellation when |
| 518 // it is displaying the spinner to the user. | 518 // it is displaying the spinner to the user. |
| 519 TEST_P(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { | 519 TEST_P(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { |
| 520 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 520 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 521 .WillRepeatedly(Return(true)); | 521 .WillRepeatedly(Return(true)); |
| 522 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); | 522 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 523 mock_signin_->Initialize(profile_.get()); | 523 mock_signin_->Initialize(profile_.get(), NULL); |
| 524 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 524 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 525 .WillRepeatedly(Return(true)); | 525 .WillRepeatedly(Return(true)); |
| 526 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 526 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 527 .WillRepeatedly(Return(false)); | 527 .WillRepeatedly(Return(false)); |
| 528 error_ = GoogleServiceAuthError::AuthErrorNone(); | 528 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 529 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 529 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 530 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); | 530 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); |
| 531 | 531 |
| 532 // We're simulating a user setting up sync, which would cause the backend to | 532 // We're simulating a user setting up sync, which would cause the backend to |
| 533 // kick off initialization, but not download user data types. The sync | 533 // kick off initialization, but not download user data types. The sync |
| 534 // backend will try to download control data types (e.g encryption info), but | 534 // backend will try to download control data types (e.g encryption info), but |
| 535 // that won't finish for this test as we're simulating cancelling while the | 535 // that won't finish for this test as we're simulating cancelling while the |
| 536 // spinner is showing. | 536 // spinner is showing. |
| 537 handler_->HandleShowSetupUI(NULL); | 537 handler_->HandleShowSetupUI(NULL); |
| 538 | 538 |
| 539 EXPECT_EQ(handler_.get(), | 539 EXPECT_EQ(handler_.get(), |
| 540 LoginUIServiceFactory::GetForProfile( | 540 LoginUIServiceFactory::GetForProfile( |
| 541 profile_.get())->current_login_ui()); | 541 profile_.get())->current_login_ui()); |
| 542 | 542 |
| 543 ExpectSpinnerAndClose(); | 543 ExpectSpinnerAndClose(); |
| 544 } | 544 } |
| 545 | 545 |
| 546 // Verifies that the handler correctly transitions from showing the spinner | 546 // Verifies that the handler correctly transitions from showing the spinner |
| 547 // to showing a configuration page when signin completes successfully. | 547 // to showing a configuration page when signin completes successfully. |
| 548 TEST_P(SyncSetupHandlerTest, | 548 TEST_P(SyncSetupHandlerTest, |
| 549 DisplayConfigureWithBackendDisabledAndSigninSuccess) { | 549 DisplayConfigureWithBackendDisabledAndSigninSuccess) { |
| 550 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 550 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 551 .WillRepeatedly(Return(true)); | 551 .WillRepeatedly(Return(true)); |
| 552 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); | 552 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 553 mock_signin_->Initialize(profile_.get()); | 553 mock_signin_->Initialize(profile_.get(), NULL); |
| 554 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 554 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 555 .WillRepeatedly(Return(true)); | 555 .WillRepeatedly(Return(true)); |
| 556 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 556 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 557 .WillRepeatedly(Return(false)); | 557 .WillRepeatedly(Return(false)); |
| 558 error_ = GoogleServiceAuthError::AuthErrorNone(); | 558 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 559 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 559 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 560 // Sync backend is stopped initially, and will start up. | 560 // Sync backend is stopped initially, and will start up. |
| 561 EXPECT_CALL(*mock_pss_, sync_initialized()) | 561 EXPECT_CALL(*mock_pss_, sync_initialized()) |
| 562 .WillRepeatedly(Return(false)); | 562 .WillRepeatedly(Return(false)); |
| 563 SetDefaultExpectationsForConfigPage(); | 563 SetDefaultExpectationsForConfigPage(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 // Verifies the case where the user cancels after the sync backend has | 601 // Verifies the case where the user cancels after the sync backend has |
| 602 // initialized (meaning it already transitioned from the spinner to a proper | 602 // initialized (meaning it already transitioned from the spinner to a proper |
| 603 // configuration page, tested by | 603 // configuration page, tested by |
| 604 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user | 604 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user |
| 605 // before the user has continued on. | 605 // before the user has continued on. |
| 606 TEST_P(SyncSetupHandlerTest, | 606 TEST_P(SyncSetupHandlerTest, |
| 607 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { | 607 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { |
| 608 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 608 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 609 .WillRepeatedly(Return(true)); | 609 .WillRepeatedly(Return(true)); |
| 610 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); | 610 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 611 mock_signin_->Initialize(profile_.get()); | 611 mock_signin_->Initialize(profile_.get(), NULL); |
| 612 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 612 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 613 .WillRepeatedly(Return(true)); | 613 .WillRepeatedly(Return(true)); |
| 614 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 614 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 615 .WillRepeatedly(Return(false)); | 615 .WillRepeatedly(Return(false)); |
| 616 error_ = GoogleServiceAuthError::AuthErrorNone(); | 616 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 617 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 617 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 618 EXPECT_CALL(*mock_pss_, sync_initialized()) | 618 EXPECT_CALL(*mock_pss_, sync_initialized()) |
| 619 .WillOnce(Return(false)) | 619 .WillOnce(Return(false)) |
| 620 .WillRepeatedly(Return(true)); | 620 .WillRepeatedly(Return(true)); |
| 621 SetDefaultExpectationsForConfigPage(); | 621 SetDefaultExpectationsForConfigPage(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 632 EXPECT_EQ(NULL, | 632 EXPECT_EQ(NULL, |
| 633 LoginUIServiceFactory::GetForProfile( | 633 LoginUIServiceFactory::GetForProfile( |
| 634 profile_.get())->current_login_ui()); | 634 profile_.get())->current_login_ui()); |
| 635 } | 635 } |
| 636 | 636 |
| 637 TEST_P(SyncSetupHandlerTest, | 637 TEST_P(SyncSetupHandlerTest, |
| 638 DisplayConfigureWithBackendDisabledAndSigninFalied) { | 638 DisplayConfigureWithBackendDisabledAndSigninFalied) { |
| 639 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 639 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 640 .WillRepeatedly(Return(true)); | 640 .WillRepeatedly(Return(true)); |
| 641 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); | 641 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser); |
| 642 mock_signin_->Initialize(profile_.get()); | 642 mock_signin_->Initialize(profile_.get(), NULL); |
| 643 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) | 643 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()) |
| 644 .WillRepeatedly(Return(true)); | 644 .WillRepeatedly(Return(true)); |
| 645 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 645 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 646 .WillRepeatedly(Return(false)); | 646 .WillRepeatedly(Return(false)); |
| 647 error_ = GoogleServiceAuthError::AuthErrorNone(); | 647 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 648 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 648 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 649 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); | 649 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); |
| 650 | 650 |
| 651 handler_->OpenSyncSetup(); | 651 handler_->OpenSyncSetup(); |
| 652 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 652 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 ExpectConfig(); | 1331 ExpectConfig(); |
| 1332 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1332 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 1333 DictionaryValue* dictionary; | 1333 DictionaryValue* dictionary; |
| 1334 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1334 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 1335 CheckBool(dictionary, "encryptAllData", true); | 1335 CheckBool(dictionary, "encryptAllData", true); |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, | 1338 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, |
| 1339 SyncSetupHandlerTest, | 1339 SyncSetupHandlerTest, |
| 1340 Values(true, false)); | 1340 Values(true, false)); |
| OLD | NEW |