OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sync/sessions/nudge_tracker.h" |
| 6 |
| 7 #include "sync/internal_api/public/base/model_type_invalidation_map.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace syncer { |
| 11 |
| 12 namespace { |
| 13 |
| 14 ModelTypeSet ParamsMeaningAllEnabledTypes() { |
| 15 ModelTypeSet request_params(BOOKMARKS, AUTOFILL); |
| 16 return request_params; |
| 17 } |
| 18 |
| 19 ModelTypeSet ParamsMeaningJustOneEnabledType() { |
| 20 return ModelTypeSet(AUTOFILL); |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 namespace sessions { |
| 26 |
| 27 TEST(NudgeTrackerTest, CoalesceSources) { |
| 28 ModelTypeInvalidationMap one_type = |
| 29 ModelTypeSetToInvalidationMap( |
| 30 ParamsMeaningJustOneEnabledType(), |
| 31 std::string()); |
| 32 ModelTypeInvalidationMap all_types = |
| 33 ModelTypeSetToInvalidationMap( |
| 34 ParamsMeaningAllEnabledTypes(), |
| 35 std::string()); |
| 36 sessions::SyncSourceInfo source_one( |
| 37 sync_pb::GetUpdatesCallerInfo::NOTIFICATION, one_type); |
| 38 sessions::SyncSourceInfo source_two( |
| 39 sync_pb::GetUpdatesCallerInfo::LOCAL, all_types); |
| 40 |
| 41 NudgeTracker tracker; |
| 42 EXPECT_TRUE(tracker.IsEmpty()); |
| 43 |
| 44 tracker.CoalesceSources(source_one); |
| 45 EXPECT_EQ(source_one.updates_source, tracker.source_info().updates_source); |
| 46 |
| 47 tracker.CoalesceSources(source_two); |
| 48 EXPECT_EQ(source_two.updates_source, tracker.source_info().updates_source); |
| 49 } |
| 50 |
| 51 TEST(NudgeTrackerTest, LocallyModifiedTypes_WithInvalidationFirst) { |
| 52 ModelTypeInvalidationMap one_type = |
| 53 ModelTypeSetToInvalidationMap( |
| 54 ParamsMeaningJustOneEnabledType(), |
| 55 std::string()); |
| 56 ModelTypeInvalidationMap all_types = |
| 57 ModelTypeSetToInvalidationMap( |
| 58 ParamsMeaningAllEnabledTypes(), |
| 59 std::string()); |
| 60 sessions::SyncSourceInfo source_one( |
| 61 sync_pb::GetUpdatesCallerInfo::NOTIFICATION, all_types); |
| 62 sessions::SyncSourceInfo source_two( |
| 63 sync_pb::GetUpdatesCallerInfo::LOCAL, one_type); |
| 64 |
| 65 NudgeTracker tracker; |
| 66 EXPECT_TRUE(tracker.IsEmpty()); |
| 67 EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Empty()); |
| 68 |
| 69 tracker.CoalesceSources(source_one); |
| 70 EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Empty()); |
| 71 |
| 72 tracker.CoalesceSources(source_two); |
| 73 // TODO: This result is wrong, but that's how the code has always been. A |
| 74 // local invalidation for a single type should mean that we have only one |
| 75 // locally modified source. It should not "inherit" the list of data types |
| 76 // from the previous source. |
| 77 EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Equals( |
| 78 ParamsMeaningAllEnabledTypes())); |
| 79 } |
| 80 |
| 81 TEST(NudgeTrackerTest, LocallyModifiedTypes_WithInvalidationSecond) { |
| 82 ModelTypeInvalidationMap one_type = |
| 83 ModelTypeSetToInvalidationMap( |
| 84 ParamsMeaningJustOneEnabledType(), |
| 85 std::string()); |
| 86 ModelTypeInvalidationMap all_types = |
| 87 ModelTypeSetToInvalidationMap( |
| 88 ParamsMeaningAllEnabledTypes(), |
| 89 std::string()); |
| 90 sessions::SyncSourceInfo source_one( |
| 91 sync_pb::GetUpdatesCallerInfo::LOCAL, one_type); |
| 92 sessions::SyncSourceInfo source_two( |
| 93 sync_pb::GetUpdatesCallerInfo::NOTIFICATION, all_types); |
| 94 |
| 95 NudgeTracker tracker; |
| 96 EXPECT_TRUE(tracker.IsEmpty()); |
| 97 EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Empty()); |
| 98 |
| 99 tracker.CoalesceSources(source_one); |
| 100 EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Equals( |
| 101 ParamsMeaningJustOneEnabledType())); |
| 102 |
| 103 tracker.CoalesceSources(source_two); |
| 104 |
| 105 // TODO: This result is wrong, but that's how the code has always been. |
| 106 // The receipt of an invalidation should have no effect on the set of |
| 107 // locally modified types. |
| 108 EXPECT_TRUE(tracker.GetLocallyModifiedTypes().Empty()); |
| 109 } |
| 110 |
| 111 } // namespace sessions |
| 112 } // namespace syncer |
OLD | NEW |