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

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

Issue 9395058: [Sync] Remove SyncableServiceAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 9 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/app_notification_data_type_controller_unittest.cc
diff --git a/chrome/browser/sync/glue/app_notification_data_type_controller_unittest.cc b/chrome/browser/sync/glue/app_notification_data_type_controller_unittest.cc
index 40bd305c40d43b0cd7cda2b36e28dce64ff3a789..b63ef7cbdd79551411906f36008c56978d654125 100644
--- a/chrome/browser/sync/glue/app_notification_data_type_controller_unittest.cc
+++ b/chrome/browser/sync/glue/app_notification_data_type_controller_unittest.cc
@@ -9,10 +9,10 @@
#include "base/tracked_objects.h"
#include "chrome/browser/extensions/app_notification_manager.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/sync/api/fake_syncable_service.h"
#include "chrome/browser/sync/glue/app_notification_data_type_controller.h"
-#include "chrome/browser/sync/glue/change_processor_mock.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/profile_sync_components_factory_mock.h"
#include "chrome/browser/sync/profile_sync_service_mock.h"
#include "chrome/common/chrome_notification_types.h"
@@ -21,11 +21,6 @@
#include "content/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
-using browser_sync::AppNotificationDataTypeController;
-using browser_sync::ChangeProcessorMock;
-using browser_sync::DataTypeController;
-using browser_sync::ModelAssociatorMock;
-using browser_sync::StartCallbackMock;
using content::BrowserThread;
using testing::_;
using testing::DoAll;
@@ -33,6 +28,13 @@ using testing::InvokeWithoutArgs;
using testing::Return;
using testing::SetArgumentPointee;
+namespace browser_sync {
+namespace {
+
+ACTION_P(ReturnAndRelease, change_processor) {
+ return change_processor->release();
+}
+
class TestAppNotificationDataTypeController
: public AppNotificationDataTypeController {
public:
@@ -59,7 +61,8 @@ class SyncAppNotificationDataTypeControllerTest
public:
SyncAppNotificationDataTypeControllerTest()
: ui_thread_(BrowserThread::UI, &ui_loop_),
- file_thread_(BrowserThread::FILE) {
+ file_thread_(BrowserThread::FILE),
+ change_processor_(new FakeGenericChangeProcessor()) {
}
virtual void SetUp() {
@@ -67,14 +70,12 @@ class SyncAppNotificationDataTypeControllerTest
file_thread_.Start();
profile_.reset(new TestingProfile());
- model_associator_ = new ModelAssociatorMock();
- change_processor_ = new ChangeProcessorMock();
- profile_sync_factory_.reset(new ProfileSyncComponentsFactoryMock(
- model_associator_, change_processor_));
+ profile_sync_factory_.reset(new ProfileSyncComponentsFactoryMock());
app_notif_dtc_ = new TestAppNotificationDataTypeController(
profile_sync_factory_.get(),
profile_.get(),
&service_);
+ SetStartExpectations();
}
virtual void TearDown() { }
@@ -105,21 +106,21 @@ class SyncAppNotificationDataTypeControllerTest
WaitForFileThread();
}
- void SetAssociateExpectations() {
- EXPECT_CALL(*model_associator_, CryptoReadyIfNecessary()).
- WillRepeatedly(Return(true));
+ void SetStartExpectations() {
+ // Ownership gets passed to caller of CreateGenericChangeProcessor.
EXPECT_CALL(*profile_sync_factory_,
- CreateAppNotificationSyncComponents(_, _));
- EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
- WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true)));
- EXPECT_CALL(*model_associator_, AssociateModels(_)).
- WillRepeatedly(Return(true));
+ GetSyncableServiceForType(syncable::APP_NOTIFICATIONS)).
+ WillOnce(Return(syncable_service_.AsWeakPtr()));
+ EXPECT_CALL(*profile_sync_factory_, CreateGenericChangeProcessor(_, _, _)).
+ WillOnce(ReturnAndRelease(&change_processor_));
+ }
+
+ void SetActivateExpectations() {
EXPECT_CALL(service_, ActivateDataType(_, _, _));
}
void SetStopExpectations() {
EXPECT_CALL(service_, DeactivateDataType(_));
- EXPECT_CALL(*model_associator_, DisassociateModels(_));
}
void PumpLoop() {
@@ -133,8 +134,8 @@ class SyncAppNotificationDataTypeControllerTest
scoped_refptr<TestAppNotificationDataTypeController> app_notif_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_;
};
@@ -142,9 +143,9 @@ class SyncAppNotificationDataTypeControllerTest
// successfully.
TEST_F(SyncAppNotificationDataTypeControllerTest, StartManagerReady) {
InitAndLoadManager();
+ SetActivateExpectations();
EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state());
- SetAssociateExpectations();
EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
app_notif_dtc_->Start(
base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
@@ -154,9 +155,10 @@ TEST_F(SyncAppNotificationDataTypeControllerTest, StartManagerReady) {
// When notification manager is not ready, sync assocation should wait
// until loaded event is seen.
TEST_F(SyncAppNotificationDataTypeControllerTest, StartManagerNotReady) {
- EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state());
- SetAssociateExpectations();
+ SetActivateExpectations();
EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
+
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state());
app_notif_dtc_->Start(
base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
EXPECT_EQ(DataTypeController::MODEL_STARTING, app_notif_dtc_->state());
@@ -169,85 +171,68 @@ TEST_F(SyncAppNotificationDataTypeControllerTest, StartManagerNotReady) {
app_notif_dtc_->GetAppNotificationManager()),
content::NotificationService::NoDetails());
EXPECT_EQ(DataTypeController::RUNNING, app_notif_dtc_->state());
+ EXPECT_TRUE(syncable_service_.syncing());
}
TEST_F(SyncAppNotificationDataTypeControllerTest, StartFirstRun) {
InitAndLoadManager();
- SetAssociateExpectations();
- EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
- WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(true)));
+ SetActivateExpectations();
EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _));
- app_notif_dtc_->Start(
- base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
-}
+ change_processor_->set_sync_model_has_user_created_nodes(false);
-TEST_F(SyncAppNotificationDataTypeControllerTest, StartOk) {
- InitAndLoadManager();
- SetAssociateExpectations();
- EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
- WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true)));
- EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
app_notif_dtc_->Start(
base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
+ EXPECT_EQ(DataTypeController::RUNNING, app_notif_dtc_->state());
+ EXPECT_TRUE(syncable_service_.syncing());
}
TEST_F(SyncAppNotificationDataTypeControllerTest, StartAssociationFailed) {
InitAndLoadManager();
- EXPECT_CALL(*profile_sync_factory_,
- CreateAppNotificationSyncComponents(_, _));
- 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::APP_NOTIFICATIONS),
- Return(false)));
-
EXPECT_CALL(start_callback_,
Run(DataTypeController::ASSOCIATION_FAILED, _));
+ syncable_service_.set_merge_data_and_start_syncing_error(
+ SyncError(FROM_HERE, "Error", syncable::APP_NOTIFICATIONS));
+
app_notif_dtc_->Start(
base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
EXPECT_EQ(DataTypeController::DISABLED, app_notif_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
}
TEST_F(SyncAppNotificationDataTypeControllerTest,
StartAssociationTriggersUnrecoverableError) {
InitAndLoadManager();
- // Set up association to fail with an unrecoverable error.
- EXPECT_CALL(*profile_sync_factory_,
- CreateAppNotificationSyncComponents(_, _));
- 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);
+
app_notif_dtc_->Start(
base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
}
TEST_F(SyncAppNotificationDataTypeControllerTest, Stop) {
InitAndLoadManager();
- SetAssociateExpectations();
+ SetActivateExpectations();
SetStopExpectations();
+ EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state());
-
- EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
+ EXPECT_FALSE(syncable_service_.syncing());
app_notif_dtc_->Start(
base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
EXPECT_EQ(DataTypeController::RUNNING, app_notif_dtc_->state());
+ EXPECT_TRUE(syncable_service_.syncing());
app_notif_dtc_->Stop();
EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
}
TEST_F(SyncAppNotificationDataTypeControllerTest, OnUnrecoverableError) {
InitAndLoadManager();
- SetAssociateExpectations();
- EXPECT_CALL(*model_associator_, SyncModelHasUserCreatedNodes(_)).
- WillRepeatedly(DoAll(SetArgumentPointee<0>(true), Return(true)));
+ SetActivateExpectations();
EXPECT_CALL(service_, OnUnrecoverableError(_, _)).
WillOnce(InvokeWithoutArgs(app_notif_dtc_.get(),
&AppNotificationDataTypeController::Stop));
@@ -256,7 +241,14 @@ TEST_F(SyncAppNotificationDataTypeControllerTest, OnUnrecoverableError) {
EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
app_notif_dtc_->Start(
base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
+ EXPECT_EQ(DataTypeController::RUNNING, app_notif_dtc_->state());
+ EXPECT_TRUE(syncable_service_.syncing());
// This should cause app_notif_dtc_->Stop() to be called.
app_notif_dtc_->OnUnrecoverableError(FROM_HERE, "Test");
PumpLoop();
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, app_notif_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
}
+
+} // namespace
+} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698