xref: /aosp_15_r20/external/cronet/components/metrics/ui/form_factor_metrics_provider_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2022 The Chromium Authors
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/metrics/ui/form_factor_metrics_provider.h"
6 
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/metrics_proto/system_profile.pb.h"
9 
10 namespace metrics {
11 namespace {
12 
13 constexpr SystemProfileProto::Hardware::FormFactor kFormFactor =
14     SystemProfileProto::Hardware::FORM_FACTOR_DESKTOP;
15 
16 class TestFormFactorMetricsProvider : public FormFactorMetricsProvider {
17  public:
18   TestFormFactorMetricsProvider() = default;
19 
20   TestFormFactorMetricsProvider(const TestFormFactorMetricsProvider&) = delete;
21   TestFormFactorMetricsProvider& operator=(
22       const TestFormFactorMetricsProvider&) = delete;
23 
24   ~TestFormFactorMetricsProvider() override = default;
25 
26  private:
GetFormFactor() const27   SystemProfileProto::Hardware::FormFactor GetFormFactor() const override {
28     return kFormFactor;
29   }
30 };
31 
32 }  // namespace
33 
TEST(FormFactorMetricsProviderTest,ProvideSystemProfileMetrics)34 TEST(FormFactorMetricsProviderTest, ProvideSystemProfileMetrics) {
35   TestFormFactorMetricsProvider provider;
36   SystemProfileProto system_profile;
37 
38   provider.ProvideSystemProfileMetrics(&system_profile);
39 
40   // Verify that the system profile has the form factor set.
41   const SystemProfileProto::Hardware& hardware = system_profile.hardware();
42   ASSERT_TRUE(hardware.has_form_factor());
43   EXPECT_EQ(kFormFactor, hardware.form_factor());
44 }
45 
46 }  // namespace metrics
47