This source file includes following definitions.
- type_
- LoadModels
- OnModelLoaded
- StartAssociating
- FinishStart
- Stop
- type
- name
- model_safe_group
- state
- OnSingleDatatypeUnrecoverableError
- RecordUnrecoverableError
- SetDelayModelLoad
- SetModelLoadError
- SimulateModelLoadFinishing
#include "components/sync_driver/fake_data_type_controller.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using syncer::ModelType;
namespace browser_sync {
FakeDataTypeController::FakeDataTypeController(ModelType type)
: DataTypeController(base::MessageLoopProxy::current(), base::Closure()),
state_(NOT_RUNNING),
model_load_delayed_(false),
type_(type) {}
FakeDataTypeController::~FakeDataTypeController() {
}
void FakeDataTypeController::LoadModels(
const ModelLoadCallback& model_load_callback) {
if (state_ != NOT_RUNNING) {
ADD_FAILURE();
return;
}
if (model_load_delayed_ == false) {
if (load_error_.IsSet())
state_ = DISABLED;
else
state_ = MODEL_LOADED;
model_load_callback.Run(type(), load_error_);
} else {
model_load_callback_ = model_load_callback;
state_ = MODEL_STARTING;
}
}
void FakeDataTypeController::OnModelLoaded() {
NOTREACHED();
}
void FakeDataTypeController::StartAssociating(
const StartCallback& start_callback) {
last_start_callback_ = start_callback;
state_ = ASSOCIATING;
}
void FakeDataTypeController::FinishStart(StartResult result) {
if (last_start_callback_.is_null()) {
ADD_FAILURE();
return;
}
syncer::SyncMergeResult local_merge_result(type());
syncer::SyncMergeResult syncer_merge_result(type());
if (result <= OK_FIRST_RUN) {
state_ = RUNNING;
} else if (result == ASSOCIATION_FAILED) {
state_ = DISABLED;
local_merge_result.set_error(
syncer::SyncError(FROM_HERE,
syncer::SyncError::DATATYPE_ERROR,
"Association failed",
type()));
} else {
state_ = NOT_RUNNING;
local_merge_result.set_error(
syncer::SyncError(FROM_HERE,
syncer::SyncError::DATATYPE_ERROR,
"Fake error",
type()));
}
StartCallback start_callback = last_start_callback_;
last_start_callback_.Reset();
start_callback.Run(result,
local_merge_result,
syncer_merge_result);
}
void FakeDataTypeController::Stop() {
state_ = NOT_RUNNING;
if (!model_load_callback_.is_null()) {
SimulateModelLoadFinishing();
}
if (!last_start_callback_.is_null()) {
syncer::SyncError error(FROM_HERE,
syncer::SyncError::DATATYPE_ERROR,
"Fake error",
type_);
syncer::SyncMergeResult local_merge_result(type_);
local_merge_result.set_error(error);
last_start_callback_.Run(ABORTED,
local_merge_result,
syncer::SyncMergeResult(type_));
}
}
ModelType FakeDataTypeController::type() const {
return type_;
}
std::string FakeDataTypeController::name() const {
return ModelTypeToString(type_);
}
syncer::ModelSafeGroup FakeDataTypeController::model_safe_group() const {
ADD_FAILURE();
return syncer::GROUP_PASSIVE;
}
DataTypeController::State FakeDataTypeController::state() const {
return state_;
}
void FakeDataTypeController::OnSingleDatatypeUnrecoverableError(
const tracked_objects::Location& from_here,
const std::string& message) {
ADD_FAILURE() << message;
}
void FakeDataTypeController::RecordUnrecoverableError(
const tracked_objects::Location& from_here,
const std::string& message) {
ADD_FAILURE() << message;
}
void FakeDataTypeController::SetDelayModelLoad() {
model_load_delayed_ = true;
}
void FakeDataTypeController::SetModelLoadError(syncer::SyncError error) {
load_error_ = error;
}
void FakeDataTypeController::SimulateModelLoadFinishing() {
ModelLoadCallback model_load_callback = model_load_callback_;
model_load_callback.Run(type(), load_error_);
model_load_callback_.Reset();
}
}