| 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 "components/browser_sync/profile_sync_service.h" | 5 #include "components/browser_sync/profile_sync_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "components/sync/engine/fake_sync_engine.h" | 34 #include "components/sync/engine/fake_sync_engine.h" |
| 35 #include "components/sync_preferences/testing_pref_service_syncable.h" | 35 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 36 #include "components/version_info/version_info_values.h" | 36 #include "components/version_info/version_info_values.h" |
| 37 #include "google_apis/gaia/gaia_constants.h" | 37 #include "google_apis/gaia/gaia_constants.h" |
| 38 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 41 | 41 |
| 42 using syncer::DataTypeController; | 42 using syncer::DataTypeController; |
| 43 using syncer::FakeSyncEngine; | 43 using syncer::FakeSyncEngine; |
| 44 using syncer::ModelTypeSet; |
| 44 using syncer::SyncMergeResult; | 45 using syncer::SyncMergeResult; |
| 45 using testing::Return; | 46 using testing::Return; |
| 46 | 47 |
| 47 namespace browser_sync { | 48 namespace browser_sync { |
| 48 | 49 |
| 49 namespace { | 50 namespace { |
| 50 | 51 |
| 51 const char kGaiaId[] = "12345"; | 52 const char kGaiaId[] = "12345"; |
| 52 const char kEmail[] = "test_user@gmail.com"; | 53 const char kEmail[] = "test_user@gmail.com"; |
| 53 | 54 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 syncer::ConfigureReason reason) override { | 65 syncer::ConfigureReason reason) override { |
| 65 DCHECK(!configure_called_.is_null()); | 66 DCHECK(!configure_called_.is_null()); |
| 66 configure_called_.Run(reason); | 67 configure_called_.Run(reason); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void ReenableType(syncer::ModelType type) override {} | 70 void ReenableType(syncer::ModelType type) override {} |
| 70 void ResetDataTypeErrors() override {} | 71 void ResetDataTypeErrors() override {} |
| 71 void PurgeForMigration(syncer::ModelTypeSet undesired_types, | 72 void PurgeForMigration(syncer::ModelTypeSet undesired_types, |
| 72 syncer::ConfigureReason reason) override {} | 73 syncer::ConfigureReason reason) override {} |
| 73 void Stop() override{}; | 74 void Stop() override{}; |
| 74 State state() const override { return syncer::DataTypeManager::CONFIGURED; }; | 75 ModelTypeSet GetActiveDataTypes() const override { return ModelTypeSet(); } |
| 76 State state() const override { return syncer::DataTypeManager::CONFIGURED; } |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 ConfigureCalled configure_called_; | 79 ConfigureCalled configure_called_; |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 ACTION_P(ReturnNewDataTypeManager, configure_called) { | 82 ACTION_P(ReturnNewDataTypeManager, configure_called) { |
| 81 return new FakeDataTypeManager(configure_called); | 83 return new FakeDataTypeManager(configure_called); |
| 82 } | 84 } |
| 83 | 85 |
| 84 using testing::Return; | 86 using testing::Return; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 sync_pb::EncryptedData()); | 254 sync_pb::EncryptedData()); |
| 253 } | 255 } |
| 254 | 256 |
| 255 void TriggerDataTypeStartRequest() { | 257 void TriggerDataTypeStartRequest() { |
| 256 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS); | 258 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS); |
| 257 } | 259 } |
| 258 | 260 |
| 259 void OnConfigureCalled(syncer::ConfigureReason configure_reason) { | 261 void OnConfigureCalled(syncer::ConfigureReason configure_reason) { |
| 260 syncer::DataTypeManager::ConfigureResult result; | 262 syncer::DataTypeManager::ConfigureResult result; |
| 261 result.status = syncer::DataTypeManager::OK; | 263 result.status = syncer::DataTypeManager::OK; |
| 264 if (configure_reason == syncer::CONFIGURE_REASON_CATCH_UP) |
| 265 result.was_catch_up_configure = true; |
| 262 service()->OnConfigureDone(result); | 266 service()->OnConfigureDone(result); |
| 263 } | 267 } |
| 264 | 268 |
| 265 FakeDataTypeManager::ConfigureCalled GetDefaultConfigureCalledCallback() { | 269 FakeDataTypeManager::ConfigureCalled GetDefaultConfigureCalledCallback() { |
| 266 return base::Bind(&ProfileSyncServiceTest::OnConfigureCalled, | 270 return base::Bind(&ProfileSyncServiceTest::OnConfigureCalled, |
| 267 base::Unretained(this)); | 271 base::Unretained(this)); |
| 268 } | 272 } |
| 269 | 273 |
| 270 void OnConfigureCalledRecordReason(syncer::ConfigureReason* reason_dest, | 274 void OnConfigureCalledRecordReason(syncer::ConfigureReason* reason_dest, |
| 271 syncer::ConfigureReason reason) { | 275 syncer::ConfigureReason reason) { |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 731 |
| 728 // Simulate user entering encryption passphrase. Ensure that catch up | 732 // Simulate user entering encryption passphrase. Ensure that catch up |
| 729 // configure cycle is started (DTM::Configure is called with | 733 // configure cycle is started (DTM::Configure is called with |
| 730 // CONFIGURE_REASON_CATCH_UP). | 734 // CONFIGURE_REASON_CATCH_UP). |
| 731 const syncer::SyncEncryptionHandler::NigoriState nigori_state; | 735 const syncer::SyncEncryptionHandler::NigoriState nigori_state; |
| 732 service()->OnLocalSetPassphraseEncryption(nigori_state); | 736 service()->OnLocalSetPassphraseEncryption(nigori_state); |
| 733 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); | 737 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); |
| 734 EXPECT_TRUE(captured_callback.is_null()); | 738 EXPECT_TRUE(captured_callback.is_null()); |
| 735 | 739 |
| 736 // Simulate configure successful. Ensure that SBH::ClearServerData is called. | 740 // Simulate configure successful. Ensure that SBH::ClearServerData is called. |
| 741 result.was_catch_up_configure = true; |
| 737 service()->OnConfigureDone(result); | 742 service()->OnConfigureDone(result); |
| 743 result.was_catch_up_configure = false; |
| 738 EXPECT_FALSE(captured_callback.is_null()); | 744 EXPECT_FALSE(captured_callback.is_null()); |
| 739 | 745 |
| 740 // Once SBH::ClearServerData finishes successfully ensure that sync is | 746 // Once SBH::ClearServerData finishes successfully ensure that sync is |
| 741 // restarted. | 747 // restarted. |
| 742 configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; | 748 configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; |
| 743 ExpectSyncEngineCreation(1); | 749 ExpectSyncEngineCreation(1); |
| 744 ExpectDataTypeManagerCreation( | 750 ExpectDataTypeManagerCreation( |
| 745 1, GetRecordingConfigureCalledCallback(&configure_reason)); | 751 1, GetRecordingConfigureCalledCallback(&configure_reason)); |
| 746 captured_callback.Run(); | 752 captured_callback.Run(); |
| 747 testing::Mock::VerifyAndClearExpectations(component_factory()); | 753 testing::Mock::VerifyAndClearExpectations(component_factory()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | 792 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); |
| 787 EXPECT_TRUE(captured_callback.is_null()); | 793 EXPECT_TRUE(captured_callback.is_null()); |
| 788 | 794 |
| 789 // Simulate configure successful. This time it should be catch up. | 795 // Simulate configure successful. This time it should be catch up. |
| 790 service()->OnConfigureDone(result); | 796 service()->OnConfigureDone(result); |
| 791 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); | 797 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); |
| 792 EXPECT_TRUE(captured_callback.is_null()); | 798 EXPECT_TRUE(captured_callback.is_null()); |
| 793 | 799 |
| 794 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is | 800 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is |
| 795 // called. | 801 // called. |
| 802 result.was_catch_up_configure = true; |
| 796 service()->OnConfigureDone(result); | 803 service()->OnConfigureDone(result); |
| 804 result.was_catch_up_configure = false; |
| 797 EXPECT_FALSE(captured_callback.is_null()); | 805 EXPECT_FALSE(captured_callback.is_null()); |
| 798 | 806 |
| 799 ExpectSyncEngineCreation(1); | 807 ExpectSyncEngineCreation(1); |
| 800 ExpectDataTypeManagerCreation( | 808 ExpectDataTypeManagerCreation( |
| 801 1, GetRecordingConfigureCalledCallback(&configure_reason)); | 809 1, GetRecordingConfigureCalledCallback(&configure_reason)); |
| 802 captured_callback.Run(); | 810 captured_callback.Run(); |
| 803 testing::Mock::VerifyAndClearExpectations(component_factory()); | 811 testing::Mock::VerifyAndClearExpectations(component_factory()); |
| 804 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | 812 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); |
| 805 } | 813 } |
| 806 | 814 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 846 |
| 839 // Simulate configure successful. This time it should be catch up. | 847 // Simulate configure successful. This time it should be catch up. |
| 840 syncer::DataTypeManager::ConfigureResult result; | 848 syncer::DataTypeManager::ConfigureResult result; |
| 841 result.status = syncer::DataTypeManager::OK; | 849 result.status = syncer::DataTypeManager::OK; |
| 842 service()->OnConfigureDone(result); | 850 service()->OnConfigureDone(result); |
| 843 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); | 851 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); |
| 844 EXPECT_TRUE(captured_callback.is_null()); | 852 EXPECT_TRUE(captured_callback.is_null()); |
| 845 | 853 |
| 846 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is | 854 // Simulate catch up configure successful. Ensure that SBH::ClearServerData is |
| 847 // called. | 855 // called. |
| 856 result.was_catch_up_configure = true; |
| 848 service()->OnConfigureDone(result); | 857 service()->OnConfigureDone(result); |
| 858 result.was_catch_up_configure = false; |
| 849 EXPECT_FALSE(captured_callback.is_null()); | 859 EXPECT_FALSE(captured_callback.is_null()); |
| 850 | 860 |
| 851 ExpectSyncEngineCreation(1); | 861 ExpectSyncEngineCreation(1); |
| 852 ExpectDataTypeManagerCreation( | 862 ExpectDataTypeManagerCreation( |
| 853 1, GetRecordingConfigureCalledCallback(&configure_reason)); | 863 1, GetRecordingConfigureCalledCallback(&configure_reason)); |
| 854 captured_callback.Run(); | 864 captured_callback.Run(); |
| 855 testing::Mock::VerifyAndClearExpectations(component_factory()); | 865 testing::Mock::VerifyAndClearExpectations(component_factory()); |
| 856 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); | 866 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); |
| 857 } | 867 } |
| 858 | 868 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 // Progress the controller to RUNNING first, which is how the service | 965 // Progress the controller to RUNNING first, which is how the service |
| 956 // determines whether a type is enabled. | 966 // determines whether a type is enabled. |
| 957 controller->StartAssociating(base::Bind(&DoNothing)); | 967 controller->StartAssociating(base::Bind(&DoNothing)); |
| 958 controller->FinishStart(DataTypeController::OK_FIRST_RUN); | 968 controller->FinishStart(DataTypeController::OK_FIRST_RUN); |
| 959 service()->RegisterDataTypeController(std::move(controller)); | 969 service()->RegisterDataTypeController(std::move(controller)); |
| 960 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate()); | 970 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate()); |
| 961 } | 971 } |
| 962 | 972 |
| 963 } // namespace | 973 } // namespace |
| 964 } // namespace browser_sync | 974 } // namespace browser_sync |
| OLD | NEW |