| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/settings/sync_handler.h" | 5 #include "chrome/browser/ui/webui/settings/sync_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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // unit testing context. See the destructor to SyncHandler. This is hacky. | 159 // unit testing context. See the destructor to SyncHandler. This is hacky. |
| 160 set_web_ui(nullptr); | 160 set_web_ui(nullptr); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void FocusUI() override {} | 163 void FocusUI() override {} |
| 164 | 164 |
| 165 using SyncHandler::is_configuring_sync; | 165 using SyncHandler::is_configuring_sync; |
| 166 | 166 |
| 167 private: | 167 private: |
| 168 #if !defined(OS_CHROMEOS) | 168 #if !defined(OS_CHROMEOS) |
| 169 void DisplayGaiaLoginInNewTabOrWindow() override {} | 169 void DisplayGaiaLoginInNewTabOrWindow( |
| 170 signin_metrics::AccessPoint access_point) override {} |
| 170 #endif | 171 #endif |
| 171 | 172 |
| 172 DISALLOW_COPY_AND_ASSIGN(TestingSyncHandler); | 173 DISALLOW_COPY_AND_ASSIGN(TestingSyncHandler); |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 // The boolean parameter indicates whether the test is run with ClientOAuth | 176 // The boolean parameter indicates whether the test is run with ClientOAuth |
| 176 // or not. The test parameter is a bool: whether or not to test with/ | 177 // or not. The test parameter is a bool: whether or not to test with/ |
| 177 // /ClientLogin enabled or not. | 178 // /ClientLogin enabled or not. |
| 178 class SyncHandlerTest : public testing::Test { | 179 class SyncHandlerTest : public testing::Test { |
| 179 public: | 180 public: |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 391 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 391 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 392 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 392 .WillRepeatedly(Return(true)); | 393 .WillRepeatedly(Return(true)); |
| 393 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 394 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 394 .WillRepeatedly(Return(false)); | 395 .WillRepeatedly(Return(false)); |
| 395 error_ = GoogleServiceAuthError::AuthErrorNone(); | 396 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 396 // Sync backend is stopped initially, and will start up. | 397 // Sync backend is stopped initially, and will start up. |
| 397 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 398 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); |
| 398 SetDefaultExpectationsForConfigPage(); | 399 SetDefaultExpectationsForConfigPage(); |
| 399 | 400 |
| 400 handler_->OpenSyncSetup(); | 401 handler_->OpenSyncSetup(nullptr); |
| 401 | 402 |
| 402 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. | 403 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. |
| 403 EXPECT_EQ(1U, web_ui_.call_data().size()); | 404 EXPECT_EQ(1U, web_ui_.call_data().size()); |
| 404 | 405 |
| 405 const content::TestWebUI::CallData& data0 = *web_ui_.call_data()[0]; | 406 const content::TestWebUI::CallData& data0 = *web_ui_.call_data()[0]; |
| 406 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data0.function_name()); | 407 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data0.function_name()); |
| 407 std::string page; | 408 std::string page; |
| 408 ASSERT_TRUE(data0.arg1()->GetAsString(&page)); | 409 ASSERT_TRUE(data0.arg1()->GetAsString(&page)); |
| 409 EXPECT_EQ(page, "spinner"); | 410 EXPECT_EQ(page, "spinner"); |
| 410 | 411 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 441 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 442 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 442 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 443 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 443 .WillRepeatedly(Return(true)); | 444 .WillRepeatedly(Return(true)); |
| 444 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 445 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 445 .WillRepeatedly(Return(false)); | 446 .WillRepeatedly(Return(false)); |
| 446 error_ = GoogleServiceAuthError::AuthErrorNone(); | 447 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 447 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) | 448 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) |
| 448 .WillOnce(Return(false)) | 449 .WillOnce(Return(false)) |
| 449 .WillRepeatedly(Return(true)); | 450 .WillRepeatedly(Return(true)); |
| 450 SetDefaultExpectationsForConfigPage(); | 451 SetDefaultExpectationsForConfigPage(); |
| 451 handler_->OpenSyncSetup(); | 452 handler_->OpenSyncSetup(nullptr); |
| 452 | 453 |
| 453 // It's important to tell sync the user cancelled the setup flow before we | 454 // It's important to tell sync the user cancelled the setup flow before we |
| 454 // tell it we're through with the setup progress. | 455 // tell it we're through with the setup progress. |
| 455 testing::InSequence seq; | 456 testing::InSequence seq; |
| 456 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); | 457 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); |
| 457 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); | 458 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); |
| 458 | 459 |
| 459 handler_->CloseSyncSetup(); | 460 handler_->CloseSyncSetup(); |
| 460 EXPECT_EQ(NULL, | 461 EXPECT_EQ(NULL, |
| 461 LoginUIServiceFactory::GetForProfile( | 462 LoginUIServiceFactory::GetForProfile( |
| 462 profile_.get())->current_login_ui()); | 463 profile_.get())->current_login_ui()); |
| 463 } | 464 } |
| 464 | 465 |
| 465 TEST_F(SyncHandlerTest, | 466 TEST_F(SyncHandlerTest, |
| 466 DisplayConfigureWithBackendDisabledAndSigninFailed) { | 467 DisplayConfigureWithBackendDisabledAndSigninFailed) { |
| 467 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 468 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 468 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 469 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 469 .WillRepeatedly(Return(true)); | 470 .WillRepeatedly(Return(true)); |
| 470 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 471 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 471 .WillRepeatedly(Return(false)); | 472 .WillRepeatedly(Return(false)); |
| 472 error_ = GoogleServiceAuthError::AuthErrorNone(); | 473 error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 473 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 474 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); |
| 474 | 475 |
| 475 handler_->OpenSyncSetup(); | 476 handler_->OpenSyncSetup(nullptr); |
| 476 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 477 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
| 477 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); | 478 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); |
| 478 std::string page; | 479 std::string page; |
| 479 ASSERT_TRUE(data.arg1()->GetAsString(&page)); | 480 ASSERT_TRUE(data.arg1()->GetAsString(&page)); |
| 480 EXPECT_EQ(page, "spinner"); | 481 EXPECT_EQ(page, "spinner"); |
| 481 Mock::VerifyAndClearExpectations(mock_pss_); | 482 Mock::VerifyAndClearExpectations(mock_pss_); |
| 482 error_ = GoogleServiceAuthError( | 483 error_ = GoogleServiceAuthError( |
| 483 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 484 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 484 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); | 485 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); |
| 485 NotifySyncListeners(); | 486 NotifySyncListeners(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 499 | 500 |
| 500 TEST_F(SyncHandlerNonCrosTest, HandleGaiaAuthFailure) { | 501 TEST_F(SyncHandlerNonCrosTest, HandleGaiaAuthFailure) { |
| 501 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 502 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
| 502 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 503 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 503 .WillRepeatedly(Return(false)); | 504 .WillRepeatedly(Return(false)); |
| 504 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 505 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 505 .WillRepeatedly(Return(false)); | 506 .WillRepeatedly(Return(false)); |
| 506 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 507 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 507 .WillRepeatedly(Return(false)); | 508 .WillRepeatedly(Return(false)); |
| 508 // Open the web UI. | 509 // Open the web UI. |
| 509 handler_->OpenSyncSetup(); | 510 handler_->OpenSyncSetup(nullptr); |
| 510 | 511 |
| 511 ASSERT_FALSE(handler_->is_configuring_sync()); | 512 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 512 } | 513 } |
| 513 | 514 |
| 514 // TODO(kochi): We need equivalent tests for ChromeOS. | 515 // TODO(kochi): We need equivalent tests for ChromeOS. |
| 515 TEST_F(SyncHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { | 516 TEST_F(SyncHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { |
| 516 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 517 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
| 517 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 518 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 518 .WillRepeatedly(Return(false)); | 519 .WillRepeatedly(Return(false)); |
| 519 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 520 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 520 .WillRepeatedly(Return(false)); | 521 .WillRepeatedly(Return(false)); |
| 521 // Open the web UI. | 522 // Open the web UI. |
| 522 handler_->OpenSyncSetup(); | 523 handler_->OpenSyncSetup(nullptr); |
| 523 | 524 |
| 524 ASSERT_FALSE(handler_->is_configuring_sync()); | 525 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 525 } | 526 } |
| 526 | 527 |
| 527 TEST_F(SyncHandlerNonCrosTest, GaiaErrorInitializingSync) { | 528 TEST_F(SyncHandlerNonCrosTest, GaiaErrorInitializingSync) { |
| 528 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 529 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
| 529 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 530 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| 530 .WillRepeatedly(Return(false)); | 531 .WillRepeatedly(Return(false)); |
| 531 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 532 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 532 .WillRepeatedly(Return(false)); | 533 .WillRepeatedly(Return(false)); |
| 533 // Open the web UI. | 534 // Open the web UI. |
| 534 handler_->OpenSyncSetup(); | 535 handler_->OpenSyncSetup(nullptr); |
| 535 | 536 |
| 536 ASSERT_FALSE(handler_->is_configuring_sync()); | 537 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 537 } | 538 } |
| 538 | 539 |
| 539 #endif // #if !defined(OS_CHROMEOS) | 540 #endif // #if !defined(OS_CHROMEOS) |
| 540 | 541 |
| 541 TEST_F(SyncHandlerTest, TestSyncEverything) { | 542 TEST_F(SyncHandlerTest, TestSyncEverything) { |
| 542 std::string args = GetConfiguration( | 543 std::string args = GetConfiguration( |
| 543 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); | 544 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); |
| 544 base::ListValue list_args; | 545 base::ListValue list_args; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 } | 754 } |
| 754 | 755 |
| 755 TEST_F(SyncHandlerTest, ShowSyncSetup) { | 756 TEST_F(SyncHandlerTest, ShowSyncSetup) { |
| 756 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 757 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 757 .WillRepeatedly(Return(false)); | 758 .WillRepeatedly(Return(false)); |
| 758 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 759 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 759 .WillRepeatedly(Return(false)); | 760 .WillRepeatedly(Return(false)); |
| 760 SetupInitializedProfileSyncService(); | 761 SetupInitializedProfileSyncService(); |
| 761 // This should display the sync setup dialog (not login). | 762 // This should display the sync setup dialog (not login). |
| 762 SetDefaultExpectationsForConfigPage(); | 763 SetDefaultExpectationsForConfigPage(); |
| 763 handler_->OpenSyncSetup(); | 764 handler_->OpenSyncSetup(nullptr); |
| 764 | 765 |
| 765 ExpectConfig(); | 766 ExpectConfig(); |
| 766 } | 767 } |
| 767 | 768 |
| 768 // We do not display signin on chromeos in the case of auth error. | 769 // We do not display signin on chromeos in the case of auth error. |
| 769 TEST_F(SyncHandlerTest, ShowSigninOnAuthError) { | 770 TEST_F(SyncHandlerTest, ShowSigninOnAuthError) { |
| 770 // Initialize the system to a signed in state, but with an auth error. | 771 // Initialize the system to a signed in state, but with an auth error. |
| 771 error_ = GoogleServiceAuthError( | 772 error_ = GoogleServiceAuthError( |
| 772 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 773 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 773 | 774 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 790 // sync backend (which will fail due to the auth error). This should only | 791 // sync backend (which will fail due to the auth error). This should only |
| 791 // happen if the user manually navigates to chrome://settings/syncSetup - | 792 // happen if the user manually navigates to chrome://settings/syncSetup - |
| 792 // clicking on the button in the UI will sign the user out rather than | 793 // clicking on the button in the UI will sign the user out rather than |
| 793 // displaying a spinner. Should be no visible UI on ChromeOS in this case. | 794 // displaying a spinner. Should be no visible UI on ChromeOS in this case. |
| 794 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile( | 795 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile( |
| 795 profile_.get())->current_login_ui()); | 796 profile_.get())->current_login_ui()); |
| 796 #else | 797 #else |
| 797 | 798 |
| 798 // On ChromeOS, this should display the spinner while we try to startup the | 799 // On ChromeOS, this should display the spinner while we try to startup the |
| 799 // sync backend, and on desktop this displays the login dialog. | 800 // sync backend, and on desktop this displays the login dialog. |
| 800 handler_->OpenSyncSetup(); | 801 handler_->OpenSyncSetup(nullptr); |
| 801 | 802 |
| 802 // Sync setup is closed when re-auth is in progress. | 803 // Sync setup is closed when re-auth is in progress. |
| 803 EXPECT_EQ(NULL, | 804 EXPECT_EQ(NULL, |
| 804 LoginUIServiceFactory::GetForProfile( | 805 LoginUIServiceFactory::GetForProfile( |
| 805 profile_.get())->current_login_ui()); | 806 profile_.get())->current_login_ui()); |
| 806 | 807 |
| 807 ASSERT_FALSE(handler_->is_configuring_sync()); | 808 ASSERT_FALSE(handler_->is_configuring_sync()); |
| 808 #endif | 809 #endif |
| 809 } | 810 } |
| 810 | 811 |
| 811 TEST_F(SyncHandlerTest, ShowSetupSyncEverything) { | 812 TEST_F(SyncHandlerTest, ShowSetupSyncEverything) { |
| 812 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 813 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 813 .WillRepeatedly(Return(false)); | 814 .WillRepeatedly(Return(false)); |
| 814 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 815 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 815 .WillRepeatedly(Return(false)); | 816 .WillRepeatedly(Return(false)); |
| 816 SetupInitializedProfileSyncService(); | 817 SetupInitializedProfileSyncService(); |
| 817 SetDefaultExpectationsForConfigPage(); | 818 SetDefaultExpectationsForConfigPage(); |
| 818 // This should display the sync setup dialog (not login). | 819 // This should display the sync setup dialog (not login). |
| 819 handler_->OpenSyncSetup(); | 820 handler_->OpenSyncSetup(nullptr); |
| 820 | 821 |
| 821 ExpectConfig(); | 822 ExpectConfig(); |
| 822 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 823 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
| 823 const base::DictionaryValue* dictionary = nullptr; | 824 const base::DictionaryValue* dictionary = nullptr; |
| 824 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 825 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
| 825 CheckBool(dictionary, "syncAllDataTypes", true); | 826 CheckBool(dictionary, "syncAllDataTypes", true); |
| 826 CheckBool(dictionary, "appsRegistered", true); | 827 CheckBool(dictionary, "appsRegistered", true); |
| 827 CheckBool(dictionary, "autofillRegistered", true); | 828 CheckBool(dictionary, "autofillRegistered", true); |
| 828 CheckBool(dictionary, "bookmarksRegistered", true); | 829 CheckBool(dictionary, "bookmarksRegistered", true); |
| 829 CheckBool(dictionary, "extensionsRegistered", true); | 830 CheckBool(dictionary, "extensionsRegistered", true); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 843 TEST_F(SyncHandlerTest, ShowSetupManuallySyncAll) { | 844 TEST_F(SyncHandlerTest, ShowSetupManuallySyncAll) { |
| 844 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 845 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 845 .WillRepeatedly(Return(false)); | 846 .WillRepeatedly(Return(false)); |
| 846 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 847 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 847 .WillRepeatedly(Return(false)); | 848 .WillRepeatedly(Return(false)); |
| 848 SetupInitializedProfileSyncService(); | 849 SetupInitializedProfileSyncService(); |
| 849 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); | 850 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); |
| 850 sync_prefs.SetKeepEverythingSynced(false); | 851 sync_prefs.SetKeepEverythingSynced(false); |
| 851 SetDefaultExpectationsForConfigPage(); | 852 SetDefaultExpectationsForConfigPage(); |
| 852 // This should display the sync setup dialog (not login). | 853 // This should display the sync setup dialog (not login). |
| 853 handler_->OpenSyncSetup(); | 854 handler_->OpenSyncSetup(nullptr); |
| 854 | 855 |
| 855 ExpectConfig(); | 856 ExpectConfig(); |
| 856 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 857 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
| 857 const base::DictionaryValue* dictionary = nullptr; | 858 const base::DictionaryValue* dictionary = nullptr; |
| 858 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 859 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
| 859 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes()); | 860 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes()); |
| 860 } | 861 } |
| 861 | 862 |
| 862 TEST_F(SyncHandlerTest, ShowSetupSyncForAllTypesIndividually) { | 863 TEST_F(SyncHandlerTest, ShowSetupSyncForAllTypesIndividually) { |
| 863 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); | 864 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); |
| 864 syncer::ModelTypeSet::Iterator it; | 865 syncer::ModelTypeSet::Iterator it; |
| 865 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { | 866 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { |
| 866 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 867 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 867 .WillRepeatedly(Return(false)); | 868 .WillRepeatedly(Return(false)); |
| 868 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 869 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 869 .WillRepeatedly(Return(false)); | 870 .WillRepeatedly(Return(false)); |
| 870 SetupInitializedProfileSyncService(); | 871 SetupInitializedProfileSyncService(); |
| 871 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); | 872 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); |
| 872 sync_prefs.SetKeepEverythingSynced(false); | 873 sync_prefs.SetKeepEverythingSynced(false); |
| 873 SetDefaultExpectationsForConfigPage(); | 874 SetDefaultExpectationsForConfigPage(); |
| 874 syncer::ModelTypeSet types; | 875 syncer::ModelTypeSet types; |
| 875 types.Put(it.Get()); | 876 types.Put(it.Get()); |
| 876 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). | 877 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). |
| 877 WillRepeatedly(Return(types)); | 878 WillRepeatedly(Return(types)); |
| 878 | 879 |
| 879 // This should display the sync setup dialog (not login). | 880 // This should display the sync setup dialog (not login). |
| 880 handler_->OpenSyncSetup(); | 881 handler_->OpenSyncSetup(nullptr); |
| 881 | 882 |
| 882 ExpectConfig(); | 883 ExpectConfig(); |
| 883 // Close the config overlay. | 884 // Close the config overlay. |
| 884 LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed( | 885 LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed( |
| 885 handler_.get()); | 886 handler_.get()); |
| 886 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 887 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
| 887 const base::DictionaryValue* dictionary = nullptr; | 888 const base::DictionaryValue* dictionary = nullptr; |
| 888 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 889 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
| 889 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types); | 890 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types); |
| 890 Mock::VerifyAndClearExpectations(mock_pss_); | 891 Mock::VerifyAndClearExpectations(mock_pss_); |
| 891 // Clean up so we can loop back to display the dialog again. | 892 // Clean up so we can loop back to display the dialog again. |
| 892 web_ui_.ClearTrackedCalls(); | 893 web_ui_.ClearTrackedCalls(); |
| 893 } | 894 } |
| 894 } | 895 } |
| 895 | 896 |
| 896 TEST_F(SyncHandlerTest, ShowSetupGaiaPassphraseRequired) { | 897 TEST_F(SyncHandlerTest, ShowSetupGaiaPassphraseRequired) { |
| 897 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 898 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 898 .WillRepeatedly(Return(true)); | 899 .WillRepeatedly(Return(true)); |
| 899 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 900 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 900 .WillRepeatedly(Return(false)); | 901 .WillRepeatedly(Return(false)); |
| 901 SetupInitializedProfileSyncService(); | 902 SetupInitializedProfileSyncService(); |
| 902 SetDefaultExpectationsForConfigPage(); | 903 SetDefaultExpectationsForConfigPage(); |
| 903 | 904 |
| 904 // This should display the sync setup dialog (not login). | 905 // This should display the sync setup dialog (not login). |
| 905 handler_->OpenSyncSetup(); | 906 handler_->OpenSyncSetup(nullptr); |
| 906 | 907 |
| 907 ExpectConfig(); | 908 ExpectConfig(); |
| 908 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 909 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
| 909 const base::DictionaryValue* dictionary = nullptr; | 910 const base::DictionaryValue* dictionary = nullptr; |
| 910 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 911 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
| 911 CheckBool(dictionary, "showPassphrase", true); | 912 CheckBool(dictionary, "showPassphrase", true); |
| 912 CheckBool(dictionary, "usePassphrase", false); | 913 CheckBool(dictionary, "usePassphrase", false); |
| 913 CheckBool(dictionary, "passphraseFailed", false); | 914 CheckBool(dictionary, "passphraseFailed", false); |
| 914 } | 915 } |
| 915 | 916 |
| 916 TEST_F(SyncHandlerTest, ShowSetupCustomPassphraseRequired) { | 917 TEST_F(SyncHandlerTest, ShowSetupCustomPassphraseRequired) { |
| 917 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 918 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 918 .WillRepeatedly(Return(true)); | 919 .WillRepeatedly(Return(true)); |
| 919 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 920 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 920 .WillRepeatedly(Return(true)); | 921 .WillRepeatedly(Return(true)); |
| 921 EXPECT_CALL(*mock_pss_, GetPassphraseType()) | 922 EXPECT_CALL(*mock_pss_, GetPassphraseType()) |
| 922 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE)); | 923 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE)); |
| 923 SetupInitializedProfileSyncService(); | 924 SetupInitializedProfileSyncService(); |
| 924 SetDefaultExpectationsForConfigPage(); | 925 SetDefaultExpectationsForConfigPage(); |
| 925 | 926 |
| 926 // This should display the sync setup dialog (not login). | 927 // This should display the sync setup dialog (not login). |
| 927 handler_->OpenSyncSetup(); | 928 handler_->OpenSyncSetup(nullptr); |
| 928 | 929 |
| 929 ExpectConfig(); | 930 ExpectConfig(); |
| 930 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 931 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
| 931 const base::DictionaryValue* dictionary = nullptr; | 932 const base::DictionaryValue* dictionary = nullptr; |
| 932 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 933 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
| 933 CheckBool(dictionary, "showPassphrase", true); | 934 CheckBool(dictionary, "showPassphrase", true); |
| 934 CheckBool(dictionary, "usePassphrase", true); | 935 CheckBool(dictionary, "usePassphrase", true); |
| 935 CheckBool(dictionary, "passphraseFailed", false); | 936 CheckBool(dictionary, "passphraseFailed", false); |
| 936 } | 937 } |
| 937 | 938 |
| 938 TEST_F(SyncHandlerTest, ShowSetupEncryptAll) { | 939 TEST_F(SyncHandlerTest, ShowSetupEncryptAll) { |
| 939 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 940 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 940 .WillRepeatedly(Return(false)); | 941 .WillRepeatedly(Return(false)); |
| 941 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 942 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 942 .WillRepeatedly(Return(false)); | 943 .WillRepeatedly(Return(false)); |
| 943 SetupInitializedProfileSyncService(); | 944 SetupInitializedProfileSyncService(); |
| 944 SetDefaultExpectationsForConfigPage(); | 945 SetDefaultExpectationsForConfigPage(); |
| 945 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled()) | 946 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled()) |
| 946 .WillRepeatedly(Return(true)); | 947 .WillRepeatedly(Return(true)); |
| 947 | 948 |
| 948 // This should display the sync setup dialog (not login). | 949 // This should display the sync setup dialog (not login). |
| 949 handler_->OpenSyncSetup(); | 950 handler_->OpenSyncSetup(nullptr); |
| 950 | 951 |
| 951 ExpectConfig(); | 952 ExpectConfig(); |
| 952 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 953 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
| 953 const base::DictionaryValue* dictionary = nullptr; | 954 const base::DictionaryValue* dictionary = nullptr; |
| 954 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 955 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
| 955 CheckBool(dictionary, "encryptAllData", true); | 956 CheckBool(dictionary, "encryptAllData", true); |
| 956 } | 957 } |
| 957 | 958 |
| 958 TEST_F(SyncHandlerTest, ShowSetupEncryptAllDisallowed) { | 959 TEST_F(SyncHandlerTest, ShowSetupEncryptAllDisallowed) { |
| 959 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) | 960 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) |
| 960 .WillRepeatedly(Return(false)); | 961 .WillRepeatedly(Return(false)); |
| 961 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) | 962 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) |
| 962 .WillRepeatedly(Return(false)); | 963 .WillRepeatedly(Return(false)); |
| 963 SetupInitializedProfileSyncService(); | 964 SetupInitializedProfileSyncService(); |
| 964 SetDefaultExpectationsForConfigPage(); | 965 SetDefaultExpectationsForConfigPage(); |
| 965 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) | 966 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) |
| 966 .WillRepeatedly(Return(false)); | 967 .WillRepeatedly(Return(false)); |
| 967 | 968 |
| 968 // This should display the sync setup dialog (not login). | 969 // This should display the sync setup dialog (not login). |
| 969 handler_->OpenSyncSetup(); | 970 handler_->OpenSyncSetup(nullptr); |
| 970 | 971 |
| 971 ExpectConfig(); | 972 ExpectConfig(); |
| 972 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; | 973 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; |
| 973 const base::DictionaryValue* dictionary = nullptr; | 974 const base::DictionaryValue* dictionary = nullptr; |
| 974 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); | 975 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); |
| 975 CheckBool(dictionary, "encryptAllData", false); | 976 CheckBool(dictionary, "encryptAllData", false); |
| 976 CheckBool(dictionary, "encryptAllDataAllowed", false); | 977 CheckBool(dictionary, "encryptAllDataAllowed", false); |
| 977 } | 978 } |
| 978 | 979 |
| 979 TEST_F(SyncHandlerTest, TurnOnEncryptAllDisallowed) { | 980 TEST_F(SyncHandlerTest, TurnOnEncryptAllDisallowed) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 991 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); | 992 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); |
| 992 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); | 993 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); |
| 993 handler_->HandleConfigure(&list_args); | 994 handler_->HandleConfigure(&list_args); |
| 994 | 995 |
| 995 // Ensure that we navigated to the "done" state since we don't need a | 996 // Ensure that we navigated to the "done" state since we don't need a |
| 996 // passphrase. | 997 // passphrase. |
| 997 ExpectDone(); | 998 ExpectDone(); |
| 998 } | 999 } |
| 999 | 1000 |
| 1000 } // namespace settings | 1001 } // namespace settings |
| OLD | NEW |