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

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

Issue 2950173003: Support add-on 'field trial' records. (Closed)
Patch Set: addressed review comments by asvitkine Created 3 years, 5 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"
11 #include "components/variations/metrics_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace metrics { 14 namespace metrics {
14 15
15 class PersistentSystemProfileTest : public testing::Test { 16 class PersistentSystemProfileTest : public testing::Test {
16 public: 17 public:
17 const int32_t kAllocatorMemorySize = 1 << 20; // 1 MiB 18 const int32_t kAllocatorMemorySize = 1 << 20; // 1 MiB
18 19
19 PersistentSystemProfileTest() {} 20 PersistentSystemProfileTest() {}
20 ~PersistentSystemProfileTest() override {} 21 ~PersistentSystemProfileTest() override {}
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 128
128 ASSERT_TRUE( 129 ASSERT_TRUE(
129 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2)); 130 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &proto2));
130 ASSERT_EQ(2, proto2.field_trial_size()); 131 ASSERT_EQ(2, proto2.field_trial_size());
131 EXPECT_EQ(123U, proto2.field_trial(0).name_id()); 132 EXPECT_EQ(123U, proto2.field_trial(0).name_id());
132 EXPECT_EQ(456U, proto2.field_trial(0).group_id()); 133 EXPECT_EQ(456U, proto2.field_trial(0).group_id());
133 EXPECT_EQ(78U, proto2.field_trial(1).name_id()); 134 EXPECT_EQ(78U, proto2.field_trial(1).name_id());
134 EXPECT_EQ(90U, proto2.field_trial(1).group_id()); 135 EXPECT_EQ(90U, proto2.field_trial(1).group_id());
135 } 136 }
136 137
138 TEST_F(PersistentSystemProfileTest, ProfileExtensions) {
139 persistent_profile()->AddFieldTrial("sna", "foo");
140
141 SystemProfileProto fetched;
142 ASSERT_FALSE(
143 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &fetched));
144
145 SystemProfileProto proto;
146 SystemProfileProto::FieldTrial* trial = proto.add_field_trial();
147 trial->set_name_id(123);
148 trial->set_group_id(456);
149
150 persistent_profile()->SetSystemProfile(proto, false);
151 ASSERT_TRUE(
152 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &fetched));
153 ASSERT_EQ(2, fetched.field_trial_size());
154 EXPECT_EQ(123U, fetched.field_trial(0).name_id());
155 EXPECT_EQ(456U, fetched.field_trial(0).group_id());
156 EXPECT_EQ(metrics::HashName("sna"), fetched.field_trial(1).name_id());
157 EXPECT_EQ(metrics::HashName("foo"), fetched.field_trial(1).group_id());
158
159 persistent_profile()->AddFieldTrial("foo", "bar");
160 ASSERT_TRUE(
161 PersistentSystemProfile::GetSystemProfile(*memory_allocator(), &fetched));
162 ASSERT_EQ(3, fetched.field_trial_size());
163 EXPECT_EQ(123U, fetched.field_trial(0).name_id());
164 EXPECT_EQ(456U, fetched.field_trial(0).group_id());
165 EXPECT_EQ(metrics::HashName("sna"), fetched.field_trial(1).name_id());
166 EXPECT_EQ(metrics::HashName("foo"), fetched.field_trial(1).group_id());
167 EXPECT_EQ(metrics::HashName("foo"), fetched.field_trial(2).name_id());
168 EXPECT_EQ(metrics::HashName("bar"), fetched.field_trial(2).group_id());
169 }
170
137 } // namespace metrics 171 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/persistent_system_profile.cc ('k') | components/variations/active_field_trials.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698