| 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/sessions/nudge_tracker.h" | 8 #include "sync/sessions/nudge_tracker.h" |
| 9 #include "sync/test/mock_invalidation.h" | 9 #include "sync/test/mock_invalidation.h" |
| 10 #include "sync/test/mock_invalidation_tracker.h" | 10 #include "sync/test/mock_invalidation_tracker.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 | 61 |
| 62 void SetInvalidationsInSync() { | 62 void SetInvalidationsInSync() { |
| 63 nudge_tracker_.OnInvalidationsEnabled(); | 63 nudge_tracker_.OnInvalidationsEnabled(); |
| 64 nudge_tracker_.RecordSuccessfulSyncCycle(); | 64 nudge_tracker_.RecordSuccessfulSyncCycle(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 scoped_ptr<InvalidationInterface> BuildInvalidation( | 67 scoped_ptr<InvalidationInterface> BuildInvalidation( |
| 68 int64 version, | 68 int64 version, |
| 69 const std::string& payload) { | 69 const std::string& payload) { |
| 70 return MockInvalidation::Build(version, payload) | 70 return MockInvalidation::Build(version, payload); |
| 71 .PassAs<InvalidationInterface>(); | |
| 72 } | 71 } |
| 73 | 72 |
| 74 static scoped_ptr<InvalidationInterface> BuildUnknownVersionInvalidation() { | 73 static scoped_ptr<InvalidationInterface> BuildUnknownVersionInvalidation() { |
| 75 return MockInvalidation::BuildUnknownVersion() | 74 return MockInvalidation::BuildUnknownVersion(); |
| 76 .PassAs<InvalidationInterface>(); | |
| 77 } | 75 } |
| 78 | 76 |
| 79 protected: | 77 protected: |
| 80 NudgeTracker nudge_tracker_; | 78 NudgeTracker nudge_tracker_; |
| 81 }; | 79 }; |
| 82 | 80 |
| 83 // Exercise an empty NudgeTracker. | 81 // Exercise an empty NudgeTracker. |
| 84 // Use with valgrind to detect uninitialized members. | 82 // Use with valgrind to detect uninitialized members. |
| 85 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) { | 83 TEST_F(NudgeTrackerTest, EmptyNudgeTracker) { |
| 86 // Now we're at the normal, "idle" state. | 84 // Now we're at the normal, "idle" state. |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 return tracker_.IsDropped(tracking_id); | 821 return tracker_.IsDropped(tracking_id); |
| 824 } | 822 } |
| 825 | 823 |
| 826 int SendInvalidation(ModelType type, int version, const std::string& hint) { | 824 int SendInvalidation(ModelType type, int version, const std::string& hint) { |
| 827 // Build and register the invalidation. | 825 // Build and register the invalidation. |
| 828 scoped_ptr<TrackableMockInvalidation> inv = | 826 scoped_ptr<TrackableMockInvalidation> inv = |
| 829 tracker_.IssueInvalidation(version, hint); | 827 tracker_.IssueInvalidation(version, hint); |
| 830 int id = inv->GetTrackingId(); | 828 int id = inv->GetTrackingId(); |
| 831 | 829 |
| 832 // Send it to the NudgeTracker. | 830 // Send it to the NudgeTracker. |
| 833 nudge_tracker_.RecordRemoteInvalidation( | 831 nudge_tracker_.RecordRemoteInvalidation(type, inv.Pass()); |
| 834 type, inv.PassAs<InvalidationInterface>()); | |
| 835 | 832 |
| 836 // Return its ID to the test framework for use in assertions. | 833 // Return its ID to the test framework for use in assertions. |
| 837 return id; | 834 return id; |
| 838 } | 835 } |
| 839 | 836 |
| 840 int SendUnknownVersionInvalidation(ModelType type) { | 837 int SendUnknownVersionInvalidation(ModelType type) { |
| 841 // Build and register the invalidation. | 838 // Build and register the invalidation. |
| 842 scoped_ptr<TrackableMockInvalidation> inv = | 839 scoped_ptr<TrackableMockInvalidation> inv = |
| 843 tracker_.IssueUnknownVersionInvalidation(); | 840 tracker_.IssueUnknownVersionInvalidation(); |
| 844 int id = inv->GetTrackingId(); | 841 int id = inv->GetTrackingId(); |
| 845 | 842 |
| 846 // Send it to the NudgeTracker. | 843 // Send it to the NudgeTracker. |
| 847 nudge_tracker_.RecordRemoteInvalidation( | 844 nudge_tracker_.RecordRemoteInvalidation(type, inv.Pass()); |
| 848 type, inv.PassAs<InvalidationInterface>()); | |
| 849 | 845 |
| 850 // Return its ID to the test framework for use in assertions. | 846 // Return its ID to the test framework for use in assertions. |
| 851 return id; | 847 return id; |
| 852 } | 848 } |
| 853 | 849 |
| 854 bool AllInvalidationsAccountedFor() const { | 850 bool AllInvalidationsAccountedFor() const { |
| 855 return tracker_.AllInvalidationsAccountedFor(); | 851 return tracker_.AllInvalidationsAccountedFor(); |
| 856 } | 852 } |
| 857 | 853 |
| 858 void RecordSuccessfulSyncCycle() { | 854 void RecordSuccessfulSyncCycle() { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 EXPECT_TRUE(IsInvalidationAcknowledged(inv2_id)); | 959 EXPECT_TRUE(IsInvalidationAcknowledged(inv2_id)); |
| 964 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id)); | 960 EXPECT_TRUE(IsInvalidationAcknowledged(inv3_id)); |
| 965 EXPECT_TRUE(IsInvalidationAcknowledged(inv4_id)); | 961 EXPECT_TRUE(IsInvalidationAcknowledged(inv4_id)); |
| 966 EXPECT_TRUE(IsInvalidationAcknowledged(inv5_id)); | 962 EXPECT_TRUE(IsInvalidationAcknowledged(inv5_id)); |
| 967 | 963 |
| 968 EXPECT_TRUE(AllInvalidationsAccountedFor()); | 964 EXPECT_TRUE(AllInvalidationsAccountedFor()); |
| 969 } | 965 } |
| 970 | 966 |
| 971 } // namespace sessions | 967 } // namespace sessions |
| 972 } // namespace syncer | 968 } // namespace syncer |
| OLD | NEW |