This source file includes following definitions.
- GetStatus
- AddHighPriorityTypesTo
- ConfigureDataTypes
- last_ready_task
- set_expected_configure_types
- set_passphrase_required
- set_encrypted_types
- IsPassphraseRequired
- GetEncryptedDataTypes
- custom_priority_types_
- set_priority_types
- configure_result
- OnModelAssociationDone
- GetPriorityTypes
- SetUp
- SetConfigureStartExpectation
- SetConfigureDoneExpectation
- Configure
- FinishDownload
- AddController
- GetController
- FailEncryptionFor
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/sync/glue/data_type_manager_impl.h"
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "chrome/browser/chrome_notification_types.h"
#include "components/sync_driver/backend_data_type_configurer.h"
#include "components/sync_driver/data_type_controller.h"
#include "components/sync_driver/data_type_encryption_handler.h"
#include "components/sync_driver/data_type_manager_observer.h"
#include "components/sync_driver/failed_data_types_handler.h"
#include "components/sync_driver/fake_data_type_controller.h"
#include "content/public/test/test_browser_thread.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/configure_reason.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace browser_sync {
using syncer::ModelType;
using syncer::ModelTypeSet;
using syncer::ModelTypeToString;
using syncer::BOOKMARKS;
using syncer::APPS;
using syncer::PASSWORDS;
using syncer::PREFERENCES;
using syncer::NIGORI;
using testing::_;
using testing::Mock;
using testing::ResultOf;
namespace {
DataTypeManager::ConfigureStatus GetStatus(
const DataTypeManager::ConfigureResult& result) {
return result.status;
}
syncer::ModelTypeSet AddHighPriorityTypesTo(syncer::ModelTypeSet types) {
syncer::ModelTypeSet result = syncer::ControlTypes();
result.PutAll(types);
return result;
}
class FakeBackendDataTypeConfigurer : public BackendDataTypeConfigurer {
public:
FakeBackendDataTypeConfigurer() {}
virtual ~FakeBackendDataTypeConfigurer() {}
virtual void ConfigureDataTypes(
syncer::ConfigureReason reason,
const DataTypeConfigStateMap& config_state_map,
const base::Callback<void(ModelTypeSet,
ModelTypeSet)>& ready_task,
const base::Callback<void()>& retry_callback) OVERRIDE {
last_ready_task_ = ready_task;
if (!expected_configure_types_.Empty()) {
EXPECT_TRUE(
expected_configure_types_.Equals(
GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map)))
<< syncer::ModelTypeSetToString(expected_configure_types_)
<< " v.s. "
<< syncer::ModelTypeSetToString(
GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map));
}
}
base::Callback<void(ModelTypeSet, ModelTypeSet)> last_ready_task() const {
return last_ready_task_;
}
void set_expected_configure_types(syncer::ModelTypeSet types) {
expected_configure_types_ = types;
}
private:
base::Callback<void(ModelTypeSet, ModelTypeSet)> last_ready_task_;
syncer::ModelTypeSet expected_configure_types_;
};
class DataTypeManagerObserverMock : public DataTypeManagerObserver {
public:
DataTypeManagerObserverMock() {}
virtual ~DataTypeManagerObserverMock() {}
MOCK_METHOD1(OnConfigureDone,
void(const browser_sync::DataTypeManager::ConfigureResult&));
MOCK_METHOD0(OnConfigureRetry, void());
MOCK_METHOD0(OnConfigureStart, void());
};
class FakeDataTypeEncryptionHandler : public DataTypeEncryptionHandler {
public:
FakeDataTypeEncryptionHandler();
virtual ~FakeDataTypeEncryptionHandler();
virtual bool IsPassphraseRequired() const OVERRIDE;
virtual syncer::ModelTypeSet GetEncryptedDataTypes() const OVERRIDE;
void set_passphrase_required(bool passphrase_required) {
passphrase_required_ = passphrase_required;
}
void set_encrypted_types(syncer::ModelTypeSet encrypted_types) {
encrypted_types_ = encrypted_types;
}
private:
bool passphrase_required_;
syncer::ModelTypeSet encrypted_types_;
};
FakeDataTypeEncryptionHandler::FakeDataTypeEncryptionHandler()
: passphrase_required_(false) {}
FakeDataTypeEncryptionHandler::~FakeDataTypeEncryptionHandler() {}
bool FakeDataTypeEncryptionHandler::IsPassphraseRequired() const {
return passphrase_required_;
}
syncer::ModelTypeSet
FakeDataTypeEncryptionHandler::GetEncryptedDataTypes() const {
return encrypted_types_;
}
}
class TestDataTypeManager : public DataTypeManagerImpl {
public:
TestDataTypeManager(
const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
debug_info_listener,
BackendDataTypeConfigurer* configurer,
const DataTypeController::TypeMap* controllers,
const DataTypeEncryptionHandler* encryption_handler,
DataTypeManagerObserver* observer,
FailedDataTypesHandler* failed_data_types_handler)
: DataTypeManagerImpl(debug_info_listener,
controllers,
encryption_handler,
configurer,
observer,
failed_data_types_handler),
custom_priority_types_(syncer::ControlTypes()) {}
void set_priority_types(const syncer::ModelTypeSet& priority_types) {
custom_priority_types_ = priority_types;
}
DataTypeManager::ConfigureResult configure_result() const {
return configure_result_;
}
virtual void OnModelAssociationDone(
const DataTypeManager::ConfigureResult& result) OVERRIDE {
configure_result_ = result;
DataTypeManagerImpl::OnModelAssociationDone(result);
}
private:
virtual syncer::ModelTypeSet GetPriorityTypes() const OVERRIDE {
return custom_priority_types_;
}
syncer::ModelTypeSet custom_priority_types_;
DataTypeManager::ConfigureResult configure_result_;
};
class SyncDataTypeManagerImplTest : public testing::Test {
public:
SyncDataTypeManagerImplTest()
: ui_thread_(content::BrowserThread::UI, &ui_loop_) {}
virtual ~SyncDataTypeManagerImplTest() {
}
protected:
virtual void SetUp() {
dtm_.reset(
new TestDataTypeManager(
syncer::WeakHandle<syncer::DataTypeDebugInfoListener>(),
&configurer_,
&controllers_,
&encryption_handler_,
&observer_,
&failed_data_types_handler_));
}
void SetConfigureStartExpectation() {
EXPECT_CALL(observer_, OnConfigureStart());
}
void SetConfigureDoneExpectation(DataTypeManager::ConfigureStatus status) {
EXPECT_CALL(observer_, OnConfigureDone(ResultOf(&GetStatus, status)));
}
void Configure(DataTypeManagerImpl* dtm,
const syncer::ModelTypeSet& desired_types) {
dtm->Configure(desired_types, syncer::CONFIGURE_REASON_RECONFIGURATION);
}
void FinishDownload(const DataTypeManager& dtm,
ModelTypeSet types_to_configure,
ModelTypeSet failed_download_types) {
EXPECT_TRUE(DataTypeManager::DOWNLOAD_PENDING == dtm.state() ||
DataTypeManager::CONFIGURING == dtm.state());
ASSERT_FALSE(configurer_.last_ready_task().is_null());
configurer_.last_ready_task().Run(
syncer::Difference(types_to_configure, failed_download_types),
failed_download_types);
}
void AddController(ModelType model_type) {
controllers_[model_type] = new FakeDataTypeController(model_type);
}
scoped_refptr<FakeDataTypeController> GetController(
ModelType model_type) const {
DataTypeController::TypeMap::const_iterator it =
controllers_.find(model_type);
if (it == controllers_.end()) {
return NULL;
}
return make_scoped_refptr(
static_cast<FakeDataTypeController*>(it->second.get()));
}
void FailEncryptionFor(syncer::ModelTypeSet encrypted_types) {
encryption_handler_.set_passphrase_required(true);
encryption_handler_.set_encrypted_types(encrypted_types);
}
base::MessageLoopForUI ui_loop_;
content::TestBrowserThread ui_thread_;
DataTypeController::TypeMap controllers_;
FakeBackendDataTypeConfigurer configurer_;
DataTypeManagerObserverMock observer_;
scoped_ptr<TestDataTypeManager> dtm_;
FailedDataTypesHandler failed_data_types_handler_;
FakeDataTypeEncryptionHandler encryption_handler_;
};
TEST_F(SyncDataTypeManagerImplTest, NoControllers) {
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet());
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureOne) {
AddController(BOOKMARKS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureOneStopWhileDownloadPending) {
AddController(BOOKMARKS);
{
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::ABORTED);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
configurer_.last_ready_task().Run(ModelTypeSet(BOOKMARKS), ModelTypeSet());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureOneStopWhileStartingModel) {
AddController(BOOKMARKS);
{
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::ABORTED);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
dtm_.reset();
}
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureOneStopWhileAssociating) {
AddController(BOOKMARKS);
{
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::ABORTED);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
dtm_.reset();
}
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
}
TEST_F(SyncDataTypeManagerImplTest, OneWaitingForCrypto) {
AddController(PASSWORDS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::PARTIAL_SUCCESS);
const ModelTypeSet types(PASSWORDS);
dtm_->set_priority_types(AddHighPriorityTypesTo(types));
Configure(dtm_.get(), types);
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
FailEncryptionFor(types);
GetController(PASSWORDS)->FinishStart(DataTypeController::NEEDS_CRYPTO);
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureOneThenBoth) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
Mock::VerifyAndClearExpectations(&observer_);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureOneThenSwitch) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
Mock::VerifyAndClearExpectations(&observer_);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureWhileOneInFlight) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, OneFailingController) {
AddController(BOOKMARKS);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::UNRECOVERABLE_ERROR);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(
DataTypeController::UNRECOVERABLE_ERROR);
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, SecondControllerFails) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::UNRECOVERABLE_ERROR);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(PREFERENCES)->FinishStart(
DataTypeController::UNRECOVERABLE_ERROR);
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, OneControllerFailsAssociation) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::PARTIAL_SUCCESS);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(PREFERENCES)->FinishStart(
DataTypeController::ASSOCIATION_FAILED);
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureWhileDownloadPending) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureWhileDownloadPendingWithFailure) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, MigrateAll) {
AddController(BOOKMARKS);
dtm_->set_priority_types(AddHighPriorityTypesTo(ModelTypeSet(BOOKMARKS)));
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
Mock::VerifyAndClearExpectations(&observer_);
ModelTypeSet to_migrate;
to_migrate.Put(BOOKMARKS);
to_migrate.PutAll(syncer::ControlTypes());
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
dtm_->PurgeForMigration(to_migrate,
syncer::CONFIGURE_REASON_MIGRATION);
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
Mock::VerifyAndClearExpectations(&observer_);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), to_migrate);
FinishDownload(*dtm_, to_migrate, ModelTypeSet());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, ConfigureDuringPurge) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
Mock::VerifyAndClearExpectations(&observer_);
SetConfigureStartExpectation();
dtm_->PurgeForMigration(ModelTypeSet(NIGORI),
syncer::CONFIGURE_REASON_MIGRATION);
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
Mock::VerifyAndClearExpectations(&observer_);
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
Mock::VerifyAndClearExpectations(&observer_);
SetConfigureDoneExpectation(DataTypeManager::OK);
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, PrioritizedConfiguration) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
dtm_->set_priority_types(
AddHighPriorityTypesTo(syncer::ModelTypeSet(PREFERENCES)));
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
configurer_.set_expected_configure_types(
AddHighPriorityTypesTo(ModelTypeSet(PREFERENCES)));
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
configurer_.set_expected_configure_types(ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, PrioritizedConfigurationReconfigure) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
AddController(APPS);
dtm_->set_priority_types(
AddHighPriorityTypesTo(syncer::ModelTypeSet(PREFERENCES)));
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
configurer_.set_expected_configure_types(
AddHighPriorityTypesTo(ModelTypeSet(PREFERENCES)));
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
configurer_.set_expected_configure_types(ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES, APPS));
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
configurer_.set_expected_configure_types(
AddHighPriorityTypesTo(ModelTypeSet(PREFERENCES)));
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
configurer_.set_expected_configure_types(ModelTypeSet(BOOKMARKS, APPS));
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS, APPS), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
GetController(APPS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
}
TEST_F(SyncDataTypeManagerImplTest, PrioritizedConfigurationStop) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
dtm_->set_priority_types(
AddHighPriorityTypesTo(syncer::ModelTypeSet(PREFERENCES)));
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::ABORTED);
configurer_.set_expected_configure_types(
AddHighPriorityTypesTo(ModelTypeSet(PREFERENCES)));
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
configurer_.set_expected_configure_types(ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
EXPECT_EQ(DataTypeController::ASSOCIATING,
GetController(PREFERENCES)->state());
EXPECT_EQ(DataTypeController::MODEL_LOADED,
GetController(BOOKMARKS)->state());
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
EXPECT_EQ(DataTypeController::NOT_RUNNING,
GetController(PREFERENCES)->state());
EXPECT_EQ(DataTypeController::NOT_RUNNING, GetController(BOOKMARKS)->state());
}
TEST_F(SyncDataTypeManagerImplTest, PrioritizedConfigurationDownloadError) {
AddController(BOOKMARKS);
AddController(PREFERENCES);
dtm_->set_priority_types(
AddHighPriorityTypesTo(syncer::ModelTypeSet(PREFERENCES)));
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::UNRECOVERABLE_ERROR);
configurer_.set_expected_configure_types(
AddHighPriorityTypesTo(ModelTypeSet(PREFERENCES)));
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
configurer_.set_expected_configure_types(ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
EXPECT_EQ(DataTypeController::ASSOCIATING,
GetController(PREFERENCES)->state());
EXPECT_EQ(DataTypeController::MODEL_LOADED,
GetController(BOOKMARKS)->state());
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet(BOOKMARKS));
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
EXPECT_EQ(DataTypeController::NOT_RUNNING,
GetController(PREFERENCES)->state());
EXPECT_EQ(DataTypeController::NOT_RUNNING, GetController(BOOKMARKS)->state());
}
TEST_F(SyncDataTypeManagerImplTest, HighPriorityAssociationFailure) {
AddController(PREFERENCES);
AddController(BOOKMARKS);
dtm_->set_priority_types(
AddHighPriorityTypesTo(syncer::ModelTypeSet(PREFERENCES)));
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::PARTIAL_SUCCESS);
configurer_.set_expected_configure_types(
AddHighPriorityTypesTo(ModelTypeSet(PREFERENCES)));
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
configurer_.set_expected_configure_types(ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
EXPECT_EQ(DataTypeController::ASSOCIATING,
GetController(PREFERENCES)->state());
EXPECT_EQ(DataTypeController::MODEL_LOADED,
GetController(BOOKMARKS)->state());
GetController(PREFERENCES)->FinishStart(
DataTypeController::ASSOCIATION_FAILED);
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
configurer_.set_expected_configure_types(syncer::ControlTypes());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
configurer_.set_expected_configure_types(ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(), ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
EXPECT_EQ(DataTypeController::ASSOCIATING,
GetController(BOOKMARKS)->state());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
EXPECT_EQ(DataTypeController::NOT_RUNNING,
GetController(PREFERENCES)->state());
EXPECT_EQ(DataTypeController::RUNNING, GetController(BOOKMARKS)->state());
}
TEST_F(SyncDataTypeManagerImplTest, LowPriorityAssociationFailure) {
AddController(PREFERENCES);
AddController(BOOKMARKS);
dtm_->set_priority_types(
AddHighPriorityTypesTo(syncer::ModelTypeSet(PREFERENCES)));
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::PARTIAL_SUCCESS);
configurer_.set_expected_configure_types(
AddHighPriorityTypesTo(ModelTypeSet(PREFERENCES)));
Configure(dtm_.get(), ModelTypeSet(BOOKMARKS, PREFERENCES));
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
configurer_.set_expected_configure_types(ModelTypeSet(BOOKMARKS));
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURING, dtm_->state());
EXPECT_EQ(DataTypeController::ASSOCIATING,
GetController(PREFERENCES)->state());
EXPECT_EQ(DataTypeController::MODEL_LOADED,
GetController(BOOKMARKS)->state());
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
GetController(PREFERENCES)->FinishStart(DataTypeController::OK);
EXPECT_EQ(DataTypeController::RUNNING, GetController(PREFERENCES)->state());
configurer_.set_expected_configure_types(
AddHighPriorityTypesTo(ModelTypeSet(PREFERENCES)));
GetController(BOOKMARKS)->FinishStart(DataTypeController::ASSOCIATION_FAILED);
EXPECT_EQ(DataTypeController::NOT_RUNNING,
GetController(BOOKMARKS)->state());
EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm_->state());
configurer_.set_expected_configure_types(ModelTypeSet());
FinishDownload(*dtm_, ModelTypeSet(PREFERENCES), ModelTypeSet());
EXPECT_EQ(DataTypeManager::CONFIGURED, dtm_->state());
EXPECT_EQ(DataTypeController::RUNNING, GetController(PREFERENCES)->state());
EXPECT_EQ(DataTypeController::NOT_RUNNING,
GetController(BOOKMARKS)->state());
}
TEST_F(SyncDataTypeManagerImplTest, FilterDesiredTypes) {
AddController(BOOKMARKS);
ModelTypeSet types(BOOKMARKS, APPS);
dtm_->set_priority_types(AddHighPriorityTypesTo(types));
SetConfigureStartExpectation();
SetConfigureDoneExpectation(DataTypeManager::OK);
syncer::ModelTypeSet expected_types = syncer::ControlTypes();
expected_types.Put(BOOKMARKS);
configurer_.set_expected_configure_types(expected_types);
Configure(dtm_.get(), types);
FinishDownload(*dtm_, ModelTypeSet(BOOKMARKS), ModelTypeSet());
GetController(BOOKMARKS)->FinishStart(DataTypeController::OK);
dtm_->Stop();
EXPECT_EQ(DataTypeManager::STOPPED, dtm_->state());
}
}