Chromium Code Reviews| Index: components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc |
| diff --git a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc |
| index cb08eefd8395921510033df511472b131fe93bee..36adcf1a9f2079531c56bf5a215301c5d710b8ac 100644 |
| --- a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc |
| +++ b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc |
| @@ -239,7 +239,7 @@ class ContentSubresourceFilterDriverFactoryTest |
| client_ = new MockSubresourceFilterClient(ruleset_dealer_.get()); |
| ContentSubresourceFilterDriverFactory::CreateForWebContents( |
| RenderViewHostTestHarness::web_contents(), base::WrapUnique(client())); |
| - ResetConfigurationToEnableFilteringOnSocialEngineeringSites(); |
| + ResetConfigurationToEnableFilteringOnPhishingSites(); |
| // Add a subframe. |
| content::RenderFrameHostTester* rfh_tester = |
| @@ -265,10 +265,16 @@ class ContentSubresourceFilterDriverFactoryTest |
| Configuration(ActivationLevel::ENABLED, ActivationScope::ALL_SITES)); |
| } |
| - void ResetConfigurationToEnableFilteringOnSocialEngineeringSites() { |
| - ResetConfiguration(Configuration( |
| - ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST, |
| - ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
| + void ResetConfigurationToEnableFilteringOnPhishingSites() { |
| + ResetConfiguration(Configuration::MakePresetForLiveRunOnPhishingSites()); |
| + } |
| + |
| + Configuration GetExactlyOneEnabledConfig() { |
| + const auto config_list = GetEnabledConfigurations(); |
| + EXPECT_EQ(1u, config_list->configs_by_decreasing_priority().size()); |
| + if (config_list->configs_by_decreasing_priority().empty()) |
|
pkalinnikov
2017/05/04 12:04:22
Given that ParseEnabledConfigurations always pushe
engedy
2017/05/05 12:25:42
Yes, I made this cleaner.
pkalinnikov
2017/05/05 13:29:58
Yup, looks better.
|
| + return Configuration(); |
| + return (config_list->configs_by_decreasing_priority().front()); |
| } |
| ContentSubresourceFilterDriverFactory* factory() { |
| @@ -480,15 +486,6 @@ class ContentSubresourceFilterDriverFactoryTest |
| } |
| private: |
| - static bool expected_measure_performance() { |
| - const double rate = GetActiveConfigurations() |
| - ->the_one_and_only() |
| - .performance_measurement_rate; |
| - // Note: The case when 0 < rate < 1 is not deterministic, don't test it. |
| - EXPECT_TRUE(rate == 0 || rate == 1); |
| - return rate == 1; |
| - } |
| - |
| testing::ScopedSubresourceFilterConfigurator scoped_configuration_; |
| testing::TestRulesetCreator test_ruleset_creator_; |
| testing::TestRulesetPair test_ruleset_pair_; |
| @@ -541,7 +538,7 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| Configuration config(ActivationLevel::DISABLED, |
| ActivationScope::ACTIVATION_LIST, |
| ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| - config.activation_level = ActivationLevel::DISABLED; |
| + config.activation_options.activation_level = ActivationLevel::DISABLED; |
| ResetConfiguration(std::move(config)); |
| const GURL url(kExampleUrlWithParams); |
| @@ -576,7 +573,7 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| Configuration config(ActivationLevel::ENABLED, |
| ActivationScope::ACTIVATION_LIST, |
| ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| - config.performance_measurement_rate = 1.0; |
| + config.activation_options.performance_measurement_rate = 1.0; |
| ResetConfiguration(std::move(config)); |
| EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
| @@ -694,7 +691,7 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { |
| TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| SuppressNotificationVisibility) { |
| Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| - config.should_suppress_notifications = true; |
| + config.activation_options.should_suppress_notifications = true; |
| ResetConfiguration(std::move(config)); |
| NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| ActivationDecision::ACTIVATED); |
| @@ -734,7 +731,7 @@ TEST_F(ContentSubresourceFilterDriverFactoryTest, WhitelistSiteOnReload) { |
| << " transition = \"" << test_case.transition << "\""); |
| Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| - config.should_whitelist_site_on_reload = true; |
| + config.activation_options.should_whitelist_site_on_reload = true; |
| ResetConfiguration(std::move(config)); |
| NavigateAndExpectActivation( |
| @@ -761,12 +758,13 @@ TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, |
| NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| test_data.expected_activation_decision); |
| factory()->client()->WhitelistInCurrentWebContents(url); |
| + bool expect_activation_is_disabled = |
| + GetExactlyOneEnabledConfig().activation_options.activation_level == |
| + ActivationLevel::DISABLED; |
| NavigateAndExpectActivation( |
| {true}, {GURL(kExampleUrlWithParams)}, NO_REDIRECTS_HIT, |
| - GetActiveConfigurations()->the_one_and_only().activation_level == |
| - ActivationLevel::DISABLED |
| - ? ActivationDecision::ACTIVATION_DISABLED |
| - : ActivationDecision::URL_WHITELISTED); |
| + expect_activation_is_disabled ? ActivationDecision::ACTIVATION_DISABLED |
| + : ActivationDecision::URL_WHITELISTED); |
| } |
| TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, |
| @@ -808,13 +806,14 @@ TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| test_data.expected_activation_decision); |
| if (test_data.url_matches_activation_list) { |
| factory()->client()->WhitelistInCurrentWebContents(test_url); |
| - NavigateAndExpectActivation( |
| - {test_data.url_matches_activation_list}, {GURL(kExampleUrlWithParams)}, |
| - expected_pattern, |
| - GetActiveConfigurations()->the_one_and_only().activation_scope == |
| - ActivationScope::NO_SITES |
| - ? ActivationDecision::ACTIVATION_DISABLED |
| - : ActivationDecision::URL_WHITELISTED); |
| + bool expect_activation_is_disabled = |
| + GetExactlyOneEnabledConfig().activation_conditions.activation_scope == |
| + ActivationScope::NO_SITES; |
| + NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| + {GURL(kExampleUrlWithParams)}, expected_pattern, |
| + expect_activation_is_disabled |
| + ? ActivationDecision::ACTIVATION_DISABLED |
| + : ActivationDecision::URL_WHITELISTED); |
| } |
| }; |
| @@ -836,13 +835,14 @@ TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| "https://example.test"}; |
| for (auto* url : unsupported_urls) { |
| SCOPED_TRACE(url); |
| + bool expect_activation_is_disabled = |
| + GetExactlyOneEnabledConfig().activation_conditions.activation_scope == |
| + ActivationScope::NO_SITES; |
| RedirectChainMatchPattern expected_pattern = EMPTY; |
| NavigateAndExpectActivation( |
| {test_data.url_matches_activation_list}, {GURL(url)}, expected_pattern, |
| - GetActiveConfigurations()->the_one_and_only().activation_scope == |
| - ActivationScope::NO_SITES |
| - ? ActivationDecision::ACTIVATION_DISABLED |
| - : ActivationDecision::UNSUPPORTED_SCHEME); |
| + expect_activation_is_disabled ? ActivationDecision::ACTIVATION_DISABLED |
| + : ActivationDecision::UNSUPPORTED_SCHEME); |
| } |
| for (auto* url : supported_urls) { |
| SCOPED_TRACE(url); |