| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/sync_driver/model_association_manager.h" | 5 #include "components/sync/driver/model_association_manager.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "components/sync_driver/fake_data_type_controller.h" | 9 #include "components/sync/driver/fake_data_type_controller.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using ::testing::_; | 13 using ::testing::_; |
| 14 | 14 |
| 15 namespace sync_driver { | 15 namespace sync_driver { |
| 16 | 16 |
| 17 class MockModelAssociationManagerDelegate : | 17 class MockModelAssociationManagerDelegate |
| 18 public ModelAssociationManagerDelegate { | 18 : public ModelAssociationManagerDelegate { |
| 19 public: | 19 public: |
| 20 MockModelAssociationManagerDelegate() {} | 20 MockModelAssociationManagerDelegate() {} |
| 21 ~MockModelAssociationManagerDelegate() {} | 21 ~MockModelAssociationManagerDelegate() {} |
| 22 MOCK_METHOD0(OnAllDataTypesReadyForConfigure, void()); | 22 MOCK_METHOD0(OnAllDataTypesReadyForConfigure, void()); |
| 23 MOCK_METHOD2(OnSingleDataTypeAssociationDone, | 23 MOCK_METHOD2(OnSingleDataTypeAssociationDone, |
| 24 void(syncer::ModelType type, | 24 void(syncer::ModelType type, |
| 25 const syncer::DataTypeAssociationStats& association_stats)); | 25 const syncer::DataTypeAssociationStats& association_stats)); |
| 26 MOCK_METHOD2(OnSingleDataTypeWillStop, | 26 MOCK_METHOD2(OnSingleDataTypeWillStop, |
| 27 void(syncer::ModelType, const syncer::SyncError& error)); | 27 void(syncer::ModelType, const syncer::SyncError& error)); |
| 28 MOCK_METHOD1(OnModelAssociationDone, void( | 28 MOCK_METHOD1(OnModelAssociationDone, |
| 29 const DataTypeManager::ConfigureResult& result)); | 29 void(const DataTypeManager::ConfigureResult& result)); |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 FakeDataTypeController* GetController( | 32 FakeDataTypeController* GetController( |
| 33 const DataTypeController::TypeMap& controllers, | 33 const DataTypeController::TypeMap& controllers, |
| 34 syncer::ModelType model_type) { | 34 syncer::ModelType model_type) { |
| 35 DataTypeController::TypeMap::const_iterator it = | 35 DataTypeController::TypeMap::const_iterator it = controllers.find(model_type); |
| 36 controllers.find(model_type); | |
| 37 if (it == controllers.end()) { | 36 if (it == controllers.end()) { |
| 38 return NULL; | 37 return NULL; |
| 39 } | 38 } |
| 40 return static_cast<FakeDataTypeController*>(it->second.get()); | 39 return static_cast<FakeDataTypeController*>(it->second.get()); |
| 41 } | 40 } |
| 42 | 41 |
| 43 ACTION_P(VerifyResult, expected_result) { | 42 ACTION_P(VerifyResult, expected_result) { |
| 44 EXPECT_EQ(arg0.status, expected_result.status); | 43 EXPECT_EQ(arg0.status, expected_result.status); |
| 45 EXPECT_EQ(expected_result.requested_types, arg0.requested_types); | 44 EXPECT_EQ(expected_result.requested_types, arg0.requested_types); |
| 46 } | 45 } |
| 47 | 46 |
| 48 class SyncModelAssociationManagerTest : public testing::Test { | 47 class SyncModelAssociationManagerTest : public testing::Test { |
| 49 public: | 48 public: |
| 50 SyncModelAssociationManagerTest() { | 49 SyncModelAssociationManagerTest() {} |
| 51 } | |
| 52 | 50 |
| 53 protected: | 51 protected: |
| 54 base::MessageLoopForUI ui_loop_; | 52 base::MessageLoopForUI ui_loop_; |
| 55 MockModelAssociationManagerDelegate delegate_; | 53 MockModelAssociationManagerDelegate delegate_; |
| 56 DataTypeController::TypeMap controllers_; | 54 DataTypeController::TypeMap controllers_; |
| 57 }; | 55 }; |
| 58 | 56 |
| 59 // Start a type and make sure ModelAssociationManager callst the |Start| | 57 // Start a type and make sure ModelAssociationManager callst the |Start| |
| 60 // method and calls the callback when it is done. | 58 // method and calls the callback when it is done. |
| 61 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { | 59 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { |
| 62 controllers_[syncer::BOOKMARKS] = | 60 controllers_[syncer::BOOKMARKS] = |
| 63 new FakeDataTypeController(syncer::BOOKMARKS); | 61 new FakeDataTypeController(syncer::BOOKMARKS); |
| 64 controllers_[syncer::APPS] = | 62 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); |
| 65 new FakeDataTypeController(syncer::APPS); | 63 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 66 ModelAssociationManager model_association_manager(&controllers_, | |
| 67 &delegate_); | |
| 68 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); | 64 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
| 69 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 65 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 70 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 66 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 71 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 67 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 72 WillOnce(VerifyResult(expected_result)); | 68 .WillOnce(VerifyResult(expected_result)); |
| 73 | 69 |
| 74 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 70 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 75 DataTypeController::NOT_RUNNING); | 71 DataTypeController::NOT_RUNNING); |
| 76 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 72 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 77 DataTypeController::NOT_RUNNING); | 73 DataTypeController::NOT_RUNNING); |
| 78 | 74 |
| 79 // Initialize() kicks off model loading. | 75 // Initialize() kicks off model loading. |
| 80 model_association_manager.Initialize(types); | 76 model_association_manager.Initialize(types); |
| 81 | 77 |
| 82 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 78 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 83 DataTypeController::MODEL_LOADED); | 79 DataTypeController::MODEL_LOADED); |
| 84 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 80 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 85 DataTypeController::MODEL_LOADED); | 81 DataTypeController::MODEL_LOADED); |
| 86 | 82 |
| 87 model_association_manager.StartAssociationAsync(types); | 83 model_association_manager.StartAssociationAsync(types); |
| 88 | 84 |
| 89 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 85 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 90 DataTypeController::ASSOCIATING); | 86 DataTypeController::ASSOCIATING); |
| 91 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 87 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 92 DataTypeController::ASSOCIATING); | 88 DataTypeController::ASSOCIATING); |
| 93 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 89 GetController(controllers_, syncer::BOOKMARKS) |
| 94 DataTypeController::OK); | 90 ->FinishStart(DataTypeController::OK); |
| 95 GetController(controllers_, syncer::APPS)->FinishStart( | 91 GetController(controllers_, syncer::APPS) |
| 96 DataTypeController::OK); | 92 ->FinishStart(DataTypeController::OK); |
| 97 } | 93 } |
| 98 | 94 |
| 99 // Start a type and call stop before it finishes associating. | 95 // Start a type and call stop before it finishes associating. |
| 100 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { | 96 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { |
| 101 controllers_[syncer::BOOKMARKS] = | 97 controllers_[syncer::BOOKMARKS] = |
| 102 new FakeDataTypeController(syncer::BOOKMARKS); | 98 new FakeDataTypeController(syncer::BOOKMARKS); |
| 103 ModelAssociationManager model_association_manager( | 99 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 104 &controllers_, | |
| 105 &delegate_); | |
| 106 | 100 |
| 107 syncer::ModelTypeSet types; | 101 syncer::ModelTypeSet types; |
| 108 types.Put(syncer::BOOKMARKS); | 102 types.Put(syncer::BOOKMARKS); |
| 109 | 103 |
| 110 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, | 104 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, |
| 111 types); | 105 types); |
| 112 | 106 |
| 113 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 107 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 114 WillOnce(VerifyResult(expected_result)); | 108 .WillOnce(VerifyResult(expected_result)); |
| 115 EXPECT_CALL(delegate_, | 109 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 116 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 117 | 110 |
| 118 model_association_manager.Initialize(types); | 111 model_association_manager.Initialize(types); |
| 119 model_association_manager.StartAssociationAsync(types); | 112 model_association_manager.StartAssociationAsync(types); |
| 120 | 113 |
| 121 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 114 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 122 DataTypeController::ASSOCIATING); | 115 DataTypeController::ASSOCIATING); |
| 123 model_association_manager.Stop(); | 116 model_association_manager.Stop(); |
| 124 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 117 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 125 DataTypeController::NOT_RUNNING); | 118 DataTypeController::NOT_RUNNING); |
| 126 } | 119 } |
| 127 | 120 |
| 128 // Start a type, let it finish and then call stop. | 121 // Start a type, let it finish and then call stop. |
| 129 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { | 122 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { |
| 130 controllers_[syncer::BOOKMARKS] = | 123 controllers_[syncer::BOOKMARKS] = |
| 131 new FakeDataTypeController(syncer::BOOKMARKS); | 124 new FakeDataTypeController(syncer::BOOKMARKS); |
| 132 ModelAssociationManager model_association_manager( | 125 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 133 &controllers_, | |
| 134 &delegate_); | |
| 135 syncer::ModelTypeSet types; | 126 syncer::ModelTypeSet types; |
| 136 types.Put(syncer::BOOKMARKS); | 127 types.Put(syncer::BOOKMARKS); |
| 137 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 128 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 138 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 129 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 139 WillOnce(VerifyResult(expected_result)); | 130 .WillOnce(VerifyResult(expected_result)); |
| 140 EXPECT_CALL(delegate_, | 131 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 141 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 142 | 132 |
| 143 model_association_manager.Initialize(types); | 133 model_association_manager.Initialize(types); |
| 144 model_association_manager.StartAssociationAsync(types); | 134 model_association_manager.StartAssociationAsync(types); |
| 145 | 135 |
| 146 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 136 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 147 DataTypeController::ASSOCIATING); | 137 DataTypeController::ASSOCIATING); |
| 148 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 138 GetController(controllers_, syncer::BOOKMARKS) |
| 149 DataTypeController::OK); | 139 ->FinishStart(DataTypeController::OK); |
| 150 | 140 |
| 151 model_association_manager.Stop(); | 141 model_association_manager.Stop(); |
| 152 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 142 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 153 DataTypeController::NOT_RUNNING); | 143 DataTypeController::NOT_RUNNING); |
| 154 } | 144 } |
| 155 | 145 |
| 156 // Make a type fail model association and verify correctness. | 146 // Make a type fail model association and verify correctness. |
| 157 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { | 147 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { |
| 158 controllers_[syncer::BOOKMARKS] = | 148 controllers_[syncer::BOOKMARKS] = |
| 159 new FakeDataTypeController(syncer::BOOKMARKS); | 149 new FakeDataTypeController(syncer::BOOKMARKS); |
| 160 ModelAssociationManager model_association_manager( | 150 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 161 &controllers_, | |
| 162 &delegate_); | |
| 163 syncer::ModelTypeSet types; | 151 syncer::ModelTypeSet types; |
| 164 types.Put(syncer::BOOKMARKS); | 152 types.Put(syncer::BOOKMARKS); |
| 165 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 153 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 166 EXPECT_CALL(delegate_, | 154 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 167 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 155 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 168 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 156 .WillOnce(VerifyResult(expected_result)); |
| 169 WillOnce(VerifyResult(expected_result)); | |
| 170 | 157 |
| 171 model_association_manager.Initialize(types); | 158 model_association_manager.Initialize(types); |
| 172 model_association_manager.StartAssociationAsync(types); | 159 model_association_manager.StartAssociationAsync(types); |
| 173 | 160 |
| 174 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 161 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 175 DataTypeController::ASSOCIATING); | 162 DataTypeController::ASSOCIATING); |
| 176 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 163 GetController(controllers_, syncer::BOOKMARKS) |
| 177 DataTypeController::ASSOCIATION_FAILED); | 164 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); |
| 178 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 165 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 179 DataTypeController::NOT_RUNNING); | 166 DataTypeController::NOT_RUNNING); |
| 180 } | 167 } |
| 181 | 168 |
| 182 // Ensure configuring stops when a type returns a unrecoverable error. | 169 // Ensure configuring stops when a type returns a unrecoverable error. |
| 183 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { | 170 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
| 184 controllers_[syncer::BOOKMARKS] = | 171 controllers_[syncer::BOOKMARKS] = |
| 185 new FakeDataTypeController(syncer::BOOKMARKS); | 172 new FakeDataTypeController(syncer::BOOKMARKS); |
| 186 ModelAssociationManager model_association_manager( | 173 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 187 &controllers_, | |
| 188 &delegate_); | |
| 189 syncer::ModelTypeSet types; | 174 syncer::ModelTypeSet types; |
| 190 types.Put(syncer::BOOKMARKS); | 175 types.Put(syncer::BOOKMARKS); |
| 191 DataTypeManager::ConfigureResult expected_result( | 176 DataTypeManager::ConfigureResult expected_result( |
| 192 DataTypeManager::UNRECOVERABLE_ERROR, types); | 177 DataTypeManager::UNRECOVERABLE_ERROR, types); |
| 193 EXPECT_CALL(delegate_, | 178 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 194 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 179 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 195 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 180 .WillOnce(VerifyResult(expected_result)); |
| 196 WillOnce(VerifyResult(expected_result)); | |
| 197 | 181 |
| 198 model_association_manager.Initialize(types); | 182 model_association_manager.Initialize(types); |
| 199 | 183 |
| 200 model_association_manager.StartAssociationAsync(types); | 184 model_association_manager.StartAssociationAsync(types); |
| 201 | 185 |
| 202 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 186 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 203 DataTypeController::ASSOCIATING); | 187 DataTypeController::ASSOCIATING); |
| 204 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 188 GetController(controllers_, syncer::BOOKMARKS) |
| 205 DataTypeController::UNRECOVERABLE_ERROR); | 189 ->FinishStart(DataTypeController::UNRECOVERABLE_ERROR); |
| 206 } | 190 } |
| 207 | 191 |
| 208 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { | 192 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { |
| 209 controllers_[syncer::BOOKMARKS] = | 193 controllers_[syncer::BOOKMARKS] = |
| 210 new FakeDataTypeController(syncer::BOOKMARKS); | 194 new FakeDataTypeController(syncer::BOOKMARKS); |
| 211 controllers_[syncer::APPS] = | 195 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); |
| 212 new FakeDataTypeController(syncer::APPS); | |
| 213 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); | 196 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 214 ModelAssociationManager model_association_manager(&controllers_, | 197 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 215 &delegate_); | |
| 216 syncer::ModelTypeSet types; | 198 syncer::ModelTypeSet types; |
| 217 types.Put(syncer::BOOKMARKS); | 199 types.Put(syncer::BOOKMARKS); |
| 218 types.Put(syncer::APPS); | 200 types.Put(syncer::APPS); |
| 219 | 201 |
| 220 DataTypeManager::ConfigureResult expected_result_partially_done( | 202 DataTypeManager::ConfigureResult expected_result_partially_done( |
| 221 DataTypeManager::OK, types); | 203 DataTypeManager::OK, types); |
| 222 | 204 |
| 223 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 205 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 224 WillOnce(VerifyResult(expected_result_partially_done)); | 206 .WillOnce(VerifyResult(expected_result_partially_done)); |
| 225 | 207 |
| 226 model_association_manager.Initialize(types); | 208 model_association_manager.Initialize(types); |
| 227 model_association_manager.StartAssociationAsync(types); | 209 model_association_manager.StartAssociationAsync(types); |
| 228 GetController(controllers_, syncer::APPS)->FinishStart( | 210 GetController(controllers_, syncer::APPS) |
| 229 DataTypeController::OK); | 211 ->FinishStart(DataTypeController::OK); |
| 230 | 212 |
| 231 EXPECT_CALL(delegate_, | 213 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 232 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 233 model_association_manager.GetTimerForTesting()->user_task().Run(); | 214 model_association_manager.GetTimerForTesting()->user_task().Run(); |
| 234 | 215 |
| 235 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 216 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 236 GetController(controllers_, syncer::BOOKMARKS)->state()); | 217 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 237 } | 218 } |
| 238 | 219 |
| 239 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { | 220 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
| 240 controllers_[syncer::BOOKMARKS] = | 221 controllers_[syncer::BOOKMARKS] = |
| 241 new FakeDataTypeController(syncer::BOOKMARKS); | 222 new FakeDataTypeController(syncer::BOOKMARKS); |
| 242 controllers_[syncer::APPS] = | 223 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); |
| 243 new FakeDataTypeController(syncer::APPS); | 224 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 244 ModelAssociationManager model_association_manager(&controllers_, | |
| 245 &delegate_); | |
| 246 syncer::ModelTypeSet types; | 225 syncer::ModelTypeSet types; |
| 247 types.Put(syncer::BOOKMARKS); | 226 types.Put(syncer::BOOKMARKS); |
| 248 types.Put(syncer::APPS); | 227 types.Put(syncer::APPS); |
| 249 | 228 |
| 250 DataTypeManager::ConfigureResult result_1st( | 229 DataTypeManager::ConfigureResult result_1st( |
| 251 DataTypeManager::OK, | 230 DataTypeManager::OK, syncer::ModelTypeSet(syncer::BOOKMARKS)); |
| 252 syncer::ModelTypeSet(syncer::BOOKMARKS)); | |
| 253 DataTypeManager::ConfigureResult result_2nd( | 231 DataTypeManager::ConfigureResult result_2nd( |
| 254 DataTypeManager::OK, | 232 DataTypeManager::OK, syncer::ModelTypeSet(syncer::APPS)); |
| 255 syncer::ModelTypeSet(syncer::APPS)); | 233 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 256 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 234 .Times(2) |
| 257 Times(2). | 235 .WillOnce(VerifyResult(result_1st)) |
| 258 WillOnce(VerifyResult(result_1st)). | 236 .WillOnce(VerifyResult(result_2nd)); |
| 259 WillOnce(VerifyResult(result_2nd)); | |
| 260 | 237 |
| 261 model_association_manager.Initialize(types); | 238 model_association_manager.Initialize(types); |
| 262 | 239 |
| 263 // Start BOOKMARKS first. | 240 // Start BOOKMARKS first. |
| 264 model_association_manager.StartAssociationAsync( | 241 model_association_manager.StartAssociationAsync( |
| 265 syncer::ModelTypeSet(syncer::BOOKMARKS)); | 242 syncer::ModelTypeSet(syncer::BOOKMARKS)); |
| 266 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 243 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 267 DataTypeController::ASSOCIATING); | 244 DataTypeController::ASSOCIATING); |
| 268 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 245 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 269 DataTypeController::MODEL_LOADED); | 246 DataTypeController::MODEL_LOADED); |
| 270 | 247 |
| 271 // Finish BOOKMARKS association. | 248 // Finish BOOKMARKS association. |
| 272 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 249 GetController(controllers_, syncer::BOOKMARKS) |
| 273 DataTypeController::OK); | 250 ->FinishStart(DataTypeController::OK); |
| 274 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 251 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 275 DataTypeController::RUNNING); | 252 DataTypeController::RUNNING); |
| 276 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 253 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 277 DataTypeController::MODEL_LOADED); | 254 DataTypeController::MODEL_LOADED); |
| 278 | 255 |
| 279 // Start APPS next. | 256 // Start APPS next. |
| 280 model_association_manager.StartAssociationAsync( | 257 model_association_manager.StartAssociationAsync( |
| 281 syncer::ModelTypeSet(syncer::APPS)); | 258 syncer::ModelTypeSet(syncer::APPS)); |
| 282 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 259 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 283 DataTypeController::ASSOCIATING); | 260 DataTypeController::ASSOCIATING); |
| 284 GetController(controllers_, syncer::APPS)->FinishStart( | 261 GetController(controllers_, syncer::APPS) |
| 285 DataTypeController::OK); | 262 ->FinishStart(DataTypeController::OK); |
| 286 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 263 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 287 DataTypeController::RUNNING); | 264 DataTypeController::RUNNING); |
| 288 } | 265 } |
| 289 | 266 |
| 290 // Test that model that failed to load between initialization and association | 267 // Test that model that failed to load between initialization and association |
| 291 // is reported and stopped properly. | 268 // is reported and stopped properly. |
| 292 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { | 269 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { |
| 293 controllers_[syncer::BOOKMARKS] = | 270 controllers_[syncer::BOOKMARKS] = |
| 294 new FakeDataTypeController(syncer::BOOKMARKS); | 271 new FakeDataTypeController(syncer::BOOKMARKS); |
| 295 GetController(controllers_, syncer::BOOKMARKS)->SetModelLoadError( | 272 GetController(controllers_, syncer::BOOKMARKS) |
| 296 syncer::SyncError(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, | 273 ->SetModelLoadError(syncer::SyncError( |
| 297 "", syncer::BOOKMARKS)); | 274 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::BOOKMARKS)); |
| 298 ModelAssociationManager model_association_manager( | 275 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 299 &controllers_, | |
| 300 &delegate_); | |
| 301 syncer::ModelTypeSet types; | 276 syncer::ModelTypeSet types; |
| 302 types.Put(syncer::BOOKMARKS); | 277 types.Put(syncer::BOOKMARKS); |
| 303 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 278 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 304 EXPECT_CALL(delegate_, | 279 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 305 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 280 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 306 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 281 .WillOnce(VerifyResult(expected_result)); |
| 307 WillOnce(VerifyResult(expected_result)); | |
| 308 | 282 |
| 309 model_association_manager.Initialize(types); | 283 model_association_manager.Initialize(types); |
| 310 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 284 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 311 GetController(controllers_, syncer::BOOKMARKS)->state()); | 285 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 312 model_association_manager.StartAssociationAsync(types); | 286 model_association_manager.StartAssociationAsync(types); |
| 313 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 287 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 314 GetController(controllers_, syncer::BOOKMARKS)->state()); | 288 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 315 } | 289 } |
| 316 | 290 |
| 317 // Test that a runtime error is handled by stopping the type. | 291 // Test that a runtime error is handled by stopping the type. |
| 318 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { | 292 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { |
| 319 controllers_[syncer::BOOKMARKS] = | 293 controllers_[syncer::BOOKMARKS] = |
| 320 new FakeDataTypeController(syncer::BOOKMARKS); | 294 new FakeDataTypeController(syncer::BOOKMARKS); |
| 321 ModelAssociationManager model_association_manager( | 295 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 322 &controllers_, | |
| 323 &delegate_); | |
| 324 syncer::ModelTypeSet types; | 296 syncer::ModelTypeSet types; |
| 325 types.Put(syncer::BOOKMARKS); | 297 types.Put(syncer::BOOKMARKS); |
| 326 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 298 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 327 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 299 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 328 WillOnce(VerifyResult(expected_result)); | 300 .WillOnce(VerifyResult(expected_result)); |
| 329 | 301 |
| 330 model_association_manager.Initialize(types); | 302 model_association_manager.Initialize(types); |
| 331 model_association_manager.StartAssociationAsync(types); | 303 model_association_manager.StartAssociationAsync(types); |
| 332 | 304 |
| 333 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 305 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 334 DataTypeController::ASSOCIATING); | 306 DataTypeController::ASSOCIATING); |
| 335 GetController(controllers_, syncer::BOOKMARKS)->FinishStart( | 307 GetController(controllers_, syncer::BOOKMARKS) |
| 336 DataTypeController::OK); | 308 ->FinishStart(DataTypeController::OK); |
| 337 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 309 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 338 DataTypeController::RUNNING); | 310 DataTypeController::RUNNING); |
| 339 | 311 |
| 340 testing::Mock::VerifyAndClearExpectations(&delegate_); | 312 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 341 EXPECT_CALL(delegate_, | 313 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 342 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | 314 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", |
| 343 syncer::SyncError error(FROM_HERE, | |
| 344 syncer::SyncError::DATATYPE_ERROR, | |
| 345 "error", | |
| 346 syncer::BOOKMARKS); | 315 syncer::BOOKMARKS); |
| 347 GetController(controllers_, syncer::BOOKMARKS) | 316 GetController(controllers_, syncer::BOOKMARKS) |
| 348 ->OnSingleDataTypeUnrecoverableError(error); | 317 ->OnSingleDataTypeUnrecoverableError(error); |
| 349 } | 318 } |
| 350 | 319 |
| 351 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { | 320 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { |
| 352 controllers_[syncer::BOOKMARKS] = | 321 controllers_[syncer::BOOKMARKS] = |
| 353 new FakeDataTypeController(syncer::BOOKMARKS); | 322 new FakeDataTypeController(syncer::BOOKMARKS); |
| 354 controllers_[syncer::APPS] = | 323 controllers_[syncer::APPS] = new FakeDataTypeController(syncer::APPS); |
| 355 new FakeDataTypeController(syncer::APPS); | 324 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 356 ModelAssociationManager model_association_manager(&controllers_, | |
| 357 &delegate_); | |
| 358 syncer::ModelTypeSet types; | 325 syncer::ModelTypeSet types; |
| 359 types.Put(syncer::BOOKMARKS); | 326 types.Put(syncer::BOOKMARKS); |
| 360 types.Put(syncer::APPS); | 327 types.Put(syncer::APPS); |
| 361 | 328 |
| 362 syncer::ModelTypeSet expected_types_unfinished; | 329 syncer::ModelTypeSet expected_types_unfinished; |
| 363 expected_types_unfinished.Put(syncer::BOOKMARKS); | 330 expected_types_unfinished.Put(syncer::BOOKMARKS); |
| 364 DataTypeManager::ConfigureResult expected_result_partially_done( | 331 DataTypeManager::ConfigureResult expected_result_partially_done( |
| 365 DataTypeManager::OK, types); | 332 DataTypeManager::OK, types); |
| 366 | 333 |
| 367 EXPECT_CALL(delegate_, OnModelAssociationDone(_)). | 334 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 368 WillOnce(VerifyResult(expected_result_partially_done)); | 335 .WillOnce(VerifyResult(expected_result_partially_done)); |
| 369 | 336 |
| 370 model_association_manager.Initialize(types); | 337 model_association_manager.Initialize(types); |
| 371 model_association_manager.StartAssociationAsync(types); | 338 model_association_manager.StartAssociationAsync(types); |
| 372 GetController(controllers_, syncer::APPS)->FinishStart( | 339 GetController(controllers_, syncer::APPS) |
| 373 DataTypeController::OK); | 340 ->FinishStart(DataTypeController::OK); |
| 374 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), | 341 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 375 DataTypeController::RUNNING); | 342 DataTypeController::RUNNING); |
| 376 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 343 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 377 DataTypeController::ASSOCIATING); | 344 DataTypeController::ASSOCIATING); |
| 378 | 345 |
| 379 EXPECT_CALL(delegate_, | 346 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 380 OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); | |
| 381 model_association_manager.GetTimerForTesting()->user_task().Run(); | 347 model_association_manager.GetTimerForTesting()->user_task().Run(); |
| 382 | 348 |
| 383 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 349 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 384 GetController(controllers_, syncer::BOOKMARKS)->state()); | 350 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 385 } | 351 } |
| 386 | 352 |
| 387 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that | 353 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that |
| 388 // require LoadModels before configuration are loaded. | 354 // require LoadModels before configuration are loaded. |
| 389 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { | 355 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { |
| 390 // Create two controllers with delayed model load. | 356 // Create two controllers with delayed model load. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 484 |
| 519 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 485 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 520 // Finish loading BOOKMARKS. This should trigger | 486 // Finish loading BOOKMARKS. This should trigger |
| 521 // OnAllDataTypesReadyForConfigure(). | 487 // OnAllDataTypesReadyForConfigure(). |
| 522 GetController(controllers_, syncer::BOOKMARKS)->SimulateModelLoadFinishing(); | 488 GetController(controllers_, syncer::BOOKMARKS)->SimulateModelLoadFinishing(); |
| 523 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), | 489 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 524 DataTypeController::MODEL_LOADED); | 490 DataTypeController::MODEL_LOADED); |
| 525 } | 491 } |
| 526 | 492 |
| 527 } // namespace sync_driver | 493 } // namespace sync_driver |
| OLD | NEW |