| OLD | NEW |
| 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 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 FieldTrialList field_trial_list2(nullptr); | 1224 FieldTrialList field_trial_list2(nullptr); |
| 1224 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); | 1225 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); |
| 1225 // 4 KiB is enough to hold the trials only created for this test. | 1226 // 4 KiB is enough to hold the trials only created for this test. |
| 1226 shm.get()->Map(4 << 10); | 1227 shm.get()->Map(4 << 10); |
| 1227 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); | 1228 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); |
| 1228 std::string check_string; | 1229 std::string check_string; |
| 1229 FieldTrialList::AllStatesToString(&check_string); | 1230 FieldTrialList::AllStatesToString(&check_string); |
| 1230 ASSERT_EQ(check_string.find("Simulated"), std::string::npos); | 1231 ASSERT_EQ(check_string.find("Simulated"), std::string::npos); |
| 1231 } | 1232 } |
| 1232 | 1233 |
| 1234 TEST(FieldTrialListTest, AssociateFieldTrialParams) { |
| 1235 std::string trial_name("Trial1"); |
| 1236 std::string group_name("Group1"); |
| 1237 |
| 1238 // Create a field trial with some params. |
| 1239 FieldTrialList field_trial_list(nullptr); |
| 1240 FieldTrialList::CreateFieldTrial(trial_name, group_name); |
| 1241 std::map<std::string, std::string> params; |
| 1242 params["key1"] = "value1"; |
| 1243 params["key2"] = "value2"; |
| 1244 FieldTrialParamAssociator::GetInstance()->AssociateFieldTrialParams( |
| 1245 trial_name, group_name, params); |
| 1246 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); |
| 1247 |
| 1248 // Clear all cached params from the associator. |
| 1249 FieldTrialParamAssociator::GetInstance()->ClearAllCachedParamsForTesting(); |
| 1250 |
| 1251 // Check that we fetch the param from shared memory properly. |
| 1252 std::map<std::string, std::string> new_params; |
| 1253 FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(trial_name, |
| 1254 &new_params); |
| 1255 EXPECT_EQ("value1", new_params["key1"]); |
| 1256 EXPECT_EQ("value2", new_params["key2"]); |
| 1257 EXPECT_EQ(2U, new_params.size()); |
| 1258 } |
| 1259 |
| 1233 } // namespace base | 1260 } // namespace base |
| OLD | NEW |