OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ |
6 #define CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ | 6 #define CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "chrome/browser/invalidation/invalidation_service.h" | 12 #include "chrome/browser/invalidation/invalidation_service.h" |
13 #include "sync/notifier/invalidator_registrar.h" | 13 #include "sync/notifier/invalidator_registrar.h" |
| 14 #include "sync/notifier/mock_ack_handler.h" |
| 15 |
| 16 namespace syncer { |
| 17 class Invalidation; |
| 18 } |
14 | 19 |
15 namespace invalidation { | 20 namespace invalidation { |
16 | 21 |
17 // An InvalidationService that emits invalidations only when | 22 // An InvalidationService that emits invalidations only when |
18 // its EmitInvalidationForTest method is called. | 23 // its EmitInvalidationForTest method is called. |
19 class FakeInvalidationService : public InvalidationService { | 24 class FakeInvalidationService : public InvalidationService { |
20 public: | 25 public: |
21 FakeInvalidationService(); | 26 FakeInvalidationService(); |
22 virtual ~FakeInvalidationService(); | 27 virtual ~FakeInvalidationService(); |
23 | 28 |
24 virtual void RegisterInvalidationHandler( | 29 virtual void RegisterInvalidationHandler( |
25 syncer::InvalidationHandler* handler) OVERRIDE; | 30 syncer::InvalidationHandler* handler) OVERRIDE; |
26 virtual void UpdateRegisteredInvalidationIds( | 31 virtual void UpdateRegisteredInvalidationIds( |
27 syncer::InvalidationHandler* handler, | 32 syncer::InvalidationHandler* handler, |
28 const syncer::ObjectIdSet& ids) OVERRIDE; | 33 const syncer::ObjectIdSet& ids) OVERRIDE; |
29 virtual void UnregisterInvalidationHandler( | 34 virtual void UnregisterInvalidationHandler( |
30 syncer::InvalidationHandler* handler) OVERRIDE; | 35 syncer::InvalidationHandler* handler) OVERRIDE; |
31 | 36 |
32 virtual void AcknowledgeInvalidation( | |
33 const invalidation::ObjectId& id, | |
34 const syncer::AckHandle& ack_handle) OVERRIDE; | |
35 | |
36 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 37 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
37 virtual std::string GetInvalidatorClientId() const OVERRIDE; | 38 virtual std::string GetInvalidatorClientId() const OVERRIDE; |
38 | 39 |
39 void SetInvalidatorState(syncer::InvalidatorState state); | 40 void SetInvalidatorState(syncer::InvalidatorState state); |
40 | 41 |
41 const syncer::InvalidatorRegistrar& invalidator_registrar() const { | 42 const syncer::InvalidatorRegistrar& invalidator_registrar() const { |
42 return invalidator_registrar_; | 43 return invalidator_registrar_; |
43 } | 44 } |
| 45 |
44 void EmitInvalidationForTest(const syncer::Invalidation& invalidation); | 46 void EmitInvalidationForTest(const syncer::Invalidation& invalidation); |
45 | 47 |
46 // Determines if the given AckHandle has been acknowledged. | 48 // Emitted invalidations will be hooked up to this AckHandler. Clients can |
47 bool IsInvalidationAcknowledged(const syncer::AckHandle& ack_handle) const; | 49 // query it to assert the invalidaitons are being acked properly. |
48 | 50 syncer::MockAckHandler* GetMockAckHandler(); |
49 // Determines if AcknowledgeInvalidation was ever called with an invalid | |
50 // ObjectId/AckHandle pair. | |
51 bool ReceivedInvalidAcknowledgement() { | |
52 return received_invalid_acknowledgement_; | |
53 } | |
54 | 51 |
55 private: | 52 private: |
56 std::string client_id_; | 53 std::string client_id_; |
57 syncer::InvalidatorRegistrar invalidator_registrar_; | 54 syncer::InvalidatorRegistrar invalidator_registrar_; |
58 typedef std::list<std::pair<syncer::AckHandle, invalidation::ObjectId> > | 55 syncer::MockAckHandler mock_ack_handler_; |
59 AckHandleList; | |
60 AckHandleList unacknowledged_handles_; | |
61 AckHandleList acknowledged_handles_; | |
62 bool received_invalid_acknowledgement_; | |
63 | 56 |
64 DISALLOW_COPY_AND_ASSIGN(FakeInvalidationService); | 57 DISALLOW_COPY_AND_ASSIGN(FakeInvalidationService); |
65 }; | 58 }; |
66 | 59 |
67 } // namespace invalidation | 60 } // namespace invalidation |
68 | 61 |
69 #endif // CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ | 62 #endif // CHROME_BROWSER_INVALIDATION_FAKE_INVALIDATION_SERVICE_H_ |
OLD | NEW |