| 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/internal_api/public/base/model_type_test_util.h" | 5 #include "sync/internal_api/public/base/model_type_test_util.h" |
| 6 #include "sync/notifier/invalidation_util.h" |
| 7 #include "sync/notifier/object_id_invalidation_map.h" |
| 6 #include "sync/sessions/nudge_tracker.h" | 8 #include "sync/sessions/nudge_tracker.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 10 |
| 9 namespace syncer { | 11 namespace syncer { |
| 10 | 12 |
| 11 namespace { | 13 namespace { |
| 12 | 14 |
| 13 testing::AssertionResult ModelTypeSetEquals(ModelTypeSet a, ModelTypeSet b) { | 15 testing::AssertionResult ModelTypeSetEquals(ModelTypeSet a, ModelTypeSet b) { |
| 14 if (a.Equals(b)) { | 16 if (a.Equals(b)) { |
| 15 return testing::AssertionSuccess(); | 17 return testing::AssertionSuccess(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, | 104 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, |
| 103 nudge_tracker.updates_source()); | 105 nudge_tracker.updates_source()); |
| 104 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS)); | 106 nudge_tracker.RecordLocalRefreshRequest(ModelTypeSet(TYPED_URLS)); |
| 105 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, | 107 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, |
| 106 nudge_tracker.updates_source()); | 108 nudge_tracker.updates_source()); |
| 107 } | 109 } |
| 108 | 110 |
| 109 TEST_F(NudgeTrackerTest, HintCoalescing) { | 111 TEST_F(NudgeTrackerTest, HintCoalescing) { |
| 110 NudgeTracker nudge_tracker; | 112 NudgeTracker nudge_tracker; |
| 111 | 113 |
| 114 invalidation::ObjectId bookmarks_id; |
| 115 ASSERT_TRUE(RealModelTypeToObjectId(BOOKMARKS, &bookmarks_id)); |
| 116 invalidation::ObjectId passwords_id; |
| 117 ASSERT_TRUE(RealModelTypeToObjectId(PASSWORDS, &passwords_id)); |
| 118 |
| 112 // Easy case: record one hint. | 119 // Easy case: record one hint. |
| 113 { | 120 { |
| 114 ObjectIdInvalidationMap invalidation_map = | 121 ObjectIdInvalidationMap invalidation_map = |
| 115 BuildInvalidationMap(BOOKMARKS, 1, "bm_hint_1"); | 122 BuildInvalidationMap(BOOKMARKS, 1, "bm_hint_1"); |
| 116 nudge_tracker.RecordRemoteInvalidation(invalidation_map); | 123 nudge_tracker.RecordRemoteInvalidation(invalidation_map); |
| 117 | 124 |
| 118 sync_pb::GetUpdateTriggers gu_trigger; | 125 sync_pb::GetUpdateTriggers gu_trigger; |
| 119 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger); | 126 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger); |
| 120 ASSERT_EQ(1, gu_trigger.notification_hint_size()); | 127 ASSERT_EQ(1, gu_trigger.notification_hint_size()); |
| 121 EXPECT_EQ("bm_hint_1", gu_trigger.notification_hint(0)); | 128 EXPECT_EQ("bm_hint_1", gu_trigger.notification_hint(0)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 sync_pb::GetUpdateTriggers pw_gu_trigger; | 164 sync_pb::GetUpdateTriggers pw_gu_trigger; |
| 158 nudge_tracker.FillProtoMessage(PASSWORDS, &pw_gu_trigger); | 165 nudge_tracker.FillProtoMessage(PASSWORDS, &pw_gu_trigger); |
| 159 ASSERT_EQ(1, pw_gu_trigger.notification_hint_size()); | 166 ASSERT_EQ(1, pw_gu_trigger.notification_hint_size()); |
| 160 EXPECT_EQ("pw_hint_1", pw_gu_trigger.notification_hint(0)); | 167 EXPECT_EQ("pw_hint_1", pw_gu_trigger.notification_hint(0)); |
| 161 EXPECT_FALSE(pw_gu_trigger.client_dropped_hints()); | 168 EXPECT_FALSE(pw_gu_trigger.client_dropped_hints()); |
| 162 } | 169 } |
| 163 } | 170 } |
| 164 | 171 |
| 165 TEST_F(NudgeTrackerTest, DropHintsLocally) { | 172 TEST_F(NudgeTrackerTest, DropHintsLocally) { |
| 166 NudgeTracker nudge_tracker; | 173 NudgeTracker nudge_tracker; |
| 167 ObjectIdInvalidationMap invalidation_map = | |
| 168 BuildInvalidationMap(BOOKMARKS, 1, "hint"); | |
| 169 | 174 |
| 175 invalidation::ObjectId bookmarks_id; |
| 176 ASSERT_TRUE(RealModelTypeToObjectId(BOOKMARKS, &bookmarks_id)); |
| 177 |
| 178 ObjectIdInvalidationMap invalidation_map; |
| 170 for (size_t i = 0; i < GetHintBufferSize(); ++i) { | 179 for (size_t i = 0; i < GetHintBufferSize(); ++i) { |
| 171 nudge_tracker.RecordRemoteInvalidation(invalidation_map); | 180 invalidation_map.Insert(Invalidation::Init(bookmarks_id, i, "hint")); |
| 172 } | 181 } |
| 182 nudge_tracker.RecordRemoteInvalidation(invalidation_map); |
| 183 |
| 173 { | 184 { |
| 174 sync_pb::GetUpdateTriggers gu_trigger; | 185 sync_pb::GetUpdateTriggers gu_trigger; |
| 175 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger); | 186 nudge_tracker.FillProtoMessage(BOOKMARKS, &gu_trigger); |
| 176 EXPECT_EQ(GetHintBufferSize(), | 187 EXPECT_EQ(GetHintBufferSize(), |
| 177 static_cast<size_t>(gu_trigger.notification_hint_size())); | 188 static_cast<size_t>(gu_trigger.notification_hint_size())); |
| 178 EXPECT_FALSE(gu_trigger.client_dropped_hints()); | 189 EXPECT_FALSE(gu_trigger.client_dropped_hints()); |
| 179 } | 190 } |
| 180 | 191 |
| 181 // Force an overflow. | 192 // Force an overflow. |
| 182 ObjectIdInvalidationMap invalidation_map2 = | 193 ObjectIdInvalidationMap invalidation_map2 = |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 EXPECT_EQ(throttle2_length - throttle1_length, | 470 EXPECT_EQ(throttle2_length - throttle1_length, |
| 460 nudge_tracker.GetTimeUntilNextUnthrottle(t1)); | 471 nudge_tracker.GetTimeUntilNextUnthrottle(t1)); |
| 461 | 472 |
| 462 // Expire the second interval. | 473 // Expire the second interval. |
| 463 nudge_tracker.UpdateTypeThrottlingState(t2); | 474 nudge_tracker.UpdateTypeThrottlingState(t2); |
| 464 EXPECT_TRUE(nudge_tracker.GetThrottledTypes().Empty()); | 475 EXPECT_TRUE(nudge_tracker.GetThrottledTypes().Empty()); |
| 465 } | 476 } |
| 466 | 477 |
| 467 } // namespace sessions | 478 } // namespace sessions |
| 468 } // namespace syncer | 479 } // namespace syncer |
| OLD | NEW |