| 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/syncable/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
| 15 #include "sync/sessions/session_state.h" | 15 #include "sync/sessions/session_state.h" |
| 16 #include "sync/sessions/status_controller.h" | 16 #include "sync/sessions/status_controller.h" |
| 17 #include "sync/syncable/syncable_id.h" | 17 #include "sync/syncable/syncable_id.h" |
| 18 #include "sync/syncable/write_transaction.h" | 18 #include "sync/syncable/write_transaction.h" |
| 19 #include "sync/test/engine/fake_model_worker.h" | 19 #include "sync/test/engine/fake_model_worker.h" |
| 20 #include "sync/test/engine/test_directory_setter_upper.h" | 20 #include "sync/test/engine/test_directory_setter_upper.h" |
| 21 #include "sync/test/fake_extensions_activity_monitor.h" | 21 #include "sync/test/fake_extensions_activity_monitor.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 namespace syncer { | 24 namespace syncer { |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 payload = "test2"; | 489 payload = "test2"; |
| 490 types_with_payloads = | 490 types_with_payloads = |
| 491 syncable::ModelTypePayloadMapFromEnumSet(types, payload); | 491 syncable::ModelTypePayloadMapFromEnumSet(types, payload); |
| 492 | 492 |
| 493 ASSERT_EQ(3U, types_with_payloads.size()); | 493 ASSERT_EQ(3U, types_with_payloads.size()); |
| 494 EXPECT_EQ(types_with_payloads[syncable::BOOKMARKS], payload); | 494 EXPECT_EQ(types_with_payloads[syncable::BOOKMARKS], payload); |
| 495 EXPECT_EQ(types_with_payloads[syncable::PASSWORDS], payload); | 495 EXPECT_EQ(types_with_payloads[syncable::PASSWORDS], payload); |
| 496 EXPECT_EQ(types_with_payloads[syncable::AUTOFILL], payload); | 496 EXPECT_EQ(types_with_payloads[syncable::AUTOFILL], payload); |
| 497 } | 497 } |
| 498 | 498 |
| 499 TEST_F(SyncSessionTest, MakeTypePayloadMapFromRoutingInfo) { | |
| 500 std::string payload = "test"; | |
| 501 syncable::ModelTypePayloadMap types_with_payloads | |
| 502 = syncable::ModelTypePayloadMapFromRoutingInfo(routes_, payload); | |
| 503 ASSERT_EQ(routes_.size(), types_with_payloads.size()); | |
| 504 for (ModelSafeRoutingInfo::iterator iter = routes_.begin(); | |
| 505 iter != routes_.end(); | |
| 506 ++iter) { | |
| 507 EXPECT_EQ(payload, types_with_payloads[iter->first]); | |
| 508 } | |
| 509 } | |
| 510 | |
| 511 TEST_F(SyncSessionTest, CoalescePayloads) { | |
| 512 syncable::ModelTypePayloadMap original; | |
| 513 std::string empty_payload; | |
| 514 std::string payload1 = "payload1"; | |
| 515 std::string payload2 = "payload2"; | |
| 516 std::string payload3 = "payload3"; | |
| 517 original[syncable::BOOKMARKS] = empty_payload; | |
| 518 original[syncable::PASSWORDS] = payload1; | |
| 519 original[syncable::AUTOFILL] = payload2; | |
| 520 original[syncable::THEMES] = payload3; | |
| 521 | |
| 522 syncable::ModelTypePayloadMap update; | |
| 523 update[syncable::BOOKMARKS] = empty_payload; // Same. | |
| 524 update[syncable::PASSWORDS] = empty_payload; // Overwrite with empty. | |
| 525 update[syncable::AUTOFILL] = payload1; // Overwrite with non-empty. | |
| 526 update[syncable::SESSIONS] = payload2; // New. | |
| 527 // Themes untouched. | |
| 528 | |
| 529 CoalescePayloads(&original, update); | |
| 530 ASSERT_EQ(5U, original.size()); | |
| 531 EXPECT_EQ(empty_payload, original[syncable::BOOKMARKS]); | |
| 532 EXPECT_EQ(payload1, original[syncable::PASSWORDS]); | |
| 533 EXPECT_EQ(payload1, original[syncable::AUTOFILL]); | |
| 534 EXPECT_EQ(payload2, original[syncable::SESSIONS]); | |
| 535 EXPECT_EQ(payload3, original[syncable::THEMES]); | |
| 536 } | |
| 537 | |
| 538 } // namespace | 499 } // namespace |
| 539 } // namespace sessions | 500 } // namespace sessions |
| 540 } // namespace syncer | 501 } // namespace syncer |
| OLD | NEW |