| Index: chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc
|
| diff --git a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc
|
| index 490916273e2cfa7e4d835c789279b873d2e7ed28..311f8691a7e3ba01452749bc96103f3deb33cba3 100644
|
| --- a/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc
|
| +++ b/chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc
|
| @@ -9,9 +9,9 @@
|
| #include "base/tracked_objects.h"
|
| #include "chrome/browser/search_engines/template_url_service_factory.h"
|
| #include "chrome/browser/search_engines/template_url_service_test_util.h"
|
| -#include "chrome/browser/sync/glue/change_processor_mock.h"
|
| +#include "chrome/browser/sync/api/fake_syncable_service.h"
|
| #include "chrome/browser/sync/glue/data_type_controller_mock.h"
|
| -#include "chrome/browser/sync/glue/model_associator_mock.h"
|
| +#include "chrome/browser/sync/glue/fake_generic_change_processor.h"
|
| #include "chrome/browser/sync/glue/search_engine_data_type_controller.h"
|
| #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
|
| #include "chrome/browser/sync/profile_sync_service_mock.h"
|
| @@ -20,34 +20,34 @@
|
| #include "content/public/browser/notification_service.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -using browser_sync::ChangeProcessorMock;
|
| -using browser_sync::DataTypeController;
|
| -using browser_sync::ModelAssociatorMock;
|
| -using browser_sync::SearchEngineDataTypeController;
|
| -using browser_sync::StartCallbackMock;
|
| using testing::_;
|
| using testing::DoAll;
|
| using testing::InvokeWithoutArgs;
|
| using testing::Return;
|
| using testing::SetArgumentPointee;
|
|
|
| +namespace browser_sync {
|
| +namespace {
|
| +
|
| +ACTION_P(ReturnAndRelease, change_processor) {
|
| + return change_processor->release();
|
| +}
|
| +
|
| class SyncSearchEngineDataTypeControllerTest : public testing::Test {
|
| public:
|
| - SyncSearchEngineDataTypeControllerTest() {}
|
| + SyncSearchEngineDataTypeControllerTest()
|
| + : change_processor_(new FakeGenericChangeProcessor()) {}
|
|
|
| virtual void SetUp() {
|
| test_util_.SetUp();
|
| - model_associator_ = new ModelAssociatorMock();
|
| - change_processor_ = new ChangeProcessorMock();
|
| - profile_sync_factory_.reset(
|
| - new ProfileSyncComponentsFactoryMock(model_associator_,
|
| - change_processor_));
|
| + profile_sync_factory_.reset(new ProfileSyncComponentsFactoryMock());
|
| // Feed the DTC test_util_'s profile so it is reused later.
|
| // This allows us to control the associated TemplateURLService.
|
| search_engine_dtc_ =
|
| new SearchEngineDataTypeController(profile_sync_factory_.get(),
|
| test_util_.profile(),
|
| &service_);
|
| + SetStartExpectations();
|
| }
|
|
|
| virtual void TearDown() {
|
| @@ -60,20 +60,21 @@ class SyncSearchEngineDataTypeControllerTest : public testing::Test {
|
| test_util_.VerifyLoad();
|
| }
|
|
|
| - void SetAssociateExpectations() {
|
| - EXPECT_CALL(*model_associator_, CryptoReadyIfNecessary()).
|
| - WillRepeatedly(Return(true));
|
| - EXPECT_CALL(*profile_sync_factory_, CreateSearchEngineSyncComponents(_, _));
|
| - EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
|
| - WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true)));
|
| - EXPECT_CALL(*model_associator_, AssociateModels(_)).
|
| - WillRepeatedly(Return(true));
|
| - EXPECT_CALL(service_, ActivateDataType(_, _, _));
|
| + void SetStartExpectations() {
|
| + // Ownership gets passed to caller of CreateGenericChangeProcessor.
|
| + EXPECT_CALL(*profile_sync_factory_,
|
| + GetSyncableServiceForType(syncable::SEARCH_ENGINES)).
|
| + WillOnce(Return(syncable_service_.AsWeakPtr()));
|
| + EXPECT_CALL(*profile_sync_factory_, CreateGenericChangeProcessor(_, _, _)).
|
| + WillOnce(ReturnAndRelease(&change_processor_));
|
| + }
|
| +
|
| + void SetActivateExpectations() {
|
| + EXPECT_CALL(service_, ActivateDataType(syncable::SEARCH_ENGINES, _, _));
|
| }
|
|
|
| void SetStopExpectations() {
|
| - EXPECT_CALL(service_, DeactivateDataType(_));
|
| - EXPECT_CALL(*model_associator_, DisassociateModels(_));
|
| + EXPECT_CALL(service_, DeactivateDataType(syncable::SEARCH_ENGINES));
|
| }
|
|
|
| // This also manages a BrowserThread and MessageLoop for us. Note that this
|
| @@ -83,31 +84,34 @@ class SyncSearchEngineDataTypeControllerTest : public testing::Test {
|
| scoped_refptr<SearchEngineDataTypeController> search_engine_dtc_;
|
| scoped_ptr<ProfileSyncComponentsFactoryMock> profile_sync_factory_;
|
| ProfileSyncServiceMock service_;
|
| - ModelAssociatorMock* model_associator_;
|
| - ChangeProcessorMock* change_processor_;
|
| + scoped_ptr<FakeGenericChangeProcessor> change_processor_;
|
| + FakeSyncableService syncable_service_;
|
| StartCallbackMock start_callback_;
|
| };
|
|
|
| TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceReady) {
|
| // We want to start ready.
|
| PreloadTemplateURLService();
|
| - SetAssociateExpectations();
|
| + SetActivateExpectations();
|
| + EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
|
|
|
| EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state());
|
| -
|
| - EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
|
| + EXPECT_FALSE(syncable_service_.syncing());
|
| search_engine_dtc_->Start(
|
| base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
|
| EXPECT_EQ(DataTypeController::RUNNING, search_engine_dtc_->state());
|
| + EXPECT_TRUE(syncable_service_.syncing());
|
| }
|
|
|
| TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceNotReady) {
|
| - SetAssociateExpectations();
|
| -
|
| + SetActivateExpectations();
|
| EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
|
| +
|
| + EXPECT_FALSE(syncable_service_.syncing());
|
| search_engine_dtc_->Start(
|
| base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
|
| EXPECT_EQ(DataTypeController::MODEL_STARTING, search_engine_dtc_->state());
|
| + EXPECT_FALSE(syncable_service_.syncing());
|
|
|
| // Send the notification that the TemplateURLService has started.
|
| content::NotificationService::current()->Notify(
|
| @@ -115,83 +119,71 @@ TEST_F(SyncSearchEngineDataTypeControllerTest, StartURLServiceNotReady) {
|
| content::Source<TemplateURLService>(test_util_.model()),
|
| content::NotificationService::NoDetails());
|
| EXPECT_EQ(DataTypeController::RUNNING, search_engine_dtc_->state());
|
| + EXPECT_TRUE(syncable_service_.syncing());
|
| }
|
|
|
| TEST_F(SyncSearchEngineDataTypeControllerTest, StartFirstRun) {
|
| PreloadTemplateURLService();
|
| - SetAssociateExpectations();
|
| - EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
|
| - WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true)));
|
| + SetActivateExpectations();
|
| + change_processor_->set_sync_model_has_user_created_nodes(false);
|
| EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _));
|
| - search_engine_dtc_->Start(
|
| - base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
|
| -}
|
|
|
| -TEST_F(SyncSearchEngineDataTypeControllerTest, StartOk) {
|
| - PreloadTemplateURLService();
|
| - SetAssociateExpectations();
|
| - EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
|
| - WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true)));
|
| -
|
| - EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
|
| search_engine_dtc_->Start(
|
| base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
|
| + EXPECT_TRUE(syncable_service_.syncing());
|
| }
|
|
|
| TEST_F(SyncSearchEngineDataTypeControllerTest, StartAssociationFailed) {
|
| PreloadTemplateURLService();
|
| - EXPECT_CALL(*profile_sync_factory_, CreateSearchEngineSyncComponents(_, _));
|
| - EXPECT_CALL(*model_associator_, CryptoReadyIfNecessary()).
|
| - WillRepeatedly(Return(true));
|
| - EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
|
| - WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true)));
|
| - EXPECT_CALL(*model_associator_, AssociateModels(_)).
|
| - WillRepeatedly(DoAll(browser_sync::SetSyncError(syncable::SEARCH_ENGINES),
|
| - Return(false)));
|
| -
|
| + SetStopExpectations();
|
| EXPECT_CALL(start_callback_,
|
| Run(DataTypeController::ASSOCIATION_FAILED, _));
|
| + syncable_service_.set_merge_data_and_start_syncing_error(
|
| + SyncError(FROM_HERE, "Error", syncable::SEARCH_ENGINES));
|
| +
|
| search_engine_dtc_->Start(
|
| base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
|
| EXPECT_EQ(DataTypeController::DISABLED, search_engine_dtc_->state());
|
| + EXPECT_FALSE(syncable_service_.syncing());
|
| + search_engine_dtc_->Stop();
|
| + EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state());
|
| + EXPECT_FALSE(syncable_service_.syncing());
|
| }
|
|
|
| TEST_F(SyncSearchEngineDataTypeControllerTest,
|
| StartAssociationTriggersUnrecoverableError) {
|
| PreloadTemplateURLService();
|
| - // Set up association to fail with an unrecoverable error.
|
| - EXPECT_CALL(*profile_sync_factory_, CreateSearchEngineSyncComponents(_, _));
|
| - EXPECT_CALL(*model_associator_, CryptoReadyIfNecessary()).
|
| - WillRepeatedly(Return(true));
|
| - EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
|
| - WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false)));
|
| EXPECT_CALL(start_callback_,
|
| Run(DataTypeController::UNRECOVERABLE_ERROR, _));
|
| + // Set up association to fail with an unrecoverable error.
|
| + change_processor_->set_sync_model_has_user_created_nodes_success(false);
|
| +
|
| search_engine_dtc_->Start(
|
| base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
|
| EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state());
|
| + EXPECT_FALSE(syncable_service_.syncing());
|
| }
|
|
|
| TEST_F(SyncSearchEngineDataTypeControllerTest, Stop) {
|
| PreloadTemplateURLService();
|
| - SetAssociateExpectations();
|
| + SetActivateExpectations();
|
| SetStopExpectations();
|
| + EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
|
|
|
| EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state());
|
| -
|
| - EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
|
| + EXPECT_FALSE(syncable_service_.syncing());
|
| search_engine_dtc_->Start(
|
| base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
|
| EXPECT_EQ(DataTypeController::RUNNING, search_engine_dtc_->state());
|
| + EXPECT_TRUE(syncable_service_.syncing());
|
| search_engine_dtc_->Stop();
|
| EXPECT_EQ(DataTypeController::NOT_RUNNING, search_engine_dtc_->state());
|
| + EXPECT_FALSE(syncable_service_.syncing());
|
| }
|
|
|
| TEST_F(SyncSearchEngineDataTypeControllerTest, OnUnrecoverableError) {
|
| PreloadTemplateURLService();
|
| - SetAssociateExpectations();
|
| - EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
|
| - WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true)));
|
| + SetActivateExpectations();
|
| EXPECT_CALL(service_, OnUnrecoverableError(_, _)).
|
| WillOnce(InvokeWithoutArgs(search_engine_dtc_.get(),
|
| &SearchEngineDataTypeController::Stop));
|
| @@ -204,3 +196,5 @@ TEST_F(SyncSearchEngineDataTypeControllerTest, OnUnrecoverableError) {
|
| search_engine_dtc_->OnUnrecoverableError(FROM_HERE, "Test");
|
| }
|
|
|
| +} // namespace
|
| +} // namespace browser_sync
|
|
|