mock_report_queue_provider.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_PROVIDER_H_
  5. #define COMPONENTS_REPORTING_CLIENT_MOCK_REPORT_QUEUE_PROVIDER_H_
  6. #include <memory>
  7. #include "base/sequence_checker.h"
  8. #include "base/task/sequenced_task_runner.h"
  9. #include "components/reporting/client/report_queue.h"
  10. #include "components/reporting/client/report_queue_configuration.h"
  11. #include "components/reporting/client/report_queue_provider.h"
  12. #include "testing/gmock/include/gmock/gmock.h"
  13. namespace reporting {
  14. class MockReportQueueProvider : public ReportQueueProvider {
  15. public:
  16. MockReportQueueProvider();
  17. MockReportQueueProvider(const MockReportQueueProvider&) = delete;
  18. MockReportQueueProvider& operator=(const MockReportQueueProvider&) = delete;
  19. ~MockReportQueueProvider() override;
  20. // This method will make sure - by mocking - that CreateQueue on the provider
  21. // always returns a new std::unique_ptr<MockReportQueue> to simulate the
  22. // original behaviour. Note times is also added to be expected so you should
  23. // know how often you expect this method to be called.
  24. void ExpectCreateNewQueueAndReturnNewMockQueue(size_t times);
  25. // This method will make sure - by mocking - that CreateNewSpeculativeQueue on
  26. // the provider always returns a new std::unique_ptr<MockReportQueue,
  27. // base::OnTaskRunnerDeleter> on a sequenced task runner to simulate the
  28. // original behaviour. Note times is also added to be expected so you should
  29. // know how often you expect this method to be called.
  30. void ExpectCreateNewSpeculativeQueueAndReturnNewMockQueue(size_t times);
  31. // The following mocks will be invoked on the same thread
  32. // MockReportQueueProvider was constructed on.
  33. MOCK_METHOD(void,
  34. CreateNewQueueMock,
  35. (std::unique_ptr<ReportQueueConfiguration> config,
  36. CreateReportQueueCallback cb),
  37. ());
  38. MOCK_METHOD(
  39. (StatusOr<std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter>>),
  40. CreateNewSpeculativeQueueMock,
  41. (),
  42. ());
  43. MOCK_METHOD(void, OnInitCompletedMock, (), ());
  44. MOCK_METHOD(void,
  45. ConfigureReportQueueMock,
  46. (std::unique_ptr<ReportQueueConfiguration> configuration,
  47. ReportQueueProvider::ReportQueueConfiguredCallback callback),
  48. ());
  49. void CheckOnThread() const;
  50. private:
  51. // Implementations of ReportQueueProvider virtual methods.
  52. void OnInitCompleted() override;
  53. void CreateNewQueue(std::unique_ptr<ReportQueueConfiguration> config,
  54. CreateReportQueueCallback cb) override;
  55. StatusOr<std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter>>
  56. CreateNewSpeculativeQueue() override;
  57. void ConfigureReportQueue(
  58. std::unique_ptr<ReportQueueConfiguration> report_queue_config,
  59. ReportQueueConfiguredCallback completion_cb) override;
  60. scoped_refptr<StorageModuleInterface> storage_;
  61. const scoped_refptr<base::SequencedTaskRunner> test_sequenced_task_runner_;
  62. SEQUENCE_CHECKER(test_sequence_checker_);
  63. };
  64. } // namespace reporting
  65. #endif // COMPONENTS_REPORTING_CLIENT_MOCK_REPORT_QUEUE_PROVIDER_H_