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

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

Issue 2876153002: Support Using ScopedFeatureList in BrowserTest (Closed)
Patch Set: Ilya comment 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{
Ilya Sherman 2017/06/09 20:19:28 nit: Please add an extra space before the curly br
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 ContentBrowserTest::SetUp();
195 }
196
197 std::string enabled_features_;
198
199 private:
200 base::test::ScopedFeatureList scoped_feature_list_;
201 };
202
203 IN_PROC_BROWSER_TEST_F(ContentBrowserTestScopedFeatureListTest,
204 FeatureListTest) {
205 std::string enabled_features0;
206 std::string disabled_features0;
207
208 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features0,
209 &disabled_features0);
210
211 base::StringPiece enabled_features = enabled_features0;
212
213 // Ensure we repected the features from command line.
214 std::vector<base::StringPiece> original_enabled_features =
215 base::SplitStringPiece(enabled_features_, ",", base::TRIM_WHITESPACE,
216 base::SPLIT_WANT_NONEMPTY);
217
218 for (base::StringPiece enabled_feature : original_enabled_features) {
219 EXPECT_NE(enabled_features.find(enabled_feature), base::StringPiece::npos);
220 }
221
222 // Ensure kTestFeatureForContentBrowserTest enabled.
223 EXPECT_TRUE(base::FeatureList::IsEnabled(kTestFeatureForContentBrowserTest));
Ilya Sherman 2017/06/09 20:19:28 I don't understand. Where is the feature being en
chaopeng 2017/06/13 04:16:32 Sorry, Forgot to test it before send to you.
224 }
225
226 namespace {
227
181 void CallbackChecker(bool* non_nested_task_ran) { 228 void CallbackChecker(bool* non_nested_task_ran) {
182 *non_nested_task_ran = true; 229 *non_nested_task_ran = true;
183 } 230 }
184 231
185 } // namespace 232 } // namespace
186 233
187 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, NonNestableTask) { 234 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, NonNestableTask) {
188 bool non_nested_task_ran = false; 235 bool non_nested_task_ran = false;
189 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( 236 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
190 FROM_HERE, base::Bind(&CallbackChecker, &non_nested_task_ran)); 237 FROM_HERE, base::Bind(&CallbackChecker, &non_nested_task_ran));
191 content::RunAllPendingInMessageLoop(); 238 content::RunAllPendingInMessageLoop();
192 ASSERT_TRUE(non_nested_task_ran); 239 ASSERT_TRUE(non_nested_task_ran);
193 } 240 }
194 241
195 } // namespace content 242 } // namespace content
OLDNEW
« chrome/test/base/test_launcher_utils.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