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" |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1180 FieldTrialList field_trial_list(nullptr); | 1180 FieldTrialList field_trial_list(nullptr); |
1181 FieldTrialList::CreateFieldTrial("Trial1", "Group1"); | 1181 FieldTrialList::CreateFieldTrial("Trial1", "Group1"); |
1182 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); | 1182 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); |
1183 FieldTrialList::AllStatesToString(&save_string); | 1183 FieldTrialList::AllStatesToString(&save_string); |
1184 handle = base::SharedMemory::DuplicateHandle( | 1184 handle = base::SharedMemory::DuplicateHandle( |
1185 field_trial_list.field_trial_allocator_->shared_memory()->handle()); | 1185 field_trial_list.field_trial_allocator_->shared_memory()->handle()); |
1186 } | 1186 } |
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( |
1191 4 << 10); // This is enough to hold the trials created for this test. | |
Alexei Svitkine (slow)
2016/11/21 19:13:58
Nit: If you have to wrap because of end of line co
lawrencewu
2016/11/21 19:18:50
Done.
| |
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, DoNotAddSimulatedFieldTrialsToAllocator) { | |
1199 constexpr char kTrialName[] = "trial"; | |
1200 base::SharedMemoryHandle handle; | |
1201 { | |
1202 // Create a simulated trial and a real trial and call group() on them, which | |
1203 // should only add the real trial to the field trial allocator. | |
1204 FieldTrialList field_trial_list(nullptr); | |
1205 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); | |
1206 | |
1207 // This shouldn't add to the allocator. | |
1208 FieldTrial* simulated_trial = FieldTrial::CreateSimulatedFieldTrial( | |
1209 kTrialName, 100, "Simulated", 0.95); | |
1210 simulated_trial->group(); | |
1211 | |
1212 // This should add to the allocator. | |
1213 FieldTrial* real_trial = | |
1214 FieldTrialList::CreateFieldTrial(kTrialName, "Real"); | |
1215 real_trial->group(); | |
1216 | |
1217 handle = base::SharedMemory::DuplicateHandle( | |
1218 field_trial_list.field_trial_allocator_->shared_memory()->handle()); | |
1219 } | |
1220 | |
1221 // Check that there's only one entry in the allocator. | |
1222 FieldTrialList field_trial_list2(nullptr); | |
1223 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); | |
1224 shm.get()->Map( | |
1225 4 << 10); // This is enough to hold the trials created in this test. | |
1226 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); | |
1227 std::string check_string; | |
1228 FieldTrialList::AllStatesToString(&check_string); | |
1229 ASSERT_EQ(check_string.find("Simulated"), std::string::npos); | |
1230 } | |
1231 | |
1197 } // namespace base | 1232 } // namespace base |
OLD | NEW |