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

Side by Side Diff: chrome/browser/subresource_filter/subresource_filter_browsertest.cc

Issue 2910843002: [Cleanup] Move all browsertests to use ScopedFeatureList to modify features
Patch Set: Move SFL calls to constructor Created 3 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <map> 5 #include <map>
6 #include <memory> 6 #include <memory>
7 #include <sstream> 7 #include <sstream>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 28 matching lines...) Expand all
39 #include "chrome/browser/ui/browser_commands.h" 39 #include "chrome/browser/ui/browser_commands.h"
40 #include "chrome/browser/ui/browser_navigator.h" 40 #include "chrome/browser/ui/browser_navigator.h"
41 #include "chrome/browser/ui/browser_navigator_params.h" 41 #include "chrome/browser/ui/browser_navigator_params.h"
42 #include "chrome/browser/ui/tabs/tab_strip_model.h" 42 #include "chrome/browser/ui/tabs/tab_strip_model.h"
43 #include "chrome/common/chrome_paths.h" 43 #include "chrome/common/chrome_paths.h"
44 #include "chrome/common/url_constants.h" 44 #include "chrome/common/url_constants.h"
45 #include "chrome/test/base/in_process_browser_test.h" 45 #include "chrome/test/base/in_process_browser_test.h"
46 #include "chrome/test/base/ui_test_utils.h" 46 #include "chrome/test/base/ui_test_utils.h"
47 #include "components/content_settings/core/browser/host_content_settings_map.h" 47 #include "components/content_settings/core/browser/host_content_settings_map.h"
48 #include "components/content_settings/core/common/content_settings.h" 48 #include "components/content_settings/core/common/content_settings.h"
49 #include "components/safe_browsing/features.h"
49 #include "components/safe_browsing_db/test_database_manager.h" 50 #include "components/safe_browsing_db/test_database_manager.h"
50 #include "components/safe_browsing_db/util.h" 51 #include "components/safe_browsing_db/util.h"
51 #include "components/safe_browsing_db/v4_database.h" 52 #include "components/safe_browsing_db/v4_database.h"
52 #include "components/security_interstitials/content/unsafe_resource.h" 53 #include "components/security_interstitials/content/unsafe_resource.h"
53 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter.h" 54 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter.h"
54 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter_test_utils.h" 55 #include "components/subresource_filter/content/browser/async_document_subresour ce_filter_test_utils.h"
55 #include "components/subresource_filter/content/browser/content_ruleset_service. h" 56 #include "components/subresource_filter/content/browser/content_ruleset_service. h"
56 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" 57 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h"
57 #include "components/subresource_filter/core/browser/subresource_filter_constant s.h" 58 #include "components/subresource_filter/core/browser/subresource_filter_constant s.h"
58 #include "components/subresource_filter/core/browser/subresource_filter_features .h" 59 #include "components/subresource_filter/core/browser/subresource_filter_features .h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // specified in the field trial configuration. 204 // specified in the field trial configuration.
204 IN_PROC_BROWSER_TEST_F(SubresourceFilterDisabledByDefaultBrowserTest, 205 IN_PROC_BROWSER_TEST_F(SubresourceFilterDisabledByDefaultBrowserTest,
205 RulesetServiceNotCreated) { 206 RulesetServiceNotCreated) {
206 EXPECT_FALSE(g_browser_process->subresource_filter_ruleset_service()); 207 EXPECT_FALSE(g_browser_process->subresource_filter_ruleset_service());
207 } 208 }
208 209
209 // SubresourceFilterBrowserTest ----------------------------------------------- 210 // SubresourceFilterBrowserTest -----------------------------------------------
210 211
211 class SubresourceFilterBrowserTest : public InProcessBrowserTest { 212 class SubresourceFilterBrowserTest : public InProcessBrowserTest {
212 public: 213 public:
213 SubresourceFilterBrowserTest() {} 214 SubresourceFilterBrowserTest() {
215 scoped_feature_list_.InitWithFeatures(
216 {kSafeBrowsingSubresourceFilter,
217 kSafeBrowsingSubresourceFilterExperimentalUI,
218 safe_browsing::kV4OnlyEnabled},
219 {});
220 }
221
214 ~SubresourceFilterBrowserTest() override {} 222 ~SubresourceFilterBrowserTest() override {}
215 223
216 protected: 224 protected:
217 void SetUpCommandLine(base::CommandLine* command_line) override {
218 command_line->AppendSwitchASCII(switches::kEnableFeatures,
219 base::JoinString(RequiredFeatures(), ","));
220 }
221
222 std::vector<base::StringPiece> RequiredFeatures() const {
223 return {kSafeBrowsingSubresourceFilter.name, "SafeBrowsingV4OnlyEnabled",
224 kSafeBrowsingSubresourceFilterExperimentalUI.name};
225 }
226
227 void SetUp() override { 225 void SetUp() override {
228 sb_factory_ = 226 sb_factory_ =
229 base::MakeUnique<safe_browsing::TestSafeBrowsingServiceFactory>( 227 base::MakeUnique<safe_browsing::TestSafeBrowsingServiceFactory>(
230 safe_browsing::V4FeatureList::V4UsageStatus::V4_ONLY); 228 safe_browsing::V4FeatureList::V4UsageStatus::V4_ONLY);
231 sb_factory_->SetTestUIManager(new FakeSafeBrowsingUIManager()); 229 sb_factory_->SetTestUIManager(new FakeSafeBrowsingUIManager());
232 safe_browsing::SafeBrowsingService::RegisterFactory(sb_factory_.get()); 230 safe_browsing::SafeBrowsingService::RegisterFactory(sb_factory_.get());
233 231
234 safe_browsing::V4Database::RegisterStoreFactoryForTest( 232 safe_browsing::V4Database::RegisterStoreFactoryForTest(
235 base::WrapUnique(new safe_browsing::TestV4StoreFactory())); 233 base::WrapUnique(new safe_browsing::TestV4StoreFactory()));
236 234
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 419
422 std::unique_ptr<safe_browsing::TestSafeBrowsingServiceFactory> sb_factory_; 420 std::unique_ptr<safe_browsing::TestSafeBrowsingServiceFactory> sb_factory_;
423 // Owned by the V4Database. 421 // Owned by the V4Database.
424 safe_browsing::TestV4DatabaseFactory* v4_db_factory_; 422 safe_browsing::TestV4DatabaseFactory* v4_db_factory_;
425 // Owned by the V4GetHashProtocolManager. 423 // Owned by the V4GetHashProtocolManager.
426 safe_browsing::TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_; 424 safe_browsing::TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_;
427 425
428 // Owned by the profile. 426 // Owned by the profile.
429 SubresourceFilterContentSettingsManager* settings_manager_; 427 SubresourceFilterContentSettingsManager* settings_manager_;
430 428
429 base::test::ScopedFeatureList scoped_feature_list_;
430
431 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterBrowserTest); 431 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterBrowserTest);
432 }; 432 };
433 433
434 enum WebSocketCreationPolicy { 434 enum WebSocketCreationPolicy {
435 IN_MAIN_FRAME, 435 IN_MAIN_FRAME,
436 IN_WORKER, 436 IN_WORKER,
437 }; 437 };
438 class SubresourceFilterWebSocketBrowserTest 438 class SubresourceFilterWebSocketBrowserTest
439 : public SubresourceFilterBrowserTest, 439 : public SubresourceFilterBrowserTest,
440 public ::testing::WithParamInterface<WebSocketCreationPolicy> { 440 public ::testing::WithParamInterface<WebSocketCreationPolicy> {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 475
476 enum class OffMainThreadFetchPolicy { 476 enum class OffMainThreadFetchPolicy {
477 kEnabled, 477 kEnabled,
478 kDisabled, 478 kDisabled,
479 }; 479 };
480 480
481 class SubresourceFilterWorkerFetchBrowserTest 481 class SubresourceFilterWorkerFetchBrowserTest
482 : public SubresourceFilterBrowserTest, 482 : public SubresourceFilterBrowserTest,
483 public ::testing::WithParamInterface<OffMainThreadFetchPolicy> { 483 public ::testing::WithParamInterface<OffMainThreadFetchPolicy> {
484 public: 484 public:
485 SubresourceFilterWorkerFetchBrowserTest() {} 485 SubresourceFilterWorkerFetchBrowserTest() {
486 if (GetParam() == OffMainThreadFetchPolicy::kEnabled) {
487 scoped_feature_list_.InitAndEnableFeature(features::kOffMainThreadFetch);
488 } else {
489 scoped_feature_list_.InitAndDisableFeature(features::kOffMainThreadFetch);
490 }
491 }
492
486 ~SubresourceFilterWorkerFetchBrowserTest() override {} 493 ~SubresourceFilterWorkerFetchBrowserTest() override {}
487 494
488 protected: 495 protected:
489 void SetUpCommandLine(base::CommandLine* command_line) override {
490 std::vector<base::StringPiece> features =
491 SubresourceFilterBrowserTest::RequiredFeatures();
492 if (GetParam() == OffMainThreadFetchPolicy::kEnabled) {
493 features.push_back(features::kOffMainThreadFetch.name);
494 } else {
495 command_line->AppendSwitchASCII(switches::kDisableFeatures,
496 features::kOffMainThreadFetch.name);
497 }
498 command_line->AppendSwitchASCII(switches::kEnableFeatures,
499 base::JoinString(features, ","));
500 }
501
502 void ClearTitle() { 496 void ClearTitle() {
503 ASSERT_TRUE(content::ExecuteScript(web_contents()->GetMainFrame(), 497 ASSERT_TRUE(content::ExecuteScript(web_contents()->GetMainFrame(),
504 "document.title = \"\";")); 498 "document.title = \"\";"));
505 } 499 }
506 500
507 private: 501 private:
502 base::test::ScopedFeatureList scoped_feature_list_;
508 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterWorkerFetchBrowserTest); 503 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterWorkerFetchBrowserTest);
509 }; 504 };
510 505
511 // Tests ----------------------------------------------------------------------- 506 // Tests -----------------------------------------------------------------------
512 507
513 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) { 508 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) {
514 content::ConsoleObserverDelegate console_observer(web_contents(), 509 content::ConsoleObserverDelegate console_observer(web_contents(),
515 kActivationConsoleMessage); 510 kActivationConsoleMessage);
516 web_contents()->SetDelegate(&console_observer); 511 web_contents()->SetDelegate(&console_observer);
517 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); 512 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html"));
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 std::string(kSubresourceFilterOnlySuffix), 1816 std::string(kSubresourceFilterOnlySuffix),
1822 false, 1); 1817 false, 1);
1823 1818
1824 tester.ExpectUniqueSample(std::string(kMatchesPatternHistogramName) + 1819 tester.ExpectUniqueSample(std::string(kMatchesPatternHistogramName) +
1825 std::string(kPhishingInterstitialSuffix), 1820 std::string(kPhishingInterstitialSuffix),
1826 false, 1); 1821 false, 1);
1827 } 1822 }
1828 #endif 1823 #endif
1829 1824
1830 } // namespace subresource_filter 1825 } // namespace subresource_filter
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_browser_tests.cc ('k') | chrome/browser/task_manager/task_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698