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 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 } | 1138 } |
1139 | 1139 |
1140 #if defined(OS_WIN) | 1140 #if defined(OS_WIN) |
1141 TEST(FieldTrialListTest, TestCopyFieldTrialStateToFlags) { | 1141 TEST(FieldTrialListTest, TestCopyFieldTrialStateToFlags) { |
1142 base::FieldTrialList field_trial_list( | 1142 base::FieldTrialList field_trial_list( |
1143 base::MakeUnique<base::MockEntropyProvider>()); | 1143 base::MakeUnique<base::MockEntropyProvider>()); |
1144 base::FieldTrialList::CreateFieldTrial("Trial1", "Group1"); | 1144 base::FieldTrialList::CreateFieldTrial("Trial1", "Group1"); |
1145 base::FilePath test_file_path = base::FilePath(FILE_PATH_LITERAL("Program")); | 1145 base::FilePath test_file_path = base::FilePath(FILE_PATH_LITERAL("Program")); |
1146 base::CommandLine cmd_line = base::CommandLine(test_file_path); | 1146 base::CommandLine cmd_line = base::CommandLine(test_file_path); |
1147 const char field_trial_handle[] = "test-field-trial-handle"; | 1147 const char field_trial_handle[] = "test-field-trial-handle"; |
1148 const char enable_features_switch[] = "test-enable-features"; | |
1149 const char disable_features_switch[] = "test-disable-features"; | |
1148 | 1150 |
1149 base::FieldTrialList::CopyFieldTrialStateToFlags(field_trial_handle, | 1151 base::FieldTrialList::CopyFieldTrialStateToFlags( |
1150 &cmd_line); | 1152 field_trial_handle, enable_features_switch, disable_features_switch, |
1153 &cmd_line); | |
1151 EXPECT_TRUE(cmd_line.HasSwitch(field_trial_handle) || | 1154 EXPECT_TRUE(cmd_line.HasSwitch(field_trial_handle) || |
1152 cmd_line.HasSwitch(switches::kForceFieldTrials)); | 1155 cmd_line.HasSwitch(switches::kForceFieldTrials)); |
1153 } | 1156 } |
1154 #endif | 1157 #endif |
1155 | 1158 |
1159 #if !defined(OS_IOS) | |
1156 TEST(FieldTrialListTest, InstantiateAllocator) { | 1160 TEST(FieldTrialListTest, InstantiateAllocator) { |
1161 std::unique_ptr<FeatureList> feature_list(new FeatureList); | |
Alexei Svitkine (slow)
2016/12/02 20:14:28
This doesn't actually register the instance. (It d
lawrencewu
2016/12/02 20:36:32
Done. This also turned out to be the cause of thos
| |
1162 | |
1157 FieldTrialList field_trial_list(nullptr); | 1163 FieldTrialList field_trial_list(nullptr); |
1158 FieldTrialList::CreateFieldTrial("Trial1", "Group1"); | 1164 FieldTrialList::CreateFieldTrial("Trial1", "Group1"); |
1159 | 1165 |
1160 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); | 1166 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); |
1161 void* memory = field_trial_list.field_trial_allocator_->shared_memory(); | 1167 void* memory = field_trial_list.field_trial_allocator_->shared_memory(); |
1162 size_t used = field_trial_list.field_trial_allocator_->used(); | 1168 size_t used = field_trial_list.field_trial_allocator_->used(); |
1163 | 1169 |
1164 // Ensure that the function is idempotent. | 1170 // Ensure that the function is idempotent. |
1165 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); | 1171 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); |
1166 void* new_memory = field_trial_list.field_trial_allocator_->shared_memory(); | 1172 void* new_memory = field_trial_list.field_trial_allocator_->shared_memory(); |
1167 size_t new_used = field_trial_list.field_trial_allocator_->used(); | 1173 size_t new_used = field_trial_list.field_trial_allocator_->used(); |
1168 EXPECT_EQ(memory, new_memory); | 1174 EXPECT_EQ(memory, new_memory); |
1169 EXPECT_EQ(used, new_used); | 1175 EXPECT_EQ(used, new_used); |
1170 } | 1176 } |
1177 #endif | |
1171 | 1178 |
1172 TEST(FieldTrialListTest, AddTrialsToAllocator) { | 1179 TEST(FieldTrialListTest, AddTrialsToAllocator) { |
1173 std::string save_string; | 1180 std::string save_string; |
1174 base::SharedMemoryHandle handle; | 1181 base::SharedMemoryHandle handle; |
1175 | 1182 |
1176 // Scoping the first FieldTrialList, as we need another one to test that it | 1183 // Scoping the first FieldTrialList, as we need another one to test that it |
1177 // matches. | 1184 // matches. |
1178 { | 1185 { |
1179 FieldTrialList field_trial_list(nullptr); | 1186 FieldTrialList field_trial_list(nullptr); |
1180 FieldTrialList::CreateFieldTrial("Trial1", "Group1"); | 1187 FieldTrialList::CreateFieldTrial("Trial1", "Group1"); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1301 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); | 1308 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); |
1302 // 4 KiB is enough to hold the trials only created for this test. | 1309 // 4 KiB is enough to hold the trials only created for this test. |
1303 shm.get()->Map(4 << 10); | 1310 shm.get()->Map(4 << 10); |
1304 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); | 1311 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); |
1305 std::string check_string; | 1312 std::string check_string; |
1306 FieldTrialList::AllStatesToString(&check_string); | 1313 FieldTrialList::AllStatesToString(&check_string); |
1307 EXPECT_EQ("*Trial1/Group1/", check_string); | 1314 EXPECT_EQ("*Trial1/Group1/", check_string); |
1308 } | 1315 } |
1309 | 1316 |
1310 } // namespace base | 1317 } // namespace base |
OLD | NEW |