xref: /aosp_15_r20/external/cronet/components/metrics/entropy_state_provider_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2020 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/entropy_state_provider.h"
6 
7 #include "components/metrics/metrics_pref_names.h"
8 #include "components/metrics/metrics_service.h"
9 #include "components/prefs/testing_pref_service.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/metrics_proto/system_profile.pb.h"
12 
13 namespace metrics {
14 
15 class EntropyStateProviderTest : public testing::Test {
16  public:
EntropyStateProviderTest()17   EntropyStateProviderTest() {
18     MetricsService::RegisterPrefs(prefs_.registry());
19   }
20 
21   EntropyStateProviderTest(const EntropyStateProviderTest&) = delete;
22   EntropyStateProviderTest& operator=(const EntropyStateProviderTest&) = delete;
23 
24  protected:
25   TestingPrefServiceSimple prefs_;
26 };
27 
TEST_F(EntropyStateProviderTest,PopulateAllLowEntropySources)28 TEST_F(EntropyStateProviderTest, PopulateAllLowEntropySources) {
29   const int new_low_source = 1234;
30   const int old_low_source = 5678;
31   const int pseudo_low_source = 4321;
32   prefs_.SetInteger(prefs::kMetricsLowEntropySource, new_low_source);
33   prefs_.SetInteger(prefs::kMetricsOldLowEntropySource, old_low_source);
34   prefs_.SetInteger(prefs::kMetricsPseudoLowEntropySource, pseudo_low_source);
35 
36   EntropyStateProvider provider(&prefs_);
37   SystemProfileProto system_profile;
38 
39   provider.ProvideSystemProfileMetrics(&system_profile);
40 
41   EXPECT_EQ(new_low_source, system_profile.low_entropy_source());
42   EXPECT_EQ(old_low_source, system_profile.old_low_entropy_source());
43   EXPECT_EQ(pseudo_low_source, system_profile.pseudo_low_entropy_source());
44 }
45 
46 }  // namespace metrics
47