model_load_manager_unittest.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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
  3. // found in the LICENSE file.
  4. #include "components/sync/driver/model_load_manager.h"
  5. #include <memory>
  6. #include "base/callback.h"
  7. #include "base/run_loop.h"
  8. #include "base/test/task_environment.h"
  9. #include "components/sync/driver/configure_context.h"
  10. #include "components/sync/driver/fake_data_type_controller.h"
  11. #include "testing/gmock/include/gmock/gmock.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. using ::testing::_;
  14. namespace syncer {
  15. namespace {
  16. ConfigureContext BuildConfigureContext(SyncMode sync_mode = SyncMode::kFull) {
  17. ConfigureContext context;
  18. context.sync_mode = sync_mode;
  19. context.cache_guid = "test_cache_guid";
  20. return context;
  21. }
  22. } // namespace
  23. class MockModelLoadManagerDelegate : public ModelLoadManagerDelegate {
  24. public:
  25. MockModelLoadManagerDelegate() = default;
  26. ~MockModelLoadManagerDelegate() override = default;
  27. MOCK_METHOD(void, OnAllDataTypesReadyForConfigure, (), (override));
  28. MOCK_METHOD(void,
  29. OnSingleDataTypeWillStop,
  30. (ModelType, const SyncError& error),
  31. (override));
  32. };
  33. class SyncModelLoadManagerTest : public testing::Test {
  34. public:
  35. SyncModelLoadManagerTest() = default;
  36. FakeDataTypeController* GetController(ModelType model_type) {
  37. auto it = controllers_.find(model_type);
  38. if (it == controllers_.end()) {
  39. return nullptr;
  40. }
  41. return static_cast<FakeDataTypeController*>(it->second.get());
  42. }
  43. protected:
  44. base::test::SingleThreadTaskEnvironment task_environment_{
  45. base::test::SingleThreadTaskEnvironment::MainThreadType::UI};
  46. testing::NiceMock<MockModelLoadManagerDelegate> delegate_;
  47. DataTypeController::TypeMap controllers_;
  48. };
  49. // Start a type and make sure ModelLoadManager callst the |Start|
  50. // method and calls the callback when it is done.
  51. TEST_F(SyncModelLoadManagerTest, SimpleModelStart) {
  52. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  53. controllers_[APPS] = std::make_unique<FakeDataTypeController>(APPS);
  54. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  55. ModelTypeSet types(BOOKMARKS, APPS);
  56. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  57. EXPECT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  58. EXPECT_EQ(GetController(APPS)->state(), DataTypeController::NOT_RUNNING);
  59. // Initialize() kicks off model loading.
  60. model_load_manager.Initialize(/*preferred_types_without_errors=*/types,
  61. /*preferred_types=*/types,
  62. BuildConfigureContext());
  63. EXPECT_EQ(GetController(BOOKMARKS)->state(),
  64. DataTypeController::MODEL_LOADED);
  65. EXPECT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_LOADED);
  66. }
  67. // Start a type, let it finish and then call stop.
  68. TEST_F(SyncModelLoadManagerTest, StopAfterFinish) {
  69. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  70. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  71. ModelTypeSet types;
  72. types.Put(BOOKMARKS);
  73. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _));
  74. model_load_manager.Initialize(/*preferred_types_without_errors=*/types,
  75. /*preferred_types=*/types,
  76. BuildConfigureContext());
  77. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  78. DataTypeController::MODEL_LOADED);
  79. model_load_manager.Stop(ShutdownReason::STOP_SYNC_AND_KEEP_DATA);
  80. EXPECT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  81. EXPECT_EQ(0, GetController(BOOKMARKS)->model()->clear_metadata_call_count());
  82. }
  83. // Test that a model that failed to load is reported and stopped properly.
  84. TEST_F(SyncModelLoadManagerTest, ModelLoadFail) {
  85. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  86. GetController(BOOKMARKS)->model()->SimulateModelError(
  87. ModelError(FROM_HERE, "Test error"));
  88. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  89. ModelTypeSet types;
  90. types.Put(BOOKMARKS);
  91. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _));
  92. model_load_manager.Initialize(/*preferred_types_without_errors=*/types,
  93. /*preferred_types=*/types,
  94. BuildConfigureContext());
  95. EXPECT_EQ(DataTypeController::FAILED, GetController(BOOKMARKS)->state());
  96. }
  97. // Test that a runtime error is handled by stopping the type.
  98. TEST_F(SyncModelLoadManagerTest, StopAfterConfiguration) {
  99. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  100. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  101. ModelTypeSet types;
  102. types.Put(BOOKMARKS);
  103. model_load_manager.Initialize(/*preferred_types_without_errors=*/types,
  104. /*preferred_types=*/types,
  105. BuildConfigureContext());
  106. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  107. DataTypeController::MODEL_LOADED);
  108. testing::Mock::VerifyAndClearExpectations(&delegate_);
  109. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _));
  110. GetController(BOOKMARKS)->model()->SimulateModelError(
  111. ModelError(FROM_HERE, "Test error"));
  112. }
  113. // Test that OnAllDataTypesReadyForConfigure is called when all datatypes that
  114. // require LoadModels before configuration are loaded.
  115. TEST_F(SyncModelLoadManagerTest, OnAllDataTypesReadyForConfigure) {
  116. // Create two controllers with delayed model load.
  117. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  118. controllers_[APPS] = std::make_unique<FakeDataTypeController>(APPS);
  119. GetController(BOOKMARKS)->model()->EnableManualModelStart();
  120. GetController(APPS)->model()->EnableManualModelStart();
  121. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  122. ModelTypeSet types(BOOKMARKS, APPS);
  123. // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not
  124. // loaded yet.
  125. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0);
  126. model_load_manager.Initialize(/*preferred_types_without_errors=*/types,
  127. /*preferred_types=*/types,
  128. BuildConfigureContext());
  129. EXPECT_EQ(GetController(BOOKMARKS)->state(),
  130. DataTypeController::MODEL_STARTING);
  131. EXPECT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_STARTING);
  132. // Finish loading BOOKMARKS, but APPS are still loading.
  133. GetController(BOOKMARKS)->model()->SimulateModelStartFinished();
  134. EXPECT_EQ(GetController(BOOKMARKS)->state(),
  135. DataTypeController::MODEL_LOADED);
  136. testing::Mock::VerifyAndClearExpectations(&delegate_);
  137. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  138. // Finish loading APPS. This should trigger OnAllDataTypesReadyForConfigure.
  139. GetController(APPS)->model()->SimulateModelStartFinished();
  140. EXPECT_EQ(GetController(BOOKMARKS)->state(),
  141. DataTypeController::MODEL_LOADED);
  142. EXPECT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_LOADED);
  143. // Call ModelLoadManager::Initialize with reduced set of datatypes.
  144. // All datatypes in reduced set are already loaded.
  145. // OnAllDataTypesReadyForConfigure() should be called.
  146. testing::Mock::VerifyAndClearExpectations(&delegate_);
  147. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  148. ModelTypeSet reduced_types(APPS);
  149. model_load_manager.Initialize(
  150. /*preferred_types_without_errors=*/reduced_types,
  151. /*preferred_types=*/reduced_types, BuildConfigureContext());
  152. EXPECT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  153. EXPECT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_LOADED);
  154. EXPECT_EQ(1, GetController(BOOKMARKS)->model()->clear_metadata_call_count());
  155. }
  156. // Test that OnAllDataTypesReadyForConfigure() is called correctly after
  157. // LoadModels fails for one of datatypes.
  158. TEST_F(SyncModelLoadManagerTest,
  159. OnAllDataTypesReadyForConfigure_FailedLoadModels) {
  160. controllers_[APPS] = std::make_unique<FakeDataTypeController>(APPS);
  161. GetController(APPS)->model()->EnableManualModelStart();
  162. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  163. ModelTypeSet types(APPS);
  164. // OnAllDataTypesReadyForConfigure shouldn't be called, APPS data type is not
  165. // loaded yet.
  166. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0);
  167. model_load_manager.Initialize(/*preferred_types_without_errors=*/types,
  168. /*preferred_types=*/types,
  169. BuildConfigureContext());
  170. EXPECT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_STARTING);
  171. testing::Mock::VerifyAndClearExpectations(&delegate_);
  172. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  173. // Simulate model load error for APPS and finish loading it. This should
  174. // trigger OnAllDataTypesReadyForConfigure.
  175. GetController(APPS)->model()->SimulateModelError(
  176. ModelError(FROM_HERE, "Test error"));
  177. EXPECT_EQ(GetController(APPS)->state(), DataTypeController::FAILED);
  178. }
  179. // Test that if one of the types fails while another is still being loaded then
  180. // OnAllDataTypesReadyForConfgiure is still called correctly.
  181. TEST_F(SyncModelLoadManagerTest,
  182. OnAllDataTypesReadyForConfigure_TypeFailedAfterLoadModels) {
  183. // Create two controllers with delayed model load. Both should block
  184. // configuration.
  185. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  186. controllers_[APPS] = std::make_unique<FakeDataTypeController>(APPS);
  187. GetController(BOOKMARKS)->model()->EnableManualModelStart();
  188. GetController(APPS)->model()->EnableManualModelStart();
  189. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  190. ModelTypeSet types(BOOKMARKS, APPS);
  191. // Apps will finish loading but bookmarks won't.
  192. // OnAllDataTypesReadyForConfigure shouldn't be called.
  193. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0);
  194. model_load_manager.Initialize(/*preferred_types_without_errors=*/types,
  195. /*preferred_types=*/types,
  196. BuildConfigureContext());
  197. GetController(APPS)->model()->SimulateModelStartFinished();
  198. EXPECT_EQ(GetController(BOOKMARKS)->state(),
  199. DataTypeController::MODEL_STARTING);
  200. EXPECT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_LOADED);
  201. testing::Mock::VerifyAndClearExpectations(&delegate_);
  202. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure()).Times(0);
  203. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(APPS, _));
  204. // Apps datatype reports failure.
  205. GetController(APPS)->model()->SimulateModelError(
  206. ModelError(FROM_HERE, "Test error"));
  207. testing::Mock::VerifyAndClearExpectations(&delegate_);
  208. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  209. // Finish loading BOOKMARKS. This should trigger
  210. // OnAllDataTypesReadyForConfigure().
  211. GetController(BOOKMARKS)->model()->SimulateModelStartFinished();
  212. EXPECT_EQ(GetController(BOOKMARKS)->state(),
  213. DataTypeController::MODEL_LOADED);
  214. }
  215. // Test that Stop clears metadata for disabled type.
  216. TEST_F(SyncModelLoadManagerTest, StopClearMetadata) {
  217. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  218. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  219. ASSERT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  220. ModelTypeSet types(BOOKMARKS);
  221. // Initialize() kicks off model loading.
  222. model_load_manager.Initialize(/*preferred_types_without_errors=*/types,
  223. /*preferred_types=*/types,
  224. BuildConfigureContext());
  225. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  226. DataTypeController::MODEL_LOADED);
  227. model_load_manager.Stop(ShutdownReason::DISABLE_SYNC_AND_CLEAR_DATA);
  228. EXPECT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  229. EXPECT_EQ(1, GetController(BOOKMARKS)->model()->clear_metadata_call_count());
  230. }
  231. // Test that stopping a single type clears the metadata for the disabled type.
  232. TEST_F(SyncModelLoadManagerTest, StopDataType) {
  233. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  234. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  235. ASSERT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  236. // Initialize() kicks off model loading.
  237. model_load_manager.Initialize(
  238. /*preferred_types_without_errors=*/ModelTypeSet(BOOKMARKS),
  239. /*preferred_types=*/ModelTypeSet(BOOKMARKS), BuildConfigureContext());
  240. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  241. DataTypeController::MODEL_LOADED);
  242. model_load_manager.StopDatatype(
  243. BOOKMARKS, ShutdownReason::DISABLE_SYNC_AND_CLEAR_DATA,
  244. SyncError(FROM_HERE, syncer::SyncError::UNREADY_ERROR,
  245. "Data type is unready.", BOOKMARKS));
  246. EXPECT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  247. EXPECT_EQ(1, GetController(BOOKMARKS)->model()->clear_metadata_call_count());
  248. }
  249. // Test that stopping a single type is ignored when the type is not running.
  250. TEST_F(SyncModelLoadManagerTest, StopDataType_NotRunning) {
  251. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  252. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  253. ASSERT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  254. model_load_manager.StopDatatype(
  255. BOOKMARKS, ShutdownReason::DISABLE_SYNC_AND_CLEAR_DATA,
  256. SyncError(FROM_HERE, syncer::SyncError::UNREADY_ERROR,
  257. "Data type is unready.", BOOKMARKS));
  258. // The state should still be not running.
  259. EXPECT_EQ(GetController(BOOKMARKS)->state(), DataTypeController::NOT_RUNNING);
  260. }
  261. // Test that Initialize stops controllers with KEEP_METADATA for preferred
  262. // types.
  263. TEST_F(SyncModelLoadManagerTest, KeepsMetadataForPreferredDataType) {
  264. // Initialize the manager with two data types.
  265. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  266. controllers_[APPS] = std::make_unique<FakeDataTypeController>(APPS);
  267. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  268. ModelTypeSet preferred_types(BOOKMARKS, APPS);
  269. ModelTypeSet desired_types = preferred_types;
  270. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  271. model_load_manager.Initialize(desired_types, preferred_types,
  272. BuildConfigureContext());
  273. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  274. DataTypeController::MODEL_LOADED);
  275. ASSERT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_LOADED);
  276. testing::Mock::VerifyAndClearExpectations(&delegate_);
  277. // Stop one data type without disabling sync.
  278. desired_types.Remove(APPS);
  279. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(APPS, _));
  280. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  281. model_load_manager.Initialize(desired_types, preferred_types,
  282. BuildConfigureContext());
  283. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  284. DataTypeController::MODEL_LOADED);
  285. ASSERT_EQ(GetController(APPS)->state(), DataTypeController::NOT_RUNNING);
  286. EXPECT_EQ(0, GetController(APPS)->model()->clear_metadata_call_count());
  287. }
  288. // Test that Initialize stops controllers with CLEAR_METADATA for
  289. // no-longer-preferred types.
  290. TEST_F(SyncModelLoadManagerTest, ClearsMetadataForNotPreferredDataType) {
  291. // Initialize the manager with two data types.
  292. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(BOOKMARKS);
  293. controllers_[APPS] = std::make_unique<FakeDataTypeController>(APPS);
  294. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  295. ModelTypeSet preferred_types(BOOKMARKS, APPS);
  296. ModelTypeSet desired_types = preferred_types;
  297. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  298. model_load_manager.Initialize(desired_types, preferred_types,
  299. BuildConfigureContext());
  300. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  301. DataTypeController::MODEL_LOADED);
  302. ASSERT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_LOADED);
  303. testing::Mock::VerifyAndClearExpectations(&delegate_);
  304. // Disable one data type.
  305. preferred_types.Remove(APPS);
  306. desired_types.Remove(APPS);
  307. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(APPS, _));
  308. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  309. model_load_manager.Initialize(desired_types, preferred_types,
  310. BuildConfigureContext());
  311. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  312. DataTypeController::MODEL_LOADED);
  313. ASSERT_EQ(GetController(APPS)->state(), DataTypeController::NOT_RUNNING);
  314. EXPECT_EQ(1, GetController(APPS)->model()->clear_metadata_call_count());
  315. }
  316. TEST_F(SyncModelLoadManagerTest, SwitchFromOnDiskToInMemoryRestartsTypes) {
  317. // Initialize the manager with two data types.
  318. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(
  319. BOOKMARKS, /*enable_transport_only_model=*/true);
  320. controllers_[APPS] = std::make_unique<FakeDataTypeController>(
  321. APPS, /*enable_transport_only_model=*/true);
  322. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  323. ModelTypeSet preferred_types(BOOKMARKS, APPS);
  324. ModelTypeSet desired_types = preferred_types;
  325. ConfigureContext configure_context;
  326. configure_context.sync_mode = SyncMode::kFull;
  327. configure_context.cache_guid = "test_cache_guid";
  328. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  329. model_load_manager.Initialize(desired_types, preferred_types,
  330. configure_context);
  331. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  332. DataTypeController::MODEL_LOADED);
  333. ASSERT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_LOADED);
  334. testing::Mock::VerifyAndClearExpectations(&delegate_);
  335. // Switch to in-memory storage.
  336. configure_context.sync_mode = SyncMode::kTransportOnly;
  337. desired_types.Remove(APPS);
  338. preferred_types.Remove(APPS);
  339. // Data types should get restarted.
  340. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(APPS, _));
  341. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _));
  342. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  343. model_load_manager.Initialize(desired_types, preferred_types,
  344. configure_context);
  345. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  346. DataTypeController::MODEL_LOADED);
  347. ASSERT_EQ(GetController(APPS)->state(), DataTypeController::NOT_RUNNING);
  348. // Since we switched to in-memory storage, the metadata for the now-disabled
  349. // type should NOT get cleared.
  350. EXPECT_EQ(0, GetController(APPS)->model()->clear_metadata_call_count());
  351. }
  352. TEST_F(SyncModelLoadManagerTest,
  353. SwitchFromTransportOnlyToFullSyncRestartsTypes) {
  354. // Initialize the manager with two data types.
  355. controllers_[BOOKMARKS] = std::make_unique<FakeDataTypeController>(
  356. BOOKMARKS, /*enable_transport_only_model=*/true);
  357. controllers_[APPS] = std::make_unique<FakeDataTypeController>(
  358. APPS, /*enable_transport_only_model=*/true);
  359. ModelLoadManager model_load_manager(&controllers_, &delegate_);
  360. ModelTypeSet preferred_types(BOOKMARKS, APPS);
  361. ModelTypeSet desired_types = preferred_types;
  362. ConfigureContext configure_context;
  363. configure_context.sync_mode = SyncMode::kTransportOnly;
  364. configure_context.cache_guid = "test_cache_guid";
  365. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  366. model_load_manager.Initialize(desired_types, preferred_types,
  367. configure_context);
  368. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  369. DataTypeController::MODEL_LOADED);
  370. ASSERT_EQ(GetController(APPS)->state(), DataTypeController::MODEL_LOADED);
  371. testing::Mock::VerifyAndClearExpectations(&delegate_);
  372. // Switch to full-sync mode.
  373. configure_context.sync_mode = SyncMode::kFull;
  374. desired_types.Remove(APPS);
  375. preferred_types.Remove(APPS);
  376. // Data types should get restarted.
  377. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(APPS, _));
  378. EXPECT_CALL(delegate_, OnSingleDataTypeWillStop(BOOKMARKS, _));
  379. EXPECT_CALL(delegate_, OnAllDataTypesReadyForConfigure());
  380. model_load_manager.Initialize(desired_types, preferred_types,
  381. configure_context);
  382. ASSERT_EQ(GetController(BOOKMARKS)->state(),
  383. DataTypeController::MODEL_LOADED);
  384. ASSERT_EQ(GetController(APPS)->state(), DataTypeController::NOT_RUNNING);
  385. // The metadata for the now-disabled type should get cleared.
  386. EXPECT_EQ(1, GetController(APPS)
  387. ->model(SyncMode::kTransportOnly)
  388. ->clear_metadata_call_count());
  389. }
  390. } // namespace syncer