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

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

Issue 23754021: Invalidation trickles mega-patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
« no previous file with comments | « sync/notifier/invalidator_registrar_unittest.cc ('k') | sync/notifier/mock_ack_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // 74 //
75 // Easy! 75 // Easy!
76 76
77 #ifndef SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ 77 #ifndef SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_
78 #define SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ 78 #define SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_
79 79
80 #include "base/basictypes.h" 80 #include "base/basictypes.h"
81 #include "base/compiler_specific.h" 81 #include "base/compiler_specific.h"
82 #include "google/cacheinvalidation/include/types.h" 82 #include "google/cacheinvalidation/include/types.h"
83 #include "google/cacheinvalidation/types.pb.h" 83 #include "google/cacheinvalidation/types.pb.h"
84 #include "sync/internal_api/public/base/object_id_invalidation_map_test_util.h"
84 #include "sync/notifier/fake_invalidation_handler.h" 85 #include "sync/notifier/fake_invalidation_handler.h"
85 #include "sync/notifier/fake_invalidation_state_tracker.h" 86 #include "sync/notifier/fake_invalidation_state_tracker.h"
86 #include "sync/notifier/invalidator.h" 87 #include "sync/notifier/invalidator.h"
87 #include "sync/notifier/object_id_invalidation_map.h"
88 #include "sync/notifier/object_id_invalidation_map_test_util.h"
89 #include "testing/gtest/include/gtest/gtest.h" 88 #include "testing/gtest/include/gtest/gtest.h"
90 89
91 namespace syncer { 90 namespace syncer {
92 91
93 template <typename InvalidatorTestDelegate> 92 template <typename InvalidatorTestDelegate>
94 class InvalidatorTest : public testing::Test { 93 class InvalidatorTest : public testing::Test {
95 protected: 94 protected:
96 InvalidatorTest() 95 InvalidatorTest()
97 : id1(ipc::invalidation::ObjectSource::TEST, "a"), 96 : id1(ipc::invalidation::ObjectSource::TEST, "a"),
98 id2(ipc::invalidation::ObjectSource::TEST, "b"), 97 id2(ipc::invalidation::ObjectSource::TEST, "b"),
(...skipping 29 matching lines...) Expand all
128 // handler, and then unregister the handler, dispatching invalidations in 127 // handler, and then unregister the handler, dispatching invalidations in
129 // between. The handler should only see invalidations when its registered and 128 // between. The handler should only see invalidations when its registered and
130 // its IDs are registered. 129 // its IDs are registered.
131 TYPED_TEST_P(InvalidatorTest, Basic) { 130 TYPED_TEST_P(InvalidatorTest, Basic) {
132 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); 131 Invalidator* const invalidator = this->CreateAndInitializeInvalidator();
133 132
134 FakeInvalidationHandler handler; 133 FakeInvalidationHandler handler;
135 134
136 invalidator->RegisterHandler(&handler); 135 invalidator->RegisterHandler(&handler);
137 136
138 ObjectIdInvalidationMap states; 137 ObjectIdInvalidationMap invalidation_map;
139 states[this->id1].payload = "1"; 138 invalidation_map.Insert(Invalidation::Init(this->id1, 1, "1"));
140 states[this->id2].payload = "2"; 139 invalidation_map.Insert(Invalidation::Init(this->id2, 2, "2"));
141 states[this->id3].payload = "3"; 140 invalidation_map.Insert(Invalidation::Init(this->id3, 3, "3"));
142 141
143 // Should be ignored since no IDs are registered to |handler|. 142 // Should be ignored since no IDs are registered to |handler|.
144 this->delegate_.TriggerOnIncomingInvalidation(states); 143 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map);
145 EXPECT_EQ(0, handler.GetInvalidationCount()); 144 EXPECT_EQ(0, handler.GetInvalidationCount());
146 145
147 ObjectIdSet ids; 146 ObjectIdSet ids;
148 ids.insert(this->id1); 147 ids.insert(this->id1);
149 ids.insert(this->id2); 148 ids.insert(this->id2);
150 invalidator->UpdateRegisteredIds(&handler, ids); 149 invalidator->UpdateRegisteredIds(&handler, ids);
151 150
152 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); 151 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED);
153 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); 152 EXPECT_EQ(INVALIDATIONS_ENABLED, handler.GetInvalidatorState());
154 153
155 ObjectIdInvalidationMap expected_states; 154 ObjectIdInvalidationMap expected_invalidations;
156 expected_states[this->id1].payload = "1"; 155 expected_invalidations.Insert(Invalidation::Init(this->id1, 1, "1"));
157 expected_states[this->id2].payload = "2"; 156 expected_invalidations.Insert(Invalidation::Init(this->id2, 2, "2"));
158 157
159 this->delegate_.TriggerOnIncomingInvalidation(states); 158 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map);
160 EXPECT_EQ(1, handler.GetInvalidationCount()); 159 EXPECT_EQ(1, handler.GetInvalidationCount());
161 EXPECT_THAT(expected_states, Eq(handler.GetLastInvalidationMap())); 160 EXPECT_THAT(expected_invalidations, Eq(handler.GetLastInvalidationMap()));
162 161
163 ids.erase(this->id1); 162 ids.erase(this->id1);
164 ids.insert(this->id3); 163 ids.insert(this->id3);
165 invalidator->UpdateRegisteredIds(&handler, ids); 164 invalidator->UpdateRegisteredIds(&handler, ids);
166 165
167 expected_states.erase(this->id1); 166 expected_invalidations = ObjectIdInvalidationMap();
168 expected_states[this->id3].payload = "3"; 167 expected_invalidations.Insert(Invalidation::Init(this->id2, 2, "2"));
168 expected_invalidations.Insert(Invalidation::Init(this->id3, 3, "3"));
169 169
170 // Removed object IDs should not be notified, newly-added ones should. 170 // Removed object IDs should not be notified, newly-added ones should.
171 this->delegate_.TriggerOnIncomingInvalidation(states); 171 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map);
172 EXPECT_EQ(2, handler.GetInvalidationCount()); 172 EXPECT_EQ(2, handler.GetInvalidationCount());
173 EXPECT_THAT(expected_states, Eq(handler.GetLastInvalidationMap())); 173 EXPECT_THAT(expected_invalidations, Eq(handler.GetLastInvalidationMap()));
174 174
175 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 175 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
176 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, 176 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR,
177 handler.GetInvalidatorState()); 177 handler.GetInvalidatorState());
178 178
179 this->delegate_.TriggerOnInvalidatorStateChange( 179 this->delegate_.TriggerOnInvalidatorStateChange(
180 INVALIDATION_CREDENTIALS_REJECTED); 180 INVALIDATION_CREDENTIALS_REJECTED);
181 EXPECT_EQ(INVALIDATION_CREDENTIALS_REJECTED, 181 EXPECT_EQ(INVALIDATION_CREDENTIALS_REJECTED,
182 handler.GetInvalidatorState()); 182 handler.GetInvalidatorState());
183 183
184 invalidator->UnregisterHandler(&handler); 184 invalidator->UnregisterHandler(&handler);
185 185
186 // Should be ignored since |handler| isn't registered anymore. 186 // Should be ignored since |handler| isn't registered anymore.
187 this->delegate_.TriggerOnIncomingInvalidation(states); 187 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map);
188 EXPECT_EQ(2, handler.GetInvalidationCount()); 188 EXPECT_EQ(2, handler.GetInvalidationCount());
189 } 189 }
190 190
191 // Register handlers and some IDs for those handlers, register a handler with 191 // Register handlers and some IDs for those handlers, register a handler with
192 // no IDs, and register a handler with some IDs but unregister it. Then, 192 // no IDs, and register a handler with some IDs but unregister it. Then,
193 // dispatch some invalidations and invalidations. Handlers that are registered 193 // dispatch some invalidations and invalidations. Handlers that are registered
194 // should get invalidations, and the ones that have registered IDs should 194 // should get invalidations, and the ones that have registered IDs should
195 // receive invalidations for those IDs. 195 // receive invalidations for those IDs.
196 TYPED_TEST_P(InvalidatorTest, MultipleHandlers) { 196 TYPED_TEST_P(InvalidatorTest, MultipleHandlers) {
197 Invalidator* const invalidator = this->CreateAndInitializeInvalidator(); 197 Invalidator* const invalidator = this->CreateAndInitializeInvalidator();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 229
230 invalidator->UnregisterHandler(&handler4); 230 invalidator->UnregisterHandler(&handler4);
231 231
232 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); 232 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED);
233 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); 233 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState());
234 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); 234 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState());
235 EXPECT_EQ(INVALIDATIONS_ENABLED, handler3.GetInvalidatorState()); 235 EXPECT_EQ(INVALIDATIONS_ENABLED, handler3.GetInvalidatorState());
236 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState()); 236 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState());
237 237
238 { 238 {
239 ObjectIdInvalidationMap states; 239 ObjectIdInvalidationMap invalidation_map;
240 states[this->id1].payload = "1"; 240 invalidation_map.Insert(Invalidation::Init(this->id1, 1, "1"));
241 states[this->id2].payload = "2"; 241 invalidation_map.Insert(Invalidation::Init(this->id2, 2, "2"));
242 states[this->id3].payload = "3"; 242 invalidation_map.Insert(Invalidation::Init(this->id3, 3, "3"));
243 states[this->id4].payload = "4"; 243 invalidation_map.Insert(Invalidation::Init(this->id4, 4, "4"));
244 this->delegate_.TriggerOnIncomingInvalidation(states);
245 244
246 ObjectIdInvalidationMap expected_states; 245 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map);
247 expected_states[this->id1].payload = "1"; 246
248 expected_states[this->id2].payload = "2"; 247 ObjectIdInvalidationMap expected_invalidations;
248 expected_invalidations.Insert(Invalidation::Init(this->id1, 1, "1"));
249 expected_invalidations.Insert(Invalidation::Init(this->id2, 2, "2"));
249 250
250 EXPECT_EQ(1, handler1.GetInvalidationCount()); 251 EXPECT_EQ(1, handler1.GetInvalidationCount());
251 EXPECT_THAT(expected_states, Eq(handler1.GetLastInvalidationMap())); 252 EXPECT_THAT(expected_invalidations, Eq(handler1.GetLastInvalidationMap()));
252 253
253 expected_states.clear(); 254 expected_invalidations = ObjectIdInvalidationMap();
254 expected_states[this->id3].payload = "3"; 255 expected_invalidations.Insert(Invalidation::Init(this->id3, 3, "3"));
255 256
256 EXPECT_EQ(1, handler2.GetInvalidationCount()); 257 EXPECT_EQ(1, handler2.GetInvalidationCount());
257 EXPECT_THAT(expected_states, Eq(handler2.GetLastInvalidationMap())); 258 EXPECT_THAT(expected_invalidations, Eq(handler2.GetLastInvalidationMap()));
258 259
259 EXPECT_EQ(0, handler3.GetInvalidationCount()); 260 EXPECT_EQ(0, handler3.GetInvalidationCount());
260 EXPECT_EQ(0, handler4.GetInvalidationCount()); 261 EXPECT_EQ(0, handler4.GetInvalidationCount());
261 } 262 }
262 263
263 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 264 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
264 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState()); 265 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState());
265 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState()); 266 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState());
266 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler3.GetInvalidatorState()); 267 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler3.GetInvalidatorState());
267 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState()); 268 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler4.GetInvalidatorState());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 300
300 // Unregister the IDs for the first observer. It should not receive any 301 // Unregister the IDs for the first observer. It should not receive any
301 // further invalidations. 302 // further invalidations.
302 invalidator->UpdateRegisteredIds(&handler1, ObjectIdSet()); 303 invalidator->UpdateRegisteredIds(&handler1, ObjectIdSet());
303 304
304 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED); 305 this->delegate_.TriggerOnInvalidatorStateChange(INVALIDATIONS_ENABLED);
305 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); 306 EXPECT_EQ(INVALIDATIONS_ENABLED, handler1.GetInvalidatorState());
306 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); 307 EXPECT_EQ(INVALIDATIONS_ENABLED, handler2.GetInvalidatorState());
307 308
308 { 309 {
309 ObjectIdInvalidationMap states; 310 ObjectIdInvalidationMap invalidation_map;
310 states[this->id1].payload = "1"; 311 invalidation_map.Insert(Invalidation::Init(this->id1, 1, "1"));
311 states[this->id2].payload = "2"; 312 invalidation_map.Insert(Invalidation::Init(this->id2, 2, "2"));
312 states[this->id3].payload = "3"; 313 invalidation_map.Insert(Invalidation::Init(this->id3, 3, "3"));
313 this->delegate_.TriggerOnIncomingInvalidation(states); 314 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map);
314 EXPECT_EQ(0, handler1.GetInvalidationCount()); 315 EXPECT_EQ(0, handler1.GetInvalidationCount());
315 EXPECT_EQ(1, handler2.GetInvalidationCount()); 316 EXPECT_EQ(1, handler2.GetInvalidationCount());
316 } 317 }
317 318
318 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR); 319 this->delegate_.TriggerOnInvalidatorStateChange(TRANSIENT_INVALIDATION_ERROR);
319 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState()); 320 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler1.GetInvalidatorState());
320 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState()); 321 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, handler2.GetInvalidatorState());
321 322
322 invalidator->UnregisterHandler(&handler2); 323 invalidator->UnregisterHandler(&handler2);
323 invalidator->UnregisterHandler(&handler1); 324 invalidator->UnregisterHandler(&handler1);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 invalidator->UnregisterHandler(&handler); 368 invalidator->UnregisterHandler(&handler);
368 } 369 }
369 370
370 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest, 371 REGISTER_TYPED_TEST_CASE_P(InvalidatorTest,
371 Basic, MultipleHandlers, EmptySetUnregisters, 372 Basic, MultipleHandlers, EmptySetUnregisters,
372 GetInvalidatorStateAlwaysCurrent); 373 GetInvalidatorStateAlwaysCurrent);
373 374
374 } // namespace syncer 375 } // namespace syncer
375 376
376 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_ 377 #endif // SYNC_NOTIFIER_INVALIDATOR_TEST_TEMPLATE_H_
OLDNEW
« no previous file with comments | « sync/notifier/invalidator_registrar_unittest.cc ('k') | sync/notifier/mock_ack_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698