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

Side by Side Diff: base/metrics/field_trial_unittest.cc

Issue 2463223002: Store field trial parameters in shared memory (Closed)
Patch Set: fix compilation error Created 4 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/metrics/field_trial.h" 5 #include "base/metrics/field_trial.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/build_time.h" 10 #include "base/build_time.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/field_trial_param_associator.h"
15 #include "base/rand_util.h" 16 #include "base/rand_util.h"
16 #include "base/run_loop.h" 17 #include "base/run_loop.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
19 #include "base/test/gtest_util.h" 20 #include "base/test/gtest_util.h"
20 #include "base/test/mock_entropy_provider.h" 21 #include "base/test/mock_entropy_provider.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace base { 24 namespace base {
24 25
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1188
1188 FieldTrialList field_trial_list2(nullptr); 1189 FieldTrialList field_trial_list2(nullptr);
1189 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); 1190 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true));
1190 shm.get()->Map(4 << 10); // Hardcoded, equal to kFieldTrialAllocationSize. 1191 shm.get()->Map(4 << 10); // Hardcoded, equal to kFieldTrialAllocationSize.
1191 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); 1192 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm));
1192 std::string check_string; 1193 std::string check_string;
1193 FieldTrialList::AllStatesToString(&check_string); 1194 FieldTrialList::AllStatesToString(&check_string);
1194 EXPECT_EQ(save_string, check_string); 1195 EXPECT_EQ(save_string, check_string);
1195 } 1196 }
1196 1197
1198 TEST(FieldTrialListTest, AssociateFieldTrialParams) {
1199 std::string trial_name("Trial1");
1200 std::string group_name("Group1");
1201
1202 // Create a field trial with some params.
1203 FieldTrialList field_trial_list(nullptr);
1204 FieldTrialList::CreateFieldTrial(trial_name, group_name);
1205 std::map<std::string, std::string> params;
1206 params["key1"] = "value1";
1207 params["key2"] = "value2";
1208 FieldTrialParamAssociator::GetInstance()->AssociateFieldTrialParams(
1209 trial_name, group_name, params);
1210 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
1211
1212 // Clear all cached params from the associator.
1213 FieldTrialParamAssociator::GetInstance()->ClearAllCachedParamsForTesting();
1214
1215 // Check that we fetch the param from shared memory properly.
1216 std::map<std::string, std::string> new_params;
1217 FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(trial_name,
1218 &new_params);
1219 EXPECT_EQ("value1", new_params["key1"]);
1220 EXPECT_EQ("value2", new_params["key2"]);
1221 EXPECT_EQ(static_cast<unsigned long>(2), new_params.size());
Alexei Svitkine (slow) 2016/11/23 17:23:40 Instead of the cast, I think you can do 2U
lawrencewu 2016/11/23 19:07:33 Done.
1222 }
1223
1197 } // namespace base 1224 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698