Index: chrome/test/base/in_process_browser_test_browsertest.cc |
diff --git a/chrome/test/base/in_process_browser_test_browsertest.cc b/chrome/test/base/in_process_browser_test_browsertest.cc |
index 22953ce9dade2ffb78d3bdfd66fd90ff02d407e6..58ec13282616dfe152f69512560701e056ef8a34 100644 |
--- a/chrome/test/base/in_process_browser_test_browsertest.cc |
+++ b/chrome/test/base/in_process_browser_test_browsertest.cc |
@@ -5,9 +5,12 @@ |
#include <stddef.h> |
#include <string.h> |
+#include "base/command_line.h" |
#include "base/files/file_util.h" |
#include "base/macros.h" |
#include "base/path_service.h" |
+#include "base/strings/string_split.h" |
+#include "base/test/scoped_feature_list.h" |
#include "chrome/browser/after_startup_task_utils.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
@@ -17,6 +20,7 @@ |
#include "content/public/browser/render_view_host.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_contents_observer.h" |
+#include "content/public/common/content_switches.h" |
#include "net/base/filename_util.h" |
#include "net/base/net_errors.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -150,4 +154,57 @@ IN_PROC_BROWSER_TEST_F( |
EXPECT_NE("", test_result); |
} |
+const base::Feature kTestFeatureForBrowserTest{ |
+ "TestFeatureForBrowserTest", base::FEATURE_DISABLED_BY_DEFAULT}; |
Ilya Sherman
2017/06/07 21:32:36
Is it worth having both an enabled and a disabled
Ilya Sherman
2017/06/07 21:32:36
nit: Please define this in an anonymous namespace.
chaopeng
2017/06/09 04:49:05
This file is already in anonymous.
|
+ |
+class BrowserTestScopedFeatureListTest : public InProcessBrowserTest { |
+ public: |
+ void SetUp() override { |
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
+ enabled_features_ = |
+ command_line->GetSwitchValueASCII(switches::kEnableFeatures); |
+ disabled_features_ = |
+ command_line->GetSwitchValueASCII(switches::kEnableFeatures); |
Ilya Sherman
2017/06/07 21:32:36
Same questions apply here as for the other test.
|
+ scoped_feature_list_.InitAndEnableFeature(kTestFeatureForBrowserTest); |
+ InProcessBrowserTest::SetUp(); |
+ } |
+ |
+ std::string enabled_features_; |
+ std::string disabled_features_; |
+ |
+ private: |
+ base::test::ScopedFeatureList scoped_feature_list_; |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(BrowserTestScopedFeatureListTest, FeatureListTest) { |
+ std::string enabled_features0; |
+ std::string disabled_features0; |
+ |
+ base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features0, |
+ &disabled_features0); |
+ |
+ base::StringPiece enabled_features = enabled_features0; |
+ base::StringPiece disabled_features = disabled_features0; |
+ |
+ // Ensure we repected the features from command line. |
+ std::vector<base::StringPiece> original_enabled_features = |
+ base::SplitStringPiece(enabled_features_, ",", base::TRIM_WHITESPACE, |
+ base::SPLIT_WANT_NONEMPTY); |
+ std::vector<base::StringPiece> original_disabled_features = |
+ base::SplitStringPiece(disabled_features_, ",", base::TRIM_WHITESPACE, |
+ base::SPLIT_WANT_NONEMPTY); |
+ |
+ for (base::StringPiece enabled_feature : original_enabled_features) { |
+ EXPECT_NE(enabled_features.find(enabled_feature), base::StringPiece::npos); |
+ } |
+ |
+ for (base::StringPiece disabled_feature : original_disabled_features) { |
+ EXPECT_NE(disabled_features.find(disabled_feature), |
+ base::StringPiece::npos); |
+ } |
+ |
+ // Ensure kTestFeatureForBrowserTest enabled. |
+ EXPECT_TRUE(base::FeatureList::IsEnabled(kTestFeatureForBrowserTest)); |
+} |
+ |
} // namespace |