| 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 "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/strings/string_util.h" |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 const char kFeatureOnByDefaultName[] = "OnByDefault"; | 17 const char kFeatureOnByDefaultName[] = "OnByDefault"; |
| 17 struct Feature kFeatureOnByDefault { | 18 struct Feature kFeatureOnByDefault { |
| 18 kFeatureOnByDefaultName, FEATURE_ENABLED_BY_DEFAULT | 19 kFeatureOnByDefaultName, FEATURE_ENABLED_BY_DEFAULT |
| 19 }; | 20 }; |
| 20 | 21 |
| 21 const char kFeatureOffByDefaultName[] = "OffByDefault"; | 22 const char kFeatureOffByDefaultName[] = "OffByDefault"; |
| 22 struct Feature kFeatureOffByDefault { | 23 struct Feature kFeatureOffByDefault { |
| 23 kFeatureOffByDefaultName, FEATURE_DISABLED_BY_DEFAULT | 24 kFeatureOffByDefaultName, FEATURE_DISABLED_BY_DEFAULT |
| 24 }; | 25 }; |
| 25 | 26 |
| 27 std::string SortFeatureListString(const std::string& feature_list) { |
| 28 std::vector<std::string> features = |
| 29 FeatureList::SplitFeatureListString(feature_list); |
| 30 std::sort(features.begin(), features.end()); |
| 31 return JoinString(features, ","); |
| 32 } |
| 33 |
| 26 } // namespace | 34 } // namespace |
| 27 | 35 |
| 28 class FeatureListTest : public testing::Test { | 36 class FeatureListTest : public testing::Test { |
| 29 public: | 37 public: |
| 30 FeatureListTest() : feature_list_(nullptr) { | 38 FeatureListTest() : feature_list_(nullptr) { |
| 31 RegisterFeatureListInstance(make_scoped_ptr(new FeatureList)); | 39 RegisterFeatureListInstance(make_scoped_ptr(new FeatureList)); |
| 32 } | 40 } |
| 33 ~FeatureListTest() override { ClearFeatureListInstance(); } | 41 ~FeatureListTest() override { ClearFeatureListInstance(); } |
| 34 | 42 |
| 35 void RegisterFeatureListInstance(scoped_ptr<FeatureList> feature_list) { | 43 void RegisterFeatureListInstance(scoped_ptr<FeatureList> feature_list) { |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 EXPECT_TRUE(FieldTrialList::IsTrialActive(kTrialName)); | 309 EXPECT_TRUE(FieldTrialList::IsTrialActive(kTrialName)); |
| 302 EXPECT_EQ(kForcedOffGroupName, disable_trial->group_name()); | 310 EXPECT_EQ(kForcedOffGroupName, disable_trial->group_name()); |
| 303 } else if (enable_trial) { | 311 } else if (enable_trial) { |
| 304 EXPECT_TRUE(FeatureList::IsEnabled(kFeatureOffByDefault)); | 312 EXPECT_TRUE(FeatureList::IsEnabled(kFeatureOffByDefault)); |
| 305 EXPECT_TRUE(FieldTrialList::IsTrialActive(kTrialName)); | 313 EXPECT_TRUE(FieldTrialList::IsTrialActive(kTrialName)); |
| 306 EXPECT_EQ(kForcedOnGroupName, enable_trial->group_name()); | 314 EXPECT_EQ(kForcedOnGroupName, enable_trial->group_name()); |
| 307 } | 315 } |
| 308 } | 316 } |
| 309 } | 317 } |
| 310 | 318 |
| 319 TEST_F(FeatureListTest, GetFeatureOverrides) { |
| 320 ClearFeatureListInstance(); |
| 321 FieldTrialList field_trial_list(nullptr); |
| 322 scoped_ptr<FeatureList> feature_list(new FeatureList); |
| 323 feature_list->InitializeFromCommandLine("A,X", "D"); |
| 324 |
| 325 FieldTrial* trial = FieldTrialList::CreateFieldTrial("Trial", "Group"); |
| 326 feature_list->RegisterFieldTrialOverride(kFeatureOffByDefaultName, |
| 327 FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 328 trial); |
| 329 |
| 330 RegisterFeatureListInstance(feature_list.Pass()); |
| 331 |
| 332 std::string enable_features; |
| 333 std::string disable_features; |
| 334 FeatureList::GetInstance()->GetFeatureOverrides(&enable_features, |
| 335 &disable_features); |
| 336 EXPECT_EQ("A,OffByDefault,X", SortFeatureListString(enable_features)); |
| 337 EXPECT_EQ("D", SortFeatureListString(disable_features)); |
| 338 } |
| 339 |
| 311 } // namespace base | 340 } // namespace base |
| OLD | NEW |