[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / metrics / gms_metrics_provider_unittest.cc
1 // Copyright 2023 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/gms_metrics_provider.h"
6
7 #include "base/android/build_info.h"
8 #include "base/test/metrics/histogram_tester.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace metrics {
12 namespace {
13
14 // Same as GmsMetricsProvider but Gms version is mocked for easy testing.
15 class MockedGmsMetricsProvider : public GmsMetricsProvider {
16  public:
17   void SetGmsVersionForTesting(const std::string& version) {
18     version_ = version;
19   }
20
21  private:
22   // GmsMetricsProvider.
23   std::string GetGMSVersion() override { return version_; }
24
25   std::string version_;
26 };
27
28 }  // namespace
29
30 class GmsMetricsProviderTest : public testing::Test {
31  protected:
32   GmsMetricsProviderTest() = default;
33
34   base::HistogramTester& histogram_tester() { return histogram_tester_; }
35   MockedGmsMetricsProvider& gms_metrics_provider() {
36     return gms_metrics_provider_;
37   }
38
39  private:
40   base::HistogramTester histogram_tester_;
41   MockedGmsMetricsProvider gms_metrics_provider_;
42 };
43
44 TEST_F(GmsMetricsProviderTest, TestMetricsReportedCorrectly) {
45   gms_metrics_provider().SetGmsVersionForTesting("234012000");
46   gms_metrics_provider().ProvideHistograms();
47
48   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
49                                         /*sample=*/23401,
50                                         /*expected_bucket_count=*/1);
51
52   gms_metrics_provider().SetGmsVersionForTesting("234016000");
53   gms_metrics_provider().ProvideHistograms();
54
55   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
56                                         /*sample=*/23401,
57                                         /*expected_bucket_count=*/2);
58
59   gms_metrics_provider().SetGmsVersionForTesting("234082000");
60   gms_metrics_provider().ProvideHistograms();
61
62   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
63                                         /*sample=*/23401,
64                                         /*expected_bucket_count=*/3);
65 }
66
67 TEST_F(GmsMetricsProviderTest, TestMetricsReportedCorrectlyForBeta) {
68   gms_metrics_provider().SetGmsVersionForTesting("234002000");
69   gms_metrics_provider().ProvideHistograms();
70
71   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
72                                         /*sample=*/23400,
73                                         /*expected_bucket_count=*/1);
74
75   gms_metrics_provider().SetGmsVersionForTesting("234008000");
76   gms_metrics_provider().ProvideHistograms();
77
78   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
79                                         /*sample=*/23400,
80                                         /*expected_bucket_count=*/2);
81
82   gms_metrics_provider().SetGmsVersionForTesting("234010000");
83   gms_metrics_provider().ProvideHistograms();
84
85   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
86                                         /*sample=*/23400,
87                                         /*expected_bucket_count=*/3);
88 }
89
90 TEST_F(GmsMetricsProviderTest, TestGMSNotInstalled) {
91   gms_metrics_provider().SetGmsVersionForTesting("0");
92   gms_metrics_provider().ProvideHistograms();
93
94   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
95                                         /*sample=*/0,
96                                         /*expected_bucket_count=*/1);
97 }
98
99 TEST_F(GmsMetricsProviderTest, TestGMSVersionInvalid) {
100   gms_metrics_provider().SetGmsVersionForTesting("aaaa");
101   gms_metrics_provider().ProvideHistograms();
102
103   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
104                                         /*sample=*/1,
105                                         /*expected_bucket_count=*/1);
106 }
107
108 TEST_F(GmsMetricsProviderTest, TestGMSVersionOutOfRange) {
109   gms_metrics_provider().SetGmsVersionForTesting("11111");
110   gms_metrics_provider().ProvideHistograms();
111
112   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
113                                         /*sample=*/2,
114                                         /*expected_bucket_count=*/1);
115
116   gms_metrics_provider().SetGmsVersionForTesting("999999999");
117   gms_metrics_provider().ProvideHistograms();
118
119   histogram_tester().ExpectUniqueSample("Android.PlayServices.ShortVersion",
120                                         /*sample=*/2,
121                                         /*expected_bucket_count=*/2);
122 }
123
124 }  // namespace metrics