Commit 24ab870c authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Use syncer::TestSyncService in UserEventServiceImplTest

One less custom subclass of FakeSyncService :)

Bug: 859874
Change-Id: Idfafda6dcb3ab705a6c6410d27dd4087b0d91699
Reviewed-on: https://chromium-review.googlesource.com/c/1318979
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarvitaliii <vitaliii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606398}
parent 74ea7417
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
#include "components/sync/driver/fake_sync_service.h"
#include "components/sync/driver/sync_driver_switches.h" #include "components/sync/driver/sync_driver_switches.h"
#include "components/sync/driver/test_sync_service.h"
#include "components/sync/model/mock_model_type_change_processor.h" #include "components/sync/model/mock_model_type_change_processor.h"
#include "components/sync/model/model_type_store_test_util.h" #include "components/sync/model/model_type_store_test_util.h"
#include "components/sync/protocol/sync.pb.h" #include "components/sync/protocol/sync.pb.h"
...@@ -70,35 +70,6 @@ MATCHER_P(HasFieldTrialVariationIds, expected_variation_id, "") { ...@@ -70,35 +70,6 @@ MATCHER_P(HasFieldTrialVariationIds, expected_variation_id, "") {
expected_variation_id; expected_variation_id;
} }
// TODO(vitaliii): Merge this into FakeSyncService and use it instead.
class TestSyncService : public FakeSyncService {
public:
TestSyncService(bool is_engine_initialized,
bool is_using_secondary_passphrase,
ModelTypeSet preferred_data_types)
: is_engine_initialized_(is_engine_initialized),
is_using_secondary_passphrase_(is_using_secondary_passphrase),
preferred_data_types_(preferred_data_types) {}
TransportState GetTransportState() const override {
return is_engine_initialized_ ? TransportState::ACTIVE
: TransportState::INITIALIZING;
}
bool IsUsingSecondaryPassphrase() const override {
return is_using_secondary_passphrase_;
}
ModelTypeSet GetPreferredDataTypes() const override {
return preferred_data_types_;
}
private:
bool is_engine_initialized_;
bool is_using_secondary_passphrase_;
ModelTypeSet preferred_data_types_;
};
class TestGlobalIdMapper : public GlobalIdMapper { class TestGlobalIdMapper : public GlobalIdMapper {
void AddGlobalIdChangeObserver(GlobalIdChange callback) override {} void AddGlobalIdChangeObserver(GlobalIdChange callback) override {}
int64_t GetLatestGlobalId(int64_t global_id) override { return global_id; } int64_t GetLatestGlobalId(int64_t global_id) override { return global_id; }
...@@ -106,9 +77,8 @@ class TestGlobalIdMapper : public GlobalIdMapper { ...@@ -106,9 +77,8 @@ class TestGlobalIdMapper : public GlobalIdMapper {
class UserEventServiceImplTest : public testing::Test { class UserEventServiceImplTest : public testing::Test {
protected: protected:
UserEventServiceImplTest() UserEventServiceImplTest() : field_trial_list_(nullptr) {
: field_trial_list_(nullptr), sync_service_.SetPreferredDataTypes({HISTORY_DELETE_DIRECTIVES});
sync_service_(true, false, {HISTORY_DELETE_DIRECTIVES}) {
ON_CALL(mock_processor_, IsTrackingMetadata()) ON_CALL(mock_processor_, IsTrackingMetadata())
.WillByDefault(testing::Return(true)); .WillByDefault(testing::Return(true));
} }
...@@ -124,13 +94,13 @@ class UserEventServiceImplTest : public testing::Test { ...@@ -124,13 +94,13 @@ class UserEventServiceImplTest : public testing::Test {
new_value); new_value);
} }
TestSyncService* sync_service() { return &sync_service_; } syncer::TestSyncService* sync_service() { return &sync_service_; }
MockModelTypeChangeProcessor* mock_processor() { return &mock_processor_; } MockModelTypeChangeProcessor* mock_processor() { return &mock_processor_; }
private: private:
base::MessageLoop message_loop_; base::MessageLoop message_loop_;
base::FieldTrialList field_trial_list_; base::FieldTrialList field_trial_list_;
TestSyncService sync_service_; syncer::TestSyncService sync_service_;
testing::NiceMock<MockModelTypeChangeProcessor> mock_processor_; testing::NiceMock<MockModelTypeChangeProcessor> mock_processor_;
TestGlobalIdMapper mapper_; TestGlobalIdMapper mapper_;
...@@ -164,8 +134,8 @@ TEST_F(UserEventServiceImplTest, ShouldRecord) { ...@@ -164,8 +134,8 @@ TEST_F(UserEventServiceImplTest, ShouldRecord) {
TEST_F(UserEventServiceImplTest, ShouldRecordNoHistory) { TEST_F(UserEventServiceImplTest, ShouldRecordNoHistory) {
SetIsSeparateConsentTypeEnabledFeature(false); SetIsSeparateConsentTypeEnabledFeature(false);
TestSyncService no_history_sync_service(true, false, ModelTypeSet()); sync_service()->SetPreferredDataTypes({});
UserEventServiceImpl service(&no_history_sync_service, MakeBridge()); UserEventServiceImpl service(sync_service(), MakeBridge());
// Only record events without navigation ids when history sync is off. // Only record events without navigation ids when history sync is off.
EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0); EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0);
...@@ -177,8 +147,8 @@ TEST_F(UserEventServiceImplTest, ShouldRecordNoHistory) { ...@@ -177,8 +147,8 @@ TEST_F(UserEventServiceImplTest, ShouldRecordNoHistory) {
TEST_F(UserEventServiceImplTest, ShouldRecordUserConsentNoHistory) { TEST_F(UserEventServiceImplTest, ShouldRecordUserConsentNoHistory) {
SetIsSeparateConsentTypeEnabledFeature(false); SetIsSeparateConsentTypeEnabledFeature(false);
TestSyncService no_history_sync_service(true, false, ModelTypeSet()); sync_service()->SetPreferredDataTypes({});
UserEventServiceImpl service(&no_history_sync_service, MakeBridge()); UserEventServiceImpl service(sync_service(), MakeBridge());
// UserConsent recording doesn't need history sync to be enabled. // UserConsent recording doesn't need history sync to be enabled.
EXPECT_CALL(*mock_processor(), Put(_, _, _)); EXPECT_CALL(*mock_processor(), Put(_, _, _));
...@@ -188,9 +158,8 @@ TEST_F(UserEventServiceImplTest, ShouldRecordUserConsentNoHistory) { ...@@ -188,9 +158,8 @@ TEST_F(UserEventServiceImplTest, ShouldRecordUserConsentNoHistory) {
TEST_F(UserEventServiceImplTest, ShouldRecordPassphrase) { TEST_F(UserEventServiceImplTest, ShouldRecordPassphrase) {
SetIsSeparateConsentTypeEnabledFeature(false); SetIsSeparateConsentTypeEnabledFeature(false);
TestSyncService passphrase_sync_service(true, true, sync_service()->SetIsUsingSecondaryPassphrase(true);
{HISTORY_DELETE_DIRECTIVES}); UserEventServiceImpl service(sync_service(), MakeBridge());
UserEventServiceImpl service(&passphrase_sync_service, MakeBridge());
// Only record events without navigation ids when a passphrase is used. // Only record events without navigation ids when a passphrase is used.
EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0); EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0);
...@@ -203,10 +172,9 @@ TEST_F(UserEventServiceImplTest, ShouldRecordPassphrase) { ...@@ -203,10 +172,9 @@ TEST_F(UserEventServiceImplTest, ShouldRecordPassphrase) {
TEST_F(UserEventServiceImplTest, ShouldRecordEngineOff) { TEST_F(UserEventServiceImplTest, ShouldRecordEngineOff) {
SetIsSeparateConsentTypeEnabledFeature(false); SetIsSeparateConsentTypeEnabledFeature(false);
TestSyncService engine_not_initialized_sync_service( sync_service()->SetTransportState(
false, false, {HISTORY_DELETE_DIRECTIVES}); syncer::SyncService::TransportState::INITIALIZING);
UserEventServiceImpl service(&engine_not_initialized_sync_service, UserEventServiceImpl service(sync_service(), MakeBridge());
MakeBridge());
// Only record events without navigation ids when the engine is off. // Only record events without navigation ids when the engine is off.
EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0); EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0);
...@@ -288,12 +256,9 @@ TEST_F( ...@@ -288,12 +256,9 @@ TEST_F(
WithConsentsTypeShouldRecordWhenBothHistoryAndEventsDatatypesAreEnabled) { WithConsentsTypeShouldRecordWhenBothHistoryAndEventsDatatypesAreEnabled) {
SetIsSeparateConsentTypeEnabledFeature(true); SetIsSeparateConsentTypeEnabledFeature(true);
TestSyncService sync_service( sync_service()->SetPreferredDataTypes(
/*is_engine_initialized=*/true, {HISTORY_DELETE_DIRECTIVES, USER_EVENTS});
/*is_using_secondary_passphrase=*/false, UserEventServiceImpl service(sync_service(), MakeBridge());
/*preferred_data_types=*/{HISTORY_DELETE_DIRECTIVES, USER_EVENTS});
UserEventServiceImpl service(&sync_service, MakeBridge());
EXPECT_CALL(*mock_processor(), Put(_, _, _)); EXPECT_CALL(*mock_processor(), Put(_, _, _));
service.RecordUserEvent(AsTest(Event())); service.RecordUserEvent(AsTest(Event()));
} }
...@@ -302,12 +267,7 @@ TEST_F(UserEventServiceImplTest, ...@@ -302,12 +267,7 @@ TEST_F(UserEventServiceImplTest,
WithConsentsTypeShouldNotRecordWhenEventsDatatypeIsDisabled) { WithConsentsTypeShouldNotRecordWhenEventsDatatypeIsDisabled) {
SetIsSeparateConsentTypeEnabledFeature(true); SetIsSeparateConsentTypeEnabledFeature(true);
TestSyncService sync_service( UserEventServiceImpl service(sync_service(), MakeBridge());
/*is_engine_initialized=*/true,
/*is_using_secondary_passphrase=*/false,
/*preferred_data_types=*/{HISTORY_DELETE_DIRECTIVES});
UserEventServiceImpl service(&sync_service, MakeBridge());
// USER_EVENTS type is disabled, thus, they should not be recorded. // USER_EVENTS type is disabled, thus, they should not be recorded.
EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0); EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0);
service.RecordUserEvent(AsTest(Event())); service.RecordUserEvent(AsTest(Event()));
...@@ -317,12 +277,8 @@ TEST_F(UserEventServiceImplTest, ...@@ -317,12 +277,8 @@ TEST_F(UserEventServiceImplTest,
WithConsentsTypeShouldNotRecordWhenHistoryDatatypeIsDisabled) { WithConsentsTypeShouldNotRecordWhenHistoryDatatypeIsDisabled) {
SetIsSeparateConsentTypeEnabledFeature(true); SetIsSeparateConsentTypeEnabledFeature(true);
TestSyncService sync_service( sync_service()->SetPreferredDataTypes({USER_EVENTS});
/*is_engine_initialized=*/true, UserEventServiceImpl service(sync_service(), MakeBridge());
/*is_using_secondary_passphrase=*/false,
/*preferred_data_types=*/{USER_EVENTS});
UserEventServiceImpl service(&sync_service, MakeBridge());
// Even though USER_EVENTS type is enabled, events cannot be recorded when // Even though USER_EVENTS type is enabled, events cannot be recorded when
// history sync is disabled. // history sync is disabled.
EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0); EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0);
...@@ -334,12 +290,11 @@ TEST_F(UserEventServiceImplTest, ...@@ -334,12 +290,11 @@ TEST_F(UserEventServiceImplTest,
WithConsentsTypeShouldNotRecordWhenEngineIsNotInitialized) { WithConsentsTypeShouldNotRecordWhenEngineIsNotInitialized) {
SetIsSeparateConsentTypeEnabledFeature(true); SetIsSeparateConsentTypeEnabledFeature(true);
TestSyncService sync_service( sync_service()->SetPreferredDataTypes(
/*is_engine_initialized=*/false, {HISTORY_DELETE_DIRECTIVES, USER_EVENTS});
/*is_using_secondary_passphrase=*/false, sync_service()->SetTransportState(
/*preferred_data_types=*/{HISTORY_DELETE_DIRECTIVES, USER_EVENTS}); syncer::SyncService::TransportState::INITIALIZING);
UserEventServiceImpl service(sync_service(), MakeBridge());
UserEventServiceImpl service(&sync_service, MakeBridge());
// Even though USER_EVENTS type is enabled, events cannot be recorded because // Even though USER_EVENTS type is enabled, events cannot be recorded because
// we can't trust uninitialized engine. // we can't trust uninitialized engine.
EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0); EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0);
...@@ -350,12 +305,10 @@ TEST_F(UserEventServiceImplTest, ...@@ -350,12 +305,10 @@ TEST_F(UserEventServiceImplTest,
WithConsentsTypeShouldNotRecordWhenPassphraseIsUsed) { WithConsentsTypeShouldNotRecordWhenPassphraseIsUsed) {
SetIsSeparateConsentTypeEnabledFeature(true); SetIsSeparateConsentTypeEnabledFeature(true);
TestSyncService sync_service( sync_service()->SetPreferredDataTypes(
/*is_engine_initialized=*/true, {HISTORY_DELETE_DIRECTIVES, USER_EVENTS});
/*is_using_secondary_passphrase=*/true, sync_service()->SetIsUsingSecondaryPassphrase(true);
/*preferred_data_types=*/{HISTORY_DELETE_DIRECTIVES, USER_EVENTS}); UserEventServiceImpl service(sync_service(), MakeBridge());
UserEventServiceImpl service(&sync_service, MakeBridge());
// Even though USER_EVENTS type is enabled, events cannot be recorded // Even though USER_EVENTS type is enabled, events cannot be recorded
// because custom passphrase is used. // because custom passphrase is used.
EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0); EXPECT_CALL(*mock_processor(), Put(_, _, _)).Times(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment