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

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

Issue 6874018: make new syncer thread the default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Send for CR. Created 9 years, 8 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/data_type_manager_impl_unittest.cc
diff --git a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc
index d8d875b612569d5d1e7805191753c1741664f755..7a37f389f077027162703503423aa052c279e162 100644
--- a/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc
+++ b/chrome/browser/sync/glue/data_type_manager_impl_unittest.cc
@@ -1,688 +1,3 @@
// Copyright (c) 2011 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 <set>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop.h"
-#include "base/stl_util-inl.h"
-#include "base/task.h"
-#include "chrome/browser/sync/glue/data_type_controller.h"
-#include "chrome/browser/sync/glue/data_type_controller_mock.h"
-#include "chrome/browser/sync/glue/data_type_manager_impl.h"
-#include "chrome/browser/sync/glue/sync_backend_host_mock.h"
-#include "chrome/browser/sync/profile_sync_test_util.h"
-#include "chrome/browser/sync/syncable/model_type.h"
-#include "content/browser/browser_thread.h"
-#include "content/common/notification_details.h"
-#include "content/common/notification_observer_mock.h"
-#include "content/common/notification_registrar.h"
-#include "content/common/notification_service.h"
-#include "content/common/notification_type.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using browser_sync::DataTypeManager;
-using browser_sync::DataTypeManagerImpl;
-using browser_sync::DataTypeController;
-using browser_sync::DataTypeControllerMock;
-using browser_sync::SyncBackendHostMock;
-using testing::_;
-using testing::AtLeast;
-using testing::DoAll;
-using testing::DoDefault;
-using testing::InSequence;
-using testing::Mock;
-using testing::Property;
-using testing::Pointee;
-using testing::Return;
-using testing::SaveArg;
-
-ACTION_P(InvokeCallback, callback_result) {
- arg0->Run(callback_result, FROM_HERE);
- delete arg0;
-}
-
-ACTION_P2(InvokeCallbackPointer, callback, argument) {
- callback->Run(argument, FROM_HERE);
- delete callback;
-}
-
-class DataTypeManagerImplTest : public testing::Test {
- public:
- DataTypeManagerImplTest()
- : ui_thread_(BrowserThread::UI, &message_loop_) {}
-
- virtual ~DataTypeManagerImplTest() {
- }
-
- protected:
- virtual void SetUp() {
- registrar_.Add(&observer_,
- NotificationType::SYNC_CONFIGURE_START,
- NotificationService::AllSources());
- registrar_.Add(&observer_,
- NotificationType::SYNC_CONFIGURE_DONE,
- NotificationService::AllSources());
- }
-
- DataTypeControllerMock* MakeBookmarkDTC() {
- DataTypeControllerMock* dtc = new DataTypeControllerMock();
- EXPECT_CALL(*dtc, enabled()).WillRepeatedly(Return(true));
- EXPECT_CALL(*dtc, type()).WillRepeatedly(Return(syncable::BOOKMARKS));
- EXPECT_CALL(*dtc, name()).WillRepeatedly(Return("bookmark"));
- return dtc;
- }
-
- DataTypeControllerMock* MakePreferenceDTC() {
- DataTypeControllerMock* dtc = new DataTypeControllerMock();
- EXPECT_CALL(*dtc, enabled()).WillRepeatedly(Return(true));
- EXPECT_CALL(*dtc, type()).WillRepeatedly(Return(syncable::PREFERENCES));
- EXPECT_CALL(*dtc, name()).WillRepeatedly(Return("preference"));
- return dtc;
- }
-
- DataTypeControllerMock* MakePasswordDTC() {
- DataTypeControllerMock* dtc = new DataTypeControllerMock();
- SetPasswordDTCExpectations(dtc);
- return dtc;
- }
-
- void SetPasswordDTCExpectations(DataTypeControllerMock* dtc) {
- EXPECT_CALL(*dtc, enabled()).WillRepeatedly(Return(true));
- EXPECT_CALL(*dtc, type()).WillRepeatedly(Return(syncable::PASSWORDS));
- EXPECT_CALL(*dtc, name()).WillRepeatedly(Return("passwords"));
- }
-
- void SetStartStopExpectations(DataTypeControllerMock* mock_dtc) {
- InSequence seq;
- EXPECT_CALL(*mock_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- EXPECT_CALL(*mock_dtc, Start(_)).
- WillOnce(InvokeCallback((DataTypeController::OK)));
- EXPECT_CALL(*mock_dtc, state()).
- WillRepeatedly(Return(DataTypeController::RUNNING));
- EXPECT_CALL(*mock_dtc, Stop()).Times(1);
- EXPECT_CALL(*mock_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- }
-
- void SetBusyStartStopExpectations(DataTypeControllerMock* mock_dtc,
- DataTypeController::State busy_state) {
- InSequence seq;
- EXPECT_CALL(*mock_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- EXPECT_CALL(*mock_dtc, Start(_)).
- WillOnce(InvokeCallback((DataTypeController::OK)));
- EXPECT_CALL(*mock_dtc, state()).
- WillRepeatedly(Return(busy_state));
- EXPECT_CALL(*mock_dtc, Stop()).Times(1);
- EXPECT_CALL(*mock_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- }
-
- void SetNotUsedExpectations(DataTypeControllerMock* mock_dtc) {
- EXPECT_CALL(*mock_dtc, Start(_)).Times(0);
- EXPECT_CALL(*mock_dtc, Stop()).Times(0);
- EXPECT_CALL(*mock_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- }
-
- void SetConfigureStartExpectation() {
- EXPECT_CALL(
- observer_,
- Observe(NotificationType(NotificationType::SYNC_CONFIGURE_START),
- _, _));
- }
-
- void SetConfigureDoneExpectation(DataTypeManager::ConfigureResult result) {
- EXPECT_CALL(
- observer_,
- Observe(NotificationType(NotificationType::SYNC_CONFIGURE_DONE), _,
- Property(&Details<DataTypeManager::ConfigureResult>::ptr,
- Pointee(result))));
- }
-
- void SetBackendExpectations(int times) {
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(times);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(times);
- EXPECT_CALL(backend_, RequestPause()).Times(times);
- EXPECT_CALL(backend_, RequestResume()).Times(times);
- }
-
- MessageLoopForUI message_loop_;
- BrowserThread ui_thread_;
- DataTypeController::TypeMap controllers_;
- SyncBackendHostMock backend_;
- NotificationObserverMock observer_;
- NotificationRegistrar registrar_;
- std::set<syncable::ModelType> types_;
-};
-
-TEST_F(DataTypeManagerImplTest, NoControllers) {
- DataTypeManagerImpl dtm(&backend_, controllers_);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, ConfigureOne) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
- SetBackendExpectations(1);
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::BOOKMARKS);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, ConfigureOneStopWhileStarting) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetBusyStartStopExpectations(bookmark_dtc,
- DataTypeController::MODEL_STARTING);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
- SetBackendExpectations(1);
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::BOOKMARKS);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, ConfigureOneStopWhileAssociating) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetBusyStartStopExpectations(bookmark_dtc, DataTypeController::ASSOCIATING);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
- SetBackendExpectations(1);
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::BOOKMARKS);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, OneWaitingForCrypto) {
- DataTypeControllerMock* password_dtc = MakePasswordDTC();
- EXPECT_CALL(*password_dtc, state()).Times(AtLeast(2)).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- EXPECT_CALL(*password_dtc, Start(_)).
- WillOnce(InvokeCallback((DataTypeController::NEEDS_CRYPTO)));
-
- controllers_[syncable::PASSWORDS] = password_dtc;
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- EXPECT_CALL(backend_, RequestPause()).Times(1);
-
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::PASSWORDS);
- SetConfigureStartExpectation();
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::BLOCKED, dtm.state());
-
- Mock::VerifyAndClearExpectations(&backend_);
- Mock::VerifyAndClearExpectations(&observer_);
- Mock::VerifyAndClearExpectations(password_dtc);
-
- SetConfigureDoneExpectation(DataTypeManager::OK);
- SetPasswordDTCExpectations(password_dtc);
- EXPECT_CALL(*password_dtc, state()).
- WillOnce(Return(DataTypeController::NOT_RUNNING)).
- WillRepeatedly(Return(DataTypeController::RUNNING));
- EXPECT_CALL(*password_dtc, Start(_)).
- WillOnce(InvokeCallback((DataTypeController::OK)));
-
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- EXPECT_CALL(backend_, RequestResume()).Times(1);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- EXPECT_CALL(*password_dtc, Stop()).Times(1);
- dtm.Stop();
-
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-
-TEST_F(DataTypeManagerImplTest, ConfigureOneThenAnother) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
- DataTypeControllerMock* preference_dtc = MakePreferenceDTC();
- SetStartStopExpectations(preference_dtc);
- controllers_[syncable::PREFERENCES] = preference_dtc;
-
- SetBackendExpectations(2);
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::BOOKMARKS);
-
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
-
- types_.insert(syncable::PREFERENCES);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
-
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
-
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, ConfigureOneThenSwitch) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
- DataTypeControllerMock* preference_dtc = MakePreferenceDTC();
- SetStartStopExpectations(preference_dtc);
- controllers_[syncable::PREFERENCES] = preference_dtc;
-
- SetBackendExpectations(2);
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::BOOKMARKS);
-
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
-
- types_.clear();
- types_.insert(syncable::PREFERENCES);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
-
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, ConfigureWhileOneInFlight) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- // Save the callback here so we can interrupt startup.
- DataTypeController::StartCallback* callback;
- {
- InSequence seq;
- EXPECT_CALL(*bookmark_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- EXPECT_CALL(*bookmark_dtc, Start(_)).
- WillOnce(SaveArg<0>(&callback));
- EXPECT_CALL(*bookmark_dtc, state()).
- WillRepeatedly(Return(DataTypeController::RUNNING));
- EXPECT_CALL(*bookmark_dtc, Stop()).Times(1);
- EXPECT_CALL(*bookmark_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- }
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- DataTypeControllerMock* preference_dtc = MakePreferenceDTC();
- SetStartStopExpectations(preference_dtc);
- controllers_[syncable::PREFERENCES] = preference_dtc;
-
- // Request/Resume only called once due to the configures being inlined.
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(2);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(2);
- EXPECT_CALL(backend_, RequestPause()).Times(1);
- EXPECT_CALL(backend_, RequestResume()).Times(1);
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::BOOKMARKS);
-
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
-
- // At this point, the bookmarks dtc should be in flight. Add
- // preferences and continue starting bookmarks.
- types_.insert(syncable::PREFERENCES);
- dtm.Configure(types_);
- callback->Run(DataTypeController::OK, FROM_HERE);
- delete callback;
-
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
-
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, ConfigureWhilePausePending) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
- DataTypeControllerMock* preference_dtc = MakePreferenceDTC();
- SetStartStopExpectations(preference_dtc);
- controllers_[syncable::PREFERENCES] = preference_dtc;
-
- // Don't notify the first time pause is called.
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(2);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(2);
- EXPECT_CALL(backend_, RequestPause()).
- WillOnce(Return(true));
- EXPECT_CALL(backend_, RequestResume()).Times(1);
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::BOOKMARKS);
-
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::PAUSE_PENDING, dtm.state());
-
- // Configure while pause pending.
- types_.insert(syncable::PREFERENCES);
- dtm.Configure(types_);
-
- // Send the SYNC_PAUSED notification. This will allow the DTM to
- // wake up and restart itself with the new configuration.
- NotificationService::current()->Notify(NotificationType::SYNC_PAUSED,
- NotificationService::AllSources(),
- NotificationService::NoDetails());
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, StopWhilePausePending) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetNotUsedExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- // Never notify when RequestPause is called.
- EXPECT_CALL(backend_, RequestPause()).WillOnce(Return(true));
- EXPECT_CALL(backend_, RequestResume()).Times(0);
- DataTypeManagerImpl dtm(&backend_, controllers_);
-
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::ABORTED);
- types_.insert(syncable::BOOKMARKS);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::PAUSE_PENDING, dtm.state());
-
- // Stop while pause pending.
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-
- // We should be able to safely handle a SYNC_PAUSED notification.
- NotificationService::current()->Notify(NotificationType::SYNC_PAUSED,
- NotificationService::AllSources(),
- NotificationService::NoDetails());
-}
-
-TEST_F(DataTypeManagerImplTest, ConfigureWhileResumePending) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
- DataTypeControllerMock* preference_dtc = MakePreferenceDTC();
- SetStartStopExpectations(preference_dtc);
- controllers_[syncable::PREFERENCES] = preference_dtc;
-
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(2);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(2);
- EXPECT_CALL(backend_, RequestPause()).Times(2);
- // Don't notify the first time resume is called.
- EXPECT_CALL(backend_, RequestResume()).
- WillOnce(Return(true)).
- WillOnce(DoDefault());
- DataTypeManagerImpl dtm(&backend_, controllers_);
- types_.insert(syncable::BOOKMARKS);
-
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::RESUME_PENDING, dtm.state());
-
- // Configure while resume pending.
- types_.insert(syncable::PREFERENCES);
- dtm.Configure(types_);
-
- // Send the SYNC_PAUSED notification. This will allow the DTM to
- // wake up and restart itself with the new configuration.
- NotificationService::current()->Notify(NotificationType::SYNC_RESUMED,
- NotificationService::AllSources(),
- NotificationService::NoDetails());
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, StopWhileResumePending) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- EXPECT_CALL(backend_, RequestPause()).Times(1);
- // Never notify pause resumed.
- EXPECT_CALL(backend_, RequestResume()).WillOnce(Return(true));
- DataTypeManagerImpl dtm(&backend_, controllers_);
-
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::ABORTED);
- types_.insert(syncable::BOOKMARKS);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::RESUME_PENDING, dtm.state());
-
- // Stop while pause pending.
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-
- // We should be able to safely handle a SYNC_RESUMED notification.
- NotificationService::current()->Notify(NotificationType::SYNC_RESUMED,
- NotificationService::AllSources(),
- NotificationService::NoDetails());
-}
-
-TEST_F(DataTypeManagerImplTest, OneFailingController) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- EXPECT_CALL(*bookmark_dtc, Start(_)).
- WillOnce(InvokeCallback((DataTypeController::ASSOCIATION_FAILED)));
- EXPECT_CALL(*bookmark_dtc, Stop()).Times(0);
- EXPECT_CALL(*bookmark_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- DataTypeManagerImpl dtm(&backend_, controllers_);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::ASSOCIATION_FAILED);
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- EXPECT_CALL(backend_, RequestPause()).Times(1);
- EXPECT_CALL(backend_, RequestResume()).Times(0);
-
- types_.insert(syncable::BOOKMARKS);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, StopWhileInFlight) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- DataTypeControllerMock* preference_dtc = MakePreferenceDTC();
- // Save the callback here so we can interrupt startup.
- DataTypeController::StartCallback* callback;
- EXPECT_CALL(*preference_dtc, Start(_)).
- WillOnce(SaveArg<0>(&callback));
- EXPECT_CALL(*preference_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- controllers_[syncable::PREFERENCES] = preference_dtc;
-
- DataTypeManagerImpl dtm(&backend_, controllers_);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::ABORTED);
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- EXPECT_CALL(backend_, RequestPause()).Times(1);
- EXPECT_CALL(backend_, RequestResume()).Times(0);
-
- types_.insert(syncable::BOOKMARKS);
- types_.insert(syncable::PREFERENCES);
- dtm.Configure(types_);
- // Configure should stop in the CONFIGURING state because we are
- // waiting for the preferences callback to be invoked.
- EXPECT_EQ(DataTypeManager::CONFIGURING, dtm.state());
-
- // Call stop before the preference callback is invoked.
- EXPECT_CALL(*preference_dtc, Stop()).
- WillOnce(InvokeCallbackPointer(callback, DataTypeController::ABORTED));
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, SecondControllerFails) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- DataTypeControllerMock* preference_dtc = MakePreferenceDTC();
- EXPECT_CALL(*preference_dtc, Start(_)).
- WillOnce(InvokeCallback((DataTypeController::ASSOCIATION_FAILED)));
- EXPECT_CALL(*preference_dtc, Stop()).Times(0);
- EXPECT_CALL(*preference_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- controllers_[syncable::PREFERENCES] = preference_dtc;
-
- DataTypeManagerImpl dtm(&backend_, controllers_);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::ASSOCIATION_FAILED);
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- EXPECT_CALL(backend_, RequestPause()).Times(1);
- EXPECT_CALL(backend_, RequestResume()).Times(0);
-
- types_.insert(syncable::BOOKMARKS);
- types_.insert(syncable::PREFERENCES);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, PauseFailed) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- EXPECT_CALL(*bookmark_dtc, Start(_)).Times(0);
- EXPECT_CALL(*bookmark_dtc, state()).
- WillRepeatedly(Return(DataTypeController::NOT_RUNNING));
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- DataTypeManagerImpl dtm(&backend_, controllers_);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::UNRECOVERABLE_ERROR);
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- EXPECT_CALL(backend_, RequestPause()).WillOnce(Return(false));
- EXPECT_CALL(backend_, RequestResume()).Times(0);
-
- types_.insert(syncable::BOOKMARKS);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, ResumeFailed) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- DataTypeManagerImpl dtm(&backend_, controllers_);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::UNRECOVERABLE_ERROR);
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).Times(1);
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(1);
- EXPECT_CALL(backend_, RequestPause()).Times(1);
- EXPECT_CALL(backend_, RequestResume()).WillOnce(Return(false));
-
- types_.insert(syncable::BOOKMARKS);
- dtm.Configure(types_);
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, ConfigureWhileDownloadPending) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetStartStopExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- DataTypeControllerMock* preference_dtc = MakePreferenceDTC();
- SetStartStopExpectations(preference_dtc);
- controllers_[syncable::PREFERENCES] = preference_dtc;
-
- DataTypeManagerImpl dtm(&backend_, controllers_);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::OK);
- CancelableTask* task;
- // Grab the task the first time this is called so we can configure
- // before it is finished.
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).
- WillOnce(SaveArg<2>(&task)).
- WillOnce(DoDefault());
- EXPECT_CALL(backend_, StartSyncingWithServer()).Times(2);
- EXPECT_CALL(backend_, RequestPause()).Times(1);
- EXPECT_CALL(backend_, RequestResume()).Times(1);
-
- types_.insert(syncable::BOOKMARKS);
- dtm.Configure(types_);
- // Configure should stop in the DOWNLOAD_PENDING state because we
- // are waiting for the download ready task to be run.
- EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm.state());
-
- types_.insert(syncable::PREFERENCES);
- dtm.Configure(types_);
-
- // Running the task will queue a restart task to the message loop, and
- // eventually get us configured.
- task->Run();
- delete task;
- MessageLoop::current()->RunAllPending();
- EXPECT_EQ(DataTypeManager::CONFIGURED, dtm.state());
-
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-}
-
-TEST_F(DataTypeManagerImplTest, StopWhileDownloadPending) {
- DataTypeControllerMock* bookmark_dtc = MakeBookmarkDTC();
- SetNotUsedExpectations(bookmark_dtc);
- controllers_[syncable::BOOKMARKS] = bookmark_dtc;
-
- DataTypeManagerImpl dtm(&backend_, controllers_);
- SetConfigureStartExpectation();
- SetConfigureDoneExpectation(DataTypeManager::ABORTED);
- CancelableTask* task;
- // Grab the task the first time this is called so we can stop
- // before it is finished.
- EXPECT_CALL(backend_, ConfigureDataTypes(_, _, _)).
- WillOnce(SaveArg<2>(&task));
- EXPECT_CALL(backend_, StartSyncingWithServer());
- EXPECT_CALL(backend_, RequestPause()).Times(0);
- EXPECT_CALL(backend_, RequestResume()).Times(0);
-
- types_.insert(syncable::BOOKMARKS);
- dtm.Configure(types_);
- // Configure should stop in the DOWNLOAD_PENDING state because we
- // are waiting for the download ready task to be run.
- EXPECT_EQ(DataTypeManager::DOWNLOAD_PENDING, dtm.state());
-
- dtm.Stop();
- EXPECT_EQ(DataTypeManager::STOPPED, dtm.state());
-
- // It should be perfectly safe to run this task even though the DTM
- // has been stopped.
- task->Run();
- delete task;
-}

Powered by Google App Engine
This is Rietveld 408576698