fake_invalidation_service.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_INVALIDATION_IMPL_FAKE_INVALIDATION_SERVICE_H_
  5. #define COMPONENTS_INVALIDATION_IMPL_FAKE_INVALIDATION_SERVICE_H_
  6. #include <memory>
  7. #include <utility>
  8. #include "base/callback_forward.h"
  9. #include "components/invalidation/impl/fake_ack_handler.h"
  10. #include "components/invalidation/impl/invalidator_registrar_with_memory.h"
  11. #include "components/invalidation/public/invalidation_service.h"
  12. #include "components/prefs/testing_pref_service.h"
  13. namespace invalidation {
  14. class Invalidation;
  15. class InvalidationLogger;
  16. // An InvalidationService that emits invalidations only when
  17. // its EmitInvalidationForTest method is called.
  18. class FakeInvalidationService : public InvalidationService {
  19. public:
  20. FakeInvalidationService();
  21. FakeInvalidationService(const FakeInvalidationService& other) = delete;
  22. FakeInvalidationService& operator=(const FakeInvalidationService& other) =
  23. delete;
  24. ~FakeInvalidationService() override;
  25. void RegisterInvalidationHandler(InvalidationHandler* handler) override;
  26. bool UpdateInterestedTopics(InvalidationHandler* handler,
  27. const TopicSet& topics) override;
  28. void UnsubscribeFromUnregisteredTopics(InvalidationHandler* handler) override;
  29. void UnregisterInvalidationHandler(InvalidationHandler* handler) override;
  30. InvalidatorState GetInvalidatorState() const override;
  31. std::string GetInvalidatorClientId() const override;
  32. InvalidationLogger* GetInvalidationLogger() override;
  33. void RequestDetailedStatus(
  34. base::RepeatingCallback<void(base::Value::Dict)> caller) const override;
  35. void SetInvalidatorState(InvalidatorState state);
  36. const InvalidatorRegistrarWithMemory& invalidator_registrar() const {
  37. return *invalidator_registrar_;
  38. }
  39. void EmitInvalidationForTest(const Invalidation& invalidation);
  40. // Emitted invalidations will be hooked up to this AckHandler. Clients can
  41. // query it to assert the invalidaitons are being acked properly.
  42. FakeAckHandler* GetFakeAckHandler();
  43. private:
  44. std::string client_id_;
  45. // |pref_service_| must outlive |invalidator_registrar_|.
  46. TestingPrefServiceSimple pref_service_;
  47. std::unique_ptr<InvalidatorRegistrarWithMemory> invalidator_registrar_;
  48. FakeAckHandler fake_ack_handler_;
  49. };
  50. } // namespace invalidation
  51. #endif // COMPONENTS_INVALIDATION_IMPL_FAKE_INVALIDATION_SERVICE_H_