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.
5 #include "components/metrics/entropy_state_provider.h"
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"
15 class EntropyStateProviderTest : public testing::Test {
17 EntropyStateProviderTest() {
18 MetricsService::RegisterPrefs(prefs_.registry());
21 EntropyStateProviderTest(const EntropyStateProviderTest&) = delete;
22 EntropyStateProviderTest& operator=(const EntropyStateProviderTest&) = delete;
25 TestingPrefServiceSimple prefs_;
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);
36 EntropyStateProvider provider(&prefs_);
37 SystemProfileProto system_profile;
39 provider.ProvideSystemProfileMetrics(&system_profile);
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());
46 } // namespace metrics