| 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" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 session_->PrepareForAnotherSyncCycle(); | 265 session_->PrepareForAnotherSyncCycle(); |
| 266 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, | 266 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, |
| 267 session_->source().updates_source); | 267 session_->source().updates_source); |
| 268 EXPECT_FALSE(status()->conflicts_resolved()); | 268 EXPECT_FALSE(status()->conflicts_resolved()); |
| 269 EXPECT_FALSE(session_->HasMoreToSync()); | 269 EXPECT_FALSE(session_->HasMoreToSync()); |
| 270 } | 270 } |
| 271 | 271 |
| 272 TEST_F(SyncSessionTest, Coalesce) { | 272 TEST_F(SyncSessionTest, Coalesce) { |
| 273 std::vector<ModelSafeWorker*> workers_one, workers_two; | 273 std::vector<ModelSafeWorker*> workers_one, workers_two; |
| 274 ModelSafeRoutingInfo routes_one, routes_two; | 274 ModelSafeRoutingInfo routes_one, routes_two; |
| 275 ModelTypePayloadMap one_type = | 275 ModelTypeStateMap one_type = |
| 276 ModelTypePayloadMapFromEnumSet( | 276 ModelTypeStateMapFromEnumSet( |
| 277 ParamsMeaningJustOneEnabledType(), | 277 ParamsMeaningJustOneEnabledType(), |
| 278 std::string()); | 278 std::string()); |
| 279 ModelTypePayloadMap all_types = | 279 ModelTypeStateMap all_types = |
| 280 ModelTypePayloadMapFromEnumSet( | 280 ModelTypeStateMapFromEnumSet( |
| 281 ParamsMeaningAllEnabledTypes(), | 281 ParamsMeaningAllEnabledTypes(), |
| 282 std::string()); | 282 std::string()); |
| 283 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); | 283 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); |
| 284 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); | 284 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); |
| 285 | 285 |
| 286 scoped_refptr<ModelSafeWorker> passive_worker( | 286 scoped_refptr<ModelSafeWorker> passive_worker( |
| 287 new FakeModelWorker(GROUP_PASSIVE)); | 287 new FakeModelWorker(GROUP_PASSIVE)); |
| 288 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 288 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
| 289 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); | 289 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); |
| 290 workers_one.push_back(passive_worker); | 290 workers_one.push_back(passive_worker); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 std::vector<ModelSafeWorker*>::const_iterator it_ui = | 322 std::vector<ModelSafeWorker*>::const_iterator it_ui = |
| 323 std::find(one.workers().begin(), one.workers().end(), ui_worker); | 323 std::find(one.workers().begin(), one.workers().end(), ui_worker); |
| 324 EXPECT_NE(it_db, one.workers().end()); | 324 EXPECT_NE(it_db, one.workers().end()); |
| 325 EXPECT_NE(it_ui, one.workers().end()); | 325 EXPECT_NE(it_ui, one.workers().end()); |
| 326 EXPECT_EQ(routes_two, one.routing_info()); | 326 EXPECT_EQ(routes_two, one.routing_info()); |
| 327 } | 327 } |
| 328 | 328 |
| 329 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { | 329 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { |
| 330 std::vector<ModelSafeWorker*> workers_one, workers_two; | 330 std::vector<ModelSafeWorker*> workers_one, workers_two; |
| 331 ModelSafeRoutingInfo routes_one, routes_two; | 331 ModelSafeRoutingInfo routes_one, routes_two; |
| 332 ModelTypePayloadMap one_type = | 332 ModelTypeStateMap one_type = |
| 333 ModelTypePayloadMapFromEnumSet( | 333 ModelTypeStateMapFromEnumSet( |
| 334 ParamsMeaningJustOneEnabledType(), | 334 ParamsMeaningJustOneEnabledType(), |
| 335 std::string()); | 335 std::string()); |
| 336 ModelTypePayloadMap all_types = | 336 ModelTypeStateMap all_types = |
| 337 ModelTypePayloadMapFromEnumSet( | 337 ModelTypeStateMapFromEnumSet( |
| 338 ParamsMeaningAllEnabledTypes(), | 338 ParamsMeaningAllEnabledTypes(), |
| 339 std::string()); | 339 std::string()); |
| 340 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); | 340 SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); |
| 341 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); | 341 SyncSourceInfo source_two(sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); |
| 342 | 342 |
| 343 scoped_refptr<ModelSafeWorker> passive_worker( | 343 scoped_refptr<ModelSafeWorker> passive_worker( |
| 344 new FakeModelWorker(GROUP_PASSIVE)); | 344 new FakeModelWorker(GROUP_PASSIVE)); |
| 345 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 345 scoped_refptr<ModelSafeWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
| 346 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); | 346 scoped_refptr<ModelSafeWorker> ui_worker(new FakeModelWorker(GROUP_UI)); |
| 347 workers_one.push_back(passive_worker); | 347 workers_one.push_back(passive_worker); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 // Note that attempting to use EXPECT_NE would fail for an Android build due | 394 // Note that attempting to use EXPECT_NE would fail for an Android build due |
| 395 // to seeming incompatibility with gtest and stlport. | 395 // to seeming incompatibility with gtest and stlport. |
| 396 EXPECT_TRUE(it != two.routing_info().end()); | 396 EXPECT_TRUE(it != two.routing_info().end()); |
| 397 EXPECT_EQ(it->second, GROUP_DB); | 397 EXPECT_EQ(it->second, GROUP_DB); |
| 398 EXPECT_EQ(two.routing_info().size(), 1U); | 398 EXPECT_EQ(two.routing_info().size(), 1U); |
| 399 } | 399 } |
| 400 | 400 |
| 401 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { | 401 TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { |
| 402 std::vector<ModelSafeWorker*> workers_first, workers_second; | 402 std::vector<ModelSafeWorker*> workers_first, workers_second; |
| 403 ModelSafeRoutingInfo routes_first, routes_second; | 403 ModelSafeRoutingInfo routes_first, routes_second; |
| 404 ModelTypePayloadMap all_types = | 404 ModelTypeStateMap all_types = |
| 405 ModelTypePayloadMapFromEnumSet( | 405 ModelTypeStateMapFromEnumSet( |
| 406 ParamsMeaningAllEnabledTypes(), | 406 ParamsMeaningAllEnabledTypes(), |
| 407 std::string()); | 407 std::string()); |
| 408 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, | 408 SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, |
| 409 all_types); | 409 all_types); |
| 410 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, | 410 SyncSourceInfo source_second(sync_pb::GetUpdatesCallerInfo::LOCAL, |
| 411 all_types); | 411 all_types); |
| 412 | 412 |
| 413 scoped_refptr<ModelSafeWorker> passive_worker( | 413 scoped_refptr<ModelSafeWorker> passive_worker( |
| 414 new FakeModelWorker(GROUP_PASSIVE)); | 414 new FakeModelWorker(GROUP_PASSIVE)); |
| 415 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); | 415 scoped_refptr<FakeModelWorker> db_worker(new FakeModelWorker(GROUP_DB)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 EXPECT_EQ(it1->second, GROUP_DB); | 474 EXPECT_EQ(it1->second, GROUP_DB); |
| 475 | 475 |
| 476 // Note that attempting to use EXPECT_NE would fail for an Android build due | 476 // Note that attempting to use EXPECT_NE would fail for an Android build due |
| 477 // to seeming incompatibility with gtest and stlport. | 477 // to seeming incompatibility with gtest and stlport. |
| 478 EXPECT_TRUE(it2 != second.routing_info().end()); | 478 EXPECT_TRUE(it2 != second.routing_info().end()); |
| 479 EXPECT_EQ(it2->second, GROUP_UI); | 479 EXPECT_EQ(it2->second, GROUP_UI); |
| 480 EXPECT_EQ(second.routing_info().size(), 2U); | 480 EXPECT_EQ(second.routing_info().size(), 2U); |
| 481 } | 481 } |
| 482 | 482 |
| 483 | 483 |
| 484 TEST_F(SyncSessionTest, MakeTypePayloadMapFromBitSet) { | 484 TEST_F(SyncSessionTest, MakeTypeStateMapFromBitSet) { |
| 485 ModelTypeSet types; | 485 ModelTypeSet types; |
| 486 std::string payload = "test"; | 486 std::string payload = "test"; |
| 487 ModelTypePayloadMap types_with_payloads = | 487 ModelTypeStateMap type_state_map = |
| 488 ModelTypePayloadMapFromEnumSet(types, payload); | 488 ModelTypeStateMapFromEnumSet(types, payload); |
| 489 EXPECT_TRUE(types_with_payloads.empty()); | 489 EXPECT_TRUE(type_state_map.empty()); |
| 490 | 490 |
| 491 types.Put(BOOKMARKS); | 491 types.Put(BOOKMARKS); |
| 492 types.Put(PASSWORDS); | 492 types.Put(PASSWORDS); |
| 493 types.Put(AUTOFILL); | 493 types.Put(AUTOFILL); |
| 494 payload = "test2"; | 494 payload = "test2"; |
| 495 types_with_payloads = ModelTypePayloadMapFromEnumSet(types, payload); | 495 type_state_map = ModelTypeStateMapFromEnumSet(types, payload); |
| 496 | 496 |
| 497 ASSERT_EQ(3U, types_with_payloads.size()); | 497 ASSERT_EQ(3U, type_state_map.size()); |
| 498 EXPECT_EQ(types_with_payloads[BOOKMARKS], payload); | 498 EXPECT_EQ(type_state_map[BOOKMARKS].payload, payload); |
| 499 EXPECT_EQ(types_with_payloads[PASSWORDS], payload); | 499 EXPECT_EQ(type_state_map[PASSWORDS].payload, payload); |
| 500 EXPECT_EQ(types_with_payloads[AUTOFILL], payload); | 500 EXPECT_EQ(type_state_map[AUTOFILL].payload, payload); |
| 501 } | 501 } |
| 502 | 502 |
| 503 } // namespace | 503 } // namespace |
| 504 } // namespace sessions | 504 } // namespace sessions |
| 505 } // namespace syncer | 505 } // namespace syncer |
| OLD | NEW |