| 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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "components/sync/driver/fake_data_type_controller.h" | 11 #include "components/sync/driver/fake_data_type_controller.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using ::testing::_; | 15 using ::testing::_; |
| 16 | 16 |
| 17 namespace syncer { | 17 namespace sync_driver { |
| 18 | 18 |
| 19 class MockModelAssociationManagerDelegate | 19 class MockModelAssociationManagerDelegate |
| 20 : public ModelAssociationManagerDelegate { | 20 : public ModelAssociationManagerDelegate { |
| 21 public: | 21 public: |
| 22 MockModelAssociationManagerDelegate() {} | 22 MockModelAssociationManagerDelegate() {} |
| 23 ~MockModelAssociationManagerDelegate() {} | 23 ~MockModelAssociationManagerDelegate() {} |
| 24 MOCK_METHOD0(OnAllDataTypesReadyForConfigure, void()); | 24 MOCK_METHOD0(OnAllDataTypesReadyForConfigure, void()); |
| 25 MOCK_METHOD2(OnSingleDataTypeAssociationDone, | 25 MOCK_METHOD2(OnSingleDataTypeAssociationDone, |
| 26 void(ModelType type, | 26 void(syncer::ModelType type, |
| 27 const DataTypeAssociationStats& association_stats)); | 27 const syncer::DataTypeAssociationStats& association_stats)); |
| 28 MOCK_METHOD2(OnSingleDataTypeWillStop, | 28 MOCK_METHOD2(OnSingleDataTypeWillStop, |
| 29 void(ModelType, const SyncError& error)); | 29 void(syncer::ModelType, const syncer::SyncError& error)); |
| 30 MOCK_METHOD1(OnModelAssociationDone, | 30 MOCK_METHOD1(OnModelAssociationDone, |
| 31 void(const DataTypeManager::ConfigureResult& result)); | 31 void(const DataTypeManager::ConfigureResult& result)); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 FakeDataTypeController* GetController( | 34 FakeDataTypeController* GetController( |
| 35 const DataTypeController::TypeMap& controllers, | 35 const DataTypeController::TypeMap& controllers, |
| 36 ModelType model_type) { | 36 syncer::ModelType model_type) { |
| 37 DataTypeController::TypeMap::const_iterator it = controllers.find(model_type); | 37 DataTypeController::TypeMap::const_iterator it = controllers.find(model_type); |
| 38 if (it == controllers.end()) { | 38 if (it == controllers.end()) { |
| 39 return NULL; | 39 return NULL; |
| 40 } | 40 } |
| 41 return static_cast<FakeDataTypeController*>(it->second.get()); | 41 return static_cast<FakeDataTypeController*>(it->second.get()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 ACTION_P(VerifyResult, expected_result) { | 44 ACTION_P(VerifyResult, expected_result) { |
| 45 EXPECT_EQ(arg0.status, expected_result.status); | 45 EXPECT_EQ(arg0.status, expected_result.status); |
| 46 EXPECT_EQ(expected_result.requested_types, arg0.requested_types); | 46 EXPECT_EQ(expected_result.requested_types, arg0.requested_types); |
| 47 } | 47 } |
| 48 | 48 |
| 49 class SyncModelAssociationManagerTest : public testing::Test { | 49 class SyncModelAssociationManagerTest : public testing::Test { |
| 50 public: | 50 public: |
| 51 SyncModelAssociationManagerTest() {} | 51 SyncModelAssociationManagerTest() {} |
| 52 | 52 |
| 53 protected: | 53 protected: |
| 54 base::MessageLoopForUI ui_loop_; | 54 base::MessageLoopForUI ui_loop_; |
| 55 MockModelAssociationManagerDelegate delegate_; | 55 MockModelAssociationManagerDelegate delegate_; |
| 56 DataTypeController::TypeMap controllers_; | 56 DataTypeController::TypeMap controllers_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // Start a type and make sure ModelAssociationManager callst the |Start| | 59 // Start a type and make sure ModelAssociationManager callst the |Start| |
| 60 // method and calls the callback when it is done. | 60 // method and calls the callback when it is done. |
| 61 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { | 61 TEST_F(SyncModelAssociationManagerTest, SimpleModelStart) { |
| 62 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 62 controllers_[syncer::BOOKMARKS] = |
| 63 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); | 63 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 64 controllers_[syncer::APPS] = |
| 65 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 64 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 66 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 65 ModelTypeSet types(BOOKMARKS, APPS); | 67 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
| 66 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 68 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 67 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 69 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 68 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 70 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 69 .WillOnce(VerifyResult(expected_result)); | 71 .WillOnce(VerifyResult(expected_result)); |
| 70 | 72 |
| 71 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 73 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 72 DataTypeController::NOT_RUNNING); | 74 DataTypeController::NOT_RUNNING); |
| 73 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 75 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 74 DataTypeController::NOT_RUNNING); | 76 DataTypeController::NOT_RUNNING); |
| 75 | 77 |
| 76 // Initialize() kicks off model loading. | 78 // Initialize() kicks off model loading. |
| 77 model_association_manager.Initialize(types); | 79 model_association_manager.Initialize(types); |
| 78 | 80 |
| 79 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 81 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 80 DataTypeController::MODEL_LOADED); | 82 DataTypeController::MODEL_LOADED); |
| 81 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 83 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 82 DataTypeController::MODEL_LOADED); | 84 DataTypeController::MODEL_LOADED); |
| 83 | 85 |
| 84 model_association_manager.StartAssociationAsync(types); | 86 model_association_manager.StartAssociationAsync(types); |
| 85 | 87 |
| 86 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 88 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 87 DataTypeController::ASSOCIATING); | 89 DataTypeController::ASSOCIATING); |
| 88 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 90 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 89 DataTypeController::ASSOCIATING); | 91 DataTypeController::ASSOCIATING); |
| 90 GetController(controllers_, BOOKMARKS)->FinishStart(DataTypeController::OK); | 92 GetController(controllers_, syncer::BOOKMARKS) |
| 91 GetController(controllers_, APPS)->FinishStart(DataTypeController::OK); | 93 ->FinishStart(DataTypeController::OK); |
| 94 GetController(controllers_, syncer::APPS) |
| 95 ->FinishStart(DataTypeController::OK); |
| 92 } | 96 } |
| 93 | 97 |
| 94 // Start a type and call stop before it finishes associating. | 98 // Start a type and call stop before it finishes associating. |
| 95 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { | 99 TEST_F(SyncModelAssociationManagerTest, StopModelBeforeFinish) { |
| 96 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 100 controllers_[syncer::BOOKMARKS] = |
| 101 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 97 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 102 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 98 | 103 |
| 99 ModelTypeSet types; | 104 syncer::ModelTypeSet types; |
| 100 types.Put(BOOKMARKS); | 105 types.Put(syncer::BOOKMARKS); |
| 101 | 106 |
| 102 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, | 107 DataTypeManager::ConfigureResult expected_result(DataTypeManager::ABORTED, |
| 103 types); | 108 types); |
| 104 | 109 |
| 105 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 110 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 106 .WillOnce(VerifyResult(expected_result)); | 111 .WillOnce(VerifyResult(expected_result)); |
| 107 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); | 112 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 108 | 113 |
| 109 model_association_manager.Initialize(types); | 114 model_association_manager.Initialize(types); |
| 110 model_association_manager.StartAssociationAsync(types); | 115 model_association_manager.StartAssociationAsync(types); |
| 111 | 116 |
| 112 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 117 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 113 DataTypeController::ASSOCIATING); | 118 DataTypeController::ASSOCIATING); |
| 114 model_association_manager.Stop(); | 119 model_association_manager.Stop(); |
| 115 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 120 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 116 DataTypeController::NOT_RUNNING); | 121 DataTypeController::NOT_RUNNING); |
| 117 } | 122 } |
| 118 | 123 |
| 119 // Start a type, let it finish and then call stop. | 124 // Start a type, let it finish and then call stop. |
| 120 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { | 125 TEST_F(SyncModelAssociationManagerTest, StopAfterFinish) { |
| 121 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 126 controllers_[syncer::BOOKMARKS] = |
| 127 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 122 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 128 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 123 ModelTypeSet types; | 129 syncer::ModelTypeSet types; |
| 124 types.Put(BOOKMARKS); | 130 types.Put(syncer::BOOKMARKS); |
| 125 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 131 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 126 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 132 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 127 .WillOnce(VerifyResult(expected_result)); | 133 .WillOnce(VerifyResult(expected_result)); |
| 128 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); | 134 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 129 | 135 |
| 130 model_association_manager.Initialize(types); | 136 model_association_manager.Initialize(types); |
| 131 model_association_manager.StartAssociationAsync(types); | 137 model_association_manager.StartAssociationAsync(types); |
| 132 | 138 |
| 133 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 139 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 134 DataTypeController::ASSOCIATING); | 140 DataTypeController::ASSOCIATING); |
| 135 GetController(controllers_, BOOKMARKS)->FinishStart(DataTypeController::OK); | 141 GetController(controllers_, syncer::BOOKMARKS) |
| 142 ->FinishStart(DataTypeController::OK); |
| 136 | 143 |
| 137 model_association_manager.Stop(); | 144 model_association_manager.Stop(); |
| 138 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 145 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 139 DataTypeController::NOT_RUNNING); | 146 DataTypeController::NOT_RUNNING); |
| 140 } | 147 } |
| 141 | 148 |
| 142 // Make a type fail model association and verify correctness. | 149 // Make a type fail model association and verify correctness. |
| 143 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { | 150 TEST_F(SyncModelAssociationManagerTest, TypeFailModelAssociation) { |
| 144 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 151 controllers_[syncer::BOOKMARKS] = |
| 152 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 145 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 153 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 146 ModelTypeSet types; | 154 syncer::ModelTypeSet types; |
| 147 types.Put(BOOKMARKS); | 155 types.Put(syncer::BOOKMARKS); |
| 148 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 156 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 149 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); | 157 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 150 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 158 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 151 .WillOnce(VerifyResult(expected_result)); | 159 .WillOnce(VerifyResult(expected_result)); |
| 152 | 160 |
| 153 model_association_manager.Initialize(types); | 161 model_association_manager.Initialize(types); |
| 154 model_association_manager.StartAssociationAsync(types); | 162 model_association_manager.StartAssociationAsync(types); |
| 155 | 163 |
| 156 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 164 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 157 DataTypeController::ASSOCIATING); | 165 DataTypeController::ASSOCIATING); |
| 158 GetController(controllers_, BOOKMARKS) | 166 GetController(controllers_, syncer::BOOKMARKS) |
| 159 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); | 167 ->FinishStart(DataTypeController::ASSOCIATION_FAILED); |
| 160 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 168 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 161 DataTypeController::NOT_RUNNING); | 169 DataTypeController::NOT_RUNNING); |
| 162 } | 170 } |
| 163 | 171 |
| 164 // Ensure configuring stops when a type returns a unrecoverable error. | 172 // Ensure configuring stops when a type returns a unrecoverable error. |
| 165 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { | 173 TEST_F(SyncModelAssociationManagerTest, TypeReturnUnrecoverableError) { |
| 166 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 174 controllers_[syncer::BOOKMARKS] = |
| 175 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 167 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 176 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 168 ModelTypeSet types; | 177 syncer::ModelTypeSet types; |
| 169 types.Put(BOOKMARKS); | 178 types.Put(syncer::BOOKMARKS); |
| 170 DataTypeManager::ConfigureResult expected_result( | 179 DataTypeManager::ConfigureResult expected_result( |
| 171 DataTypeManager::UNRECOVERABLE_ERROR, types); | 180 DataTypeManager::UNRECOVERABLE_ERROR, types); |
| 172 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); | 181 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 173 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 182 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 174 .WillOnce(VerifyResult(expected_result)); | 183 .WillOnce(VerifyResult(expected_result)); |
| 175 | 184 |
| 176 model_association_manager.Initialize(types); | 185 model_association_manager.Initialize(types); |
| 177 | 186 |
| 178 model_association_manager.StartAssociationAsync(types); | 187 model_association_manager.StartAssociationAsync(types); |
| 179 | 188 |
| 180 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 189 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 181 DataTypeController::ASSOCIATING); | 190 DataTypeController::ASSOCIATING); |
| 182 GetController(controllers_, BOOKMARKS) | 191 GetController(controllers_, syncer::BOOKMARKS) |
| 183 ->FinishStart(DataTypeController::UNRECOVERABLE_ERROR); | 192 ->FinishStart(DataTypeController::UNRECOVERABLE_ERROR); |
| 184 } | 193 } |
| 185 | 194 |
| 186 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { | 195 TEST_F(SyncModelAssociationManagerTest, SlowTypeAsFailedType) { |
| 187 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 196 controllers_[syncer::BOOKMARKS] = |
| 188 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); | 197 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 189 GetController(controllers_, BOOKMARKS)->SetDelayModelLoad(); | 198 controllers_[syncer::APPS] = |
| 199 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 200 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 190 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 201 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 191 ModelTypeSet types; | 202 syncer::ModelTypeSet types; |
| 192 types.Put(BOOKMARKS); | 203 types.Put(syncer::BOOKMARKS); |
| 193 types.Put(APPS); | 204 types.Put(syncer::APPS); |
| 194 | 205 |
| 195 DataTypeManager::ConfigureResult expected_result_partially_done( | 206 DataTypeManager::ConfigureResult expected_result_partially_done( |
| 196 DataTypeManager::OK, types); | 207 DataTypeManager::OK, types); |
| 197 | 208 |
| 198 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 209 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 199 .WillOnce(VerifyResult(expected_result_partially_done)); | 210 .WillOnce(VerifyResult(expected_result_partially_done)); |
| 200 | 211 |
| 201 model_association_manager.Initialize(types); | 212 model_association_manager.Initialize(types); |
| 202 model_association_manager.StartAssociationAsync(types); | 213 model_association_manager.StartAssociationAsync(types); |
| 203 GetController(controllers_, APPS)->FinishStart(DataTypeController::OK); | 214 GetController(controllers_, syncer::APPS) |
| 215 ->FinishStart(DataTypeController::OK); |
| 204 | 216 |
| 205 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); | 217 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 206 model_association_manager.GetTimerForTesting()->user_task().Run(); | 218 model_association_manager.GetTimerForTesting()->user_task().Run(); |
| 207 | 219 |
| 208 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 220 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 209 GetController(controllers_, BOOKMARKS)->state()); | 221 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 210 } | 222 } |
| 211 | 223 |
| 212 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { | 224 TEST_F(SyncModelAssociationManagerTest, StartMultipleTimes) { |
| 213 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 225 controllers_[syncer::BOOKMARKS] = |
| 214 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); | 226 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 227 controllers_[syncer::APPS] = |
| 228 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 215 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 229 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 216 ModelTypeSet types; | 230 syncer::ModelTypeSet types; |
| 217 types.Put(BOOKMARKS); | 231 types.Put(syncer::BOOKMARKS); |
| 218 types.Put(APPS); | 232 types.Put(syncer::APPS); |
| 219 | 233 |
| 220 DataTypeManager::ConfigureResult result_1st(DataTypeManager::OK, | 234 DataTypeManager::ConfigureResult result_1st( |
| 221 ModelTypeSet(BOOKMARKS)); | 235 DataTypeManager::OK, syncer::ModelTypeSet(syncer::BOOKMARKS)); |
| 222 DataTypeManager::ConfigureResult result_2nd(DataTypeManager::OK, | 236 DataTypeManager::ConfigureResult result_2nd( |
| 223 ModelTypeSet(APPS)); | 237 DataTypeManager::OK, syncer::ModelTypeSet(syncer::APPS)); |
| 224 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 238 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 225 .Times(2) | 239 .Times(2) |
| 226 .WillOnce(VerifyResult(result_1st)) | 240 .WillOnce(VerifyResult(result_1st)) |
| 227 .WillOnce(VerifyResult(result_2nd)); | 241 .WillOnce(VerifyResult(result_2nd)); |
| 228 | 242 |
| 229 model_association_manager.Initialize(types); | 243 model_association_manager.Initialize(types); |
| 230 | 244 |
| 231 // Start BOOKMARKS first. | 245 // Start BOOKMARKS first. |
| 232 model_association_manager.StartAssociationAsync(ModelTypeSet(BOOKMARKS)); | 246 model_association_manager.StartAssociationAsync( |
| 233 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 247 syncer::ModelTypeSet(syncer::BOOKMARKS)); |
| 248 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 234 DataTypeController::ASSOCIATING); | 249 DataTypeController::ASSOCIATING); |
| 235 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 250 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 236 DataTypeController::MODEL_LOADED); | 251 DataTypeController::MODEL_LOADED); |
| 237 | 252 |
| 238 // Finish BOOKMARKS association. | 253 // Finish BOOKMARKS association. |
| 239 GetController(controllers_, BOOKMARKS)->FinishStart(DataTypeController::OK); | 254 GetController(controllers_, syncer::BOOKMARKS) |
| 240 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 255 ->FinishStart(DataTypeController::OK); |
| 256 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 241 DataTypeController::RUNNING); | 257 DataTypeController::RUNNING); |
| 242 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 258 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 243 DataTypeController::MODEL_LOADED); | 259 DataTypeController::MODEL_LOADED); |
| 244 | 260 |
| 245 // Start APPS next. | 261 // Start APPS next. |
| 246 model_association_manager.StartAssociationAsync(ModelTypeSet(APPS)); | 262 model_association_manager.StartAssociationAsync( |
| 247 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 263 syncer::ModelTypeSet(syncer::APPS)); |
| 264 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 248 DataTypeController::ASSOCIATING); | 265 DataTypeController::ASSOCIATING); |
| 249 GetController(controllers_, APPS)->FinishStart(DataTypeController::OK); | 266 GetController(controllers_, syncer::APPS) |
| 250 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 267 ->FinishStart(DataTypeController::OK); |
| 268 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 251 DataTypeController::RUNNING); | 269 DataTypeController::RUNNING); |
| 252 } | 270 } |
| 253 | 271 |
| 254 // Test that model that failed to load between initialization and association | 272 // Test that model that failed to load between initialization and association |
| 255 // is reported and stopped properly. | 273 // is reported and stopped properly. |
| 256 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { | 274 TEST_F(SyncModelAssociationManagerTest, ModelLoadFailBeforeAssociationStart) { |
| 257 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 275 controllers_[syncer::BOOKMARKS] = |
| 258 GetController(controllers_, BOOKMARKS) | 276 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 259 ->SetModelLoadError( | 277 GetController(controllers_, syncer::BOOKMARKS) |
| 260 SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, "", BOOKMARKS)); | 278 ->SetModelLoadError(syncer::SyncError( |
| 279 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::BOOKMARKS)); |
| 261 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 280 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 262 ModelTypeSet types; | 281 syncer::ModelTypeSet types; |
| 263 types.Put(BOOKMARKS); | 282 types.Put(syncer::BOOKMARKS); |
| 264 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 283 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 265 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); | 284 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 266 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 285 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 267 .WillOnce(VerifyResult(expected_result)); | 286 .WillOnce(VerifyResult(expected_result)); |
| 268 | 287 |
| 269 model_association_manager.Initialize(types); | 288 model_association_manager.Initialize(types); |
| 270 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 289 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 271 GetController(controllers_, BOOKMARKS)->state()); | 290 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 272 model_association_manager.StartAssociationAsync(types); | 291 model_association_manager.StartAssociationAsync(types); |
| 273 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 292 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 274 GetController(controllers_, BOOKMARKS)->state()); | 293 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 275 } | 294 } |
| 276 | 295 |
| 277 // Test that a runtime error is handled by stopping the type. | 296 // Test that a runtime error is handled by stopping the type. |
| 278 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { | 297 TEST_F(SyncModelAssociationManagerTest, StopAfterConfiguration) { |
| 279 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 298 controllers_[syncer::BOOKMARKS] = |
| 299 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 280 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 300 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 281 ModelTypeSet types; | 301 syncer::ModelTypeSet types; |
| 282 types.Put(BOOKMARKS); | 302 types.Put(syncer::BOOKMARKS); |
| 283 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 303 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 284 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 304 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 285 .WillOnce(VerifyResult(expected_result)); | 305 .WillOnce(VerifyResult(expected_result)); |
| 286 | 306 |
| 287 model_association_manager.Initialize(types); | 307 model_association_manager.Initialize(types); |
| 288 model_association_manager.StartAssociationAsync(types); | 308 model_association_manager.StartAssociationAsync(types); |
| 289 | 309 |
| 290 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 310 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 291 DataTypeController::ASSOCIATING); | 311 DataTypeController::ASSOCIATING); |
| 292 GetController(controllers_, BOOKMARKS)->FinishStart(DataTypeController::OK); | 312 GetController(controllers_, syncer::BOOKMARKS) |
| 293 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 313 ->FinishStart(DataTypeController::OK); |
| 314 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 294 DataTypeController::RUNNING); | 315 DataTypeController::RUNNING); |
| 295 | 316 |
| 296 testing::Mock::VerifyAndClearExpectations(&delegate_); | 317 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 297 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); | 318 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 298 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, "error", BOOKMARKS); | 319 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", |
| 299 GetController(controllers_, BOOKMARKS) | 320 syncer::BOOKMARKS); |
| 321 GetController(controllers_, syncer::BOOKMARKS) |
| 300 ->CreateErrorHandler() | 322 ->CreateErrorHandler() |
| 301 ->OnUnrecoverableError(error); | 323 ->OnUnrecoverableError(error); |
| 302 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
| 303 } | 325 } |
| 304 | 326 |
| 305 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { | 327 TEST_F(SyncModelAssociationManagerTest, AbortDuringAssociation) { |
| 306 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 328 controllers_[syncer::BOOKMARKS] = |
| 307 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); | 329 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 330 controllers_[syncer::APPS] = |
| 331 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 308 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 332 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 309 ModelTypeSet types; | 333 syncer::ModelTypeSet types; |
| 310 types.Put(BOOKMARKS); | 334 types.Put(syncer::BOOKMARKS); |
| 311 types.Put(APPS); | 335 types.Put(syncer::APPS); |
| 312 | 336 |
| 313 ModelTypeSet expected_types_unfinished; | 337 syncer::ModelTypeSet expected_types_unfinished; |
| 314 expected_types_unfinished.Put(BOOKMARKS); | 338 expected_types_unfinished.Put(syncer::BOOKMARKS); |
| 315 DataTypeManager::ConfigureResult expected_result_partially_done( | 339 DataTypeManager::ConfigureResult expected_result_partially_done( |
| 316 DataTypeManager::OK, types); | 340 DataTypeManager::OK, types); |
| 317 | 341 |
| 318 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) | 342 EXPECT_CALL(delegate_, OnModelAssociationDone(_)) |
| 319 .WillOnce(VerifyResult(expected_result_partially_done)); | 343 .WillOnce(VerifyResult(expected_result_partially_done)); |
| 320 | 344 |
| 321 model_association_manager.Initialize(types); | 345 model_association_manager.Initialize(types); |
| 322 model_association_manager.StartAssociationAsync(types); | 346 model_association_manager.StartAssociationAsync(types); |
| 323 GetController(controllers_, APPS)->FinishStart(DataTypeController::OK); | 347 GetController(controllers_, syncer::APPS) |
| 324 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 348 ->FinishStart(DataTypeController::OK); |
| 349 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 325 DataTypeController::RUNNING); | 350 DataTypeController::RUNNING); |
| 326 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 351 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 327 DataTypeController::ASSOCIATING); | 352 DataTypeController::ASSOCIATING); |
| 328 | 353 |
| 329 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _)); | 354 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::BOOKMARKS, _)); |
| 330 model_association_manager.GetTimerForTesting()->user_task().Run(); | 355 model_association_manager.GetTimerForTesting()->user_task().Run(); |
| 331 | 356 |
| 332 EXPECT_EQ(DataTypeController::NOT_RUNNING, | 357 EXPECT_EQ(DataTypeController::NOT_RUNNING, |
| 333 GetController(controllers_, BOOKMARKS)->state()); | 358 GetController(controllers_, syncer::BOOKMARKS)->state()); |
| 334 } | 359 } |
| 335 | 360 |
| 336 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that | 361 // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that |
| 337 // require LoadModels before configuration are loaded. | 362 // require LoadModels before configuration are loaded. |
| 338 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { | 363 TEST_F(SyncModelAssociationManagerTest, OnAllDataTypesReadyForConfigure) { |
| 339 // Create two controllers with delayed model load. | 364 // Create two controllers with delayed model load. |
| 340 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 365 controllers_[syncer::BOOKMARKS] = |
| 341 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); | 366 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 342 GetController(controllers_, BOOKMARKS)->SetDelayModelLoad(); | 367 controllers_[syncer::APPS] = |
| 343 GetController(controllers_, APPS)->SetDelayModelLoad(); | 368 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 369 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 370 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); |
| 344 | 371 |
| 345 // APPS controller requires LoadModels complete before configure. | 372 // APPS controller requires LoadModels complete before configure. |
| 346 GetController(controllers_, APPS)->SetShouldLoadModelBeforeConfigure(true); | 373 GetController(controllers_, syncer::APPS) |
| 374 ->SetShouldLoadModelBeforeConfigure(true); |
| 347 | 375 |
| 348 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 376 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 349 ModelTypeSet types(BOOKMARKS, APPS); | 377 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
| 350 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 378 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 351 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not | 379 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not |
| 352 // loaded yet. | 380 // loaded yet. |
| 353 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 381 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
| 354 | 382 |
| 355 model_association_manager.Initialize(types); | 383 model_association_manager.Initialize(types); |
| 356 | 384 |
| 357 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 385 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 358 DataTypeController::MODEL_STARTING); | 386 DataTypeController::MODEL_STARTING); |
| 359 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 387 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 360 DataTypeController::MODEL_STARTING); | 388 DataTypeController::MODEL_STARTING); |
| 361 | 389 |
| 362 testing::Mock::VerifyAndClearExpectations(&delegate_); | 390 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 363 | 391 |
| 364 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 392 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 365 // Finish loading APPS. This should trigger OnAllDataTypesReadyForConfigure | 393 // Finish loading APPS. This should trigger OnAllDataTypesReadyForConfigure |
| 366 // even though BOOKMARKS is not loaded yet. | 394 // even though BOOKMARKS is not loaded yet. |
| 367 GetController(controllers_, APPS)->SimulateModelLoadFinishing(); | 395 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); |
| 368 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 396 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 369 DataTypeController::MODEL_STARTING); | 397 DataTypeController::MODEL_STARTING); |
| 370 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 398 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 371 DataTypeController::MODEL_LOADED); | 399 DataTypeController::MODEL_LOADED); |
| 372 | 400 |
| 373 // Call ModelAssociationManager::Initialize with reduced set of datatypes. | 401 // Call ModelAssociationManager::Initialize with reduced set of datatypes. |
| 374 // All datatypes in reduced set are already loaded. | 402 // All datatypes in reduced set are already loaded. |
| 375 // OnAllDataTypesReadyForConfigure() should be called. | 403 // OnAllDataTypesReadyForConfigure() should be called. |
| 376 testing::Mock::VerifyAndClearExpectations(&delegate_); | 404 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 377 | 405 |
| 378 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 406 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 379 ModelTypeSet reduced_types(APPS); | 407 syncer::ModelTypeSet reduced_types(syncer::APPS); |
| 380 model_association_manager.Initialize(reduced_types); | 408 model_association_manager.Initialize(reduced_types); |
| 381 } | 409 } |
| 382 | 410 |
| 383 // Test that OnAllDataTypesReadyForConfigure() is called correctly after | 411 // Test that OnAllDataTypesReadyForConfigure() is called correctly after |
| 384 // LoadModels fails for one of datatypes. | 412 // LoadModels fails for one of datatypes. |
| 385 TEST_F(SyncModelAssociationManagerTest, | 413 TEST_F(SyncModelAssociationManagerTest, |
| 386 OnAllDataTypesReadyForConfigure_FailedLoadModels) { | 414 OnAllDataTypesReadyForConfigure_FailedLoadModels) { |
| 387 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); | 415 controllers_[syncer::APPS] = |
| 388 GetController(controllers_, APPS)->SetDelayModelLoad(); | 416 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 417 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); |
| 389 | 418 |
| 390 // APPS controller requires LoadModels complete before configure. | 419 // APPS controller requires LoadModels complete before configure. |
| 391 GetController(controllers_, APPS)->SetShouldLoadModelBeforeConfigure(true); | 420 GetController(controllers_, syncer::APPS) |
| 421 ->SetShouldLoadModelBeforeConfigure(true); |
| 392 | 422 |
| 393 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 423 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 394 ModelTypeSet types(APPS); | 424 syncer::ModelTypeSet types(syncer::APPS); |
| 395 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 425 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 396 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not | 426 // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not |
| 397 // loaded yet. | 427 // loaded yet. |
| 398 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 428 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
| 399 | 429 |
| 400 model_association_manager.Initialize(types); | 430 model_association_manager.Initialize(types); |
| 401 | 431 |
| 402 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 432 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 403 DataTypeController::MODEL_STARTING); | 433 DataTypeController::MODEL_STARTING); |
| 404 | 434 |
| 405 testing::Mock::VerifyAndClearExpectations(&delegate_); | 435 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 406 | 436 |
| 407 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 437 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 408 // Simulate model load error for APPS and finish loading it. This should | 438 // Simulate model load error for APPS and finish loading it. This should |
| 409 // trigger OnAllDataTypesReadyForConfigure. | 439 // trigger OnAllDataTypesReadyForConfigure. |
| 410 GetController(controllers_, APPS) | 440 GetController(controllers_, syncer::APPS) |
| 411 ->SetModelLoadError( | 441 ->SetModelLoadError(syncer::SyncError( |
| 412 SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, "", APPS)); | 442 FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "", syncer::APPS)); |
| 413 GetController(controllers_, APPS)->SimulateModelLoadFinishing(); | 443 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); |
| 414 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 444 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 415 DataTypeController::NOT_RUNNING); | 445 DataTypeController::NOT_RUNNING); |
| 416 } | 446 } |
| 417 | 447 |
| 418 // Test that if one of the types fails while another is still being loaded then | 448 // Test that if one of the types fails while another is still being loaded then |
| 419 // OnAllDataTypesReadyForConfgiure is still called correctly. | 449 // OnAllDataTypesReadyForConfgiure is still called correctly. |
| 420 TEST_F(SyncModelAssociationManagerTest, | 450 TEST_F(SyncModelAssociationManagerTest, |
| 421 OnAllDataTypesReadyForConfigure_TypeFailedAfterLoadModels) { | 451 OnAllDataTypesReadyForConfigure_TypeFailedAfterLoadModels) { |
| 422 // Create two controllers with delayed model load. Both should block | 452 // Create two controllers with delayed model load. Both should block |
| 423 // configuration. | 453 // configuration. |
| 424 controllers_[BOOKMARKS] = base::MakeUnique<FakeDataTypeController>(BOOKMARKS); | 454 controllers_[syncer::BOOKMARKS] = |
| 425 controllers_[APPS] = base::MakeUnique<FakeDataTypeController>(APPS); | 455 base::MakeUnique<FakeDataTypeController>(syncer::BOOKMARKS); |
| 426 GetController(controllers_, BOOKMARKS)->SetDelayModelLoad(); | 456 controllers_[syncer::APPS] = |
| 427 GetController(controllers_, APPS)->SetDelayModelLoad(); | 457 base::MakeUnique<FakeDataTypeController>(syncer::APPS); |
| 458 GetController(controllers_, syncer::BOOKMARKS)->SetDelayModelLoad(); |
| 459 GetController(controllers_, syncer::APPS)->SetDelayModelLoad(); |
| 428 | 460 |
| 429 GetController(controllers_, BOOKMARKS) | 461 GetController(controllers_, syncer::BOOKMARKS) |
| 430 ->SetShouldLoadModelBeforeConfigure(true); | 462 ->SetShouldLoadModelBeforeConfigure(true); |
| 431 GetController(controllers_, APPS)->SetShouldLoadModelBeforeConfigure(true); | 463 GetController(controllers_, syncer::APPS) |
| 464 ->SetShouldLoadModelBeforeConfigure(true); |
| 432 | 465 |
| 433 ModelAssociationManager model_association_manager(&controllers_, &delegate_); | 466 ModelAssociationManager model_association_manager(&controllers_, &delegate_); |
| 434 ModelTypeSet types(BOOKMARKS, APPS); | 467 syncer::ModelTypeSet types(syncer::BOOKMARKS, syncer::APPS); |
| 435 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); | 468 DataTypeManager::ConfigureResult expected_result(DataTypeManager::OK, types); |
| 436 | 469 |
| 437 // Apps will finish loading but bookmarks won't. | 470 // Apps will finish loading but bookmarks won't. |
| 438 // OnAllDataTypesReadyForConfigure shouldn't be called. | 471 // OnAllDataTypesReadyForConfigure shouldn't be called. |
| 439 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 472 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
| 440 | 473 |
| 441 model_association_manager.Initialize(types); | 474 model_association_manager.Initialize(types); |
| 442 | 475 |
| 443 GetController(controllers_, APPS)->SimulateModelLoadFinishing(); | 476 GetController(controllers_, syncer::APPS)->SimulateModelLoadFinishing(); |
| 444 | 477 |
| 445 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 478 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 446 DataTypeController::MODEL_STARTING); | 479 DataTypeController::MODEL_STARTING); |
| 447 EXPECT_EQ(GetController(controllers_, APPS)->state(), | 480 EXPECT_EQ(GetController(controllers_, syncer::APPS)->state(), |
| 448 DataTypeController::MODEL_LOADED); | 481 DataTypeController::MODEL_LOADED); |
| 449 | 482 |
| 450 testing::Mock::VerifyAndClearExpectations(&delegate_); | 483 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 451 | 484 |
| 452 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); | 485 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0); |
| 453 | 486 |
| 454 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(APPS, _)); | 487 EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(syncer::APPS, _)); |
| 455 // Apps datatype reports failure. | 488 // Apps datatype reports failure. |
| 456 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, "error", APPS); | 489 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, "error", |
| 457 GetController(controllers_, APPS) | 490 syncer::APPS); |
| 491 GetController(controllers_, syncer::APPS) |
| 458 ->CreateErrorHandler() | 492 ->CreateErrorHandler() |
| 459 ->OnUnrecoverableError(error); | 493 ->OnUnrecoverableError(error); |
| 460 base::RunLoop().RunUntilIdle(); | 494 base::RunLoop().RunUntilIdle(); |
| 461 | 495 |
| 462 testing::Mock::VerifyAndClearExpectations(&delegate_); | 496 testing::Mock::VerifyAndClearExpectations(&delegate_); |
| 463 | 497 |
| 464 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); | 498 EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()); |
| 465 // Finish loading BOOKMARKS. This should trigger | 499 // Finish loading BOOKMARKS. This should trigger |
| 466 // OnAllDataTypesReadyForConfigure(). | 500 // OnAllDataTypesReadyForConfigure(). |
| 467 GetController(controllers_, BOOKMARKS)->SimulateModelLoadFinishing(); | 501 GetController(controllers_, syncer::BOOKMARKS)->SimulateModelLoadFinishing(); |
| 468 EXPECT_EQ(GetController(controllers_, BOOKMARKS)->state(), | 502 EXPECT_EQ(GetController(controllers_, syncer::BOOKMARKS)->state(), |
| 469 DataTypeController::MODEL_LOADED); | 503 DataTypeController::MODEL_LOADED); |
| 470 } | 504 } |
| 471 | 505 |
| 472 } // namespace syncer | 506 } // namespace sync_driver |
| OLD | NEW |