Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4303)

Unified Diff: chrome/browser/sync/glue/search_engine_data_type_controller_unittest.cc

Issue 9395058: [Sync] Remove SyncableServiceAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..de2a4038c34c84ed8412a0466a5db85fc967876c 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/syncable_service_fake.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/generic_change_processor_fake.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,29 @@
#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 {
+
class SyncSearchEngineDataTypeControllerTest : public testing::Test {
public:
SyncSearchEngineDataTypeControllerTest() {}
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 +55,22 @@ 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.
+ change_processor_ = new GenericChangeProcessorFake();
+ EXPECT_CALL(*profile_sync_factory_,
+ GetSyncableServiceForType(syncable::SEARCH_ENGINES)).
+ WillOnce(Return(syncable_service_.AsWeakPtr()));
+ EXPECT_CALL(*profile_sync_factory_, CreateGenericChangeProcessor(_, _, _)).
+ WillOnce(Return(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 +80,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_;
+ GenericChangeProcessorFake* change_processor_;
+ SyncableServiceFake 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 +115,70 @@ 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_has_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_associate_success(false);
+
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_has_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 +191,5 @@ TEST_F(SyncSearchEngineDataTypeControllerTest, OnUnrecoverableError) {
search_engine_dtc_->OnUnrecoverableError(FROM_HERE, "Test");
}
+} // namespace
+} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698