OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/scoped_feature_list.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace base { |
| 13 |
| 14 class ScopedFeatureListTest : public testing::Test { |
| 15 public: |
| 16 void SetUp() override { |
| 17 // Clear default feature list; |
| 18 feature_list.Init(); |
| 19 } |
| 20 |
| 21 void ExpectFeatures(const std::string& enabled_features, |
| 22 const std::string& disabled_features) { |
| 23 base::FeatureList* list = base::FeatureList::GetInstance(); |
| 24 std::string actual_enabled_features; |
| 25 std::string actual_disabled_features; |
| 26 |
| 27 list->GetFeatureOverrides(&actual_enabled_features, |
| 28 &actual_disabled_features); |
| 29 |
| 30 EXPECT_EQ(enabled_features, actual_enabled_features); |
| 31 EXPECT_EQ(disabled_features, actual_disabled_features); |
| 32 } |
| 33 |
| 34 private: |
| 35 test::ScopedFeatureList feature_list; |
| 36 }; |
| 37 |
| 38 TEST_F(ScopedFeatureListTest, BasicScoped) { |
| 39 ExpectFeatures(std::string(), std::string()); |
| 40 { |
| 41 test::ScopedFeatureList feature_list1; |
| 42 feature_list1.InitFromCommandLine(std::string(), "OverlayScrollbar"); |
| 43 ExpectFeatures(std::string(), "OverlayScrollbar"); |
| 44 } |
| 45 ExpectFeatures(std::string(), std::string()); |
| 46 } |
| 47 |
| 48 TEST_F(ScopedFeatureListTest, TestInitWithFeatureListAndOverrides) { |
| 49 ExpectFeatures(std::string(), std::string()); |
| 50 { |
| 51 test::ScopedFeatureList feature_list1; |
| 52 std::vector<std::string> features{"OverlayScrollbar"}; |
| 53 feature_list1.InitWithFeatureListAndOverrides( |
| 54 nullptr, std::vector<std::string>(), features); |
| 55 ExpectFeatures(std::string(), "OverlayScrollbar"); |
| 56 |
| 57 { |
| 58 test::ScopedFeatureList feature_list2; |
| 59 ExpectFeatures(std::string(), "OverlayScrollbar"); |
| 60 // Given enabled list should override given feature list. |
| 61 feature_list2.InitWithFeatureListAndOverrides( |
| 62 base::FeatureList::GetInstance(), features, |
| 63 std::vector<std::string>()); |
| 64 ExpectFeatures("OverlayScrollbar", std::string()); |
| 65 } |
| 66 |
| 67 { |
| 68 test::ScopedFeatureList feature_list2; |
| 69 ExpectFeatures(std::string(), "OverlayScrollbar"); |
| 70 // Given same feature should not appear duplicate in feature list. |
| 71 feature_list2.InitWithFeatureListAndOverrides( |
| 72 base::FeatureList::GetInstance(), std::vector<std::string>(), |
| 73 features); |
| 74 ExpectFeatures(std::string(), "OverlayScrollbar"); |
| 75 } |
| 76 } |
| 77 ExpectFeatures(std::string(), std::string()); |
| 78 } |
| 79 |
| 80 } // namespace base |
OLD | NEW |