OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/sessions/sync_session.h" | 5 #include "sync/sessions/sync_session.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "sync/engine/conflict_resolver.h" | 11 #include "sync/engine/conflict_resolver.h" |
12 #include "sync/engine/syncer_types.h" | 12 #include "sync/engine/syncer_types.h" |
13 #include "sync/engine/throttled_data_type_tracker.h" | 13 #include "sync/engine/throttled_data_type_tracker.h" |
14 #include "sync/internal_api/public/base/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
15 #include "sync/internal_api/public/base/model_type_state_map_test_util.h" | 15 #include "sync/internal_api/public/base/model_type_invalidation_map_test_util.h" |
16 #include "sync/sessions/session_state.h" | 16 #include "sync/sessions/session_state.h" |
17 #include "sync/sessions/status_controller.h" | 17 #include "sync/sessions/status_controller.h" |
18 #include "sync/syncable/syncable_id.h" | 18 #include "sync/syncable/syncable_id.h" |
19 #include "sync/syncable/write_transaction.h" | 19 #include "sync/syncable/write_transaction.h" |
20 #include "sync/test/engine/fake_model_worker.h" | 20 #include "sync/test/engine/fake_model_worker.h" |
21 #include "sync/test/engine/test_directory_setter_upper.h" | 21 #include "sync/test/engine/test_directory_setter_upper.h" |
22 #include "sync/test/fake_extensions_activity_monitor.h" | 22 #include "sync/test/fake_extensions_activity_monitor.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace syncer { | 25 namespace syncer { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 session_->PrepareForAnotherSyncCycle(); | 266 session_->PrepareForAnotherSyncCycle(); |
267 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | 267 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, |
268 session_->source().updates_source); | 268 session_->source().updates_source); |
269 EXPECT_FALSE(status()->conflicts_resolved()); | 269 EXPECT_FALSE(status()->conflicts_resolved()); |
270 EXPECT_FALSE(session_->HasMoreToSync()); | 270 EXPECT_FALSE(session_->HasMoreToSync()); |
271 } | 271 } |
272 | 272 |
273 TEST_F(SyncSessionTest, Coalesce) { | 273 TEST_F(SyncSessionTest, Coalesce) { |
274 std::vector<ModelSafeWorker*> workers_one, workers_two; | 274 std::vector<ModelSafeWorker*> workers_one, workers_two; |
275 ModelSafeRoutingInfo routes_one, routes_two; | 275 ModelSafeRoutingInfo routes_one, routes_two; |
276 ModelTypeStateMap one_type = | 276 ModelTypeInvalidationMap one_type = |
277 ModelTypeSetToStateMap( | 277 ModelTypeSetToInvalidationMap( |
278 ParamsMeaningJustOneEnabledType(), | 278 ParamsMeaningJustOneEnabledType(), |
279 std::string()); | 279 std::string()); |
280 ModelTypeStateMap all_types = | 280 ModelTypeInvalidationMap all_types = |
281 ModelTypeSetToStateMap( | 281 ModelTypeSetToInvalidationMap( |
282 ParamsMeaningAllEnabledTypes(), | 282 ParamsMeaningAllEnabledTypes(), |
283 std::string()); | 283 std::string()); |
284 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); | 284 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); |
285 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); | 285 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); |
286 | 286 |
287 scoped_refptr<ModelSafeWorker> passive_worker( | 287 scoped_refptr<ModelSafeWorker> passive_worker( |
288 new FakeModelWorker(GROUP_PASSIVE)); | 288 new FakeModelWorker(GROUP_PASSIVE)); |
289 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 289 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
290 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); | 290 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); |
291 workers_one.push_back(passive_worker); | 291 workers_one.push_back(passive_worker); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 std::vector<ModelSafeWorker*>::const_iterator it_ui = | 323 std::vector<ModelSafeWorker*>::const_iterator it_ui = |
324 std::find(one.workers().begin(), one.workers().end(), ui_worker); | 324 std::find(one.workers().begin(), one.workers().end(), ui_worker); |
325 EXPECT_NE(it_db, one.workers().end()); | 325 EXPECT_NE(it_db, one.workers().end()); |
326 EXPECT_NE(it_ui, one.workers().end()); | 326 EXPECT_NE(it_ui, one.workers().end()); |
327 EXPECT_EQ(routes_two, one.routing_info()); | 327 EXPECT_EQ(routes_two, one.routing_info()); |
328 } | 328 } |
329 | 329 |
330 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { | 330 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { |
331 std::vector<ModelSafeWorker*> workers_one, workers_two; | 331 std::vector<ModelSafeWorker*> workers_one, workers_two; |
332 ModelSafeRoutingInfo routes_one, routes_two; | 332 ModelSafeRoutingInfo routes_one, routes_two; |
333 ModelTypeStateMap one_type = | 333 ModelTypeInvalidationMap one_type = |
334 ModelTypeSetToStateMap( | 334 ModelTypeSetToInvalidationMap( |
335 ParamsMeaningJustOneEnabledType(), | 335 ParamsMeaningJustOneEnabledType(), |
336 std::string()); | 336 std::string()); |
337 ModelTypeStateMap all_types = | 337 ModelTypeInvalidationMap all_types = |
338 ModelTypeSetToStateMap( | 338 ModelTypeSetToInvalidationMap( |
339 ParamsMeaningAllEnabledTypes(), | 339 ParamsMeaningAllEnabledTypes(), |
340 std::string()); | 340 std::string()); |
341 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); | 341 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); |
342 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); | 342 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); |
343 | 343 |
344 scoped_refptr<ModelSafeWorker> passive_worker( | 344 scoped_refptr<ModelSafeWorker> passive_worker( |
345 new FakeModelWorker(GROUP_PASSIVE)); | 345 new FakeModelWorker(GROUP_PASSIVE)); |
346 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 346 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
347 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); | 347 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); |
348 workers_one.push_back(passive_worker); | 348 workers_one.push_back(passive_worker); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // Note that attempting to use EXPECT_NE would fail for an Android build due | 395 // Note that attempting to use EXPECT_NE would fail for an Android build due |
396 // to seeming incompatibility with gtest and stlport. | 396 // to seeming incompatibility with gtest and stlport. |
397 EXPECT_TRUE(it != two.routing_info().end()); | 397 EXPECT_TRUE(it != two.routing_info().end()); |
398 EXPECT_EQ(it->second, GROUP_DB); | 398 EXPECT_EQ(it->second, GROUP_DB); |
399 EXPECT_EQ(two.routing_info().size(), 1U); | 399 EXPECT_EQ(two.routing_info().size(), 1U); |
400 } | 400 } |
401 | 401 |
402 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { | 402 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { |
403 std::vector<ModelSafeWorker*> workers_first, workers_second; | 403 std::vector<ModelSafeWorker*> workers_first, workers_second; |
404 ModelSafeRoutingInfo routes_first, routes_second; | 404 ModelSafeRoutingInfo routes_first, routes_second; |
405 ModelTypeStateMap all_types = | 405 ModelTypeInvalidationMap all_types = |
406 ModelTypeSetToStateMap( | 406 ModelTypeSetToInvalidationMap( |
407 ParamsMeaningAllEnabledTypes(), | 407 ParamsMeaningAllEnabledTypes(), |
408 std::string()); | 408 std::string()); |
409 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, | 409 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, |
410 all_types); | 410 all_types); |
411 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, | 411 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, |
412 all_types); | 412 all_types); |
413 | 413 |
414 scoped_refptr<ModelSafeWorker> passive_worker( | 414 scoped_refptr<ModelSafeWorker> passive_worker( |
415 new FakeModelWorker(GROUP_PASSIVE)); | 415 new FakeModelWorker(GROUP_PASSIVE)); |
416 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 416 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 EXPECT_EQ(it1->second, GROUP_DB); | 475 EXPECT_EQ(it1->second, GROUP_DB); |
476 | 476 |
477 // Note that attempting to use EXPECT_NE would fail for an Android build due | 477 // Note that attempting to use EXPECT_NE would fail for an Android build due |
478 // to seeming incompatibility with gtest and stlport. | 478 // to seeming incompatibility with gtest and stlport. |
479 EXPECT_TRUE(it2 != second.routing_info().end()); | 479 EXPECT_TRUE(it2 != second.routing_info().end()); |
480 EXPECT_EQ(it2->second, GROUP_UI); | 480 EXPECT_EQ(it2->second, GROUP_UI); |
481 EXPECT_EQ(second.routing_info().size(), 2U); | 481 EXPECT_EQ(second.routing_info().size(), 2U); |
482 } | 482 } |
483 | 483 |
484 | 484 |
485 TEST_F(SyncSessionTest, MakeTypeStateMapFromBitSet) { | 485 TEST_F(SyncSessionTest, MakeTypeInvalidationMapFromBitSet) { |
486 ModelTypeSet types; | 486 ModelTypeSet types; |
487 std::string payload = "test"; | 487 std::string payload = "test"; |
488 ModelTypeStateMap type_state_map = | 488 ModelTypeInvalidationMap invalidation_map = |
489 ModelTypeSetToStateMap(types, payload); | 489 ModelTypeSetToInvalidationMap(types, payload); |
490 EXPECT_TRUE(type_state_map.empty()); | 490 EXPECT_TRUE(invalidation_map.empty()); |
491 | 491 |
492 types.Put(BOOKMARKS); | 492 types.Put(BOOKMARKS); |
493 types.Put(PASSWORDS); | 493 types.Put(PASSWORDS); |
494 types.Put(AUTOFILL); | 494 types.Put(AUTOFILL); |
495 payload = "test2"; | 495 payload = "test2"; |
496 type_state_map = ModelTypeSetToStateMap(types, payload); | 496 invalidation_map = ModelTypeSetToInvalidationMap(types, payload); |
497 | 497 |
498 ASSERT_EQ(3U, type_state_map.size()); | 498 ASSERT_EQ(3U, invalidation_map.size()); |
499 EXPECT_EQ(type_state_map[BOOKMARKS].payload, payload); | 499 EXPECT_EQ(invalidation_map[BOOKMARKS].payload, payload); |
500 EXPECT_EQ(type_state_map[PASSWORDS].payload, payload); | 500 EXPECT_EQ(invalidation_map[PASSWORDS].payload, payload); |
501 EXPECT_EQ(type_state_map[AUTOFILL].payload, payload); | 501 EXPECT_EQ(invalidation_map[AUTOFILL].payload, payload); |
502 } | 502 } |
503 | 503 |
504 } // namespace | 504 } // namespace |
505 } // namespace sessions | 505 } // namespace sessions |
506 } // namespace syncer | 506 } // namespace syncer |
OLD | NEW |