| 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "sync/internal_api/public/base/model_type_test_util.h" | 7 #include "sync/internal_api/public/base/model_type_test_util.h" |
| 8 #include "sync/notifier/invalidation_util.h" | 8 #include "sync/notifier/invalidation_util.h" |
| 9 #include "sync/notifier/mock_ack_handler.h" | 9 #include "sync/notifier/mock_ack_handler.h" |
| 10 #include "sync/notifier/object_id_invalidation_map.h" | 10 #include "sync/notifier/object_id_invalidation_map.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 | 63 |
| 64 int ProtoRefreshRequestedCount(ModelType type) const { | 64 int ProtoRefreshRequestedCount(ModelType type) const { |
| 65 sync_pb::GetUpdateTriggers gu_trigger; | 65 sync_pb::GetUpdateTriggers gu_trigger; |
| 66 nudge_tracker_.FillProtoMessage(type, &gu_trigger); | 66 nudge_tracker_.FillProtoMessage(type, &gu_trigger); |
| 67 return gu_trigger.datatype_refresh_nudges(); | 67 return gu_trigger.datatype_refresh_nudges(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SetInvalidationsInSync() { | 70 void SetInvalidationsInSync() { |
| 71 nudge_tracker_.OnInvalidationsEnabled(); | 71 nudge_tracker_.OnInvalidationsEnabled(); |
| 72 nudge_tracker_.RecordSuccessfulSyncCycle(); | 72 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 protected: | 75 protected: |
| 76 NudgeTracker nudge_tracker_; | 76 NudgeTracker nudge_tracker_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // Exercise an empty NudgeTracker. | 79 // Exercise an empty NudgeTracker. |
| 80 // Use with valgrind to detect uninitialized members. | 80 // Use with valgrind to detect uninitialized members. |
| 81 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) { | 81 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) { |
| 82 // Now we're at the normal, "idle" state. | 82 // Now we're at the normal, "idle" state. |
| 83 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 83 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 84 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 84 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 85 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN, | 85 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN, |
| 86 nudge_tracker_.updates_source()); | 86 nudge_tracker_.updates_source()); |
| 87 | 87 |
| 88 sync_pb::GetUpdateTriggers gu_trigger; | 88 sync_pb::GetUpdateTriggers gu_trigger; |
| 89 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); | 89 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); |
| 90 | 90 |
| 91 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN, | 91 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::UNKNOWN, |
| 92 nudge_tracker_.updates_source()); | 92 nudge_tracker_.updates_source()); |
| 93 } | 93 } |
| 94 | 94 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); | 264 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); |
| 265 { | 265 { |
| 266 sync_pb::GetUpdateTriggers gu_trigger; | 266 sync_pb::GetUpdateTriggers gu_trigger; |
| 267 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); | 267 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); |
| 268 EXPECT_TRUE(gu_trigger.server_dropped_hints()); | 268 EXPECT_TRUE(gu_trigger.server_dropped_hints()); |
| 269 EXPECT_FALSE(gu_trigger.client_dropped_hints()); | 269 EXPECT_FALSE(gu_trigger.client_dropped_hints()); |
| 270 ASSERT_EQ(0, gu_trigger.notification_hint_size()); | 270 ASSERT_EQ(0, gu_trigger.notification_hint_size()); |
| 271 } | 271 } |
| 272 | 272 |
| 273 // Clear status then verify. | 273 // Clear status then verify. |
| 274 nudge_tracker_.RecordSuccessfulSyncCycle(); | 274 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 275 { | 275 { |
| 276 sync_pb::GetUpdateTriggers gu_trigger; | 276 sync_pb::GetUpdateTriggers gu_trigger; |
| 277 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); | 277 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); |
| 278 EXPECT_FALSE(gu_trigger.client_dropped_hints()); | 278 EXPECT_FALSE(gu_trigger.client_dropped_hints()); |
| 279 EXPECT_FALSE(gu_trigger.server_dropped_hints()); | 279 EXPECT_FALSE(gu_trigger.server_dropped_hints()); |
| 280 ASSERT_EQ(0, gu_trigger.notification_hint_size()); | 280 ASSERT_EQ(0, gu_trigger.notification_hint_size()); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 // Tests the receipt of 'unknown version' invalidations. This test also | 284 // Tests the receipt of 'unknown version' invalidations. This test also |
| 285 // includes a known version invalidation to mix things up a bit. | 285 // includes a known version invalidation to mix things up a bit. |
| 286 TEST_F(NudgeTrackerTest, DropHintsAtServer_WithOtherInvalidations) { | 286 TEST_F(NudgeTrackerTest, DropHintsAtServer_WithOtherInvalidations) { |
| 287 ObjectIdInvalidationMap invalidation_map; | 287 ObjectIdInvalidationMap invalidation_map; |
| 288 invalidation_map.Insert(BuildUnknownVersionInvalidation(BOOKMARKS)); | 288 invalidation_map.Insert(BuildUnknownVersionInvalidation(BOOKMARKS)); |
| 289 invalidation_map.Insert(BuildInvalidation(BOOKMARKS, 10, "hint")); | 289 invalidation_map.Insert(BuildInvalidation(BOOKMARKS, 10, "hint")); |
| 290 | 290 |
| 291 // Record the two invalidations, one with unknown version, the other unknown. | 291 // Record the two invalidations, one with unknown version, the other unknown. |
| 292 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); | 292 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); |
| 293 { | 293 { |
| 294 sync_pb::GetUpdateTriggers gu_trigger; | 294 sync_pb::GetUpdateTriggers gu_trigger; |
| 295 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); | 295 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); |
| 296 EXPECT_TRUE(gu_trigger.server_dropped_hints()); | 296 EXPECT_TRUE(gu_trigger.server_dropped_hints()); |
| 297 EXPECT_FALSE(gu_trigger.client_dropped_hints()); | 297 EXPECT_FALSE(gu_trigger.client_dropped_hints()); |
| 298 ASSERT_EQ(1, gu_trigger.notification_hint_size()); | 298 ASSERT_EQ(1, gu_trigger.notification_hint_size()); |
| 299 EXPECT_EQ("hint", gu_trigger.notification_hint(0)); | 299 EXPECT_EQ("hint", gu_trigger.notification_hint(0)); |
| 300 } | 300 } |
| 301 | 301 |
| 302 // Clear status then verify. | 302 // Clear status then verify. |
| 303 nudge_tracker_.RecordSuccessfulSyncCycle(); | 303 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 304 { | 304 { |
| 305 sync_pb::GetUpdateTriggers gu_trigger; | 305 sync_pb::GetUpdateTriggers gu_trigger; |
| 306 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); | 306 nudge_tracker_.FillProtoMessage(BOOKMARKS, &gu_trigger); |
| 307 EXPECT_FALSE(gu_trigger.client_dropped_hints()); | 307 EXPECT_FALSE(gu_trigger.client_dropped_hints()); |
| 308 EXPECT_FALSE(gu_trigger.server_dropped_hints()); | 308 EXPECT_FALSE(gu_trigger.server_dropped_hints()); |
| 309 ASSERT_EQ(0, gu_trigger.notification_hint_size()); | 309 ASSERT_EQ(0, gu_trigger.notification_hint_size()); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 | 312 |
| 313 // Checks the behaviour of the invalidations-out-of-sync flag. | 313 // Checks the behaviour of the invalidations-out-of-sync flag. |
| 314 TEST_F(NudgeTrackerTest, EnableDisableInvalidations) { | 314 TEST_F(NudgeTrackerTest, EnableDisableInvalidations) { |
| 315 // Start with invalidations offline. | 315 // Start with invalidations offline. |
| 316 nudge_tracker_.OnInvalidationsDisabled(); | 316 nudge_tracker_.OnInvalidationsDisabled(); |
| 317 EXPECT_TRUE(InvalidationsOutOfSync()); | 317 EXPECT_TRUE(InvalidationsOutOfSync()); |
| 318 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 318 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 319 | 319 |
| 320 // Simply enabling invalidations does not bring us back into sync. | 320 // Simply enabling invalidations does not bring us back into sync. |
| 321 nudge_tracker_.OnInvalidationsEnabled(); | 321 nudge_tracker_.OnInvalidationsEnabled(); |
| 322 EXPECT_TRUE(InvalidationsOutOfSync()); | 322 EXPECT_TRUE(InvalidationsOutOfSync()); |
| 323 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 323 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 324 | 324 |
| 325 // We must successfully complete a sync cycle while invalidations are enabled | 325 // We must successfully complete a sync cycle while invalidations are enabled |
| 326 // to be sure that we're in sync. | 326 // to be sure that we're in sync. |
| 327 nudge_tracker_.RecordSuccessfulSyncCycle(); | 327 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 328 EXPECT_FALSE(InvalidationsOutOfSync()); | 328 EXPECT_FALSE(InvalidationsOutOfSync()); |
| 329 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 329 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 330 | 330 |
| 331 // If the invalidator malfunctions, we go become unsynced again. | 331 // If the invalidator malfunctions, we go become unsynced again. |
| 332 nudge_tracker_.OnInvalidationsDisabled(); | 332 nudge_tracker_.OnInvalidationsDisabled(); |
| 333 EXPECT_TRUE(InvalidationsOutOfSync()); | 333 EXPECT_TRUE(InvalidationsOutOfSync()); |
| 334 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 334 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 335 | 335 |
| 336 // A sync cycle while invalidations are disabled won't reset the flag. | 336 // A sync cycle while invalidations are disabled won't reset the flag. |
| 337 nudge_tracker_.RecordSuccessfulSyncCycle(); | 337 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 338 EXPECT_TRUE(InvalidationsOutOfSync()); | 338 EXPECT_TRUE(InvalidationsOutOfSync()); |
| 339 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 339 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 340 | 340 |
| 341 // Nor will the re-enabling of invalidations be sufficient, even now that | 341 // Nor will the re-enabling of invalidations be sufficient, even now that |
| 342 // we've had a successful sync cycle. | 342 // we've had a successful sync cycle. |
| 343 nudge_tracker_.RecordSuccessfulSyncCycle(); | 343 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 344 EXPECT_TRUE(InvalidationsOutOfSync()); | 344 EXPECT_TRUE(InvalidationsOutOfSync()); |
| 345 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 345 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 346 } | 346 } |
| 347 | 347 |
| 348 // Tests that locally modified types are correctly written out to the | 348 // Tests that locally modified types are correctly written out to the |
| 349 // GetUpdateTriggers proto. | 349 // GetUpdateTriggers proto. |
| 350 TEST_F(NudgeTrackerTest, WriteLocallyModifiedTypesToProto) { | 350 TEST_F(NudgeTrackerTest, WriteLocallyModifiedTypesToProto) { |
| 351 // Should not be locally modified by default. | 351 // Should not be locally modified by default. |
| 352 EXPECT_EQ(0, ProtoLocallyModifiedCount(PREFERENCES)); | 352 EXPECT_EQ(0, ProtoLocallyModifiedCount(PREFERENCES)); |
| 353 | 353 |
| 354 // Record a local bookmark change. Verify it was registered correctly. | 354 // Record a local bookmark change. Verify it was registered correctly. |
| 355 nudge_tracker_.RecordLocalChange(ModelTypeSet(PREFERENCES)); | 355 nudge_tracker_.RecordLocalChange(ModelTypeSet(PREFERENCES)); |
| 356 EXPECT_EQ(1, ProtoLocallyModifiedCount(PREFERENCES)); | 356 EXPECT_EQ(1, ProtoLocallyModifiedCount(PREFERENCES)); |
| 357 | 357 |
| 358 // Record a successful sync cycle. Verify the count is cleared. | 358 // Record a successful sync cycle. Verify the count is cleared. |
| 359 nudge_tracker_.RecordSuccessfulSyncCycle(); | 359 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 360 EXPECT_EQ(0, ProtoLocallyModifiedCount(PREFERENCES)); | 360 EXPECT_EQ(0, ProtoLocallyModifiedCount(PREFERENCES)); |
| 361 } | 361 } |
| 362 | 362 |
| 363 // Tests that refresh requested types are correctly written out to the | 363 // Tests that refresh requested types are correctly written out to the |
| 364 // GetUpdateTriggers proto. | 364 // GetUpdateTriggers proto. |
| 365 TEST_F(NudgeTrackerTest, WriteRefreshRequestedTypesToProto) { | 365 TEST_F(NudgeTrackerTest, WriteRefreshRequestedTypesToProto) { |
| 366 // There should be no refresh requested by default. | 366 // There should be no refresh requested by default. |
| 367 EXPECT_EQ(0, ProtoRefreshRequestedCount(SESSIONS)); | 367 EXPECT_EQ(0, ProtoRefreshRequestedCount(SESSIONS)); |
| 368 | 368 |
| 369 // Record a local refresh request. Verify it was registered correctly. | 369 // Record a local refresh request. Verify it was registered correctly. |
| 370 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); | 370 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); |
| 371 EXPECT_EQ(1, ProtoRefreshRequestedCount(SESSIONS)); | 371 EXPECT_EQ(1, ProtoRefreshRequestedCount(SESSIONS)); |
| 372 | 372 |
| 373 // Record a successful sync cycle. Verify the count is cleared. | 373 // Record a successful sync cycle. Verify the count is cleared. |
| 374 nudge_tracker_.RecordSuccessfulSyncCycle(); | 374 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 375 EXPECT_EQ(0, ProtoRefreshRequestedCount(SESSIONS)); | 375 EXPECT_EQ(0, ProtoRefreshRequestedCount(SESSIONS)); |
| 376 } | 376 } |
| 377 | 377 |
| 378 // Basic tests for the IsSyncRequired() flag. | 378 // Basic tests for the IsSyncRequired() flag. |
| 379 TEST_F(NudgeTrackerTest, IsSyncRequired) { | 379 TEST_F(NudgeTrackerTest, IsSyncRequired) { |
| 380 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 380 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 381 | 381 |
| 382 // Local changes. | 382 // Local changes. |
| 383 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)); | 383 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)); |
| 384 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 384 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 385 nudge_tracker_.RecordSuccessfulSyncCycle(); | 385 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 386 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 386 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 387 | 387 |
| 388 // Refresh requests. | 388 // Refresh requests. |
| 389 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); | 389 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); |
| 390 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 390 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 391 nudge_tracker_.RecordSuccessfulSyncCycle(); | 391 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 392 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 392 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 393 | 393 |
| 394 // Invalidations. | 394 // Invalidations. |
| 395 ObjectIdInvalidationMap invalidation_map = | 395 ObjectIdInvalidationMap invalidation_map = |
| 396 BuildInvalidationMap(PREFERENCES, 1, "hint"); | 396 BuildInvalidationMap(PREFERENCES, 1, "hint"); |
| 397 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); | 397 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); |
| 398 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 398 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 399 nudge_tracker_.RecordSuccessfulSyncCycle(); | 399 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 400 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 400 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 401 } | 401 } |
| 402 | 402 |
| 403 // Basic tests for the IsGetUpdatesRequired() flag. | 403 // Basic tests for the IsGetUpdatesRequired() flag. |
| 404 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired) { | 404 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired) { |
| 405 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 405 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 406 | 406 |
| 407 // Local changes. | 407 // Local changes. |
| 408 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)); | 408 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)); |
| 409 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 409 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 410 nudge_tracker_.RecordSuccessfulSyncCycle(); | 410 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 411 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 411 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 412 | 412 |
| 413 // Refresh requests. | 413 // Refresh requests. |
| 414 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); | 414 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); |
| 415 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 415 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 416 nudge_tracker_.RecordSuccessfulSyncCycle(); | 416 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 417 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 417 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 418 | 418 |
| 419 // Invalidations. | 419 // Invalidations. |
| 420 ObjectIdInvalidationMap invalidation_map = | 420 ObjectIdInvalidationMap invalidation_map = |
| 421 BuildInvalidationMap(PREFERENCES, 1, "hint"); | 421 BuildInvalidationMap(PREFERENCES, 1, "hint"); |
| 422 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); | 422 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); |
| 423 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 423 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 424 nudge_tracker_.RecordSuccessfulSyncCycle(); | 424 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 425 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 425 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 426 } | 426 } |
| 427 | 427 |
| 428 // Test IsSyncRequired() responds correctly to data type throttling. | 428 // Test IsSyncRequired() responds correctly to data type throttling. |
| 429 TEST_F(NudgeTrackerTest, IsSyncRequired_Throttling) { | 429 TEST_F(NudgeTrackerTest, IsSyncRequired_Throttling) { |
| 430 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); | 430 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); |
| 431 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10); | 431 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10); |
| 432 const base::TimeTicks t1 = t0 + throttle_length; | 432 const base::TimeTicks t1 = t0 + throttle_length; |
| 433 | 433 |
| 434 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 434 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 435 | 435 |
| 436 // A local change to sessions enables the flag. | 436 // A local change to sessions enables the flag. |
| 437 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)); | 437 nudge_tracker_.RecordLocalChange(ModelTypeSet(SESSIONS)); |
| 438 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 438 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 439 | 439 |
| 440 // But the throttling of sessions unsets it. | 440 // But the throttling of sessions unsets it. |
| 441 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), | 441 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), |
| 442 throttle_length, | 442 throttle_length, |
| 443 t0); | 443 t0); |
| 444 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 444 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 445 | 445 |
| 446 // A refresh request for bookmarks means we have reason to sync again. | 446 // A refresh request for bookmarks means we have reason to sync again. |
| 447 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS)); | 447 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS)); |
| 448 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 448 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 449 | 449 |
| 450 // A successful sync cycle means we took care of bookmarks. | 450 // A successful sync cycle means we took care of bookmarks. |
| 451 nudge_tracker_.RecordSuccessfulSyncCycle(); | 451 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 452 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); | 452 EXPECT_FALSE(nudge_tracker_.IsSyncRequired()); |
| 453 | 453 |
| 454 // But we still haven't dealt with sessions. We'll need to remember | 454 // But we still haven't dealt with sessions. We'll need to remember |
| 455 // that sessions are out of sync and re-enable the flag when their | 455 // that sessions are out of sync and re-enable the flag when their |
| 456 // throttling interval expires. | 456 // throttling interval expires. |
| 457 nudge_tracker_.UpdateTypeThrottlingState(t1); | 457 nudge_tracker_.UpdateTypeThrottlingState(t1); |
| 458 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); | 458 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); |
| 459 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); | 459 EXPECT_TRUE(nudge_tracker_.IsSyncRequired()); |
| 460 } | 460 } |
| 461 | 461 |
| 462 // Test IsGetUpdatesRequired() responds correctly to data type throttling. | 462 // Test IsGetUpdatesRequired() responds correctly to data type throttling. |
| 463 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired_Throttling) { | 463 TEST_F(NudgeTrackerTest, IsGetUpdatesRequired_Throttling) { |
| 464 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); | 464 const base::TimeTicks t0 = base::TimeTicks::FromInternalValue(1234); |
| 465 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10); | 465 const base::TimeDelta throttle_length = base::TimeDelta::FromMinutes(10); |
| 466 const base::TimeTicks t1 = t0 + throttle_length; | 466 const base::TimeTicks t1 = t0 + throttle_length; |
| 467 | 467 |
| 468 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 468 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 469 | 469 |
| 470 // A refresh request to sessions enables the flag. | 470 // A refresh request to sessions enables the flag. |
| 471 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); | 471 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(SESSIONS)); |
| 472 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 472 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 473 | 473 |
| 474 // But the throttling of sessions unsets it. | 474 // But the throttling of sessions unsets it. |
| 475 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), | 475 nudge_tracker_.SetTypesThrottledUntil(ModelTypeSet(SESSIONS), |
| 476 throttle_length, | 476 throttle_length, |
| 477 t0); | 477 t0); |
| 478 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 478 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 479 | 479 |
| 480 // A refresh request for bookmarks means we have reason to sync again. | 480 // A refresh request for bookmarks means we have reason to sync again. |
| 481 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS)); | 481 nudge_tracker_.RecordLocalRefreshRequest(ModelTypeSet(BOOKMARKS)); |
| 482 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 482 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 483 | 483 |
| 484 // A successful sync cycle means we took care of bookmarks. | 484 // A successful sync cycle means we took care of bookmarks. |
| 485 nudge_tracker_.RecordSuccessfulSyncCycle(); | 485 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 486 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); | 486 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 487 | 487 |
| 488 // But we still haven't dealt with sessions. We'll need to remember | 488 // But we still haven't dealt with sessions. We'll need to remember |
| 489 // that sessions are out of sync and re-enable the flag when their | 489 // that sessions are out of sync and re-enable the flag when their |
| 490 // throttling interval expires. | 490 // throttling interval expires. |
| 491 nudge_tracker_.UpdateTypeThrottlingState(t1); | 491 nudge_tracker_.UpdateTypeThrottlingState(t1); |
| 492 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); | 492 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); |
| 493 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); | 493 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(base::TimeTicks::Now())); |
| 494 } | 494 } |
| 495 | 495 |
| 496 // Tests throttling-related getter functions when no types are throttled. | 496 // Tests throttling-related getter functions when no types are throttled. |
| 497 TEST_F(NudgeTrackerTest, NoTypesThrottled) { | 497 TEST_F(NudgeTrackerTest, NoTypesThrottled) { |
| 498 EXPECT_FALSE(nudge_tracker_.IsAnyTypeThrottled()); | 498 EXPECT_FALSE(nudge_tracker_.IsAnyTypeThrottled()); |
| 499 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); | 499 EXPECT_FALSE(nudge_tracker_.IsTypeThrottled(SESSIONS)); |
| 500 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty()); | 500 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty()); |
| 501 } | 501 } |
| 502 | 502 |
| 503 // Tests throttling-related getter functions when some types are throttled. | 503 // Tests throttling-related getter functions when some types are throttled. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 ModelTypeSet(SESSIONS, PREFERENCES), | 559 ModelTypeSet(SESSIONS, PREFERENCES), |
| 560 nudge_tracker_.GetThrottledTypes())); | 560 nudge_tracker_.GetThrottledTypes())); |
| 561 EXPECT_EQ(throttle2_length - throttle1_length, | 561 EXPECT_EQ(throttle2_length - throttle1_length, |
| 562 nudge_tracker_.GetTimeUntilNextUnthrottle(t1)); | 562 nudge_tracker_.GetTimeUntilNextUnthrottle(t1)); |
| 563 | 563 |
| 564 // Expire the second interval. | 564 // Expire the second interval. |
| 565 nudge_tracker_.UpdateTypeThrottlingState(t2); | 565 nudge_tracker_.UpdateTypeThrottlingState(t2); |
| 566 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty()); | 566 EXPECT_TRUE(nudge_tracker_.GetThrottledTypes().Empty()); |
| 567 } | 567 } |
| 568 | 568 |
| 569 TEST_F(NudgeTrackerTest, Retry) { |
| 570 const base::TimeTicks retry_time = base::TimeTicks::FromInternalValue(12345); |
| 571 const base::TimeTicks pre_retry_time = |
| 572 retry_time - base::TimeDelta::FromSeconds(1); |
| 573 const base::TimeTicks post_retry_time = |
| 574 retry_time + base::TimeDelta::FromSeconds(1); |
| 575 nudge_tracker_.set_next_retry_time(retry_time); |
| 576 |
| 577 EXPECT_FALSE(nudge_tracker_.IsRetryRequired(pre_retry_time)); |
| 578 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired(pre_retry_time)); |
| 579 nudge_tracker_.RecordSuccessfulSyncCycle(pre_retry_time); |
| 580 |
| 581 EXPECT_TRUE(nudge_tracker_.IsRetryRequired(post_retry_time)); |
| 582 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired(post_retry_time)); |
| 583 nudge_tracker_.RecordSuccessfulSyncCycle(post_retry_time); |
| 584 EXPECT_FALSE(nudge_tracker_.IsRetryRequired( |
| 585 post_retry_time + base::TimeDelta::FromSeconds(1))); |
| 586 } |
| 587 |
| 569 class NudgeTrackerAckTrackingTest : public NudgeTrackerTest { | 588 class NudgeTrackerAckTrackingTest : public NudgeTrackerTest { |
| 570 public: | 589 public: |
| 571 NudgeTrackerAckTrackingTest() {} | 590 NudgeTrackerAckTrackingTest() {} |
| 572 | 591 |
| 573 bool IsInvalidationUnacknowledged(const syncer::Invalidation& invalidation) { | 592 bool IsInvalidationUnacknowledged(const syncer::Invalidation& invalidation) { |
| 574 // Run pending tasks before checking with the MockAckHandler. | 593 // Run pending tasks before checking with the MockAckHandler. |
| 575 // The WeakHandle may have posted some tasks for it. | 594 // The WeakHandle may have posted some tasks for it. |
| 576 base::RunLoop().RunUntilIdle(); | 595 base::RunLoop().RunUntilIdle(); |
| 577 return mock_ack_handler_.IsUnacked(invalidation); | 596 return mock_ack_handler_.IsUnacked(invalidation); |
| 578 } | 597 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // Send it to the NudgeTracker. | 639 // Send it to the NudgeTracker. |
| 621 ObjectIdInvalidationMap invalidation_map; | 640 ObjectIdInvalidationMap invalidation_map; |
| 622 invalidation_map.Insert(invalidation); | 641 invalidation_map.Insert(invalidation); |
| 623 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); | 642 nudge_tracker_.RecordRemoteInvalidation(invalidation_map); |
| 624 | 643 |
| 625 // Return it to the test framework for use in assertions. | 644 // Return it to the test framework for use in assertions. |
| 626 return invalidation; | 645 return invalidation; |
| 627 } | 646 } |
| 628 | 647 |
| 629 void RecordSuccessfulSyncCycle() { | 648 void RecordSuccessfulSyncCycle() { |
| 630 nudge_tracker_.RecordSuccessfulSyncCycle(); | 649 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); |
| 631 } | 650 } |
| 632 | 651 |
| 633 private: | 652 private: |
| 634 syncer::MockAckHandler mock_ack_handler_; | 653 syncer::MockAckHandler mock_ack_handler_; |
| 635 base::MessageLoop loop_; | 654 base::MessageLoop loop_; |
| 636 }; | 655 }; |
| 637 | 656 |
| 638 // Test the acknowledgement of a single invalidation. | 657 // Test the acknowledgement of a single invalidation. |
| 639 TEST_F(NudgeTrackerAckTrackingTest, SimpleAcknowledgement) { | 658 TEST_F(NudgeTrackerAckTrackingTest, SimpleAcknowledgement) { |
| 640 Invalidation inv = SendInvalidation(BOOKMARKS, 10, "hint"); | 659 Invalidation inv = SendInvalidation(BOOKMARKS, 10, "hint"); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 EXPECT_TRUE(IsInvalidationAcknowledged(inv2)); | 752 EXPECT_TRUE(IsInvalidationAcknowledged(inv2)); |
| 734 EXPECT_TRUE(IsInvalidationAcknowledged(inv3)); | 753 EXPECT_TRUE(IsInvalidationAcknowledged(inv3)); |
| 735 EXPECT_TRUE(IsInvalidationAcknowledged(inv4)); | 754 EXPECT_TRUE(IsInvalidationAcknowledged(inv4)); |
| 736 EXPECT_TRUE(IsInvalidationAcknowledged(inv5)); | 755 EXPECT_TRUE(IsInvalidationAcknowledged(inv5)); |
| 737 | 756 |
| 738 EXPECT_TRUE(AllInvalidationsAccountedFor()); | 757 EXPECT_TRUE(AllInvalidationsAccountedFor()); |
| 739 } | 758 } |
| 740 | 759 |
| 741 } // namespace sessions | 760 } // namespace sessions |
| 742 } // namespace syncer | 761 } // namespace syncer |
| OLD | NEW |