Commit bc505b9f authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

ProfileSyncServiceMock cleanups

- Reorder all overrides to be grouped by interface, and match the
  interface's ordering.
- Remove a second ctor that isn't necessary anymore.
- Remove some unnecessary includes.

Bug: 910518
Change-Id: I4123e4ce9cd8eeac4fd2cef051e094cccc8c7d14
Reviewed-on: https://chromium-review.googlesource.com/c/1356702
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613059}
parent 4ca8b958
......@@ -278,9 +278,8 @@ TEST_F(SyncUIUtilTest, DistinctCasesReportUniqueMessageSets) {
std::set<base::string16> messages;
for (int idx = 0; idx != NUMBER_OF_STATUS_CASES; idx++) {
std::unique_ptr<Profile> profile = std::make_unique<TestingProfile>();
ProfileSyncService::InitParams init_params =
CreateProfileSyncServiceParamsForTest(profile.get());
NiceMock<ProfileSyncServiceMock> service(&init_params);
NiceMock<ProfileSyncServiceMock> service(
CreateProfileSyncServiceParamsForTest(profile.get()));
GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone();
EXPECT_CALL(service, GetAuthError()).WillRepeatedly(ReturnRef(error));
FakeSigninManagerForSyncUIUtilTest signin(profile.get());
......
......@@ -11,9 +11,6 @@ namespace browser_sync {
ProfileSyncServiceMock::ProfileSyncServiceMock(InitParams init_params)
: ProfileSyncService(std::move(init_params)) {}
ProfileSyncServiceMock::ProfileSyncServiceMock(InitParams* init_params)
: ProfileSyncServiceMock(std::move(*init_params)) {}
ProfileSyncServiceMock::~ProfileSyncServiceMock() {}
bool ProfileSyncServiceMock::IsAuthenticatedAccountPrimary() const {
......
......@@ -7,15 +7,10 @@
#include <memory>
#include <string>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/sync/base/model_type.h"
#include "components/sync/device_info/device_info.h"
#include "components/sync/driver/data_type_controller.h"
#include "components/sync/model/change_processor.h"
#include "components/sync/protocol/sync_protocol_error.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -25,84 +20,88 @@ namespace browser_sync {
class ProfileSyncServiceMock : public ProfileSyncService {
public:
explicit ProfileSyncServiceMock(InitParams init_params);
// The second constructor defers to the first one. Use it when you need to
// create a StrictMock or NiceMock of ProfileSyncServiceMock, because those
// template classes cannot handle the input class having constructors with
// arguments passed by value. Otherwise use the constructor above for cleaner
// code.
explicit ProfileSyncServiceMock(InitParams* init_params);
~ProfileSyncServiceMock() override;
MOCK_METHOD6(
OnEngineInitialized,
void(syncer::ModelTypeSet initial_types,
const syncer::WeakHandle<syncer::JsBackend>&,
const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&,
const std::string&,
const std::string&,
bool));
MOCK_METHOD1(OnSyncCycleCompleted, void(const syncer::SyncCycleSnapshot&));
MOCK_METHOD2(OnUserChoseDatatypes,
void(bool sync_everything, syncer::ModelTypeSet chosen_types));
MOCK_METHOD0(SetFirstSetupComplete, void());
// SyncService overrides.
MOCK_CONST_METHOD0(GetDisableReasons, int());
MOCK_CONST_METHOD0(GetTransportState, TransportState());
// TODO(crbug.com/871221): Remove this override. This is overridden here to
// return true by default, as a workaround for tests not setting up an
// authenticated account and IsSyncFeatureEnabled() therefore returning false.
bool IsAuthenticatedAccountPrimary() const override;
MOCK_CONST_METHOD0(GetAuthError, const GoogleServiceAuthError&());
MOCK_METHOD0(GetSetupInProgressHandle,
std::unique_ptr<syncer::SyncSetupInProgressHandle>());
MOCK_CONST_METHOD0(IsSetupInProgress, bool());
MOCK_CONST_METHOD0(GetPreferredDataTypes, syncer::ModelTypeSet());
MOCK_CONST_METHOD0(GetActiveDataTypes, syncer::ModelTypeSet());
MOCK_METHOD2(OnUnrecoverableError,
void(const base::Location& location,
const std::string& message));
MOCK_CONST_METHOD0(GetUserShare, syncer::UserShare*());
MOCK_METHOD0(RequestStart, void());
MOCK_METHOD0(StopAndClear, void());
MOCK_METHOD1(AddObserver, void(syncer::SyncServiceObserver*));
MOCK_METHOD1(RemoveObserver, void(syncer::SyncServiceObserver*));
MOCK_METHOD0(GetJsController, base::WeakPtr<syncer::JsController>());
MOCK_CONST_METHOD0(IsFirstSetupComplete, bool());
MOCK_CONST_METHOD0(IsEncryptEverythingAllowed, bool());
MOCK_CONST_METHOD0(IsEncryptEverythingEnabled, bool());
MOCK_CONST_METHOD0(IsPassphraseRequiredForDecryption, bool());
MOCK_CONST_METHOD0(GetExplicitPassphraseTime, base::Time());
MOCK_CONST_METHOD0(IsUsingSecondaryPassphrase, bool());
MOCK_METHOD0(EnableEncryptEverything, void());
MOCK_CONST_METHOD0(IsEncryptEverythingEnabled, bool());
MOCK_METHOD1(SetEncryptionPassphrase, void(const std::string& passphrase));
MOCK_METHOD1(SetDecryptionPassphrase, bool(const std::string& passphrase));
MOCK_CONST_METHOD0(GetActiveDataTypes, syncer::ModelTypeSet());
MOCK_CONST_METHOD0(GetPreferredDataTypes, syncer::ModelTypeSet());
MOCK_CONST_METHOD0(GetRegisteredDataTypes, syncer::ModelTypeSet());
MOCK_CONST_METHOD0(GetLastCycleSnapshot, syncer::SyncCycleSnapshot());
MOCK_CONST_METHOD0(GetUserShare, syncer::UserShare*());
MOCK_CONST_METHOD0(GetDisableReasons, int());
MOCK_CONST_METHOD0(GetTransportState, TransportState());
MOCK_CONST_METHOD1(QueryDetailedSyncStatus,
bool(syncer::SyncEngine::Status* result));
MOCK_CONST_METHOD0(GetAuthError, const GoogleServiceAuthError&());
MOCK_CONST_METHOD0(IsSetupInProgress, bool());
MOCK_CONST_METHOD0(GetLastSyncedTime, base::Time());
MOCK_METHOD1(OnActionableError, void(const syncer::SyncProtocolError&));
MOCK_CONST_METHOD1(IsDataTypeControllerRunning, bool(syncer::ModelType));
MOCK_CONST_METHOD0(GetLastCycleSnapshot, syncer::SyncCycleSnapshot());
MOCK_METHOD0(StartUpSlowEngineComponents, void());
MOCK_METHOD0(GetJsController, base::WeakPtr<syncer::JsController>());
// DataTypeManagerObserver mocks.
// SyncEngineHost overrides.
MOCK_METHOD6(
OnEngineInitialized,
void(syncer::ModelTypeSet initial_types,
const syncer::WeakHandle<syncer::JsBackend>&,
const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&,
const std::string&,
const std::string&,
bool));
MOCK_METHOD1(OnSyncCycleCompleted, void(const syncer::SyncCycleSnapshot&));
MOCK_METHOD1(OnActionableError, void(const syncer::SyncProtocolError&));
// DataTypeManagerObserver overrides.
MOCK_METHOD1(OnConfigureDone,
void(const syncer::DataTypeManager::ConfigureResult&));
MOCK_METHOD0(OnConfigureStart, void());
// DataTypeEncryptionHandler overrides.
MOCK_CONST_METHOD0(IsPassphraseRequired, bool());
MOCK_CONST_METHOD0(IsPassphraseRequiredForDecryption, bool());
MOCK_CONST_METHOD0(IsUsingSecondaryPassphrase, bool());
// syncer::UnrecoverableErrorHandler overrides.
MOCK_METHOD2(OnUnrecoverableError,
void(const base::Location& location,
const std::string& message));
// ProfileSyncService overrides.
MOCK_CONST_METHOD0(IsFirstSetupComplete, bool());
MOCK_METHOD0(SetFirstSetupComplete, void());
MOCK_METHOD0(RequestStart, void());
MOCK_METHOD2(OnUserChoseDatatypes,
void(bool sync_everything, syncer::ModelTypeSet chosen_types));
MOCK_CONST_METHOD0(GetRegisteredDataTypes, syncer::ModelTypeSet());
MOCK_CONST_METHOD1(IsDataTypeControllerRunning, bool(syncer::ModelType));
MOCK_CONST_METHOD0(GetPassphraseType, syncer::PassphraseType());
MOCK_CONST_METHOD0(GetExplicitPassphraseTime, base::Time());
MOCK_CONST_METHOD0(IsEncryptEverythingAllowed, bool());
MOCK_METHOD1(SetDecryptionPassphrase, bool(const std::string& passphrase));
MOCK_METHOD1(SetEncryptionPassphrase, void(const std::string& passphrase));
MOCK_METHOD0(StartUpSlowEngineComponents, void());
MOCK_METHOD0(OnSetupInProgressHandleDestroyed, void());
// TODO(crbug.com/871221): Remove this override. This is overridden here to
// return true by default, as a workaround for tests not setting up an
// authenticated account and IsSyncFeatureEnabled() therefore returning false.
bool IsAuthenticatedAccountPrimary() const override;
// Gives access to the real implementation of ProfileSyncService methods:
std::unique_ptr<syncer::SyncSetupInProgressHandle>
GetSetupInProgressHandleConcrete();
......
......@@ -52,7 +52,7 @@ PassphraseCollectionViewControllerTest::CreateNiceProfileSyncServiceMock(
CreateProfileSyncServiceParamsForTest(
nullptr, ios::ChromeBrowserState::FromBrowserState(context));
return std::make_unique<NiceMock<browser_sync::ProfileSyncServiceMock>>(
&init_params);
std::move(init_params));
}
PassphraseCollectionViewControllerTest::PassphraseCollectionViewControllerTest()
......
......@@ -36,7 +36,7 @@ std::unique_ptr<KeyedService> CreateNiceProfileSyncServiceMock(
CreateProfileSyncServiceParamsForTest(
nullptr, ios::ChromeBrowserState::FromBrowserState(context));
return std::make_unique<NiceMock<browser_sync::ProfileSyncServiceMock>>(
&init_params);
std::move(init_params));
}
class SyncEncryptionTableViewControllerTest
......
......@@ -126,7 +126,7 @@ class SyncSettingsCollectionViewControllerTest
CreateProfileSyncServiceParamsForTest(
nullptr, ios::ChromeBrowserState::FromBrowserState(context));
return std::make_unique<NiceMock<browser_sync::ProfileSyncServiceMock>>(
&init_params);
std::move(init_params));
}
std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService() {
......
......@@ -75,7 +75,8 @@ class CWVSyncControllerTest : public PlatformTest {
init_params.signin_scoped_device_id_callback = base::BindRepeating(
&signin::GetSigninScopedDeviceId, browser_state_.GetPrefs());
profile_sync_service_ =
std::make_unique<browser_sync::ProfileSyncServiceMock>(&init_params);
std::make_unique<browser_sync::ProfileSyncServiceMock>(
std::move(init_params));
account_tracker_service_.Initialize(browser_state_.GetPrefs(),
base::FilePath());
......
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