OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This class defines tests that implementations of InvalidationService should | 5 // This class defines tests that implementations of InvalidationService should |
6 // pass in order to be conformant. Here's how you use it to test your | 6 // pass in order to be conformant. Here's how you use it to test your |
7 // implementation. | 7 // implementation. |
8 // | 8 // |
9 // Say your class is called MyInvalidationService. Then you need to define a | 9 // Say your class is called MyInvalidationService. Then you need to define a |
10 // class called MyInvalidationServiceTestDelegate in | 10 // class called MyInvalidationServiceTestDelegate in |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // Easy! | 69 // Easy! |
70 | 70 |
71 #ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ | 71 #ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ |
72 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ | 72 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ |
73 | 73 |
74 #include "base/basictypes.h" | 74 #include "base/basictypes.h" |
75 #include "base/compiler_specific.h" | 75 #include "base/compiler_specific.h" |
76 #include "chrome/browser/invalidation/invalidation_service.h" | 76 #include "chrome/browser/invalidation/invalidation_service.h" |
77 #include "google/cacheinvalidation/include/types.h" | 77 #include "google/cacheinvalidation/include/types.h" |
78 #include "google/cacheinvalidation/types.pb.h" | 78 #include "google/cacheinvalidation/types.pb.h" |
| 79 #include "sync/internal_api/public/base/ack_handle.h" |
| 80 #include "sync/internal_api/public/base/invalidation.h" |
| 81 #include "sync/internal_api/public/base/object_id_invalidation_map_test_util.h" |
79 #include "sync/notifier/fake_invalidation_handler.h" | 82 #include "sync/notifier/fake_invalidation_handler.h" |
80 #include "sync/notifier/object_id_invalidation_map.h" | 83 #include "sync/notifier/object_id_invalidation_map.h" |
81 #include "sync/notifier/object_id_invalidation_map_test_util.h" | |
82 #include "testing/gtest/include/gtest/gtest.h" | 84 #include "testing/gtest/include/gtest/gtest.h" |
83 | 85 |
84 template <typename InvalidatorTestDelegate> | 86 template <typename InvalidatorTestDelegate> |
85 class InvalidationServiceTest : public testing::Test { | 87 class InvalidationServiceTest : public testing::Test { |
86 protected: | 88 protected: |
87 InvalidationServiceTest() | 89 InvalidationServiceTest() |
88 : id1(ipc::invalidation::ObjectSource::CHROME_SYNC, "BOOKMARK"), | 90 : id1(ipc::invalidation::ObjectSource::CHROME_SYNC, "BOOKMARK"), |
89 id2(ipc::invalidation::ObjectSource::CHROME_SYNC, "PREFERENCE"), | 91 id2(ipc::invalidation::ObjectSource::CHROME_SYNC, "PREFERENCE"), |
90 id3(ipc::invalidation::ObjectSource::CHROME_SYNC, "AUTOFILL"), | 92 id3(ipc::invalidation::ObjectSource::CHROME_SYNC, "AUTOFILL"), |
91 id4(ipc::invalidation::ObjectSource::CHROME_PUSH_MESSAGING, | 93 id4(ipc::invalidation::ObjectSource::CHROME_PUSH_MESSAGING, |
(...skipping 21 matching lines...) Expand all Loading... |
113 // between. The handler should only see invalidations when its registered and | 115 // between. The handler should only see invalidations when its registered and |
114 // its IDs are registered. | 116 // its IDs are registered. |
115 TYPED_TEST_P(InvalidationServiceTest, Basic) { | 117 TYPED_TEST_P(InvalidationServiceTest, Basic) { |
116 invalidation::InvalidationService* const invalidator = | 118 invalidation::InvalidationService* const invalidator = |
117 this->CreateAndInitializeInvalidationService(); | 119 this->CreateAndInitializeInvalidationService(); |
118 | 120 |
119 syncer::FakeInvalidationHandler handler; | 121 syncer::FakeInvalidationHandler handler; |
120 | 122 |
121 invalidator->RegisterInvalidationHandler(&handler); | 123 invalidator->RegisterInvalidationHandler(&handler); |
122 | 124 |
123 syncer::ObjectIdInvalidationMap states; | 125 syncer::ObjectIdInvalidationMap invalidation_map; |
124 states[this->id1].payload = "1"; | 126 invalidation_map.Insert(syncer::Invalidation::Init(this->id1, 1, "1")); |
125 states[this->id2].payload = "2"; | 127 invalidation_map.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
126 states[this->id3].payload = "3"; | 128 invalidation_map.Insert(syncer::Invalidation::Init(this->id3, 3, "3")); |
127 | 129 |
128 // Should be ignored since no IDs are registered to |handler|. | 130 // Should be ignored since no IDs are registered to |handler|. |
129 this->delegate_.TriggerOnIncomingInvalidation(states); | 131 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
130 EXPECT_EQ(0, handler.GetInvalidationCount()); | 132 EXPECT_EQ(0, handler.GetInvalidationCount()); |
131 | 133 |
132 syncer::ObjectIdSet ids; | 134 syncer::ObjectIdSet ids; |
133 ids.insert(this->id1); | 135 ids.insert(this->id1); |
134 ids.insert(this->id2); | 136 ids.insert(this->id2); |
135 invalidator->UpdateRegisteredInvalidationIds(&handler, ids); | 137 invalidator->UpdateRegisteredInvalidationIds(&handler, ids); |
136 | 138 |
137 this->delegate_.TriggerOnInvalidatorStateChange( | 139 this->delegate_.TriggerOnInvalidatorStateChange( |
138 syncer::INVALIDATIONS_ENABLED); | 140 syncer::INVALIDATIONS_ENABLED); |
139 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); | 141 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); |
140 | 142 |
141 syncer::ObjectIdInvalidationMap expected_states; | 143 syncer::ObjectIdInvalidationMap expected_invalidations; |
142 expected_states[this->id1].payload = "1"; | 144 expected_invalidations.Insert(syncer::Invalidation::Init(this->id1, 1, "1")); |
143 expected_states[this->id2].payload = "2"; | 145 expected_invalidations.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
144 | 146 |
145 this->delegate_.TriggerOnIncomingInvalidation(states); | 147 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
146 EXPECT_EQ(1, handler.GetInvalidationCount()); | 148 EXPECT_EQ(1, handler.GetInvalidationCount()); |
147 EXPECT_THAT(expected_states, Eq(handler.GetLastInvalidationMap())); | 149 EXPECT_THAT(expected_invalidations, Eq(handler.GetLastInvalidationMap())); |
148 | 150 |
149 ids.erase(this->id1); | 151 ids.erase(this->id1); |
150 ids.insert(this->id3); | 152 ids.insert(this->id3); |
151 invalidator->UpdateRegisteredInvalidationIds(&handler, ids); | 153 invalidator->UpdateRegisteredInvalidationIds(&handler, ids); |
152 | 154 |
153 expected_states.erase(this->id1); | 155 expected_invalidations = syncer::ObjectIdInvalidationMap(); |
154 expected_states[this->id3].payload = "3"; | 156 expected_invalidations.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
| 157 expected_invalidations.Insert(syncer::Invalidation::Init(this->id3, 3, "3")); |
155 | 158 |
156 // Removed object IDs should not be notified, newly-added ones should. | 159 // Removed object IDs should not be notified, newly-added ones should. |
157 this->delegate_.TriggerOnIncomingInvalidation(states); | 160 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
158 EXPECT_EQ(2, handler.GetInvalidationCount()); | 161 EXPECT_EQ(2, handler.GetInvalidationCount()); |
159 EXPECT_THAT(expected_states, Eq(handler.GetLastInvalidationMap())); | 162 EXPECT_THAT(expected_invalidations, Eq(handler.GetLastInvalidationMap())); |
160 | 163 |
161 this->delegate_.TriggerOnInvalidatorStateChange( | 164 this->delegate_.TriggerOnInvalidatorStateChange( |
162 syncer::TRANSIENT_INVALIDATION_ERROR); | 165 syncer::TRANSIENT_INVALIDATION_ERROR); |
163 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 166 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
164 handler.GetInvalidatorState()); | 167 handler.GetInvalidatorState()); |
165 | 168 |
166 this->delegate_.TriggerOnInvalidatorStateChange( | 169 this->delegate_.TriggerOnInvalidatorStateChange( |
167 syncer::INVALIDATIONS_ENABLED); | 170 syncer::INVALIDATIONS_ENABLED); |
168 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, | 171 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, |
169 handler.GetInvalidatorState()); | 172 handler.GetInvalidatorState()); |
170 | 173 |
171 invalidator->UnregisterInvalidationHandler(&handler); | 174 invalidator->UnregisterInvalidationHandler(&handler); |
172 | 175 |
173 // Should be ignored since |handler| isn't registered anymore. | 176 // Should be ignored since |handler| isn't registered anymore. |
174 this->delegate_.TriggerOnIncomingInvalidation(states); | 177 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
175 EXPECT_EQ(2, handler.GetInvalidationCount()); | 178 EXPECT_EQ(2, handler.GetInvalidationCount()); |
176 } | 179 } |
177 | 180 |
178 // Register handlers and some IDs for those handlers, register a handler with | 181 // Register handlers and some IDs for those handlers, register a handler with |
179 // no IDs, and register a handler with some IDs but unregister it. Then, | 182 // no IDs, and register a handler with some IDs but unregister it. Then, |
180 // dispatch some invalidations and invalidations. Handlers that are registered | 183 // dispatch some invalidations and invalidations. Handlers that are registered |
181 // should get invalidations, and the ones that have registered IDs should | 184 // should get invalidations, and the ones that have registered IDs should |
182 // receive invalidations for those IDs. | 185 // receive invalidations for those IDs. |
183 TYPED_TEST_P(InvalidationServiceTest, MultipleHandlers) { | 186 TYPED_TEST_P(InvalidationServiceTest, MultipleHandlers) { |
184 invalidation::InvalidationService* const invalidator = | 187 invalidation::InvalidationService* const invalidator = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 222 |
220 this->delegate_.TriggerOnInvalidatorStateChange( | 223 this->delegate_.TriggerOnInvalidatorStateChange( |
221 syncer::INVALIDATIONS_ENABLED); | 224 syncer::INVALIDATIONS_ENABLED); |
222 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); | 225 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); |
223 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); | 226 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); |
224 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler3.GetInvalidatorState()); | 227 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler3.GetInvalidatorState()); |
225 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 228 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
226 handler4.GetInvalidatorState()); | 229 handler4.GetInvalidatorState()); |
227 | 230 |
228 { | 231 { |
229 syncer::ObjectIdInvalidationMap states; | 232 syncer::ObjectIdInvalidationMap invalidation_map; |
230 states[this->id1].payload = "1"; | 233 invalidation_map.Insert(syncer::Invalidation::Init(this->id1, 1, "1")); |
231 states[this->id2].payload = "2"; | 234 invalidation_map.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
232 states[this->id3].payload = "3"; | 235 invalidation_map.Insert(syncer::Invalidation::Init(this->id3, 3, "3")); |
233 states[this->id4].payload = "4"; | 236 invalidation_map.Insert(syncer::Invalidation::Init(this->id4, 4, "4")); |
234 this->delegate_.TriggerOnIncomingInvalidation(states); | 237 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
235 | 238 |
236 syncer::ObjectIdInvalidationMap expected_states; | 239 syncer::ObjectIdInvalidationMap expected_invalidations; |
237 expected_states[this->id1].payload = "1"; | 240 expected_invalidations.Insert( |
238 expected_states[this->id2].payload = "2"; | 241 syncer::Invalidation::Init(this->id1, 1, "1")); |
| 242 expected_invalidations.Insert( |
| 243 syncer::Invalidation::Init(this->id2, 2, "2")); |
239 | 244 |
240 EXPECT_EQ(1, handler1.GetInvalidationCount()); | 245 EXPECT_EQ(1, handler1.GetInvalidationCount()); |
241 EXPECT_THAT(expected_states, Eq(handler1.GetLastInvalidationMap())); | 246 EXPECT_THAT(expected_invalidations, Eq(handler1.GetLastInvalidationMap())); |
242 | 247 |
243 expected_states.clear(); | 248 expected_invalidations = syncer::ObjectIdInvalidationMap(); |
244 expected_states[this->id3].payload = "3"; | 249 expected_invalidations.Insert( |
| 250 syncer::Invalidation::Init(this->id3, 3, "3")); |
245 | 251 |
246 EXPECT_EQ(1, handler2.GetInvalidationCount()); | 252 EXPECT_EQ(1, handler2.GetInvalidationCount()); |
247 EXPECT_THAT(expected_states, Eq(handler2.GetLastInvalidationMap())); | 253 EXPECT_THAT(expected_invalidations, Eq(handler2.GetLastInvalidationMap())); |
248 | 254 |
249 EXPECT_EQ(0, handler3.GetInvalidationCount()); | 255 EXPECT_EQ(0, handler3.GetInvalidationCount()); |
250 EXPECT_EQ(0, handler4.GetInvalidationCount()); | 256 EXPECT_EQ(0, handler4.GetInvalidationCount()); |
251 } | 257 } |
252 | 258 |
253 this->delegate_.TriggerOnInvalidatorStateChange( | 259 this->delegate_.TriggerOnInvalidatorStateChange( |
254 syncer::TRANSIENT_INVALIDATION_ERROR); | 260 syncer::TRANSIENT_INVALIDATION_ERROR); |
255 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 261 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
256 handler1.GetInvalidatorState()); | 262 handler1.GetInvalidatorState()); |
257 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 263 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // further invalidations. | 303 // further invalidations. |
298 invalidator->UpdateRegisteredInvalidationIds(&handler1, | 304 invalidator->UpdateRegisteredInvalidationIds(&handler1, |
299 syncer::ObjectIdSet()); | 305 syncer::ObjectIdSet()); |
300 | 306 |
301 this->delegate_.TriggerOnInvalidatorStateChange( | 307 this->delegate_.TriggerOnInvalidatorStateChange( |
302 syncer::INVALIDATIONS_ENABLED); | 308 syncer::INVALIDATIONS_ENABLED); |
303 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); | 309 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); |
304 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); | 310 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); |
305 | 311 |
306 { | 312 { |
307 syncer::ObjectIdInvalidationMap states; | 313 syncer::ObjectIdInvalidationMap invalidation_map; |
308 states[this->id1].payload = "1"; | 314 invalidation_map.Insert(syncer::Invalidation::Init(this->id1, 1, "1")); |
309 states[this->id2].payload = "2"; | 315 invalidation_map.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
310 states[this->id3].payload = "3"; | 316 invalidation_map.Insert(syncer::Invalidation::Init(this->id3, 3, "3")); |
311 this->delegate_.TriggerOnIncomingInvalidation(states); | 317 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
312 EXPECT_EQ(0, handler1.GetInvalidationCount()); | 318 EXPECT_EQ(0, handler1.GetInvalidationCount()); |
313 EXPECT_EQ(1, handler2.GetInvalidationCount()); | 319 EXPECT_EQ(1, handler2.GetInvalidationCount()); |
314 } | 320 } |
315 | 321 |
316 this->delegate_.TriggerOnInvalidatorStateChange( | 322 this->delegate_.TriggerOnInvalidatorStateChange( |
317 syncer::TRANSIENT_INVALIDATION_ERROR); | 323 syncer::TRANSIENT_INVALIDATION_ERROR); |
318 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 324 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
319 handler1.GetInvalidatorState()); | 325 handler1.GetInvalidatorState()); |
320 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 326 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
321 handler2.GetInvalidatorState()); | 327 handler2.GetInvalidatorState()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 handler.GetLastRetrievedState()); | 379 handler.GetLastRetrievedState()); |
374 | 380 |
375 invalidator->UnregisterInvalidationHandler(&handler); | 381 invalidator->UnregisterInvalidationHandler(&handler); |
376 } | 382 } |
377 | 383 |
378 REGISTER_TYPED_TEST_CASE_P(InvalidationServiceTest, | 384 REGISTER_TYPED_TEST_CASE_P(InvalidationServiceTest, |
379 Basic, MultipleHandlers, EmptySetUnregisters, | 385 Basic, MultipleHandlers, EmptySetUnregisters, |
380 GetInvalidatorStateAlwaysCurrent); | 386 GetInvalidatorStateAlwaysCurrent); |
381 | 387 |
382 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ | 388 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ |
OLD | NEW |