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

Unified Diff: components/sync_driver/model_association_manager_unittest.cc

Issue 420633002: [Sync] Cleanup datatype configuration error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 6 years, 4 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: 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
index 9282f3b6a4713fa170f957b5c5bfbde53a1703e1..906d99bb3bd3c033c4c93a3370508e65b33b586d 100644
--- a/components/sync_driver/model_association_manager_unittest.cc
+++ b/components/sync_driver/model_association_manager_unittest.cc
@@ -21,7 +21,8 @@ class MockModelAssociationManagerDelegate :
MOCK_METHOD2(OnSingleDataTypeAssociationDone,
void(syncer::ModelType type,
const syncer::DataTypeAssociationStats& association_stats));
- MOCK_METHOD1(OnSingleDataTypeWillStop, void(syncer::ModelType));
+ MOCK_METHOD2(OnSingleDataTypeWillStop,
+ void(syncer::ModelType, const syncer::SyncError& error));
MOCK_METHOD1(OnModelAssociationDone, void(
const DataTypeManager::ConfigureResult& result));
};
@@ -40,22 +41,6 @@ FakeDataTypeController* GetController(
ACTION_P(VerifyResult, expected_result) {
EXPECT_EQ(arg0.status, expected_result.status);
EXPECT_TRUE(arg0.requested_types.Equals(expected_result.requested_types));
- EXPECT_EQ(arg0.failed_data_types.size(),
- expected_result.failed_data_types.size());
-
- if (arg0.failed_data_types.size() ==
- expected_result.failed_data_types.size()) {
- std::map<syncer::ModelType, syncer::SyncError>::const_iterator it1, it2;
- for (it1 = arg0.failed_data_types.begin(),
- it2 = expected_result.failed_data_types.begin();
- it1 != arg0.failed_data_types.end();
- ++it1, ++it2) {
- EXPECT_EQ((*it1).first, (*it2).first);
- }
- }
-
- EXPECT_TRUE(arg0.unfinished_data_types.Equals(
- expected_result.unfinished_data_types));
}
class SyncModelAssociationManagerTest : public testing::Test {
@@ -79,12 +64,7 @@ TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) {
ModelAssociationManager model_association_manager(&controllers_,
&delegate_);
syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS);
- DataTypeManager::ConfigureResult expected_result(
- DataTypeManager::OK,
- types,
- std::map<syncer::ModelType, syncer::SyncError>(),
- syncer::ModelTypeSet(),
- syncer::ModelTypeSet());
+ DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types);
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
WillOnce(VerifyResult(expected_result));
@@ -124,24 +104,13 @@ TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) {
syncer::ModelTypeSet types;
types.Put(syncer::BOOKMARKS);
- std::map<syncer::ModelType, syncer::SyncError> errors;
- syncer::SyncError error(FROM_HERE,
- syncer::SyncError::DATATYPE_ERROR,
- "Failed",
- syncer::BOOKMARKS);
- errors[syncer::BOOKMARKS] = error;
-
- DataTypeManager::ConfigureResult expected_result(
- DataTypeManager::ABORTED,
- types,
- errors,
- syncer::ModelTypeSet(syncer::BOOKMARKS),
- syncer::ModelTypeSet());
+ DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED,
+ types);
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
WillOnce(VerifyResult(expected_result));
EXPECT_CALL(delegate_,
- OnSingleDataTypeWillStop(syncer::BOOKMARKS));
+ OnSingleDataTypeWillStop(syncer::BOOKMARKS, _));
model_association_manager.Initialize(types);
model_association_manager.StartAssociationAsync(types);
@@ -162,16 +131,11 @@ TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) {
&delegate_);
syncer::ModelTypeSet types;
types.Put(syncer::BOOKMARKS);
- DataTypeManager::ConfigureResult expected_result(
- DataTypeManager::OK,
- types,
- std::map<syncer::ModelType, syncer::SyncError>(),
- syncer::ModelTypeSet(),
- syncer::ModelTypeSet());
+ DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types);
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
WillOnce(VerifyResult(expected_result));
EXPECT_CALL(delegate_,
- OnSingleDataTypeWillStop(syncer::BOOKMARKS));
+ OnSingleDataTypeWillStop(syncer::BOOKMARKS, _));
model_association_manager.Initialize(types);
model_association_manager.StartAssociationAsync(types);
@@ -195,18 +159,9 @@ TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) {
&delegate_);
syncer::ModelTypeSet types;
types.Put(syncer::BOOKMARKS);
- std::map<syncer::ModelType, syncer::SyncError> errors;
- syncer::SyncError error(FROM_HERE,
- syncer::SyncError::DATATYPE_ERROR,
- "Failed",
- syncer::BOOKMARKS);
- errors[syncer::BOOKMARKS] = error;
- DataTypeManager::ConfigureResult expected_result(
- DataTypeManager::PARTIAL_SUCCESS,
- types,
- errors,
- syncer::ModelTypeSet(),
- syncer::ModelTypeSet());
+ DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types);
+ EXPECT_CALL(delegate_,
+ OnSingleDataTypeWillStop(syncer::BOOKMARKS, _));
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
WillOnce(VerifyResult(expected_result));
@@ -230,18 +185,10 @@ TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) {
&delegate_);
syncer::ModelTypeSet types;
types.Put(syncer::BOOKMARKS);
- std::map<syncer::ModelType, syncer::SyncError> errors;
- syncer::SyncError error(FROM_HERE,
- syncer::SyncError::DATATYPE_ERROR,
- "Failed",
- syncer::BOOKMARKS);
- errors[syncer::BOOKMARKS] = error;
DataTypeManager::ConfigureResult expected_result(
- DataTypeManager::UNRECOVERABLE_ERROR,
- types,
- errors,
- syncer::ModelTypeSet(),
- syncer::ModelTypeSet());
+ DataTypeManager::UNRECOVERABLE_ERROR, types);
+ EXPECT_CALL(delegate_,
+ OnSingleDataTypeWillStop(syncer::BOOKMARKS, _));
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
WillOnce(VerifyResult(expected_result));
@@ -267,21 +214,10 @@ TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) {
types.Put(syncer::BOOKMARKS);
types.Put(syncer::APPS);
- std::map<syncer::ModelType, syncer::SyncError> errors;
- syncer::SyncError error(FROM_HERE,
- syncer::SyncError::DATATYPE_ERROR,
- "Association timed out.",
- syncer::BOOKMARKS);
- errors[syncer::BOOKMARKS] = error;
-
syncer::ModelTypeSet expected_types_unfinished;
expected_types_unfinished.Put(syncer::BOOKMARKS);
DataTypeManager::ConfigureResult expected_result_partially_done(
- DataTypeManager::PARTIAL_SUCCESS,
- types,
- errors,
- expected_types_unfinished,
- syncer::ModelTypeSet());
+ DataTypeManager::OK, types);
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
WillOnce(VerifyResult(expected_result_partially_done));
@@ -291,6 +227,8 @@ TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) {
GetController(controllers_, syncer::APPS)->FinishStart(
DataTypeController::OK);
+ EXPECT_CALL(delegate_,
+ OnSingleDataTypeWillStop(syncer::BOOKMARKS, _));
model_association_manager.GetTimerForTesting()->user_task().Run();
EXPECT_EQ(DataTypeController::NOT_RUNNING,
@@ -310,16 +248,10 @@ TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) {
DataTypeManager::ConfigureResult result_1st(
DataTypeManager::OK,
- syncer::ModelTypeSet(syncer::BOOKMARKS),
- std::map<syncer::ModelType, syncer::SyncError>(),
- syncer::ModelTypeSet(),
- syncer::ModelTypeSet());
+ syncer::ModelTypeSet(syncer::BOOKMARKS));
DataTypeManager::ConfigureResult result_2nd(
DataTypeManager::OK,
- syncer::ModelTypeSet(syncer::APPS),
- std::map<syncer::ModelType, syncer::SyncError>(),
- syncer::ModelTypeSet(),
- syncer::ModelTypeSet());
+ syncer::ModelTypeSet(syncer::APPS));
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
Times(2).
WillOnce(VerifyResult(result_1st)).
@@ -367,27 +299,48 @@ TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) {
&delegate_);
syncer::ModelTypeSet types;
types.Put(syncer::BOOKMARKS);
- std::map<syncer::ModelType, syncer::SyncError> errors;
- syncer::SyncError error(FROM_HERE,
- syncer::SyncError::DATATYPE_ERROR,
- "Failed",
- syncer::BOOKMARKS);
- errors[syncer::BOOKMARKS] = error;
- DataTypeManager::ConfigureResult expected_result(
- DataTypeManager::PARTIAL_SUCCESS,
- types,
- errors,
- syncer::ModelTypeSet(),
- syncer::ModelTypeSet());
+ DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types);
+ EXPECT_CALL(delegate_,
+ OnSingleDataTypeWillStop(syncer::BOOKMARKS, _));
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
WillOnce(VerifyResult(expected_result));
model_association_manager.Initialize(types);
- EXPECT_EQ(DataTypeController::DISABLED,
+ EXPECT_EQ(DataTypeController::NOT_RUNNING,
GetController(controllers_, syncer::BOOKMARKS)->state());
model_association_manager.StartAssociationAsync(types);
EXPECT_EQ(DataTypeController::NOT_RUNNING,
GetController(controllers_, syncer::BOOKMARKS)->state());
}
+// Test that a runtime error is handled by stopping the type.
+TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) {
+ controllers_[syncer::BOOKMARKS] =
+ new FakeDataTypeController(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_, 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);
+ EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(),
+ DataTypeController::RUNNING);
+
+ testing::Mock::VerifyAndClearExpectations(&delegate_);
+ EXPECT_CALL(delegate_,
+ OnSingleDataTypeWillStop(syncer::BOOKMARKS, _));
+ GetController(controllers_, syncer::BOOKMARKS)
+ ->OnSingleDatatypeUnrecoverableError(FROM_HERE, "runtime error");
+}
+
} // namespace sync_driver
« no previous file with comments | « components/sync_driver/model_association_manager.cc ('k') | components/sync_driver/non_ui_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698