OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/feature_list.h" | 5 #include "base/feature_list.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <algorithm> |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 172 |
172 const bool expected_enabled_2 = | 173 const bool expected_enabled_2 = |
173 (test_case.trial2_state == FeatureList::OVERRIDE_ENABLE_FEATURE); | 174 (test_case.trial2_state == FeatureList::OVERRIDE_ENABLE_FEATURE); |
174 EXPECT_EQ(expected_enabled_2, FeatureList::IsEnabled(kFeatureOffByDefault)); | 175 EXPECT_EQ(expected_enabled_2, FeatureList::IsEnabled(kFeatureOffByDefault)); |
175 // The above should have activated |trial2|. | 176 // The above should have activated |trial2|. |
176 EXPECT_TRUE(FieldTrialList::IsTrialActive(trial1->trial_name())); | 177 EXPECT_TRUE(FieldTrialList::IsTrialActive(trial1->trial_name())); |
177 EXPECT_TRUE(FieldTrialList::IsTrialActive(trial2->trial_name())); | 178 EXPECT_TRUE(FieldTrialList::IsTrialActive(trial2->trial_name())); |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
| 182 TEST_F(FeatureListTest, FieldTrialAssociateUseDefault) { |
| 183 FieldTrialList field_trial_list(nullptr); |
| 184 scoped_ptr<FeatureList> feature_list(new FeatureList); |
| 185 |
| 186 FieldTrial* trial1 = FieldTrialList::CreateFieldTrial("TrialExample1", "A"); |
| 187 FieldTrial* trial2 = FieldTrialList::CreateFieldTrial("TrialExample2", "B"); |
| 188 feature_list->RegisterFieldTrialOverride( |
| 189 kFeatureOnByDefaultName, FeatureList::OVERRIDE_USE_DEFAULT, trial1); |
| 190 feature_list->RegisterFieldTrialOverride( |
| 191 kFeatureOffByDefaultName, FeatureList::OVERRIDE_USE_DEFAULT, trial2); |
| 192 RegisterFeatureListInstance(std::move(feature_list)); |
| 193 |
| 194 // Initially, neither trial should be active. |
| 195 EXPECT_FALSE(FieldTrialList::IsTrialActive(trial1->trial_name())); |
| 196 EXPECT_FALSE(FieldTrialList::IsTrialActive(trial2->trial_name())); |
| 197 |
| 198 // Check the feature enabled state is its default. |
| 199 EXPECT_TRUE(FeatureList::IsEnabled(kFeatureOnByDefault)); |
| 200 // The above should have activated |trial1|. |
| 201 EXPECT_TRUE(FieldTrialList::IsTrialActive(trial1->trial_name())); |
| 202 EXPECT_FALSE(FieldTrialList::IsTrialActive(trial2->trial_name())); |
| 203 |
| 204 // Check the feature enabled state is its default. |
| 205 EXPECT_FALSE(FeatureList::IsEnabled(kFeatureOffByDefault)); |
| 206 // The above should have activated |trial2|. |
| 207 EXPECT_TRUE(FieldTrialList::IsTrialActive(trial1->trial_name())); |
| 208 EXPECT_TRUE(FieldTrialList::IsTrialActive(trial2->trial_name())); |
| 209 } |
| 210 |
181 TEST_F(FeatureListTest, CommandLineTakesPrecedenceOverFieldTrial) { | 211 TEST_F(FeatureListTest, CommandLineTakesPrecedenceOverFieldTrial) { |
182 ClearFeatureListInstance(); | 212 ClearFeatureListInstance(); |
183 | 213 |
184 FieldTrialList field_trial_list(nullptr); | 214 FieldTrialList field_trial_list(nullptr); |
185 scoped_ptr<FeatureList> feature_list(new FeatureList); | 215 scoped_ptr<FeatureList> feature_list(new FeatureList); |
186 | 216 |
187 // The feature is explicitly enabled on the command-line. | 217 // The feature is explicitly enabled on the command-line. |
188 feature_list->InitializeFromCommandLine(kFeatureOffByDefaultName, ""); | 218 feature_list->InitializeFromCommandLine(kFeatureOffByDefaultName, ""); |
189 | 219 |
190 // But the FieldTrial would set the feature to disabled. | 220 // But the FieldTrial would set the feature to disabled. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 scoped_ptr<FeatureList> feature_list(new FeatureList); | 379 scoped_ptr<FeatureList> feature_list(new FeatureList); |
350 feature_list->InitializeFromCommandLine("A,OffByDefault<Trial,X", "D"); | 380 feature_list->InitializeFromCommandLine("A,OffByDefault<Trial,X", "D"); |
351 RegisterFeatureListInstance(std::move(feature_list)); | 381 RegisterFeatureListInstance(std::move(feature_list)); |
352 | 382 |
353 EXPECT_FALSE(FieldTrialList::IsTrialActive("Trial")); | 383 EXPECT_FALSE(FieldTrialList::IsTrialActive("Trial")); |
354 EXPECT_TRUE(FeatureList::IsEnabled(kFeatureOffByDefault)); | 384 EXPECT_TRUE(FeatureList::IsEnabled(kFeatureOffByDefault)); |
355 EXPECT_TRUE(FieldTrialList::IsTrialActive("Trial")); | 385 EXPECT_TRUE(FieldTrialList::IsTrialActive("Trial")); |
356 } | 386 } |
357 | 387 |
358 } // namespace base | 388 } // namespace base |
OLD | NEW |