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

Introduce TestSyncUserSettings

It's a simple test implementation of SyncUserSettings that mostly
forwards calls to the TestSyncService. It is not actually used yet, but
it unlocks the migration of tests over to SyncUserSettings.

Bug: 884159
Change-Id: Id9d9c03f639c6523bb6d6592517ba46d1f8f4566
Reviewed-on: https://chromium-review.googlesource.com/c/1335565
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608286}
parent 33283f19
......@@ -21,7 +21,7 @@ class SyncUserSettingsImpl : public syncer::SyncUserSettings {
public:
// Both |service| and |prefs| must not be null, and must outlive this object.
SyncUserSettingsImpl(ProfileSyncService* service, syncer::SyncPrefs* prefs);
~SyncUserSettingsImpl();
~SyncUserSettingsImpl() override;
bool IsSyncRequested() const override;
void SetSyncRequested(bool requested) override;
......
......@@ -800,6 +800,8 @@ static_library("test_support_driver") {
"driver/sync_client_mock.h",
"driver/test_sync_service.cc",
"driver/test_sync_service.h",
"driver/test_sync_user_settings.cc",
"driver/test_sync_user_settings.h",
"engine/fake_sync_engine.cc",
"engine/fake_sync_engine.h",
"engine/mock_sync_engine.cc",
......
......@@ -16,6 +16,8 @@ namespace syncer {
// This class encapsulates all the user-configurable bits of Sync.
class SyncUserSettings {
public:
virtual ~SyncUserSettings() = default;
// Whether the user wants Sync to run, a.k.a. the Sync feature toggle in
// settings. This maps to DISABLE_REASON_USER_CHOICE.
virtual bool IsSyncRequested() const = 0;
......
......@@ -23,9 +23,9 @@ SyncCycleSnapshot MakeDefaultCycleSnapshot() {
/*num_server_conflicts=*/7, /*notifications_enabled=*/false,
/*num_entries=*/0, /*sync_start_time=*/base::Time::Now(),
/*poll_finish_time=*/base::Time::Now(),
/*num_entries_by_type=*/std::vector<int>(syncer::MODEL_TYPE_COUNT, 0),
/*num_entries_by_type=*/std::vector<int>(MODEL_TYPE_COUNT, 0),
/*num_to_delete_entries_by_type=*/
std::vector<int>(syncer::MODEL_TYPE_COUNT, 0),
std::vector<int>(MODEL_TYPE_COUNT, 0),
/*get_updates_origin=*/sync_pb::SyncEnums::UNKNOWN_ORIGIN,
/*short_poll_interval=*/base::TimeDelta::FromMinutes(30),
/*long_poll_interval=*/base::TimeDelta::FromMinutes(180),
......@@ -35,7 +35,8 @@ SyncCycleSnapshot MakeDefaultCycleSnapshot() {
} // namespace
TestSyncService::TestSyncService()
: preferred_data_types_(ModelTypeSet::All()),
: user_settings_(this),
preferred_data_types_(ModelTypeSet::All()),
active_data_types_(ModelTypeSet::All()),
last_cycle_snapshot_(MakeDefaultCycleSnapshot()) {}
......@@ -94,19 +95,19 @@ void TestSyncService::SetNonEmptyLastCycleSnapshot() {
SetLastCycleSnapshot(MakeDefaultCycleSnapshot());
}
syncer::SyncUserSettings* TestSyncService::GetUserSettings() {
return nullptr;
SyncUserSettings* TestSyncService::GetUserSettings() {
return &user_settings_;
}
const syncer::SyncUserSettings* TestSyncService::GetUserSettings() const {
return nullptr;
const SyncUserSettings* TestSyncService::GetUserSettings() const {
return &user_settings_;
}
int TestSyncService::GetDisableReasons() const {
return disable_reasons_;
}
syncer::SyncService::TransportState TestSyncService::GetTransportState() const {
SyncService::TransportState TestSyncService::GetTransportState() const {
return transport_state_;
}
......@@ -206,11 +207,11 @@ UserShare* TestSyncService::GetUserShare() const {
return nullptr;
}
syncer::SyncTokenStatus TestSyncService::GetSyncTokenStatus() const {
syncer::SyncTokenStatus token;
SyncTokenStatus TestSyncService::GetSyncTokenStatus() const {
SyncTokenStatus token;
if (GetAuthError().state() != GoogleServiceAuthError::NONE) {
token.connection_status = syncer::ConnectionStatus::CONNECTION_AUTH_ERROR;
token.connection_status = ConnectionStatus::CONNECTION_AUTH_ERROR;
token.last_get_token_error =
GoogleServiceAuthError::FromServiceError("error");
}
......@@ -272,12 +273,11 @@ bool TestSyncService::IsPassphraseRequired() const {
ModelTypeSet TestSyncService::GetEncryptedDataTypes() const {
if (!using_secondary_passphrase_) {
// PASSWORDS are always encrypted.
return ModelTypeSet(syncer::PASSWORDS);
return ModelTypeSet(PASSWORDS);
}
// Some types can never be encrypted, e.g. DEVICE_INFO and
// AUTOFILL_WALLET_DATA, so make sure we don't report them as encrypted.
return syncer::Intersection(GetPreferredDataTypes(),
syncer::EncryptableUserTypes());
return Intersection(GetPreferredDataTypes(), EncryptableUserTypes());
}
void TestSyncService::Shutdown() {}
......
......@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "components/signin/core/browser/account_info.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/test_sync_user_settings.h"
#include "components/sync/engine/cycle/sync_cycle_snapshot.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "url/gurl.h"
......@@ -108,6 +109,8 @@ class TestSyncService : public SyncService {
void Shutdown() override;
private:
TestSyncUserSettings user_settings_;
int disable_reasons_ = DISABLE_REASON_NONE;
TransportState transport_state_ = TransportState::ACTIVE;
bool local_sync_enabled_ = false;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sync/driver/test_sync_user_settings.h"
#include "components/sync/base/passphrase_enums.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/test_sync_service.h"
namespace syncer {
TestSyncUserSettings::TestSyncUserSettings(TestSyncService* service)
: service_(service) {}
TestSyncUserSettings::~TestSyncUserSettings() = default;
bool TestSyncUserSettings::IsSyncRequested() const {
return !service_->HasDisableReason(SyncService::DISABLE_REASON_USER_CHOICE);
}
void TestSyncUserSettings::SetSyncRequested(bool requested) {
int disable_reasons = service_->GetDisableReasons();
if (requested) {
disable_reasons &= ~SyncService::DISABLE_REASON_USER_CHOICE;
} else {
disable_reasons |= SyncService::DISABLE_REASON_USER_CHOICE;
}
service_->SetDisableReasons(disable_reasons);
}
bool TestSyncUserSettings::IsSyncAllowedByPlatform() const {
return !service_->HasDisableReason(
SyncService::DISABLE_REASON_PLATFORM_OVERRIDE);
}
void TestSyncUserSettings::SetSyncAllowedByPlatform(bool allowed) {
int disable_reasons = service_->GetDisableReasons();
if (allowed) {
disable_reasons &= ~SyncService::DISABLE_REASON_PLATFORM_OVERRIDE;
} else {
disable_reasons |= SyncService::DISABLE_REASON_PLATFORM_OVERRIDE;
}
service_->SetDisableReasons(disable_reasons);
}
bool TestSyncUserSettings::IsFirstSetupComplete() const {
return service_->IsFirstSetupComplete();
}
void TestSyncUserSettings::SetFirstSetupComplete() {
service_->SetFirstSetupComplete();
}
bool TestSyncUserSettings::IsSyncEverythingEnabled() const {
return sync_everything_enabled_;
}
ModelTypeSet TestSyncUserSettings::GetChosenDataTypes() const {
ModelTypeSet types = service_->GetPreferredDataTypes();
types.RetainAll(UserSelectableTypes());
return types;
}
void TestSyncUserSettings::SetChosenDataTypes(bool sync_everything,
ModelTypeSet types) {
sync_everything_enabled_ = sync_everything;
service_->OnUserChoseDatatypes(sync_everything, types);
}
bool TestSyncUserSettings::IsEncryptEverythingAllowed() const {
return true;
}
void TestSyncUserSettings::SetEncryptEverythingAllowed(bool allowed) {}
bool TestSyncUserSettings::IsEncryptEverythingEnabled() const {
return service_->IsEncryptEverythingEnabled();
}
void TestSyncUserSettings::EnableEncryptEverything() {
service_->EnableEncryptEverything();
}
bool TestSyncUserSettings::IsPassphraseRequired() const {
return service_->IsPassphraseRequired();
}
bool TestSyncUserSettings::IsPassphraseRequiredForDecryption() const {
return service_->IsPassphraseRequiredForDecryption();
}
bool TestSyncUserSettings::IsUsingSecondaryPassphrase() const {
return service_->IsUsingSecondaryPassphrase();
}
base::Time TestSyncUserSettings::GetExplicitPassphraseTime() const {
return service_->GetExplicitPassphraseTime();
}
PassphraseType TestSyncUserSettings::GetPassphraseType() const {
return IsUsingSecondaryPassphrase() ? PassphraseType::CUSTOM_PASSPHRASE
: PassphraseType::IMPLICIT_PASSPHRASE;
}
void TestSyncUserSettings::SetEncryptionPassphrase(
const std::string& passphrase) {
service_->SetEncryptionPassphrase(passphrase);
}
bool TestSyncUserSettings::SetDecryptionPassphrase(
const std::string& passphrase) {
return service_->SetDecryptionPassphrase(passphrase);
}
} // namespace syncer
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SYNC_DRIVER_TEST_SYNC_USER_SETTINGS_H_
#define COMPONENTS_SYNC_DRIVER_TEST_SYNC_USER_SETTINGS_H_
#include <string>
#include "components/sync/driver/sync_user_settings.h"
namespace syncer {
class TestSyncService;
// Test implementation of SyncUserSettings that mostly forwards calls to a
// TestSyncService.
class TestSyncUserSettings : public SyncUserSettings {
public:
explicit TestSyncUserSettings(TestSyncService* service);
~TestSyncUserSettings() override;
bool IsSyncRequested() const override;
void SetSyncRequested(bool requested) override;
bool IsSyncAllowedByPlatform() const override;
void SetSyncAllowedByPlatform(bool allowed) override;
bool IsFirstSetupComplete() const override;
void SetFirstSetupComplete() override;
bool IsSyncEverythingEnabled() const override;
ModelTypeSet GetChosenDataTypes() const override;
void SetChosenDataTypes(bool sync_everything, ModelTypeSet types) override;
bool IsEncryptEverythingAllowed() const override;
void SetEncryptEverythingAllowed(bool allowed) override;
bool IsEncryptEverythingEnabled() const override;
void EnableEncryptEverything() override;
bool IsPassphraseRequired() const override;
bool IsPassphraseRequiredForDecryption() const override;
bool IsUsingSecondaryPassphrase() const override;
base::Time GetExplicitPassphraseTime() const override;
PassphraseType GetPassphraseType() const override;
void SetEncryptionPassphrase(const std::string& passphrase) override;
bool SetDecryptionPassphrase(const std::string& passphrase) override;
private:
TestSyncService* service_;
bool sync_everything_enabled_ = true;
};
} // namespace syncer
#endif // COMPONENTS_SYNC_DRIVER_TEST_SYNC_USER_SETTINGS_H_
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