Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1191)

Side by Side Diff: components/browser_sync/browser/profile_sync_service_unittest.cc

Issue 2226063002: Add a ScopedFeatureList class for testing and start using it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issue in previous patchset. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/profile_sync_service.h" 5 #include "components/browser_sync/browser/profile_sync_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/feature_list.h" 14 #include "base/feature_list.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/scoped_feature_list.h"
20 #include "base/test/sequenced_worker_pool_owner.h" 21 #include "base/test/sequenced_worker_pool_owner.h"
21 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/values.h" 23 #include "base/values.h"
23 #include "build/build_config.h" 24 #include "build/build_config.h"
24 #include "components/browser_sync/browser/profile_sync_test_util.h" 25 #include "components/browser_sync/browser/profile_sync_test_util.h"
25 #include "components/browser_sync/common/browser_sync_switches.h" 26 #include "components/browser_sync/common/browser_sync_switches.h"
26 #include "components/invalidation/impl/profile_invalidation_provider.h" 27 #include "components/invalidation/impl/profile_invalidation_provider.h"
27 #include "components/invalidation/public/invalidation_service.h" 28 #include "components/invalidation/public/invalidation_service.h"
28 #include "components/signin/core/browser/account_tracker_service.h" 29 #include "components/signin/core/browser/account_tracker_service.h"
29 #include "components/signin/core/browser/fake_signin_manager.h" 30 #include "components/signin/core/browser/fake_signin_manager.h"
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 // Verify memory pressure and shutdown recorded. 720 // Verify memory pressure and shutdown recorded.
720 EXPECT_EQ( 721 EXPECT_EQ(
721 prefs()->GetInteger(sync_driver::prefs::kSyncMemoryPressureWarningCount), 722 prefs()->GetInteger(sync_driver::prefs::kSyncMemoryPressureWarningCount),
722 2); 723 2);
723 EXPECT_TRUE(sync_prefs.DidSyncShutdownCleanly()); 724 EXPECT_TRUE(sync_prefs.DidSyncShutdownCleanly());
724 } 725 }
725 726
726 // Verify that OnLocalSetPassphraseEncryption triggers catch up configure sync 727 // Verify that OnLocalSetPassphraseEncryption triggers catch up configure sync
727 // cycle, calls ClearServerData, shuts down and restarts sync. 728 // cycle, calls ClearServerData, shuts down and restarts sync.
728 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { 729 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) {
729 base::FeatureList::ClearInstanceForTesting(); 730 base::test::ScopedFeatureList scoped_feature_list;
730 ASSERT_TRUE(base::FeatureList::InitializeInstance( 731 scoped_feature_list.InitAndEnableFeature(
731 switches::kSyncClearDataOnPassphraseEncryption.name, std::string())); 732 switches::kSyncClearDataOnPassphraseEncryption);
732 IssueTestTokens(); 733 IssueTestTokens();
733 CreateService(ProfileSyncService::AUTO_START); 734 CreateService(ProfileSyncService::AUTO_START);
734 735
735 syncer::SyncManager::ClearServerDataCallback captured_callback; 736 syncer::SyncManager::ClearServerDataCallback captured_callback;
736 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 737 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
737 738
738 // Initialize sync, ensure that both DataTypeManager and SyncBackendHost are 739 // Initialize sync, ensure that both DataTypeManager and SyncBackendHost are
739 // initialized and DTM::Configure is called with 740 // initialized and DTM::Configure is called with
740 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE. 741 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE.
741 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); 742 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback);
(...skipping 29 matching lines...) Expand all
771 testing::Mock::VerifyAndClearExpectations(component_factory()); 772 testing::Mock::VerifyAndClearExpectations(component_factory());
772 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 773 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
773 service()->OnConfigureDone(result); 774 service()->OnConfigureDone(result);
774 } 775 }
775 776
776 // Verify that if after OnLocalSetPassphraseEncryption catch up configure sync 777 // Verify that if after OnLocalSetPassphraseEncryption catch up configure sync
777 // cycle gets interrupted, it starts again after browser restart. 778 // cycle gets interrupted, it starts again after browser restart.
778 TEST_F(ProfileSyncServiceTest, 779 TEST_F(ProfileSyncServiceTest,
779 OnLocalSetPassphraseEncryption_RestartDuringCatchUp) { 780 OnLocalSetPassphraseEncryption_RestartDuringCatchUp) {
780 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 781 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
781 base::FeatureList::ClearInstanceForTesting(); 782 base::test::ScopedFeatureList scoped_feature_list;
782 ASSERT_TRUE(base::FeatureList::InitializeInstance( 783 scoped_feature_list.InitAndEnableFeature(
783 switches::kSyncClearDataOnPassphraseEncryption.name, std::string())); 784 switches::kSyncClearDataOnPassphraseEncryption);
784 IssueTestTokens(); 785 IssueTestTokens();
785 CreateService(ProfileSyncService::AUTO_START); 786 CreateService(ProfileSyncService::AUTO_START);
786 ExpectSyncBackendHostCreation(1); 787 ExpectSyncBackendHostCreation(1);
787 ExpectDataTypeManagerCreation( 788 ExpectDataTypeManagerCreation(
788 1, GetRecordingConfigureCalledCallback(&configure_reason)); 789 1, GetRecordingConfigureCalledCallback(&configure_reason));
789 InitializeForNthSync(); 790 InitializeForNthSync();
790 testing::Mock::VerifyAndClearExpectations(component_factory()); 791 testing::Mock::VerifyAndClearExpectations(component_factory());
791 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 792 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
792 sync_driver::DataTypeManager::ConfigureResult result; 793 sync_driver::DataTypeManager::ConfigureResult result;
793 result.status = sync_driver::DataTypeManager::OK; 794 result.status = sync_driver::DataTypeManager::OK;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 testing::Mock::VerifyAndClearExpectations(component_factory()); 828 testing::Mock::VerifyAndClearExpectations(component_factory());
828 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 829 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
829 } 830 }
830 831
831 // Verify that if after OnLocalSetPassphraseEncryption ClearServerData gets 832 // Verify that if after OnLocalSetPassphraseEncryption ClearServerData gets
832 // interrupted, transition again from catch up sync cycle after browser restart. 833 // interrupted, transition again from catch up sync cycle after browser restart.
833 TEST_F(ProfileSyncServiceTest, 834 TEST_F(ProfileSyncServiceTest,
834 OnLocalSetPassphraseEncryption_RestartDuringClearServerData) { 835 OnLocalSetPassphraseEncryption_RestartDuringClearServerData) {
835 syncer::SyncManager::ClearServerDataCallback captured_callback; 836 syncer::SyncManager::ClearServerDataCallback captured_callback;
836 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 837 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
837 base::FeatureList::ClearInstanceForTesting(); 838 base::test::ScopedFeatureList scoped_feature_list;
838 ASSERT_TRUE(base::FeatureList::InitializeInstance( 839 scoped_feature_list.InitAndEnableFeature(
839 switches::kSyncClearDataOnPassphraseEncryption.name, std::string())); 840 switches::kSyncClearDataOnPassphraseEncryption);
840 IssueTestTokens(); 841 IssueTestTokens();
841 CreateService(ProfileSyncService::AUTO_START); 842 CreateService(ProfileSyncService::AUTO_START);
842 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback); 843 ExpectSyncBackendHostCreationCaptureClearServerData(&captured_callback);
843 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 844 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
844 InitializeForNthSync(); 845 InitializeForNthSync();
845 testing::Mock::VerifyAndClearExpectations(component_factory()); 846 testing::Mock::VerifyAndClearExpectations(component_factory());
846 847
847 // Simulate user entering encryption passphrase. 848 // Simulate user entering encryption passphrase.
848 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 849 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
849 service()->OnLocalSetPassphraseEncryption(nigori_state); 850 service()->OnLocalSetPassphraseEncryption(nigori_state);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if 965 // dereferenced in OnSyncCycleCompleted. The fix is to use find() to check if
965 // entry for sessions exists in map. 966 // entry for sessions exists in map.
966 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) { 967 TEST_F(ProfileSyncServiceTest, ValidPointersInDTCMap) {
967 CreateService(ProfileSyncService::AUTO_START); 968 CreateService(ProfileSyncService::AUTO_START);
968 service()->OnSessionRestoreComplete(); 969 service()->OnSessionRestoreComplete();
969 service()->OnSyncCycleCompleted(); 970 service()->OnSyncCycleCompleted();
970 } 971 }
971 972
972 } // namespace 973 } // namespace
973 } // namespace browser_sync 974 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/autofill/core/browser/personal_data_manager_unittest.cc ('k') | components/flags_ui/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698