Index: base/test/scoped_feature_list.cc |
diff --git a/base/test/scoped_feature_list.cc b/base/test/scoped_feature_list.cc |
index f0f3f4edfba1f1d333ef3188836cf14273795739..68e6d4af9a5ed8f7855ece2775f87e639b4bb5fb 100644 |
--- a/base/test/scoped_feature_list.cc |
+++ b/base/test/scoped_feature_list.cc |
@@ -4,7 +4,12 @@ |
#include "base/test/scoped_feature_list.h" |
+#include <algorithm> |
#include <string> |
+#include <vector> |
+ |
+#include "base/strings/string_split.h" |
+#include "base/strings/string_util.h" |
namespace base { |
namespace test { |
@@ -70,5 +75,66 @@ void ScopedFeatureList::InitAndDisableFeature(const base::Feature& feature) { |
InitFromCommandLine(std::string(), feature.name); |
} |
+void override_feature(const std::string& feature, |
dcheng
2017/04/14 23:30:17
Nit: OverrideFeature
chaopeng
2017/04/15 00:12:54
Done.
|
+ 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.
|
+ std::vector<std::string>& add_to_list) { |
+ // Start with * means use default. |
+ if (StartsWith(feature, "*", CompareCase::SENSITIVE)) |
+ return; |
+ |
+ // Remove field_trial info. |
+ std::string feature_name = feature; |
+ std::size_t index = feature_name.find("<"); |
+ if (index != std::string::npos) |
+ feature_name = feature_name.substr(0, index); |
+ |
+ if (std::any_of( |
+ check_list.begin(), check_list.end(), |
+ [&feature_name](std::string& s) { return s == feature_name; })) |
+ return; |
+ |
+ if (std::any_of( |
+ add_to_list.begin(), add_to_list.end(), |
+ [&feature_name](std::string& s) { return s == feature_name; })) |
+ return; |
+ |
+ add_to_list.push_back(feature_name); |
+} |
+ |
+void ScopedFeatureList::InitWithFeatureListAndOverrides( |
+ base::FeatureList* feature_list, |
+ const std::vector<std::string>& override_enabled_features, |
+ const std::vector<std::string>& override_disabled_features) { |
+ std::vector<std::string> merged_enabled_features(override_enabled_features); |
+ std::vector<std::string> merged_disabled_features(override_disabled_features); |
+ |
+ 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
|
+ std::string enabled_features; |
+ std::string disabled_features; |
+ base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, |
+ &disabled_features); |
+ |
+ std::vector<std::string> enabled_features_list = SplitString( |
dcheng
2017/04/14 23:30:17
How about SplitStringPiece?
|
+ enabled_features, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); |
+ |
+ std::vector<std::string> disabled_features_list = SplitString( |
+ disabled_features, ",", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY); |
+ |
+ for (const std::string& feature : enabled_features_list) { |
+ override_feature(feature, merged_disabled_features, |
+ merged_enabled_features); |
+ } |
+ |
+ for (const std::string& feature : disabled_features_list) { |
+ override_feature(feature, merged_enabled_features, |
+ merged_disabled_features); |
+ } |
+ } |
+ |
+ std::string enabled = JoinString(merged_enabled_features, ","); |
+ std::string disabled = JoinString(merged_disabled_features, ","); |
+ InitFromCommandLine(enabled, disabled); |
+} |
+ |
} // namespace test |
} // namespace base |