Commit 01d07ebf authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

SuggestionsServiceImplTest: Use syncer::TestSyncService

instead of defining a custom MockSyncService that isn't used as a mock.

Bug: 859874
Change-Id: If1458426ff77a666a2be0dc08513a87b26ad76b0
Reviewed-on: https://chromium-review.googlesource.com/c/1322710Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606063}
parent ff6da4e1
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#include "components/suggestions/image_manager.h" #include "components/suggestions/image_manager.h"
#include "components/suggestions/proto/suggestions.pb.h" #include "components/suggestions/proto/suggestions.pb.h"
#include "components/suggestions/suggestions_store.h" #include "components/suggestions/suggestions_store.h"
#include "components/sync/driver/fake_sync_service.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
#include "components/sync/driver/test_sync_service.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
...@@ -84,19 +84,6 @@ SuggestionsProfile CreateSuggestionsProfile() { ...@@ -84,19 +84,6 @@ SuggestionsProfile CreateSuggestionsProfile() {
return profile; return profile;
} }
class MockSyncService : public syncer::FakeSyncService {
public:
MockSyncService() {}
~MockSyncService() override {}
MOCK_CONST_METHOD0(GetDisableReasons, int());
MOCK_CONST_METHOD0(GetTransportState, TransportState());
MOCK_CONST_METHOD0(IsLocalSyncEnabled, bool());
MOCK_CONST_METHOD0(IsUsingSecondaryPassphrase, bool());
MOCK_CONST_METHOD0(GetPreferredDataTypes, syncer::ModelTypeSet());
MOCK_CONST_METHOD0(GetActiveDataTypes, syncer::ModelTypeSet());
MOCK_CONST_METHOD0(GetLastCycleSnapshot, syncer::SyncCycleSnapshot());
};
class TestSuggestionsStore : public suggestions::SuggestionsStore { class TestSuggestionsStore : public suggestions::SuggestionsStore {
public: public:
TestSuggestionsStore() { cached_suggestions = CreateSuggestionsProfile(); } TestSuggestionsStore() { cached_suggestions = CreateSuggestionsProfile(); }
...@@ -150,44 +137,16 @@ class SuggestionsServiceTest : public testing::Test { ...@@ -150,44 +137,16 @@ class SuggestionsServiceTest : public testing::Test {
~SuggestionsServiceTest() override {} ~SuggestionsServiceTest() override {}
void SetUp() override { void SetUp() override {
EXPECT_CALL(*sync_service(), GetDisableReasons()) sync_service()->SetPreferredDataTypes({syncer::HISTORY_DELETE_DIRECTIVES});
.Times(AnyNumber()) sync_service()->SetActiveDataTypes({syncer::HISTORY_DELETE_DIRECTIVES});
.WillRepeatedly(Return(syncer::SyncService::DISABLE_REASON_NONE));
EXPECT_CALL(*sync_service(), GetTransportState())
.Times(AnyNumber())
.WillRepeatedly(Return(syncer::SyncService::TransportState::ACTIVE));
EXPECT_CALL(*sync_service(), IsLocalSyncEnabled())
.Times(AnyNumber())
.WillRepeatedly(Return(false));
EXPECT_CALL(*sync_service(), IsUsingSecondaryPassphrase())
.Times(AnyNumber())
.WillRepeatedly(Return(false));
EXPECT_CALL(*sync_service(), GetPreferredDataTypes())
.Times(AnyNumber())
.WillRepeatedly(
Return(syncer::ModelTypeSet(syncer::HISTORY_DELETE_DIRECTIVES)));
EXPECT_CALL(*sync_service(), GetActiveDataTypes())
.Times(AnyNumber())
.WillRepeatedly(
Return(syncer::ModelTypeSet(syncer::HISTORY_DELETE_DIRECTIVES)));
EXPECT_CALL(*sync_service(), GetLastCycleSnapshot())
.Times(AnyNumber())
.WillRepeatedly(Return(syncer::SyncCycleSnapshot(
syncer::ModelNeutralState(), syncer::ProgressMarkerMap(), false, 5,
2, 7, false, 0, base::Time::Now(), base::Time::Now(),
std::vector<int>(syncer::MODEL_TYPE_COUNT, 0),
std::vector<int>(syncer::MODEL_TYPE_COUNT, 0),
sync_pb::SyncEnums::UNKNOWN_ORIGIN,
/*short_poll_interval=*/base::TimeDelta::FromMinutes(30),
/*long_poll_interval=*/base::TimeDelta::FromMinutes(180),
/*has_remaining_local_changes=*/false)));
// These objects are owned by the SuggestionsService, but we keep the // These objects are owned by the SuggestionsService, but we keep the
// pointers around for testing. // pointers around for testing.
test_suggestions_store_ = new TestSuggestionsStore(); test_suggestions_store_ = new TestSuggestionsStore();
mock_thumbnail_manager_ = new StrictMock<MockImageManager>(); mock_thumbnail_manager_ = new StrictMock<MockImageManager>();
mock_blacklist_store_ = new StrictMock<MockBlacklistStore>(); mock_blacklist_store_ = new StrictMock<MockBlacklistStore>();
suggestions_service_ = std::make_unique<SuggestionsServiceImpl>( suggestions_service_ = std::make_unique<SuggestionsServiceImpl>(
identity_test_env_.identity_manager(), &mock_sync_service_, identity_test_env_.identity_manager(), sync_service(),
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
url_loader_factory()), url_loader_factory()),
base::WrapUnique(test_suggestions_store_), base::WrapUnique(test_suggestions_store_),
...@@ -236,7 +195,7 @@ class SuggestionsServiceTest : public testing::Test { ...@@ -236,7 +195,7 @@ class SuggestionsServiceTest : public testing::Test {
base::TestMockTimeTaskRunner* task_runner() { return task_runner_.get(); } base::TestMockTimeTaskRunner* task_runner() { return task_runner_.get(); }
MockSyncService* sync_service() { return &mock_sync_service_; } syncer::TestSyncService* sync_service() { return &test_sync_service_; }
MockImageManager* thumbnail_manager() { return mock_thumbnail_manager_; } MockImageManager* thumbnail_manager() { return mock_thumbnail_manager_; }
...@@ -259,7 +218,7 @@ class SuggestionsServiceTest : public testing::Test { ...@@ -259,7 +218,7 @@ class SuggestionsServiceTest : public testing::Test {
private: private:
scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
identity::IdentityTestEnvironment identity_test_env_; identity::IdentityTestEnvironment identity_test_env_;
MockSyncService mock_sync_service_; syncer::TestSyncService test_sync_service_;
network::TestURLLoaderFactory url_loader_factory_; network::TestURLLoaderFactory url_loader_factory_;
// Owned by the SuggestionsService. // Owned by the SuggestionsService.
...@@ -320,7 +279,7 @@ TEST_F(SuggestionsServiceTest, PersistentAuthErrorState) { ...@@ -320,7 +279,7 @@ TEST_F(SuggestionsServiceTest, PersistentAuthErrorState) {
GoogleServiceAuthError error = GoogleServiceAuthError error =
GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR); GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR);
sync_service()->set_auth_error(std::move(error)); sync_service()->SetAuthError(std::move(error));
// An no-op change should not result in a suggestions refresh. // An no-op change should not result in a suggestions refresh.
static_cast<SyncServiceObserver*>(suggestions_service()) static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service()); ->OnStateChanged(sync_service());
...@@ -340,10 +299,8 @@ TEST_F(SuggestionsServiceTest, IgnoresUninterestingSyncChange) { ...@@ -340,10 +299,8 @@ TEST_F(SuggestionsServiceTest, IgnoresUninterestingSyncChange) {
// An uninteresting change should not result in a network request (the // An uninteresting change should not result in a network request (the
// SyncState is INITIALIZED_ENABLED_HISTORY before and after). // SyncState is INITIALIZED_ENABLED_HISTORY before and after).
EXPECT_CALL(*sync_service(), GetActiveDataTypes()) sync_service()->SetActiveDataTypes(
.Times(AnyNumber()) {syncer::HISTORY_DELETE_DIRECTIVES, syncer::BOOKMARKS});
.WillRepeatedly(Return(syncer::ModelTypeSet(
syncer::HISTORY_DELETE_DIRECTIVES, syncer::BOOKMARKS)));
static_cast<SyncServiceObserver*>(suggestions_service()) static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service()); ->OnStateChanged(sync_service());
...@@ -357,9 +314,8 @@ TEST_F(SuggestionsServiceTest, IgnoresUninterestingSyncChange) { ...@@ -357,9 +314,8 @@ TEST_F(SuggestionsServiceTest, IgnoresUninterestingSyncChange) {
// This should *not* result in an automatic fetch. // This should *not* result in an automatic fetch.
TEST_F(SuggestionsServiceTest, DoesNotFetchOnStartup) { TEST_F(SuggestionsServiceTest, DoesNotFetchOnStartup) {
// The sync service starts out inactive. // The sync service starts out inactive.
EXPECT_CALL(*sync_service(), GetTransportState()) sync_service()->SetTransportState(
.WillRepeatedly( syncer::SyncService::TransportState::INITIALIZING);
Return(syncer::SyncService::TransportState::INITIALIZING));
static_cast<SyncServiceObserver*>(suggestions_service()) static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service()); ->OnStateChanged(sync_service());
...@@ -367,8 +323,8 @@ TEST_F(SuggestionsServiceTest, DoesNotFetchOnStartup) { ...@@ -367,8 +323,8 @@ TEST_F(SuggestionsServiceTest, DoesNotFetchOnStartup) {
ASSERT_FALSE(suggestions_service()->HasPendingRequestForTesting()); ASSERT_FALSE(suggestions_service()->HasPendingRequestForTesting());
// Sync getting enabled should not result in a fetch. // Sync getting enabled should not result in a fetch.
EXPECT_CALL(*sync_service(), GetTransportState()) sync_service()->SetTransportState(
.WillRepeatedly(Return(syncer::SyncService::TransportState::ACTIVE)); syncer::SyncService::TransportState::ACTIVE);
static_cast<SyncServiceObserver*>(suggestions_service()) static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service()); ->OnStateChanged(sync_service());
...@@ -401,9 +357,8 @@ TEST_F(SuggestionsServiceTest, BuildUrlWithDefaultMinZeroParamForFewFeature) { ...@@ -401,9 +357,8 @@ TEST_F(SuggestionsServiceTest, BuildUrlWithDefaultMinZeroParamForFewFeature) {
} }
TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) {
EXPECT_CALL(*sync_service(), GetTransportState()) sync_service()->SetTransportState(
.WillRepeatedly( syncer::SyncService::TransportState::INITIALIZING);
Return(syncer::SyncService::TransportState::INITIALIZING));
static_cast<SyncServiceObserver*>(suggestions_service()) static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service()); ->OnStateChanged(sync_service());
...@@ -426,11 +381,10 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) { ...@@ -426,11 +381,10 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) {
} }
TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncDisabled) { TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncDisabled) {
EXPECT_CALL(*sync_service(), GetDisableReasons()) sync_service()->SetDisableReasons(
.Times(AnyNumber()) syncer::SyncService::DISABLE_REASON_USER_CHOICE);
.WillRepeatedly(Return(syncer::SyncService::DISABLE_REASON_USER_CHOICE)); sync_service()->SetTransportState(
EXPECT_CALL(*sync_service(), GetTransportState()) syncer::SyncService::TransportState::DISABLED);
.WillRepeatedly(Return(syncer::SyncService::TransportState::DISABLED));
base::MockCallback<SuggestionsService::ResponseCallback> callback; base::MockCallback<SuggestionsService::ResponseCallback> callback;
auto subscription = suggestions_service()->AddCallback(callback.Get()); auto subscription = suggestions_service()->AddCallback(callback.Get());
......
...@@ -25,10 +25,6 @@ class FakeSyncService : public SyncService { ...@@ -25,10 +25,6 @@ class FakeSyncService : public SyncService {
FakeSyncService(); FakeSyncService();
~FakeSyncService() override; ~FakeSyncService() override;
void set_auth_error(GoogleServiceAuthError error) {
error_ = std::move(error);
}
// Dummy methods. // Dummy methods.
// SyncService implementation. // SyncService implementation.
int GetDisableReasons() const override; int GetDisableReasons() const override;
......
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