| OLD | NEW |
| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 base::FilePath test_data_dir; | 253 base::FilePath test_data_dir; |
| 254 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 254 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 255 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 255 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 256 host_resolver()->AddSimulatedFailure("host-with-dns-lookup-failure"); | 256 host_resolver()->AddSimulatedFailure("host-with-dns-lookup-failure"); |
| 257 host_resolver()->AddRule("*", "127.0.0.1"); | 257 host_resolver()->AddRule("*", "127.0.0.1"); |
| 258 content::SetupCrossSiteRedirector(embedded_test_server()); | 258 content::SetupCrossSiteRedirector(embedded_test_server()); |
| 259 ASSERT_TRUE(embedded_test_server()->Start()); | 259 ASSERT_TRUE(embedded_test_server()->Start()); |
| 260 } | 260 } |
| 261 | 261 |
| 262 virtual void SetUpActivationFeature() { | 262 virtual void SetUpActivationFeature() { |
| 263 scoped_feature_toggle_.reset(new ScopedSubresourceFilterFeatureToggle( | 263 ToggleFeatures(base::MakeUnique<ScopedSubresourceFilterFeatureToggle>( |
| 264 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 264 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 265 kActivationScopeActivationList, kActivationListPhishingInterstitial, | 265 kActivationScopeActivationList, kActivationListPhishingInterstitial, |
| 266 measure_performance_ ? "1" : "0", "" /* suppress_notifications */, | 266 measure_performance_ ? "1" : "0", "" /* suppress_notifications */, |
| 267 whitelist_site_on_reload_ ? "true" : "false")); | 267 whitelist_site_on_reload_ ? "true" : "false")); |
| 268 } | 268 } |
| 269 | 269 |
| 270 GURL GetTestUrl(const std::string& relative_url) { | 270 GURL GetTestUrl(const std::string& relative_url) { |
| 271 return embedded_test_server()->base_url().Resolve(relative_url); | 271 return embedded_test_server()->base_url().Resolve(relative_url); |
| 272 } | 272 } |
| 273 | 273 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); | 355 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void SetRulesetWithRules(const std::vector<proto::UrlRule>& rules) { | 358 void SetRulesetWithRules(const std::vector<proto::UrlRule>& rules) { |
| 359 TestRulesetPair test_ruleset_pair; | 359 TestRulesetPair test_ruleset_pair; |
| 360 ruleset_creator_.CreateRulesetWithRules(rules, &test_ruleset_pair); | 360 ruleset_creator_.CreateRulesetWithRules(rules, &test_ruleset_pair); |
| 361 ASSERT_NO_FATAL_FAILURE( | 361 ASSERT_NO_FATAL_FAILURE( |
| 362 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); | 362 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); |
| 363 } | 363 } |
| 364 | 364 |
| 365 void set_scoped_feature_toggle(ScopedSubresourceFilterFeatureToggle* toggle) { | 365 void ToggleFeatures( |
| 366 scoped_feature_toggle_.reset(toggle); | 366 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> features) { |
| 367 scoped_feature_toggle_ = std::move(features); |
| 368 ContentSubresourceFilterDriverFactory* driver_factory = |
| 369 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()); |
| 370 driver_factory->set_configuration_for_testing(GetActiveConfiguration()); |
| 367 } | 371 } |
| 368 | 372 |
| 369 private: | 373 private: |
| 370 TestRulesetCreator ruleset_creator_; | 374 TestRulesetCreator ruleset_creator_; |
| 371 | 375 |
| 372 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> scoped_feature_toggle_; | 376 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> scoped_feature_toggle_; |
| 373 TestRulesetPublisher test_ruleset_publisher_; | 377 TestRulesetPublisher test_ruleset_publisher_; |
| 374 const bool measure_performance_; | 378 const bool measure_performance_; |
| 375 const bool whitelist_site_on_reload_; | 379 const bool whitelist_site_on_reload_; |
| 376 | 380 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 }; | 456 }; |
| 453 | 457 |
| 454 #if defined(GOOGLE_CHROME_BUILD) | 458 #if defined(GOOGLE_CHROME_BUILD) |
| 455 class SubresourceFilterListBrowserTest | 459 class SubresourceFilterListBrowserTest |
| 456 : public SubresourceFilterBrowserTestImpl { | 460 : public SubresourceFilterBrowserTestImpl { |
| 457 public: | 461 public: |
| 458 SubresourceFilterListBrowserTest() | 462 SubresourceFilterListBrowserTest() |
| 459 : SubresourceFilterBrowserTestImpl(false, false) {} | 463 : SubresourceFilterBrowserTestImpl(false, false) {} |
| 460 | 464 |
| 461 void SetUpActivationFeature() override { | 465 void SetUpActivationFeature() override { |
| 462 set_scoped_feature_toggle(new ScopedSubresourceFilterFeatureToggle( | 466 ToggleFeatures(base::MakeUnique<ScopedSubresourceFilterFeatureToggle>( |
| 463 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 467 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 464 kActivationScopeActivationList, kActivationListSubresourceFilter, "0", | 468 kActivationScopeActivationList, kActivationListSubresourceFilter, "0", |
| 465 "" /* suppress_notifications */, "false")); | 469 "" /* suppress_notifications */, "false")); |
| 466 } | 470 } |
| 467 }; | 471 }; |
| 468 #endif | 472 #endif |
| 469 | 473 |
| 470 // Tests ----------------------------------------------------------------------- | 474 // Tests ----------------------------------------------------------------------- |
| 471 | 475 |
| 472 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) { | 476 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, MainFrameActivation) { |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 std::string(kSubresourceFilterOnlySuffix)), | 1328 std::string(kSubresourceFilterOnlySuffix)), |
| 1325 ::testing::IsEmpty()); | 1329 ::testing::IsEmpty()); |
| 1326 | 1330 |
| 1327 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | 1331 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + |
| 1328 std::string(kSubresourceFilterOnlySuffix)), | 1332 std::string(kSubresourceFilterOnlySuffix)), |
| 1329 ::testing::IsEmpty()); | 1333 ::testing::IsEmpty()); |
| 1330 } | 1334 } |
| 1331 #endif | 1335 #endif |
| 1332 | 1336 |
| 1333 } // namespace subresource_filter | 1337 } // namespace subresource_filter |
| OLD | NEW |