Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 invalidation_map.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); | 127 invalidation_map.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
| 128 invalidation_map.Insert(syncer::Invalidation::Init(this->id3, 3, "3")); | 128 invalidation_map.Insert(syncer::Invalidation::Init(this->id3, 3, "3")); |
| 129 | 129 |
| 130 // Should be ignored since no IDs are registered to |handler|. | 130 // Should be ignored since no IDs are registered to |handler|. |
| 131 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); | 131 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
| 132 EXPECT_EQ(0, handler.GetInvalidationCount()); | 132 EXPECT_EQ(0, handler.GetInvalidationCount()); |
| 133 | 133 |
| 134 syncer::ObjectIdSet ids; | 134 syncer::ObjectIdSet ids; |
| 135 ids.insert(this->id1); | 135 ids.insert(this->id1); |
| 136 ids.insert(this->id2); | 136 ids.insert(this->id2); |
| 137 invalidator->UpdateRegisteredInvalidationIds(&handler, ids); | 137 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds(&handler, ids)); |
| 138 | 138 |
| 139 this->delegate_.TriggerOnInvalidatorStateChange( | 139 this->delegate_.TriggerOnInvalidatorStateChange( |
| 140 syncer::INVALIDATIONS_ENABLED); | 140 syncer::INVALIDATIONS_ENABLED); |
| 141 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); | 141 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); |
| 142 | 142 |
| 143 syncer::ObjectIdInvalidationMap expected_invalidations; | 143 syncer::ObjectIdInvalidationMap expected_invalidations; |
| 144 expected_invalidations.Insert(syncer::Invalidation::Init(this->id1, 1, "1")); | 144 expected_invalidations.Insert(syncer::Invalidation::Init(this->id1, 1, "1")); |
| 145 expected_invalidations.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); | 145 expected_invalidations.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
| 146 | 146 |
| 147 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); | 147 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
| 148 EXPECT_EQ(1, handler.GetInvalidationCount()); | 148 EXPECT_EQ(1, handler.GetInvalidationCount()); |
| 149 EXPECT_THAT(expected_invalidations, Eq(handler.GetLastInvalidationMap())); | 149 EXPECT_THAT(expected_invalidations, Eq(handler.GetLastInvalidationMap())); |
| 150 | 150 |
| 151 ids.erase(this->id1); | 151 ids.erase(this->id1); |
| 152 ids.insert(this->id3); | 152 ids.insert(this->id3); |
| 153 invalidator->UpdateRegisteredInvalidationIds(&handler, ids); | 153 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds(&handler, ids)); |
| 154 | 154 |
| 155 expected_invalidations = syncer::ObjectIdInvalidationMap(); | 155 expected_invalidations = syncer::ObjectIdInvalidationMap(); |
| 156 expected_invalidations.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); | 156 expected_invalidations.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
| 157 expected_invalidations.Insert(syncer::Invalidation::Init(this->id3, 3, "3")); | 157 expected_invalidations.Insert(syncer::Invalidation::Init(this->id3, 3, "3")); |
| 158 | 158 |
| 159 // Removed object IDs should not be notified, newly-added ones should. | 159 // Removed object IDs should not be notified, newly-added ones should. |
| 160 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); | 160 this->delegate_.TriggerOnIncomingInvalidation(invalidation_map); |
| 161 EXPECT_EQ(2, handler.GetInvalidationCount()); | 161 EXPECT_EQ(2, handler.GetInvalidationCount()); |
| 162 EXPECT_THAT(expected_invalidations, Eq(handler.GetLastInvalidationMap())); | 162 EXPECT_THAT(expected_invalidations, Eq(handler.GetLastInvalidationMap())); |
| 163 | 163 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 194 | 194 |
| 195 invalidator->RegisterInvalidationHandler(&handler1); | 195 invalidator->RegisterInvalidationHandler(&handler1); |
| 196 invalidator->RegisterInvalidationHandler(&handler2); | 196 invalidator->RegisterInvalidationHandler(&handler2); |
| 197 invalidator->RegisterInvalidationHandler(&handler3); | 197 invalidator->RegisterInvalidationHandler(&handler3); |
| 198 invalidator->RegisterInvalidationHandler(&handler4); | 198 invalidator->RegisterInvalidationHandler(&handler4); |
| 199 | 199 |
| 200 { | 200 { |
| 201 syncer::ObjectIdSet ids; | 201 syncer::ObjectIdSet ids; |
| 202 ids.insert(this->id1); | 202 ids.insert(this->id1); |
| 203 ids.insert(this->id2); | 203 ids.insert(this->id2); |
| 204 invalidator->UpdateRegisteredInvalidationIds(&handler1, ids); | 204 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds(&handler1, ids)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 { | 207 { |
| 208 syncer::ObjectIdSet ids; | 208 syncer::ObjectIdSet ids; |
| 209 ids.insert(this->id3); | 209 ids.insert(this->id3); |
| 210 invalidator->UpdateRegisteredInvalidationIds(&handler2, ids); | 210 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds(&handler2, ids)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Don't register any IDs for handler3. | 213 // Don't register any IDs for handler3. |
| 214 | 214 |
| 215 { | 215 { |
| 216 syncer::ObjectIdSet ids; | 216 syncer::ObjectIdSet ids; |
| 217 ids.insert(this->id4); | 217 ids.insert(this->id4); |
| 218 invalidator->UpdateRegisteredInvalidationIds(&handler4, ids); | 218 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds(&handler4, ids)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 invalidator->UnregisterInvalidationHandler(&handler4); | 221 invalidator->UnregisterInvalidationHandler(&handler4); |
| 222 | 222 |
| 223 this->delegate_.TriggerOnInvalidatorStateChange( | 223 this->delegate_.TriggerOnInvalidatorStateChange( |
| 224 syncer::INVALIDATIONS_ENABLED); | 224 syncer::INVALIDATIONS_ENABLED); |
| 225 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); | 225 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); |
| 226 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); | 226 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); |
| 227 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler3.GetInvalidatorState()); | 227 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler3.GetInvalidatorState()); |
| 228 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 228 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 265 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
| 266 handler3.GetInvalidatorState()); | 266 handler3.GetInvalidatorState()); |
| 267 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 267 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
| 268 handler4.GetInvalidatorState()); | 268 handler4.GetInvalidatorState()); |
| 269 | 269 |
| 270 invalidator->UnregisterInvalidationHandler(&handler3); | 270 invalidator->UnregisterInvalidationHandler(&handler3); |
| 271 invalidator->UnregisterInvalidationHandler(&handler2); | 271 invalidator->UnregisterInvalidationHandler(&handler2); |
| 272 invalidator->UnregisterInvalidationHandler(&handler1); | 272 invalidator->UnregisterInvalidationHandler(&handler1); |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Multiple registrations by different handlers on the same object ID should | |
| 276 // return false. | |
| 277 TYPED_TEST_P(InvalidationServiceTest, MultipleRegistrations) { | |
| 278 invalidation::InvalidationService* const invalidator = | |
| 279 this->CreateAndInitializeInvalidationService(); | |
| 280 | |
| 281 syncer::FakeInvalidationHandler handler1; | |
| 282 syncer::FakeInvalidationHandler handler2; | |
| 283 | |
| 284 invalidator->RegisterInvalidationHandler(&handler1); | |
| 285 invalidator->RegisterInvalidationHandler(&handler2); | |
| 286 | |
| 287 // Registering both handlers for the same ObjectId. First call should succeed, | |
| 288 // second should fail. | |
| 289 syncer::ObjectIdSet ids; | |
| 290 ids.insert(this->id1); | |
| 291 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds(&handler1, ids)); | |
| 292 EXPECT_FALSE(invalidator->UpdateRegisteredInvalidationIds(&handler2, ids)); | |
| 293 | |
| 294 invalidator->UnregisterInvalidationHandler(&handler2); | |
| 295 invalidator->UnregisterInvalidationHandler(&handler1); | |
| 296 } | |
| 297 | |
| 275 // Make sure that passing an empty set to UpdateRegisteredInvalidationIds clears | 298 // Make sure that passing an empty set to UpdateRegisteredInvalidationIds clears |
| 276 // the corresponding entries for the handler. | 299 // the corresponding entries for the handler. |
| 277 TYPED_TEST_P(InvalidationServiceTest, EmptySetUnregisters) { | 300 TYPED_TEST_P(InvalidationServiceTest, EmptySetUnregisters) { |
| 278 invalidation::InvalidationService* const invalidator = | 301 invalidation::InvalidationService* const invalidator = |
| 279 this->CreateAndInitializeInvalidationService(); | 302 this->CreateAndInitializeInvalidationService(); |
| 280 | 303 |
| 281 syncer::FakeInvalidationHandler handler1; | 304 syncer::FakeInvalidationHandler handler1; |
| 282 | 305 |
| 283 // Control observer. | 306 // Control observer. |
| 284 syncer::FakeInvalidationHandler handler2; | 307 syncer::FakeInvalidationHandler handler2; |
| 285 | 308 |
| 286 invalidator->RegisterInvalidationHandler(&handler1); | 309 invalidator->RegisterInvalidationHandler(&handler1); |
| 287 invalidator->RegisterInvalidationHandler(&handler2); | 310 invalidator->RegisterInvalidationHandler(&handler2); |
| 288 | 311 |
| 289 { | 312 { |
| 290 syncer::ObjectIdSet ids; | 313 syncer::ObjectIdSet ids; |
| 291 ids.insert(this->id1); | 314 ids.insert(this->id1); |
| 292 ids.insert(this->id2); | 315 ids.insert(this->id2); |
| 293 invalidator->UpdateRegisteredInvalidationIds(&handler1, ids); | 316 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds(&handler1, ids)); |
| 294 } | 317 } |
| 295 | 318 |
| 296 { | 319 { |
| 297 syncer::ObjectIdSet ids; | 320 syncer::ObjectIdSet ids; |
| 298 ids.insert(this->id3); | 321 ids.insert(this->id3); |
| 299 invalidator->UpdateRegisteredInvalidationIds(&handler2, ids); | 322 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds(&handler2, ids)); |
| 300 } | 323 } |
| 301 | 324 |
| 302 // Unregister the IDs for the first observer. It should not receive any | 325 // Unregister the IDs for the first observer. It should not receive any |
| 303 // further invalidations. | 326 // further invalidations. |
| 304 invalidator->UpdateRegisteredInvalidationIds(&handler1, | 327 EXPECT_TRUE(invalidator->UpdateRegisteredInvalidationIds( |
| 305 syncer::ObjectIdSet()); | 328 &handler1, syncer::ObjectIdSet())); |
| 306 | 329 |
| 307 this->delegate_.TriggerOnInvalidatorStateChange( | 330 this->delegate_.TriggerOnInvalidatorStateChange( |
| 308 syncer::INVALIDATIONS_ENABLED); | 331 syncer::INVALIDATIONS_ENABLED); |
| 309 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); | 332 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler1.GetInvalidatorState()); |
| 310 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); | 333 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler2.GetInvalidatorState()); |
| 311 | 334 |
| 312 { | 335 { |
| 313 syncer::ObjectIdInvalidationMap invalidation_map; | 336 syncer::ObjectIdInvalidationMap invalidation_map; |
| 314 invalidation_map.Insert(syncer::Invalidation::Init(this->id1, 1, "1")); | 337 invalidation_map.Insert(syncer::Invalidation::Init(this->id1, 1, "1")); |
| 315 invalidation_map.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); | 338 invalidation_map.Insert(syncer::Invalidation::Init(this->id2, 2, "2")); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 syncer::TRANSIENT_INVALIDATION_ERROR); | 397 syncer::TRANSIENT_INVALIDATION_ERROR); |
| 375 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 398 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
| 376 handler.GetInvalidatorState()); | 399 handler.GetInvalidatorState()); |
| 377 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 400 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
| 378 handler.GetLastRetrievedState()); | 401 handler.GetLastRetrievedState()); |
| 379 | 402 |
| 380 invalidator->UnregisterInvalidationHandler(&handler); | 403 invalidator->UnregisterInvalidationHandler(&handler); |
| 381 } | 404 } |
| 382 | 405 |
| 383 REGISTER_TYPED_TEST_CASE_P(InvalidationServiceTest, | 406 REGISTER_TYPED_TEST_CASE_P(InvalidationServiceTest, |
| 384 Basic, MultipleHandlers, EmptySetUnregisters, | 407 Basic, |
| 408 MultipleHandlers, | |
| 409 MultipleRegistrations, | |
| 410 EmptySetUnregisters, | |
| 385 GetInvalidatorStateAlwaysCurrent); | 411 GetInvalidatorStateAlwaysCurrent); |
| 386 | 412 |
| 387 #endif // COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ | 413 #endif // COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_TEST_TEMPLATE_H_ |
| 414 // {PAV} Add test for false | |
|
maniscalco
2015/05/18 15:42:28
Remove?
pavely
2015/05/18 18:38:04
Thank you.
| |
| OLD | NEW |