Index: components/sync/driver/model_association_manager_unittest.cc |
diff --git a/components/sync_driver/model_association_manager_unittest.cc b/components/sync/driver/model_association_manager_unittest.cc |
similarity index 77% |
rename from components/sync_driver/model_association_manager_unittest.cc |
rename to components/sync/driver/model_association_manager_unittest.cc |
index f5737526c9286aab5798825f6e624f6d92afcdbc..6965d261413c76479c8c1fa27b86e57cdf0fae5b 100644 |
--- a/components/sync_driver/model_association_manager_unittest.cc |
+++ b/components/sync/driver/model_association_manager_unittest.cc |
@@ -2,11 +2,11 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "components/sync_driver/model_association_manager.h" |
+#include "components/sync/driver/model_association_manager.h" |
#include "base/callback.h" |
#include "base/message_loop/message_loop.h" |
-#include "components/sync_driver/fake_data_type_controller.h" |
+#include "components/sync/driver/fake_data_type_controller.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -14,26 +14,25 @@ using ::testing::_; |
namespace sync_driver { |
-class MockModelAssociationManagerDelegate : |
- public ModelAssociationManagerDelegate { |
+class MockModelAssociationManagerDelegate |
+ : public ModelAssociationManagerDelegate { |
public: |
MockModelAssociationManagerDelegate() {} |
~MockModelAssociationManagerDelegate() {} |
MOCK_METHOD0(OnAllDataTypesReadyForConfigure, void()); |
MOCK_METHOD2(OnSingleDataTypeAssociationDone, |
- void(syncer::ModelType type, |
- const syncer::DataTypeAssociationStats& association_stats)); |
+ void(syncer::ModelType type, |
+ const syncer::DataTypeAssociationStats& association_stats)); |
MOCK_METHOD2(OnSingleDataTypeWillStop, |
void(syncer::ModelType, const syncer::SyncError& error)); |
- MOCK_METHOD1(OnModelAssociationDone, void( |
- const DataTypeManager::ConfigureResult& result)); |
+ MOCK_METHOD1(OnModelAssociationDone, |
+ void(const DataTypeManager::ConfigureResult& result)); |
}; |
FakeDataTypeController* GetController( |
const DataTypeController::TypeMap& controllers, |
syncer::ModelType model_type) { |
- DataTypeController::TypeMap::const_iterator it = |
- controllers.find(model_type); |
+ DataTypeController::TypeMap::const_iterator it = controllers.find(model_type); |
if (it == controllers.end()) { |
return NULL; |
} |
@@ -47,8 +46,7 @@ ACTION_P(VerifyResult, expected_result) { |
class SyncModelAssociationManagerTest : public testing::Test { |
public: |
- SyncModelAssociationManagerTest() { |
- } |
+ SyncModelAssociationManagerTest() {} |
protected: |
base::MessageLoopForUI ui_loop_; |
@@ -61,15 +59,13 @@ class SyncModelAssociationManagerTest : public testing::Test { |
TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- controllers_[syncer::APPS] = |
- new FakeDataTypeController(syncer::APPS); |
- ModelAssociationManager model_association_manager(&controllers_, |
- &delegate_); |
+ controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result)); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::NOT_RUNNING); |
@@ -90,19 +86,17 @@ TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { |
DataTypeController::ASSOCIATING); |
EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
DataTypeController::ASSOCIATING); |
- GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
- DataTypeController::OK); |
- GetController(controllers_, syncer::APPS)->FinishStart( |
- DataTypeController::OK); |
+ GetController(controllers_, syncer::BOOKMARKS) |
+ ->FinishStart(DataTypeController::OK); |
+ GetController(controllers_, syncer::APPS) |
+ ->FinishStart(DataTypeController::OK); |
} |
// Start a type and call stop before it finishes associating. |
TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- ModelAssociationManager model_association_manager( |
- &controllers_, |
- &delegate_); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
@@ -110,10 +104,9 @@ TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { |
DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, |
types); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result)); |
- EXPECT_CALL(delegate_, |
- OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result)); |
+ EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
model_association_manager.Initialize(types); |
model_association_manager.StartAssociationAsync(types); |
@@ -129,24 +122,21 @@ TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { |
TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- ModelAssociationManager model_association_manager( |
- &controllers_, |
- &delegate_); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result)); |
- EXPECT_CALL(delegate_, |
- OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result)); |
+ EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
model_association_manager.Initialize(types); |
model_association_manager.StartAssociationAsync(types); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::ASSOCIATING); |
- GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
- DataTypeController::OK); |
+ GetController(controllers_, syncer::BOOKMARKS) |
+ ->FinishStart(DataTypeController::OK); |
model_association_manager.Stop(); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
@@ -157,24 +147,21 @@ TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { |
TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- ModelAssociationManager model_association_manager( |
- &controllers_, |
- &delegate_); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
- EXPECT_CALL(delegate_, |
- OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result)); |
+ EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result)); |
model_association_manager.Initialize(types); |
model_association_manager.StartAssociationAsync(types); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::ASSOCIATING); |
- GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
- DataTypeController::ASSOCIATION_FAILED); |
+ GetController(controllers_, syncer::BOOKMARKS) |
+ ->FinishStart(DataTypeController::ASSOCIATION_FAILED); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::NOT_RUNNING); |
} |
@@ -183,17 +170,14 @@ TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { |
TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- ModelAssociationManager model_association_manager( |
- &controllers_, |
- &delegate_); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
DataTypeManager::ConfigureResult expected_result( |
DataTypeManager::UNRECOVERABLE_ERROR, types); |
- EXPECT_CALL(delegate_, |
- OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result)); |
+ EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result)); |
model_association_manager.Initialize(types); |
@@ -201,18 +185,16 @@ TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::ASSOCIATING); |
- GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
- DataTypeController::UNRECOVERABLE_ERROR); |
+ GetController(controllers_, syncer::BOOKMARKS) |
+ ->FinishStart(DataTypeController::UNRECOVERABLE_ERROR); |
} |
TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- controllers_[syncer::APPS] = |
- new FakeDataTypeController(syncer::APPS); |
+ controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); |
GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
- ModelAssociationManager model_association_manager(&controllers_, |
- &delegate_); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
types.Put(syncer::APPS); |
@@ -220,16 +202,15 @@ TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { |
DataTypeManager::ConfigureResult expected_result_partially_done( |
DataTypeManager::OK, types); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result_partially_done)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result_partially_done)); |
model_association_manager.Initialize(types); |
model_association_manager.StartAssociationAsync(types); |
- GetController(controllers_, syncer::APPS)->FinishStart( |
- DataTypeController::OK); |
+ GetController(controllers_, syncer::APPS) |
+ ->FinishStart(DataTypeController::OK); |
- EXPECT_CALL(delegate_, |
- OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
+ EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
model_association_manager.GetTimerForTesting()->user_task().Run(); |
EXPECT_EQ(DataTypeController::NOT_RUNNING, |
@@ -239,24 +220,20 @@ TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { |
TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- controllers_[syncer::APPS] = |
- new FakeDataTypeController(syncer::APPS); |
- ModelAssociationManager model_association_manager(&controllers_, |
- &delegate_); |
+ controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
types.Put(syncer::APPS); |
DataTypeManager::ConfigureResult result_1st( |
- DataTypeManager::OK, |
- syncer::ModelTypeSet(syncer::BOOKMARKS)); |
+ DataTypeManager::OK, syncer::ModelTypeSet(syncer::BOOKMARKS)); |
DataTypeManager::ConfigureResult result_2nd( |
- DataTypeManager::OK, |
- syncer::ModelTypeSet(syncer::APPS)); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- Times(2). |
- WillOnce(VerifyResult(result_1st)). |
- WillOnce(VerifyResult(result_2nd)); |
+ DataTypeManager::OK, syncer::ModelTypeSet(syncer::APPS)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .Times(2) |
+ .WillOnce(VerifyResult(result_1st)) |
+ .WillOnce(VerifyResult(result_2nd)); |
model_association_manager.Initialize(types); |
@@ -269,8 +246,8 @@ TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
DataTypeController::MODEL_LOADED); |
// Finish BOOKMARKS association. |
- GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
- DataTypeController::OK); |
+ GetController(controllers_, syncer::BOOKMARKS) |
+ ->FinishStart(DataTypeController::OK); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::RUNNING); |
EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
@@ -281,8 +258,8 @@ TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
syncer::ModelTypeSet(syncer::APPS)); |
EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
DataTypeController::ASSOCIATING); |
- GetController(controllers_, syncer::APPS)->FinishStart( |
- DataTypeController::OK); |
+ GetController(controllers_, syncer::APPS) |
+ ->FinishStart(DataTypeController::OK); |
EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
DataTypeController::RUNNING); |
} |
@@ -292,19 +269,16 @@ TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError( |
- syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, |
- "", syncer::BOOKMARKS)); |
- ModelAssociationManager model_association_manager( |
- &controllers_, |
- &delegate_); |
+ GetController(controllers_, syncer::BOOKMARKS) |
+ ->SetModelLoadError(syncer::SyncError( |
+ FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::BOOKMARKS)); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
- EXPECT_CALL(delegate_, |
- OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result)); |
+ EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result)); |
model_association_manager.Initialize(types); |
EXPECT_EQ(DataTypeController::NOT_RUNNING, |
@@ -318,31 +292,26 @@ TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { |
TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- ModelAssociationManager model_association_manager( |
- &controllers_, |
- &delegate_); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result)); |
model_association_manager.Initialize(types); |
model_association_manager.StartAssociationAsync(types); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::ASSOCIATING); |
- GetController(controllers_, syncer::BOOKMARKS)->FinishStart( |
- DataTypeController::OK); |
+ GetController(controllers_, syncer::BOOKMARKS) |
+ ->FinishStart(DataTypeController::OK); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::RUNNING); |
testing::Mock::VerifyAndClearExpectations(&delegate_); |
- EXPECT_CALL(delegate_, |
- OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
- syncer::SyncError error(FROM_HERE, |
- syncer::SyncError::DATATYPE_ERROR, |
- "error", |
+ EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
+ syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", |
syncer::BOOKMARKS); |
GetController(controllers_, syncer::BOOKMARKS) |
->OnSingleDataTypeUnrecoverableError(error); |
@@ -351,10 +320,8 @@ TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { |
TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { |
controllers_[syncer::BOOKMARKS] = |
new FakeDataTypeController(syncer::BOOKMARKS); |
- controllers_[syncer::APPS] = |
- new FakeDataTypeController(syncer::APPS); |
- ModelAssociationManager model_association_manager(&controllers_, |
- &delegate_); |
+ controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); |
+ ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
syncer::ModelTypeSet types; |
types.Put(syncer::BOOKMARKS); |
types.Put(syncer::APPS); |
@@ -364,20 +331,19 @@ TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { |
DataTypeManager::ConfigureResult expected_result_partially_done( |
DataTypeManager::OK, types); |
- EXPECT_CALL(delegate_, OnModelAssociationDone(_)). |
- WillOnce(VerifyResult(expected_result_partially_done)); |
+ EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
+ .WillOnce(VerifyResult(expected_result_partially_done)); |
model_association_manager.Initialize(types); |
model_association_manager.StartAssociationAsync(types); |
- GetController(controllers_, syncer::APPS)->FinishStart( |
- DataTypeController::OK); |
+ GetController(controllers_, syncer::APPS) |
+ ->FinishStart(DataTypeController::OK); |
EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
DataTypeController::RUNNING); |
EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
DataTypeController::ASSOCIATING); |
- EXPECT_CALL(delegate_, |
- OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
+ EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
model_association_manager.GetTimerForTesting()->user_task().Run(); |
EXPECT_EQ(DataTypeController::NOT_RUNNING, |