Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: components/metrics/environment_recorder_unittest.cc

Issue 2687393004: Gather stability prefs into managing objects. (Closed)
Patch Set: Incorporate Feedback Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/metrics/environment_recorder.cc ('k') | components/metrics/metrics_log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
5 #include "components/metrics/environment_recorder.h"
6
7 #include "components/metrics/metrics_pref_names.h"
8 #include "components/metrics/proto/system_profile.pb.h"
9 #include "components/prefs/testing_pref_service.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace metrics {
13
14 class EnvironmentRecorderTest : public testing::Test {
15 public:
16 EnvironmentRecorderTest() {
17 EnvironmentRecorder::RegisterPrefs(prefs_.registry());
18 }
19
20 ~EnvironmentRecorderTest() override {}
21
22 protected:
23 TestingPrefServiceSimple prefs_;
24
25 private:
26 DISALLOW_COPY_AND_ASSIGN(EnvironmentRecorderTest);
27 };
28
29 TEST_F(EnvironmentRecorderTest, LoadEnvironmentFromPrefs) {
30 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile;
31 const char* kSystemProfileHashPref = prefs::kStabilitySavedSystemProfileHash;
32
33 // The pref value is empty, so loading it from prefs should fail.
34 {
35 EnvironmentRecorder recorder(&prefs_);
36 SystemProfileProto system_profile;
37 EXPECT_FALSE(recorder.LoadEnvironmentFromPrefs(&system_profile));
38 EXPECT_FALSE(system_profile.has_app_version());
39 }
40
41 // Do a RecordEnvironment() call and check whether the pref is recorded.
42 {
43 EnvironmentRecorder recorder(&prefs_);
44 SystemProfileProto system_profile;
45 system_profile.set_app_version("bogus version");
46 std::string serialized_profile =
47 recorder.SerializeAndRecordEnvironmentToPrefs(system_profile);
48 EXPECT_FALSE(serialized_profile.empty());
49 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty());
50 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty());
51 }
52
53 // Load it and check that it has the right value.
54 {
55 EnvironmentRecorder recorder(&prefs_);
56 SystemProfileProto system_profile;
57 EXPECT_TRUE(recorder.LoadEnvironmentFromPrefs(&system_profile));
58 EXPECT_EQ("bogus version", system_profile.app_version());
59 // Ensure that the call did not clear the prefs.
60 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty());
61 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty());
62 }
63
64 // Ensure that a non-matching hash results in the pref being invalid.
65 {
66 // Set the hash to a bad value.
67 prefs_.SetString(kSystemProfileHashPref, "deadbeef");
68 EnvironmentRecorder recorder(&prefs_);
69 SystemProfileProto system_profile;
70 EXPECT_FALSE(recorder.LoadEnvironmentFromPrefs(&system_profile));
71 EXPECT_FALSE(system_profile.has_app_version());
72 }
73 }
74
75 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/environment_recorder.cc ('k') | components/metrics/metrics_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698