#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
-namespace browser_sync {
+
+namespace sync_driver {
+
class MockModelAssociationManagerDelegate :
public ModelAssociationManagerDelegate {
public:
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));
};
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 {
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));
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);
&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);
&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));
&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));
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));
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,
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)).
&delegate_);
syncer::ModelTypeSet types;
types.Put(syncer::BOOKMARKS);
- std::map<syncer::ModelType, syncer::SyncError> errors;
+ 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::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, _));
syncer::SyncError error(FROM_HERE,
syncer::SyncError::DATATYPE_ERROR,
- "Failed",
+ "error",
syncer::BOOKMARKS);
- errors[syncer::BOOKMARKS] = error;
- DataTypeManager::ConfigureResult expected_result(
- DataTypeManager::PARTIAL_SUCCESS,
- types,
- errors,
- syncer::ModelTypeSet(),
- syncer::ModelTypeSet());
+ GetController(controllers_, syncer::BOOKMARKS)
+ ->OnSingleDataTypeUnrecoverableError(error);
+}
+
+TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) {
+ controllers_[syncer::BOOKMARKS] =
+ new FakeDataTypeController(syncer::BOOKMARKS);
+ controllers_[syncer::APPS] =
+ new FakeDataTypeController(syncer::APPS);
+ ModelAssociationManager model_association_manager(&controllers_,
+ &delegate_);
+ syncer::ModelTypeSet types;
+ types.Put(syncer::BOOKMARKS);
+ types.Put(syncer::APPS);
+
+ syncer::ModelTypeSet expected_types_unfinished;
+ expected_types_unfinished.Put(syncer::BOOKMARKS);
+ DataTypeManager::ConfigureResult expected_result_partially_done(
+ DataTypeManager::OK, types);
+
EXPECT_CALL(delegate_, OnModelAssociationDone(_)).
- WillOnce(VerifyResult(expected_result));
+ WillOnce(VerifyResult(expected_result_partially_done));
model_association_manager.Initialize(types);
- EXPECT_EQ(DataTypeController::DISABLED,
- GetController(controllers_, syncer::BOOKMARKS)->state());
model_association_manager.StartAssociationAsync(types);
+ 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, _));
+ model_association_manager.GetTimerForTesting()->user_task().Run();
+
EXPECT_EQ(DataTypeController::NOT_RUNNING,
GetController(controllers_, syncer::BOOKMARKS)->state());
}
-} // namespace browser_sync
+} // namespace sync_driver