OLD | NEW |
---|---|
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 }; | 171 }; |
170 | 172 |
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 |
181 const base::Feature kTestFeatureForContentBrowserTest{ | |
182 "TestFeatureForContentBrowserTest", base::FEATURE_DISABLED_BY_DEFAULT}; | |
Ilya Sherman
2017/06/07 21:32:36
nit: Please define this in an anonymous namespace.
Ilya Sherman
2017/06/07 21:32:37
Is it worth having both an enabled and a disabled
| |
183 | |
184 class ContentBrowserTestScopedFeatureListTest : public ContentBrowserTest { | |
185 public: | |
186 void SetUp() override { | |
187 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
188 enabled_features_ = | |
189 command_line->GetSwitchValueASCII(switches::kEnableFeatures); | |
190 disabled_features_ = | |
191 command_line->GetSwitchValueASCII(switches::kEnableFeatures); | |
Ilya Sherman
2017/06/07 21:32:36
This should probably be kDisableFeatures... though
| |
192 scoped_feature_list_.InitAndEnableFeature( | |
193 kTestFeatureForContentBrowserTest); | |
194 ContentBrowserTest::SetUp(); | |
195 } | |
196 | |
197 std::string enabled_features_; | |
198 std::string disabled_features_; | |
199 | |
200 private: | |
201 base::test::ScopedFeatureList scoped_feature_list_; | |
202 }; | |
203 | |
204 IN_PROC_BROWSER_TEST_F(ContentBrowserTestScopedFeatureListTest, | |
205 FeatureListTest) { | |
206 std::string enabled_features0; | |
207 std::string disabled_features0; | |
208 | |
209 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features0, | |
210 &disabled_features0); | |
211 | |
212 base::StringPiece enabled_features = enabled_features0; | |
213 base::StringPiece disabled_features = disabled_features0; | |
214 | |
215 // Ensure we repected the features from command line. | |
Ilya Sherman
2017/06/07 21:32:36
Is there reason to expect that there *are* feature
| |
216 std::vector<base::StringPiece> original_enabled_features = | |
217 base::SplitStringPiece(enabled_features_, ",", base::TRIM_WHITESPACE, | |
218 base::SPLIT_WANT_NONEMPTY); | |
219 std::vector<base::StringPiece> original_disabled_features = | |
220 base::SplitStringPiece(disabled_features_, ",", base::TRIM_WHITESPACE, | |
221 base::SPLIT_WANT_NONEMPTY); | |
222 | |
223 for (base::StringPiece enabled_feature : original_enabled_features) { | |
224 EXPECT_NE(enabled_features.find(enabled_feature), base::StringPiece::npos); | |
225 } | |
226 | |
227 for (base::StringPiece disabled_feature : original_disabled_features) { | |
228 EXPECT_NE(disabled_features.find(disabled_feature), | |
229 base::StringPiece::npos); | |
230 } | |
231 | |
232 // Ensure kTestFeatureForContentBrowserTest enabled. | |
233 EXPECT_TRUE(base::FeatureList::IsEnabled(kTestFeatureForContentBrowserTest)); | |
234 } | |
235 | |
179 namespace { | 236 namespace { |
180 | 237 |
181 void CallbackChecker(bool* non_nested_task_ran) { | 238 void CallbackChecker(bool* non_nested_task_ran) { |
182 *non_nested_task_ran = true; | 239 *non_nested_task_ran = true; |
183 } | 240 } |
184 | 241 |
185 } // namespace | 242 } // namespace |
186 | 243 |
187 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, NonNestableTask) { | 244 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, NonNestableTask) { |
188 bool non_nested_task_ran = false; | 245 bool non_nested_task_ran = false; |
189 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( | 246 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( |
190 FROM_HERE, base::Bind(&CallbackChecker, &non_nested_task_ran)); | 247 FROM_HERE, base::Bind(&CallbackChecker, &non_nested_task_ran)); |
191 content::RunAllPendingInMessageLoop(); | 248 content::RunAllPendingInMessageLoop(); |
192 ASSERT_TRUE(non_nested_task_ran); | 249 ASSERT_TRUE(non_nested_task_ran); |
193 } | 250 } |
194 | 251 |
195 } // namespace content | 252 } // namespace content |
OLD | NEW |