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

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

Issue 2938013002: Persist core system profile during startup. (Closed)
Patch Set: added test Created 3 years, 6 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/persistent_system_profile.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/metrics/persistent_system_profile.h" 5 #include "components/metrics/persistent_system_profile.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/persistent_memory_allocator.h" 9 #include "base/metrics/persistent_memory_allocator.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 for (size_t i = 0; i < kRecordSize; ++i) 84 for (size_t i = 0; i < kRecordSize; ++i)
85 EXPECT_EQ(buffer[i], record[i]); 85 EXPECT_EQ(buffer[i], record[i]);
86 } 86 }
87 87
88 TEST_F(PersistentSystemProfileTest, ProfileStorage) { 88 TEST_F(PersistentSystemProfileTest, ProfileStorage) {
89 SystemProfileProto proto1; 89 SystemProfileProto proto1;
90 SystemProfileProto::FieldTrial* trial = proto1.add_field_trial(); 90 SystemProfileProto::FieldTrial* trial = proto1.add_field_trial();
91 trial->set_name_id(123); 91 trial->set_name_id(123);
92 trial->set_group_id(456); 92 trial->set_group_id(456);
93 93
94 persistent_profile()->SetSystemProfile(proto1); 94 persistent_profile()->SetSystemProfile(proto1, false);
95 95
96 SystemProfileProto proto2; 96 SystemProfileProto proto2;
97 ASSERT_TRUE(PersistentSystemProfile::HasSystemProfile(*memory_allocator())); 97 ASSERT_TRUE(PersistentSystemProfile::HasSystemProfile(*memory_allocator()));
98 ASSERT_TRUE( 98 ASSERT_TRUE(
99 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2)); 99 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2));
100 ASSERT_EQ(1, proto2.field_trial_size()); 100 ASSERT_EQ(1, proto2.field_trial_size());
101 EXPECT_EQ(123U, proto2.field_trial(0).name_id()); 101 EXPECT_EQ(123U, proto2.field_trial(0).name_id());
102 EXPECT_EQ(456U, proto2.field_trial(0).group_id()); 102 EXPECT_EQ(456U, proto2.field_trial(0).group_id());
103 103
104 // Check that the profile can be overwritten. 104 // Check that the profile can be overwritten.
105 105
106 trial = proto1.add_field_trial(); 106 trial = proto1.add_field_trial();
107 trial->set_name_id(78); 107 trial->set_name_id(78);
108 trial->set_group_id(90); 108 trial->set_group_id(90);
109 109
110 persistent_profile()->SetSystemProfile(proto1); 110 persistent_profile()->SetSystemProfile(proto1, true);
111 111
112 ASSERT_TRUE( 112 ASSERT_TRUE(
113 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2)); 113 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2));
114 ASSERT_EQ(2, proto2.field_trial_size());
115 EXPECT_EQ(123U, proto2.field_trial(0).name_id());
116 EXPECT_EQ(456U, proto2.field_trial(0).group_id());
117 EXPECT_EQ(78U, proto2.field_trial(1).name_id());
118 EXPECT_EQ(90U, proto2.field_trial(1).group_id());
119
120 // Check that the profile won't be overwritten by a new non-complete profile.
121
122 trial = proto1.add_field_trial();
123 trial->set_name_id(0xC0DE);
124 trial->set_group_id(0xFEED);
125
126 persistent_profile()->SetSystemProfile(proto1, false);
127
128 ASSERT_TRUE(
129 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2));
114 ASSERT_EQ(2, proto2.field_trial_size()); 130 ASSERT_EQ(2, proto2.field_trial_size());
115 EXPECT_EQ(123U, proto2.field_trial(0).name_id()); 131 EXPECT_EQ(123U, proto2.field_trial(0).name_id());
116 EXPECT_EQ(456U, proto2.field_trial(0).group_id()); 132 EXPECT_EQ(456U, proto2.field_trial(0).group_id());
117 EXPECT_EQ(78U, proto2.field_trial(1).name_id()); 133 EXPECT_EQ(78U, proto2.field_trial(1).name_id());
118 EXPECT_EQ(90U, proto2.field_trial(1).group_id()); 134 EXPECT_EQ(90U, proto2.field_trial(1).group_id());
119 } 135 }
120 136
121 } // namespace metrics 137 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/persistent_system_profile.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698