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

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

Issue 2463223002: Store field trial parameters in shared memory (Closed)
Patch Set: address comments 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"
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1187
1188 FieldTrialList field_trial_list2(nullptr); 1188 FieldTrialList field_trial_list2(nullptr);
1189 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); 1189 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true));
1190 shm.get()->Map(4 << 10); // Hardcoded, equal to kFieldTrialAllocationSize. 1190 shm.get()->Map(4 << 10); // Hardcoded, equal to kFieldTrialAllocationSize.
1191 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); 1191 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm));
1192 std::string check_string; 1192 std::string check_string;
1193 FieldTrialList::AllStatesToString(&check_string); 1193 FieldTrialList::AllStatesToString(&check_string);
1194 EXPECT_EQ(save_string, check_string); 1194 EXPECT_EQ(save_string, check_string);
1195 } 1195 }
1196 1196
1197 TEST(FieldTrialListTest, AssociateFieldTrialParams) {
1198 std::string trial_name("Trial1");
1199 std::string group_name("Group1");
1200
1201 // Create a field trial with some params.
1202 FieldTrialList field_trial_list(nullptr);
1203 FieldTrialList::CreateFieldTrial(trial_name, group_name);
1204 std::map<std::string, std::string> params;
1205 params["key1"] = "value1";
1206 params["key2"] = "value2";
1207 FieldTrialParamAssociator::GetInstance()->AssociateFieldTrialParams(
1208 trial_name, group_name, params);
1209 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
1210
1211 // Clear all cached params from the associator.
1212 FieldTrialParamAssociator::GetInstance()->ClearAllParamsForTesting();
1213
1214 // Check that we fetch the param from shared memory properly.
1215 std::map<std::string, std::string> new_params;
1216 FieldTrialParamAssociator::GetInstance()->GetFieldTrialParamsWithGroupName(
1217 trial_name, group_name, &new_params);
1218 EXPECT_EQ(new_params["key1"], "value1");
1219 EXPECT_EQ(new_params["key2"], "value2");
1220 }
1221
1197 } // namespace base 1222 } // namespace base
OLDNEW
« base/metrics/field_trial.h ('K') | « base/metrics/field_trial_param_associator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698