Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: content/test/content_browser_test_test.cc

Issue 2876153002: Support Using ScopedFeatureList in BrowserTest (Closed)
Patch Set: ilya comments addressed Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/public/test/content_browser_test.h" 5 #include "content/public/test/content_browser_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/process/launch.h" 9 #include "base/process/launch.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/launcher/test_launcher.h" 13 #include "base/test/launcher/test_launcher.h"
14 #include "base/test/scoped_feature_list.h"
13 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
14 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
15 #include "build/build_config.h" 17 #include "build/build_config.h"
16 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_process_host_observer.h" 19 #include "content/public/browser/render_process_host_observer.h"
18 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
20 #include "content/public/test/browser_test_utils.h" 22 #include "content/public/test/browser_test_utils.h"
21 #include "content/public/test/content_browser_test_utils.h" 23 #include "content/public/test/content_browser_test_utils.h"
22 #include "content/public/test/test_launcher.h" 24 #include "content/public/test/test_launcher.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 IN_PROC_BROWSER_TEST_F(ContentBrowserTestSanityTest, Basic) { 173 IN_PROC_BROWSER_TEST_F(ContentBrowserTestSanityTest, Basic) {
172 Test(); 174 Test();
173 } 175 }
174 176
175 IN_PROC_BROWSER_TEST_F(ContentBrowserTestSanityTest, SingleProcess) { 177 IN_PROC_BROWSER_TEST_F(ContentBrowserTestSanityTest, SingleProcess) {
176 Test(); 178 Test();
177 } 179 }
178 180
179 namespace { 181 namespace {
180 182
183 const base::Feature kTestFeatureForContentBrowserTest{
184 "TestFeatureForContentBrowserTest", base::FEATURE_DISABLED_BY_DEFAULT};
185
186 } // namespace
187
188 class ContentBrowserTestScopedFeatureListTest : public ContentBrowserTest {
189 public:
190 void SetUp() override {
191 std::string disabled_features;
192 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features_,
193 &disabled_features);
194 scoped_feature_list_.InitAndEnableFeature(
195 kTestFeatureForContentBrowserTest);
196 ContentBrowserTest::SetUp();
197 }
198
199 std::string enabled_features_;
200
201 private:
202 base::test::ScopedFeatureList scoped_feature_list_;
203 };
204
205 IN_PROC_BROWSER_TEST_F(ContentBrowserTestScopedFeatureListTest,
206 FeatureListTest) {
207 std::string enabled_features0;
208 std::string disabled_features0;
209
210 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features0,
211 &disabled_features0);
212
213 base::StringPiece enabled_features = enabled_features0;
214
215 // Ensure we repected the features from command line.
216 std::vector<base::StringPiece> original_enabled_features =
217 base::SplitStringPiece(enabled_features_, ",", base::TRIM_WHITESPACE,
218 base::SPLIT_WANT_NONEMPTY);
219
220 for (base::StringPiece enabled_feature : original_enabled_features) {
221 EXPECT_NE(enabled_features.find(enabled_feature), base::StringPiece::npos);
222 }
223
224 // Ensure kTestFeatureForContentBrowserTest enabled.
225 EXPECT_TRUE(base::FeatureList::IsEnabled(kTestFeatureForContentBrowserTest));
226 }
227
228 namespace {
229
181 void CallbackChecker(bool* non_nested_task_ran) { 230 void CallbackChecker(bool* non_nested_task_ran) {
182 *non_nested_task_ran = true; 231 *non_nested_task_ran = true;
183 } 232 }
184 233
185 } // namespace 234 } // namespace
186 235
187 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, NonNestableTask) { 236 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, NonNestableTask) {
188 bool non_nested_task_ran = false; 237 bool non_nested_task_ran = false;
189 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( 238 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
190 FROM_HERE, base::Bind(&CallbackChecker, &non_nested_task_ran)); 239 FROM_HERE, base::Bind(&CallbackChecker, &non_nested_task_ran));
191 content::RunAllPendingInMessageLoop(); 240 content::RunAllPendingInMessageLoop();
192 ASSERT_TRUE(non_nested_task_ran); 241 ASSERT_TRUE(non_nested_task_ran);
193 } 242 }
194 243
195 } // namespace content 244 } // namespace content
OLDNEW
« content/public/test/browser_test_base.cc ('K') | « content/public/test/browser_test_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698