mock_report_queue.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2021 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_REPORTING_CLIENT_MOCK_REPORT_QUEUE_H_
  5. #define COMPONENTS_REPORTING_CLIENT_MOCK_REPORT_QUEUE_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback.h"
  9. #include "components/reporting/client/report_queue.h"
  10. #include "components/reporting/proto/synced/record.pb.h"
  11. #include "components/reporting/proto/synced/record_constants.pb.h"
  12. #include "components/reporting/util/status.h"
  13. #include "testing/gmock/include/gmock/gmock.h"
  14. #include "third_party/protobuf/src/google/protobuf/message_lite.h"
  15. namespace reporting {
  16. // A mock of ReportQueue for use in testing.
  17. class MockReportQueueStrict : public ReportQueue {
  18. public:
  19. MockReportQueueStrict();
  20. ~MockReportQueueStrict() override;
  21. // Mock AddRecord with record producer.
  22. // Rarely used, by default calls plain-text AddRecord.
  23. MOCK_METHOD(void,
  24. AddProducedRecord,
  25. (RecordProducer, Priority, EnqueueCallback),
  26. (const override));
  27. MOCK_METHOD(void,
  28. AddRecord,
  29. (std::string, Priority, EnqueueCallback),
  30. (const));
  31. MOCK_METHOD(void, Flush, (Priority, FlushCallback), (override));
  32. MOCK_METHOD(
  33. (base::OnceCallback<void(StatusOr<std::unique_ptr<ReportQueue>>)>),
  34. PrepareToAttachActualQueue,
  35. (),
  36. (const override));
  37. private:
  38. // Helper method that executes |record_producer| and in case of success
  39. // forwards the result to |AddRecord|. In case of failure passes Status to
  40. // |callback|.
  41. void ForwardProducedRecord(RecordProducer record_producer,
  42. Priority priority,
  43. EnqueueCallback callback);
  44. };
  45. // Most of the time no need to log uninterested calls.
  46. typedef ::testing::NiceMock<MockReportQueueStrict> MockReportQueue;
  47. } // namespace reporting
  48. #endif // COMPONENTS_REPORTING_CLIENT_MOCK_REPORT_QUEUE_H_