Move fake metric reporting classes to their own dir.
Trying to have better organization as number of files is increasing.
Bug: b:257068745
Change-Id: If82f5a650ead4158326bbf1ce2a101bef147c75f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4000302
Reviewed-by: Leonid Baraz <[email protected]>
Commit-Queue: Ahmed Nasr <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1066665}
diff --git a/components/reporting/metrics/fakes/fake_sampler.cc b/components/reporting/metrics/fakes/fake_sampler.cc
new file mode 100644
index 0000000..638337a7
--- /dev/null
+++ b/components/reporting/metrics/fakes/fake_sampler.cc
@@ -0,0 +1,75 @@
+// 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.
+
+#include "components/reporting/metrics/fakes/fake_sampler.h"
+
+#include <utility>
+
+#include "base/check.h"
+#include "base/location.h"
+#include "base/run_loop.h"
+#include "base/threading/sequenced_task_runner_handle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace reporting {
+namespace test {
+
+FakeSampler::FakeSampler() = default;
+
+FakeSampler::~FakeSampler() = default;
+
+void FakeSampler::MaybeCollect(OptionalMetricCallback cb) {
+ ++num_calls_;
+ std::move(cb).Run(metric_data_);
+}
+
+void FakeSampler::SetMetricData(absl::optional<MetricData> metric_data) {
+ metric_data_ = std::move(metric_data);
+}
+
+int FakeSampler::GetNumCollectCalls() const {
+ return num_calls_;
+}
+
+FakeDelayedSampler::FakeDelayedSampler() = default;
+
+FakeDelayedSampler::~FakeDelayedSampler() = default;
+
+void FakeDelayedSampler::MaybeCollect(OptionalMetricCallback cb) {
+ ++num_calls_;
+ cb_ = std::move(cb);
+}
+
+void FakeDelayedSampler::RunCallback() {
+ DCHECK(cb_);
+ std::move(cb_).Run(metric_data_);
+}
+
+FakeMetricEventObserver::FakeMetricEventObserver() = default;
+
+FakeMetricEventObserver::~FakeMetricEventObserver() = default;
+
+void FakeMetricEventObserver::SetOnEventObservedCallback(
+ MetricRepeatingCallback cb) {
+ EXPECT_FALSE(cb_);
+ cb_ = std::move(cb);
+}
+
+void FakeMetricEventObserver::SetReportingEnabled(bool is_enabled) {
+ is_reporting_enabled_ = is_enabled;
+}
+
+void FakeMetricEventObserver::RunCallback(MetricData metric_data) {
+ base::RunLoop run_loop;
+ cb_.Run(std::move(metric_data));
+ base::SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ run_loop.QuitClosure());
+ run_loop.Run();
+}
+
+bool FakeMetricEventObserver::GetReportingEnabled() const {
+ return is_reporting_enabled_;
+}
+} // namespace test
+} // namespace reporting