OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test/scoped_feature_list.h" | 5 #include "base/test/scoped_feature_list.h" |
6 | 6 |
7 #include <algorithm> | |
7 #include <string> | 8 #include <string> |
9 #include <vector> | |
10 | |
11 #include "base/strings/string_split.h" | |
12 #include "base/strings/string_util.h" | |
8 | 13 |
9 namespace base { | 14 namespace base { |
10 namespace test { | 15 namespace test { |
11 | 16 |
12 namespace { | 17 namespace { |
13 | 18 |
14 static std::string GetFeatureString( | 19 static std::string GetFeatureString( |
15 const std::initializer_list<base::Feature>& features) { | 20 const std::initializer_list<base::Feature>& features) { |
16 std::string output; | 21 std::string output; |
17 for (const base::Feature& feature : features) { | 22 for (const base::Feature& feature : features) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 } | 68 } |
64 | 69 |
65 void ScopedFeatureList::InitAndEnableFeature(const base::Feature& feature) { | 70 void ScopedFeatureList::InitAndEnableFeature(const base::Feature& feature) { |
66 InitFromCommandLine(feature.name, std::string()); | 71 InitFromCommandLine(feature.name, std::string()); |
67 } | 72 } |
68 | 73 |
69 void ScopedFeatureList::InitAndDisableFeature(const base::Feature& feature) { | 74 void ScopedFeatureList::InitAndDisableFeature(const base::Feature& feature) { |
70 InitFromCommandLine(std::string(), feature.name); | 75 InitFromCommandLine(std::string(), feature.name); |
71 } | 76 } |
72 | 77 |
78 void override_feature(const std::string& feature, | |
dcheng
2017/04/14 23:30:17
Nit: OverrideFeature
chaopeng
2017/04/15 00:12:54
Done.
| |
79 std::vector<std::string>& check_list, | |
dcheng
2017/04/14 23:30:17
Output parameters in Chromium should pass by point
chaopeng
2017/04/15 00:12:54
Done.
| |
80 std::vector<std::string>& add_to_list) { | |
81 // Start with * means use default. | |
82 if (StartsWith(feature, "*", CompareCase::SENSITIVE)) | |
83 return; | |
84 | |
85 // Remove field_trial info. | |
86 std::string feature_name = feature; | |
87 std::size_t index = feature_name.find("<"); | |
88 if (index != std::string::npos) | |
89 feature_name = feature_name.substr(0, index); | |
90 | |
91 if (std::any_of( | |
92 check_list.begin(), check_list.end(), | |
93 [&feature_name](std::string& s) { return s == feature_name; })) | |
94 return; | |
95 | |
96 if (std::any_of( | |
97 add_to_list.begin(), add_to_list.end(), | |
98 [&feature_name](std::string& s) { return s == feature_name; })) | |
99 return; | |
100 | |
101 add_to_list.push_back(feature_name); | |
102 } | |
103 | |
104 void ScopedFeatureList::InitWithFeatureListAndOverrides( | |
105 base::FeatureList* feature_list, | |
106 const std::vector<std::string>& override_enabled_features, | |
107 const std::vector<std::string>& override_disabled_features) { | |
108 std::vector<std::string> merged_enabled_features(override_enabled_features); | |
109 std::vector<std::string> merged_disabled_features(override_disabled_features); | |
110 | |
111 if (feature_list) { | |
dcheng
2017/04/14 23:30:17
Why do we have to handle the null case? I'm also n
chaopeng
2017/04/15 00:12:54
For the null case, we just need to write the overr
| |
112 std::string enabled_features; | |
113 std::string disabled_features; | |
114 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, | |
115 &disabled_features); | |
116 | |
117 std::vector<std::string> enabled_features_list = SplitString( | |
dcheng
2017/04/14 23:30:17
How about SplitStringPiece?
| |
118 enabled_features, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); | |
119 | |
120 std::vector<std::string> disabled_features_list = SplitString( | |
121 disabled_features, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); | |
122 | |
123 for (const std::string& feature : enabled_features_list) { | |
124 override_feature(feature, merged_disabled_features, | |
125 merged_enabled_features); | |
126 } | |
127 | |
128 for (const std::string& feature : disabled_features_list) { | |
129 override_feature(feature, merged_enabled_features, | |
130 merged_disabled_features); | |
131 } | |
132 } | |
133 | |
134 std::string enabled = JoinString(merged_enabled_features, ","); | |
135 std::string disabled = JoinString(merged_disabled_features, ","); | |
136 InitFromCommandLine(enabled, disabled); | |
137 } | |
138 | |
73 } // namespace test | 139 } // namespace test |
74 } // namespace base | 140 } // namespace base |
OLD | NEW |