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