| 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/build_time.h" | 10 #include "base/build_time.h" |
| 11 #include "base/feature_list.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 12 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 13 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 16 #include "base/test/gtest_util.h" | 19 #include "base/test/gtest_util.h" |
| 20 #include "base/test/mock_entropy_provider.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 22 |
| 19 namespace base { | 23 namespace base { |
| 20 | 24 |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 // Default group name used by several tests. | 27 // Default group name used by several tests. |
| 24 const char kDefaultGroupName[] = "DefaultGroup"; | 28 const char kDefaultGroupName[] = "DefaultGroup"; |
| 25 | 29 |
| 26 // Call FieldTrialList::FactoryGetFieldTrial() with a future expiry date. | 30 // Call FieldTrialList::FactoryGetFieldTrial() with a future expiry date. |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 // Trying to instantiate a one-time randomized field trial before the | 1129 // Trying to instantiate a one-time randomized field trial before the |
| 1126 // FieldTrialList is created should crash. | 1130 // FieldTrialList is created should crash. |
| 1127 EXPECT_DEATH_IF_SUPPORTED( | 1131 EXPECT_DEATH_IF_SUPPORTED( |
| 1128 FieldTrialList::FactoryGetFieldTrial( | 1132 FieldTrialList::FactoryGetFieldTrial( |
| 1129 "OneTimeRandomizedTrialWithoutFieldTrialList", 100, kDefaultGroupName, | 1133 "OneTimeRandomizedTrialWithoutFieldTrialList", 100, kDefaultGroupName, |
| 1130 base::FieldTrialList::kNoExpirationYear, 1, 1, | 1134 base::FieldTrialList::kNoExpirationYear, 1, 1, |
| 1131 base::FieldTrial::ONE_TIME_RANDOMIZED, NULL), | 1135 base::FieldTrial::ONE_TIME_RANDOMIZED, NULL), |
| 1132 ""); | 1136 ""); |
| 1133 } | 1137 } |
| 1134 | 1138 |
| 1139 TEST(FieldTrialListTest, TestCopyFieldTrialStateToFlags) { |
| 1140 base::FieldTrialList field_trial_list( |
| 1141 base::MakeUnique<base::MockEntropyProvider>()); |
| 1142 base::FieldTrialList::CreateFieldTrial("Trial1", "Group1"); |
| 1143 base::FilePath test_file_path = base::FilePath(FILE_PATH_LITERAL("Program")); |
| 1144 base::CommandLine cmd_line = base::CommandLine(test_file_path); |
| 1145 |
| 1146 std::unique_ptr<base::SharedMemory> field_trial_state = |
| 1147 base::FieldTrialList::CopyFieldTrialStateToFlags("field-trial-handle", |
| 1148 &cmd_line); |
| 1149 |
| 1150 EXPECT_TRUE(field_trial_state.get() == nullptr); |
| 1151 EXPECT_TRUE(cmd_line.HasSwitch(switches::kForceFieldTrials)); |
| 1152 } |
| 1153 |
| 1135 } // namespace base | 1154 } // namespace base |
| OLD | NEW |