blob: 125a49c2a4dfa6796b7864ca05930cbabcb9a688 [file] [log] [blame]
Ahmed Nasrab0e5822021-11-10 22:29:051// 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
5#include "components/reporting/metrics/fake_sampler.h"
6
Ahmed Nasr27cd9f4e2021-11-12 22:49:407#include <utility>
8
9#include "base/location.h"
10#include "base/run_loop.h"
11#include "base/threading/sequenced_task_runner_handle.h"
12#include "testing/gtest/include/gtest/gtest.h"
13
Ahmed Nasrab0e5822021-11-10 22:29:0514namespace reporting {
15namespace test {
16
17void FakeSampler::Collect(MetricCallback cb) {
18 num_calls_++;
19 std::move(cb).Run(std::move(metric_data_));
20}
21
22void FakeSampler::SetMetricData(MetricData metric_data) {
23 metric_data_ = std::move(metric_data);
24}
25
26int FakeSampler::GetNumCollectCalls() const {
27 return num_calls_;
28}
Ahmed Nasr27cd9f4e2021-11-12 22:49:4029
30FakeMetricEventObserver::FakeMetricEventObserver() = default;
31
32FakeMetricEventObserver::~FakeMetricEventObserver() = default;
33
34void FakeMetricEventObserver::SetOnEventObservedCallback(
35 MetricRepeatingCallback cb) {
36 EXPECT_FALSE(cb_);
37 cb_ = std::move(cb);
38}
39
40void FakeMetricEventObserver::SetReportingEnabled(bool is_enabled) {
41 is_reporting_enabled_ = is_enabled;
42}
43
44void FakeMetricEventObserver::RunCallback(MetricData metric_data) {
45 base::RunLoop run_loop;
46 cb_.Run(std::move(metric_data));
47 base::SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE,
48 run_loop.QuitClosure());
49 run_loop.Run();
50}
51
52bool FakeMetricEventObserver::GetReportingEnabled() const {
53 return is_reporting_enabled_;
54}
Ahmed Nasrab0e5822021-11-10 22:29:0555} // namespace test
56} // namespace reporting