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 @@
#include "components/suggestions/image_manager.h"
#include "components/suggestions/proto/suggestions.pb.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/test_sync_service.h"
#include "net/base/url_util.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
......@@ -84,19 +84,6 @@ SuggestionsProfile CreateSuggestionsProfile() {
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 {
public:
TestSuggestionsStore() { cached_suggestions = CreateSuggestionsProfile(); }
......@@ -150,44 +137,16 @@ class SuggestionsServiceTest : public testing::Test {
~SuggestionsServiceTest() override {}
void SetUp() override {
EXPECT_CALL(*sync_service(), GetDisableReasons())
.Times(AnyNumber())
.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)));
sync_service()->SetPreferredDataTypes({syncer::HISTORY_DELETE_DIRECTIVES});
sync_service()->SetActiveDataTypes({syncer::HISTORY_DELETE_DIRECTIVES});
// These objects are owned by the SuggestionsService, but we keep the
// pointers around for testing.
test_suggestions_store_ = new TestSuggestionsStore();
mock_thumbnail_manager_ = new StrictMock<MockImageManager>();
mock_blacklist_store_ = new StrictMock<MockBlacklistStore>();
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>(
url_loader_factory()),
base::WrapUnique(test_suggestions_store_),
......@@ -236,7 +195,7 @@ class SuggestionsServiceTest : public testing::Test {
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_; }
......@@ -259,7 +218,7 @@ class SuggestionsServiceTest : public testing::Test {
private:
scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
identity::IdentityTestEnvironment identity_test_env_;
MockSyncService mock_sync_service_;
syncer::TestSyncService test_sync_service_;
network::TestURLLoaderFactory url_loader_factory_;
// Owned by the SuggestionsService.
......@@ -320,7 +279,7 @@ TEST_F(SuggestionsServiceTest, PersistentAuthErrorState) {
GoogleServiceAuthError 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.
static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service());
......@@ -340,10 +299,8 @@ TEST_F(SuggestionsServiceTest, IgnoresUninterestingSyncChange) {
// An uninteresting change should not result in a network request (the
// SyncState is INITIALIZED_ENABLED_HISTORY before and after).
EXPECT_CALL(*sync_service(), GetActiveDataTypes())
.Times(AnyNumber())
.WillRepeatedly(Return(syncer::ModelTypeSet(
syncer::HISTORY_DELETE_DIRECTIVES, syncer::BOOKMARKS)));
sync_service()->SetActiveDataTypes(
{syncer::HISTORY_DELETE_DIRECTIVES, syncer::BOOKMARKS});
static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service());
......@@ -357,9 +314,8 @@ TEST_F(SuggestionsServiceTest, IgnoresUninterestingSyncChange) {
// This should *not* result in an automatic fetch.
TEST_F(SuggestionsServiceTest, DoesNotFetchOnStartup) {
// The sync service starts out inactive.
EXPECT_CALL(*sync_service(), GetTransportState())
.WillRepeatedly(
Return(syncer::SyncService::TransportState::INITIALIZING));
sync_service()->SetTransportState(
syncer::SyncService::TransportState::INITIALIZING);
static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service());
......@@ -367,8 +323,8 @@ TEST_F(SuggestionsServiceTest, DoesNotFetchOnStartup) {
ASSERT_FALSE(suggestions_service()->HasPendingRequestForTesting());
// Sync getting enabled should not result in a fetch.
EXPECT_CALL(*sync_service(), GetTransportState())
.WillRepeatedly(Return(syncer::SyncService::TransportState::ACTIVE));
sync_service()->SetTransportState(
syncer::SyncService::TransportState::ACTIVE);
static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service());
......@@ -401,9 +357,8 @@ TEST_F(SuggestionsServiceTest, BuildUrlWithDefaultMinZeroParamForFewFeature) {
}
TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) {
EXPECT_CALL(*sync_service(), GetTransportState())
.WillRepeatedly(
Return(syncer::SyncService::TransportState::INITIALIZING));
sync_service()->SetTransportState(
syncer::SyncService::TransportState::INITIALIZING);
static_cast<SyncServiceObserver*>(suggestions_service())
->OnStateChanged(sync_service());
......@@ -426,11 +381,10 @@ TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncNotInitializedEnabled) {
}
TEST_F(SuggestionsServiceTest, FetchSuggestionsDataSyncDisabled) {
EXPECT_CALL(*sync_service(), GetDisableReasons())
.Times(AnyNumber())
.WillRepeatedly(Return(syncer::SyncService::DISABLE_REASON_USER_CHOICE));
EXPECT_CALL(*sync_service(), GetTransportState())
.WillRepeatedly(Return(syncer::SyncService::TransportState::DISABLED));
sync_service()->SetDisableReasons(
syncer::SyncService::DISABLE_REASON_USER_CHOICE);
sync_service()->SetTransportState(
syncer::SyncService::TransportState::DISABLED);
base::MockCallback<SuggestionsService::ResponseCallback> callback;
auto subscription = suggestions_service()->AddCallback(callback.Get());
......
......@@ -25,10 +25,6 @@ class FakeSyncService : public SyncService {
FakeSyncService();
~FakeSyncService() override;
void set_auth_error(GoogleServiceAuthError error) {
error_ = std::move(error);
}
// Dummy methods.
// SyncService implementation.
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