component_metrics_provider_unittest.cc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2017 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/component_metrics_provider.h"
  5. #include "base/strings/utf_string_conversions.h"
  6. #include "base/version.h"
  7. #include "components/component_updater/component_updater_service.h"
  8. #include "components/component_updater/mock_component_updater_service.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. #include "third_party/metrics_proto/system_profile.pb.h"
  11. namespace metrics {
  12. using component_updater::ComponentInfo;
  13. namespace {
  14. class TestComponentMetricsProviderDelegate
  15. : public ComponentMetricsProviderDelegate {
  16. public:
  17. explicit TestComponentMetricsProviderDelegate(
  18. std::vector<ComponentInfo>& components)
  19. : components_(components) {}
  20. ~TestComponentMetricsProviderDelegate() override = default;
  21. std::vector<ComponentInfo> GetComponents() override { return components_; }
  22. private:
  23. std::vector<ComponentInfo> components_;
  24. };
  25. } // namespace
  26. class ComponentMetricsProviderTest : public testing::Test {
  27. public:
  28. ComponentMetricsProviderTest() {}
  29. ComponentMetricsProviderTest(const ComponentMetricsProviderTest&) = delete;
  30. ComponentMetricsProviderTest& operator=(const ComponentMetricsProviderTest&) =
  31. delete;
  32. ~ComponentMetricsProviderTest() override {}
  33. };
  34. TEST_F(ComponentMetricsProviderTest, ProvideComponentMetrics) {
  35. std::vector<ComponentInfo> components = {
  36. ComponentInfo(
  37. "hfnkpimlhhgieaddgfemjhofmfblmnib",
  38. "1.0846414bf2025bbc067b6fa5b61b16eda2269d8712b8fec0973b4c71fdc65ca0",
  39. u"name1", base::Version("1.2.3.4")),
  40. ComponentInfo(
  41. "oimompecagnajdejgnnjijobebaeigek",
  42. "1.adc9207a4a88ee98bf9ddf0330f35818386f1adc006bc8eee94dc59d43c0f5d6",
  43. u"name2", base::Version("5.6.7.8")),
  44. ComponentInfo(
  45. "thiscomponentfilteredfromresults",
  46. "1.b5268dc93e08d68d0be26bd8fbbb15c7b7f805cc06b4abd9d49381bc178e78cf",
  47. u"name3", base::Version("9.9.9.9"))};
  48. ComponentMetricsProvider component_provider(
  49. std::make_unique<TestComponentMetricsProviderDelegate>(components));
  50. SystemProfileProto system_profile;
  51. component_provider.ProvideSystemProfileMetrics(&system_profile);
  52. EXPECT_EQ(2, system_profile.chrome_component_size());
  53. EXPECT_EQ(SystemProfileProto_ComponentId_CRL_SET,
  54. system_profile.chrome_component(0).component_id());
  55. EXPECT_EQ("1.2.3.4", system_profile.chrome_component(0).version());
  56. EXPECT_EQ(138821963u, system_profile.chrome_component(0).omaha_fingerprint());
  57. EXPECT_EQ(SystemProfileProto_ComponentId_WIDEVINE_CDM,
  58. system_profile.chrome_component(1).component_id());
  59. EXPECT_EQ("5.6.7.8", system_profile.chrome_component(1).version());
  60. EXPECT_EQ(2915639418u,
  61. system_profile.chrome_component(1).omaha_fingerprint());
  62. }
  63. } // namespace metrics