form_factor_metrics_provider_unittest.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2022 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. #include "components/metrics/form_factor_metrics_provider.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. #include "third_party/metrics_proto/system_profile.pb.h"
  7. namespace metrics {
  8. namespace {
  9. constexpr SystemProfileProto::Hardware::FormFactor kFormFactor =
  10. SystemProfileProto::Hardware::FORM_FACTOR_DESKTOP;
  11. class TestFormFactorMetricsProvider : public FormFactorMetricsProvider {
  12. public:
  13. TestFormFactorMetricsProvider() = default;
  14. TestFormFactorMetricsProvider(const TestFormFactorMetricsProvider&) = delete;
  15. TestFormFactorMetricsProvider& operator=(
  16. const TestFormFactorMetricsProvider&) = delete;
  17. ~TestFormFactorMetricsProvider() override = default;
  18. private:
  19. SystemProfileProto::Hardware::FormFactor GetFormFactor() const override {
  20. return kFormFactor;
  21. }
  22. };
  23. } // namespace
  24. TEST(FormFactorMetricsProviderTest, ProvideSystemProfileMetrics) {
  25. TestFormFactorMetricsProvider provider;
  26. SystemProfileProto system_profile;
  27. provider.ProvideSystemProfileMetrics(&system_profile);
  28. // Verify that the system profile has the form factor set.
  29. const SystemProfileProto::Hardware& hardware = system_profile.hardware();
  30. ASSERT_TRUE(hardware.has_form_factor());
  31. EXPECT_EQ(kFormFactor, hardware.form_factor());
  32. }
  33. } // namespace metrics