Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: sync/notifier/invalidator_test_template.h

Issue 11052007: Rename ModelType/ObjectIdStateMap to InvalidationMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This class defines tests that implementations of Invalidator should pass in 5 // This class defines tests that implementations of Invalidator should pass in
6 // order to be conformant. Here's how you use it to test your implementation. 6 // order to be conformant. Here's how you use it to test your implementation.
7 // 7 //
8 // Say your class is called MyInvalidator. Then you need to define a class 8 // Say your class is called MyInvalidator. Then you need to define a class
9 // called MyInvalidatorTestDelegate in my_sync_notifier_unittest.cc like this: 9 // called MyInvalidatorTestDelegate in my_sync_notifier_unittest.cc like this:
10 // 10 //
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // // Should cause OnInvalidatorStateChange() to be called on all 49 // // Should cause OnInvalidatorStateChange() to be called on all
50 // // observers of the Invalidator implementation with the given 50 // // observers of the Invalidator implementation with the given
51 // // parameters. 51 // // parameters.
52 // void TriggerOnInvalidatorStateChange(InvalidatorState state) { 52 // void TriggerOnInvalidatorStateChange(InvalidatorState state) {
53 // ... 53 // ...
54 // } 54 // }
55 // 55 //
56 // // Should cause OnIncomingInvalidation() to be called on all 56 // // Should cause OnIncomingInvalidation() to be called on all
57 // // observers of the Invalidator implementation with the given 57 // // observers of the Invalidator implementation with the given
58 // // parameters. 58 // // parameters.
59 // void TriggerOnIncomingInvalidation(const ObjectIdStateMap& id_state_map, 59 // void TriggerOnIncomingInvalidation(
60 // IncomingInvalidationSource source) { 60 // const ObjectIdInvalidationMap& invalidation_map,
61 // IncomingInvalidationSource source) {
61 // ... 62 // ...
62 // } 63 // }
63 // 64 //
64 // // Returns whether or not the notifier handles storing the old 65 // // Returns whether or not the notifier handles storing the old
65 // // (deprecated) notifier state. 66 // // (deprecated) notifier state.
66 // static bool InvalidatorHandlesDeprecatedState() { 67 // static bool InvalidatorHandlesDeprecatedState() {
67 // return false; 68 // return false;
68 // } 69 // }
69 // }; 70 // };
70 // 71 //
(...skipping 12 matching lines...) Expand all
83 #ifndef SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ 84 #ifndef SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_
84 #define SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ 85 #define SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_
85 86
86 #include "base/basictypes.h" 87 #include "base/basictypes.h"
87 #include "base/compiler_specific.h" 88 #include "base/compiler_specific.h"
88 #include "google/cacheinvalidation/include/types.h" 89 #include "google/cacheinvalidation/include/types.h"
89 #include "google/cacheinvalidation/types.pb.h" 90 #include "google/cacheinvalidation/types.pb.h"
90 #include "sync/notifier/fake_invalidation_handler.h" 91 #include "sync/notifier/fake_invalidation_handler.h"
91 #include "sync/notifier/fake_invalidation_state_tracker.h" 92 #include "sync/notifier/fake_invalidation_state_tracker.h"
92 #include "sync/notifier/invalidator.h" 93 #include "sync/notifier/invalidator.h"
93 #include "sync/notifier/object_id_state_map.h" 94 #include "sync/notifier/object_id_invalidation_map.h"
94 #include "sync/notifier/object_id_state_map_test_util.h" 95 #include "sync/notifier/object_id_invalidation_map_test_util.h"
95 #include "testing/gtest/include/gtest/gtest.h" 96 #include "testing/gtest/include/gtest/gtest.h"
96 97
97 namespace syncer { 98 namespace syncer {
98 99
99 template <typename InvalidatorTestDelegate> 100 template <typename InvalidatorTestDelegate>
100 class InvalidatorTest : public testing::Test { 101 class InvalidatorTest : public testing::Test {
101 protected: 102 protected:
102 InvalidatorTest() 103 InvalidatorTest()
103 : id1(ipc::invalidation::ObjectSource::TEST, "a"), 104 : id1(ipc::invalidation::ObjectSource::TEST, "a"),
104 id2(ipc::invalidation::ObjectSource::TEST, "b"), 105 id2(ipc::invalidation::ObjectSource::TEST, "b"),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // handler, and then unregister the handler, dispatching invalidations in 142 // handler, and then unregister the handler, dispatching invalidations in
142 // between. The handler should only see invalidations when its registered and 143 // between. The handler should only see invalidations when its registered and
143 // its IDs are registered. 144 // its IDs are registered.
144 TYPED_TEST_P(InvalidatorTest, Basic) { 145 TYPED_TEST_P(InvalidatorTest, Basic) {
145 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); 146 Invalidator* const invalidator = this->CreateAndInitializeInvalidator();
146 147
147 FakeInvalidationHandler handler; 148 FakeInvalidationHandler handler;
148 149
149 invalidator->RegisterHandler(&handler); 150 invalidator->RegisterHandler(&handler);
150 151
151 ObjectIdStateMap states; 152 ObjectIdInvalidationMap states;
152 states[this->id1].payload = "1"; 153 states[this->id1].payload = "1";
153 states[this->id2].payload = "2"; 154 states[this->id2].payload = "2";
154 states[this->id3].payload = "3"; 155 states[this->id3].payload = "3";
155 156
156 // Should be ignored since no IDs are registered to |handler|. 157 // Should be ignored since no IDs are registered to |handler|.
157 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); 158 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION);
158 EXPECT_EQ(0, handler.GetInvalidationCount()); 159 EXPECT_EQ(0, handler.GetInvalidationCount());
159 160
160 ObjectIdSet ids; 161 ObjectIdSet ids;
161 ids.insert(this->id1); 162 ids.insert(this->id1);
162 ids.insert(this->id2); 163 ids.insert(this->id2);
163 invalidator->UpdateRegisteredIds(&handler, ids); 164 invalidator->UpdateRegisteredIds(&handler, ids);
164 165
165 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); 166 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED);
166 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); 167 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetInvalidatorState());
167 168
168 ObjectIdStateMap expected_states; 169 ObjectIdInvalidationMap expected_states;
169 expected_states[this->id1].payload = "1"; 170 expected_states[this->id1].payload = "1";
170 expected_states[this->id2].payload = "2"; 171 expected_states[this->id2].payload = "2";
171 172
172 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); 173 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION);
173 EXPECT_EQ(1, handler.GetInvalidationCount()); 174 EXPECT_EQ(1, handler.GetInvalidationCount());
174 EXPECT_THAT( 175 EXPECT_THAT(expected_states, Eq(handler.GetLastInvalidationMap()));
175 expected_states,
176 Eq(handler.GetLastInvalidationIdStateMap()));
177 EXPECT_EQ(REMOTE_INVALIDATION, handler.GetLastInvalidationSource()); 176 EXPECT_EQ(REMOTE_INVALIDATION, handler.GetLastInvalidationSource());
178 177
179 ids.erase(this->id1); 178 ids.erase(this->id1);
180 ids.insert(this->id3); 179 ids.insert(this->id3);
181 invalidator->UpdateRegisteredIds(&handler, ids); 180 invalidator->UpdateRegisteredIds(&handler, ids);
182 181
183 expected_states.erase(this->id1); 182 expected_states.erase(this->id1);
184 expected_states[this->id3].payload = "3"; 183 expected_states[this->id3].payload = "3";
185 184
186 // Removed object IDs should not be notified, newly-added ones should. 185 // Removed object IDs should not be notified, newly-added ones should.
187 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); 186 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION);
188 EXPECT_EQ(2, handler.GetInvalidationCount()); 187 EXPECT_EQ(2, handler.GetInvalidationCount());
189 EXPECT_THAT( 188 EXPECT_THAT(expected_states, Eq(handler.GetLastInvalidationMap()));
190 expected_states,
191 Eq(handler.GetLastInvalidationIdStateMap()));
192 EXPECT_EQ(REMOTE_INVALIDATION, handler.GetLastInvalidationSource()); 189 EXPECT_EQ(REMOTE_INVALIDATION, handler.GetLastInvalidationSource());
193 190
194 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 191 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
195 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, 192 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR,
196 handler.GetInvalidatorState()); 193 handler.GetInvalidatorState());
197 194
198 this->delegate_.TriggerOnInvalidatorStateChange( 195 this->delegate_.TriggerOnInvalidatorStateChange(
199 INVALIDATION_CREDENTIALS_REJECTED); 196 INVALIDATION_CREDENTIALS_REJECTED);
200 EXPECT_EQ(INVALIDATION_CREDENTIALS_REJECTED, 197 EXPECT_EQ(INVALIDATION_CREDENTIALS_REJECTED,
201 handler.GetInvalidatorState()); 198 handler.GetInvalidatorState());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 245
249 invalidator->UnregisterHandler(&handler4); 246 invalidator->UnregisterHandler(&handler4);
250 247
251 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); 248 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED);
252 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); 249 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState());
253 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); 250 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState());
254 EXPECT_EQ(INVALIDATIONS_ENABLED, handler3.GetInvalidatorState()); 251 EXPECT_EQ(INVALIDATIONS_ENABLED, handler3.GetInvalidatorState());
255 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState()); 252 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState());
256 253
257 { 254 {
258 ObjectIdStateMap states; 255 ObjectIdInvalidationMap states;
259 states[this->id1].payload = "1"; 256 states[this->id1].payload = "1";
260 states[this->id2].payload = "2"; 257 states[this->id2].payload = "2";
261 states[this->id3].payload = "3"; 258 states[this->id3].payload = "3";
262 states[this->id4].payload = "4"; 259 states[this->id4].payload = "4";
263 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); 260 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION);
264 261
265 ObjectIdStateMap expected_states; 262 ObjectIdInvalidationMap expected_states;
266 expected_states[this->id1].payload = "1"; 263 expected_states[this->id1].payload = "1";
267 expected_states[this->id2].payload = "2"; 264 expected_states[this->id2].payload = "2";
268 265
269 EXPECT_EQ(1, handler1.GetInvalidationCount()); 266 EXPECT_EQ(1, handler1.GetInvalidationCount());
270 EXPECT_THAT( 267 EXPECT_THAT(expected_states, Eq(handler1.GetLastInvalidationMap()));
271 expected_states,
272 Eq(handler1.GetLastInvalidationIdStateMap()));
273 EXPECT_EQ(REMOTE_INVALIDATION, handler1.GetLastInvalidationSource()); 268 EXPECT_EQ(REMOTE_INVALIDATION, handler1.GetLastInvalidationSource());
274 269
275 expected_states.clear(); 270 expected_states.clear();
276 expected_states[this->id3].payload = "3"; 271 expected_states[this->id3].payload = "3";
277 272
278 EXPECT_EQ(1, handler2.GetInvalidationCount()); 273 EXPECT_EQ(1, handler2.GetInvalidationCount());
279 EXPECT_THAT( 274 EXPECT_THAT(expected_states, Eq(handler2.GetLastInvalidationMap()));
280 expected_states,
281 Eq(handler2.GetLastInvalidationIdStateMap()));
282 EXPECT_EQ(REMOTE_INVALIDATION, handler2.GetLastInvalidationSource()); 275 EXPECT_EQ(REMOTE_INVALIDATION, handler2.GetLastInvalidationSource());
283 276
284 EXPECT_EQ(0, handler3.GetInvalidationCount()); 277 EXPECT_EQ(0, handler3.GetInvalidationCount());
285 EXPECT_EQ(0, handler4.GetInvalidationCount()); 278 EXPECT_EQ(0, handler4.GetInvalidationCount());
286 } 279 }
287 280
288 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 281 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
289 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState()); 282 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState());
290 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState()); 283 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState());
291 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler3.GetInvalidatorState()); 284 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler3.GetInvalidatorState());
(...skipping 28 matching lines...) Expand all
320 313
321 // Unregister the IDs for the first observer. It should not receive any 314 // Unregister the IDs for the first observer. It should not receive any
322 // further invalidations. 315 // further invalidations.
323 invalidator->UpdateRegisteredIds(&handler1, ObjectIdSet()); 316 invalidator->UpdateRegisteredIds(&handler1, ObjectIdSet());
324 317
325 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); 318 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED);
326 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); 319 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState());
327 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); 320 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState());
328 321
329 { 322 {
330 ObjectIdStateMap states; 323 ObjectIdInvalidationMap states;
331 states[this->id1].payload = "1"; 324 states[this->id1].payload = "1";
332 states[this->id2].payload = "2"; 325 states[this->id2].payload = "2";
333 states[this->id3].payload = "3"; 326 states[this->id3].payload = "3";
334 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION); 327 this->delegate_.TriggerOnIncomingInvalidation(states, REMOTE_INVALIDATION);
335 EXPECT_EQ(0, handler1.GetInvalidationCount()); 328 EXPECT_EQ(0, handler1.GetInvalidationCount());
336 EXPECT_EQ(1, handler2.GetInvalidationCount()); 329 EXPECT_EQ(1, handler2.GetInvalidationCount());
337 } 330 }
338 331
339 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 332 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
340 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState()); 333 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 EXPECT_EQ("fake_state", this->fake_tracker_.GetBootstrapData()); 412 EXPECT_EQ("fake_state", this->fake_tracker_.GetBootstrapData());
420 } 413 }
421 414
422 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest, 415 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest,
423 Basic, MultipleHandlers, EmptySetUnregisters, 416 Basic, MultipleHandlers, EmptySetUnregisters,
424 GetInvalidatorStateAlwaysCurrent, MigrateState); 417 GetInvalidatorStateAlwaysCurrent, MigrateState);
425 418
426 } // namespace syncer 419 } // namespace syncer
427 420
428 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ 421 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_
OLDNEW
« no previous file with comments | « sync/notifier/invalidator_registrar_unittest.cc ('k') | sync/notifier/non_blocking_invalidator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698