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

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

Issue 2918533003: Send metrics with embedded system profiles after system startup. (Closed)
Patch Set: fixed tests on mac 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
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 std::string serialized_proto; 94 persistent_profile()->SetSystemProfile(proto1);
Alexei Svitkine (slow) 2017/06/08 23:59:31 Nit: Name the new function that takes the proto Se
bcwhite 2017/06/09 15:09:28 It's setting a "profile", not a "profile proto" so
95 ASSERT_TRUE(proto1.SerializeToString(&serialized_proto));
96 persistent_profile()->SetSystemProfile(serialized_proto);
97 95
98 SystemProfileProto proto2; 96 SystemProfileProto proto2;
97 ASSERT_TRUE(PersistentSystemProfile::HasSystemProfile(*memory_allocator()));
99 ASSERT_TRUE( 98 ASSERT_TRUE(
100 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2)); 99 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2));
101 ASSERT_EQ(1, proto2.field_trial_size()); 100 ASSERT_EQ(1, proto2.field_trial_size());
102 EXPECT_EQ(123U, proto2.field_trial(0).name_id()); 101 EXPECT_EQ(123U, proto2.field_trial(0).name_id());
103 EXPECT_EQ(456U, proto2.field_trial(0).group_id()); 102 EXPECT_EQ(456U, proto2.field_trial(0).group_id());
104 103
105 // Check that the profile can be overwritten. 104 // Check that the profile can be overwritten.
106 105
107 trial = proto1.add_field_trial(); 106 trial = proto1.add_field_trial();
108 trial->set_name_id(78); 107 trial->set_name_id(78);
109 trial->set_group_id(90); 108 trial->set_group_id(90);
110 109
111 ASSERT_TRUE(proto1.SerializeToString(&serialized_proto)); 110 persistent_profile()->SetSystemProfile(proto1);
112 persistent_profile()->SetSystemProfile(serialized_proto);
113 111
114 ASSERT_TRUE( 112 ASSERT_TRUE(
115 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2)); 113 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2));
116 ASSERT_EQ(2, proto2.field_trial_size()); 114 ASSERT_EQ(2, proto2.field_trial_size());
117 EXPECT_EQ(123U, proto2.field_trial(0).name_id()); 115 EXPECT_EQ(123U, proto2.field_trial(0).name_id());
118 EXPECT_EQ(456U, proto2.field_trial(0).group_id()); 116 EXPECT_EQ(456U, proto2.field_trial(0).group_id());
119 EXPECT_EQ(78U, proto2.field_trial(1).name_id()); 117 EXPECT_EQ(78U, proto2.field_trial(1).name_id());
120 EXPECT_EQ(90U, proto2.field_trial(1).group_id()); 118 EXPECT_EQ(90U, proto2.field_trial(1).group_id());
121 } 119 }
122 120
123 } // namespace metrics 121 } // namespace metrics
OLDNEW
« components/metrics/metrics_service.cc ('K') | « components/metrics/persistent_system_profile.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698