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

Unified Diff: chrome/browser/sync/glue/generic_ui_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/generic_ui_data_type_controller_unittest.cc
diff --git a/chrome/browser/sync/glue/generic_ui_data_type_controller_unittest.cc b/chrome/browser/sync/glue/generic_ui_data_type_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..86929c45d3213bcfaffdb2fdfe6c41a19abc261f
--- /dev/null
+++ b/chrome/browser/sync/glue/generic_ui_data_type_controller_unittest.cc
@@ -0,0 +1,193 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "base/bind.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/tracked_objects.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/generic_ui_data_type_controller.h"
+#include "chrome/browser/sync/glue/generic_change_processor_fake.h"
+#include "chrome/browser/sync/profile_sync_components_factory_mock.h"
+#include "chrome/browser/sync/profile_sync_service_mock.h"
+#include "chrome/test/base/profile_mock.h"
+#include "content/test/test_browser_thread.h"
+
+using content::BrowserThread;
+using testing::_;
+using testing::InvokeWithoutArgs;
+using testing::Return;
+
+namespace browser_sync {
+namespace {
+
+// TODO(zea): Expand this to make the dtc type paramterizable. This will let us
+// test the basic functionality of all UIDataTypeControllers. We'll need to have
+// intelligent default values for the methods queried in the dependent services
+// (e.g. those queried in StartModels).
+class SyncGenericUIDataTypeControllerTest : public testing::Test {
+ public:
+ SyncGenericUIDataTypeControllerTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ type_(syncable::PREFERENCES){}
+
+ virtual void SetUp() {
+ profile_sync_factory_.reset(new ProfileSyncComponentsFactoryMock());
+ preference_dtc_ =
+ new GenericUIDataTypeController(type_,
+ profile_sync_factory_.get(),
+ &profile_,
+ &profile_sync_service_);
+ SetStartExpectations();
+ }
+
+ protected:
+ void SetStartExpectations() {
+ // Ownership gets passed to caller of CreateGenericChangeProcessor.
+ change_processor_ = new GenericChangeProcessorFake();
+ EXPECT_CALL(*profile_sync_factory_, GetSyncableServiceForType(type_)).
+ WillOnce(Return(syncable_service_.AsWeakPtr()));
+ EXPECT_CALL(*profile_sync_factory_, CreateGenericChangeProcessor(_, _, _)).
+ WillOnce(Return(change_processor_));
+ }
+
+ void SetActivateExpectations() {
+ EXPECT_CALL(profile_sync_service_, ActivateDataType(type_, _, _));
+ }
+
+ void SetStopExpectations() {
+ EXPECT_CALL(profile_sync_service_, DeactivateDataType(type_));
+ }
+
+ void PumpLoop() {
+ message_loop_.RunAllPending();
+ }
+
+ MessageLoopForUI message_loop_;
+ content::TestBrowserThread ui_thread_;
+ ProfileMock profile_;
+ scoped_ptr<ProfileSyncComponentsFactoryMock> profile_sync_factory_;
+ ProfileSyncServiceMock profile_sync_service_;
+ const syncable::ModelType type_;
+ StartCallbackMock start_callback_;
+ scoped_refptr<GenericUIDataTypeController> preference_dtc_;
+ GenericChangeProcessorFake* change_processor_;
+ SyncableServiceFake syncable_service_;
+};
+
+// Start the DTC. Verify that the callback is called with OK, the
+// service has been told to start syncing and that the DTC is now in RUNNING
+// state.
+TEST_F(SyncGenericUIDataTypeControllerTest, Start) {
+ SetActivateExpectations();
+ EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
+
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+ preference_dtc_->Start(
+ base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
+ EXPECT_EQ(DataTypeController::RUNNING, preference_dtc_->state());
+ EXPECT_TRUE(syncable_service_.syncing());
+}
+
+// Start and then stop the DTC. Verify that the service started and stopped
+// syncing, and that the DTC went from RUNNING to NOT_RUNNING.
+TEST_F(SyncGenericUIDataTypeControllerTest, StartStop) {
+ SetActivateExpectations();
+ SetStopExpectations();
+ EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
+
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+ preference_dtc_->Start(
+ base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
+ EXPECT_EQ(DataTypeController::RUNNING, preference_dtc_->state());
+ EXPECT_TRUE(syncable_service_.syncing());
+ preference_dtc_->Stop();
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+}
+
+// Start the DTC when no user nodes are created. Verify that the callback
+// is called with OK_FIRST_RUN. Stop the DTC.
+TEST_F(SyncGenericUIDataTypeControllerTest, StartStopFirstRun) {
+ SetActivateExpectations();
+ SetStopExpectations();
+ EXPECT_CALL(start_callback_, Run(DataTypeController::OK_FIRST_RUN, _));
+ change_processor_->set_has_nodes(false);
+
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+ preference_dtc_->Start(
+ base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
+ EXPECT_EQ(DataTypeController::RUNNING, preference_dtc_->state());
+ EXPECT_TRUE(syncable_service_.syncing());
+ preference_dtc_->Stop();
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+}
+
+// Start the DTC, but have the service fail association. Verify the callback
+// is called with ASSOCIATION_FAILED, the DTC goes to state DISABLED, and the
+// service is not syncing. Then stop the DTC.
+TEST_F(SyncGenericUIDataTypeControllerTest, StartAssociationFailed) {
+ SetStopExpectations();
+ EXPECT_CALL(start_callback_,
+ Run(DataTypeController::ASSOCIATION_FAILED, _));
+ syncable_service_.set_associate_success(false);
+
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+ preference_dtc_->Start(
+ base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
+ EXPECT_EQ(DataTypeController::DISABLED, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+ preference_dtc_->Stop();
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+}
+
+// Start the DTC but fail to check if there are user created nodes. Verify the
+// DTC calls the callback with UNRECOVERABLE_ERROR and that it goes into
+// NOT_RUNNING state. Verify the syncable service is not syncing.
+TEST_F(SyncGenericUIDataTypeControllerTest,
+ StartAssociationTriggersUnrecoverableError) {
+ EXPECT_CALL(start_callback_,
+ Run(DataTypeController::UNRECOVERABLE_ERROR, _));
+ change_processor_->set_has_nodes_success(false);
+
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+ preference_dtc_->Start(
+ base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+}
+
+// Start the DTC, but then trigger an unrecoverable error. Verify the syncer
+// gets stopped and the DTC is in NOT_RUNNING state.
+TEST_F(SyncGenericUIDataTypeControllerTest, OnUnrecoverableError) {
+ SetActivateExpectations();
+ EXPECT_CALL(profile_sync_service_, OnUnrecoverableError(_,_)).
+ WillOnce(InvokeWithoutArgs(preference_dtc_.get(),
+ &GenericUIDataTypeController::Stop));
+ SetStopExpectations();
+ EXPECT_CALL(start_callback_, Run(DataTypeController::OK, _));
+
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+ preference_dtc_->Start(
+ base::Bind(&StartCallbackMock::Run, base::Unretained(&start_callback_)));
+ EXPECT_TRUE(syncable_service_.syncing());
+ preference_dtc_->OnUnrecoverableError(FROM_HERE, "Test");
+ PumpLoop();
+ EXPECT_EQ(DataTypeController::NOT_RUNNING, preference_dtc_->state());
+ EXPECT_FALSE(syncable_service_.syncing());
+}
+
+} // namespace
+} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698