OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <memory> | 5 #include <memory> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
27 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
28 #include "components/prefs/testing_pref_service.h" | 28 #include "components/prefs/testing_pref_service.h" |
29 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 29 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
30 #include "components/subresource_filter/content/browser/content_ruleset_service.
h" | 30 #include "components/subresource_filter/content/browser/content_ruleset_service.
h" |
31 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" | 31 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" |
32 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab
ase_manager.h" | 32 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab
ase_manager.h" |
33 #include "components/subresource_filter/core/browser/ruleset_service.h" | 33 #include "components/subresource_filter/core/browser/ruleset_service.h" |
34 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" | 34 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
35 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" | 35 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" |
| 36 #include "components/subresource_filter/core/common/activation_decision.h" |
36 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | 37 #include "components/subresource_filter/core/common/test_ruleset_creator.h" |
37 #include "content/public/browser/navigation_throttle.h" | 38 #include "content/public/browser/navigation_throttle.h" |
38 #include "content/public/test/navigation_simulator.h" | 39 #include "content/public/test/navigation_simulator.h" |
39 #include "content/public/test/test_renderer_host.h" | 40 #include "content/public/test/test_renderer_host.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "url/gurl.h" | 42 #include "url/gurl.h" |
42 | 43 |
43 namespace { | 44 namespace { |
44 using subresource_filter::testing::ScopedSubresourceFilterConfigurator; | 45 using subresource_filter::testing::ScopedSubresourceFilterConfigurator; |
45 using subresource_filter::testing::ScopedSubresourceFilterFeatureToggle; | 46 using subresource_filter::testing::ScopedSubresourceFilterFeatureToggle; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 250 |
250 // Simulate explicit whitelisting and reload. | 251 // Simulate explicit whitelisting and reload. |
251 settings_manager()->WhitelistSite(url); | 252 settings_manager()->WhitelistSite(url); |
252 SimulateNavigateAndCommit(url, main_rfh()); | 253 SimulateNavigateAndCommit(url, main_rfh()); |
253 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); | 254 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); |
254 | 255 |
255 // Should not have cleared the metadata, since the site is still on the SB | 256 // Should not have cleared the metadata, since the site is still on the SB |
256 // blacklist. | 257 // blacklist. |
257 EXPECT_NE(nullptr, settings_manager()->GetSiteMetadata(url)); | 258 EXPECT_NE(nullptr, settings_manager()->GetSiteMetadata(url)); |
258 } | 259 } |
| 260 |
| 261 TEST_F(SubresourceFilterTest, |
| 262 NavigationToBadSchemeUrlWithNoActivation_DoesNotReportBadScheme) { |
| 263 // Don't report UNSUPPORTED_SCHEME if the navigation has no matching |
| 264 // configuration. |
| 265 scoped_configuration().ResetConfiguration(subresource_filter::Configuration( |
| 266 subresource_filter::ActivationLevel::DISABLED, |
| 267 subresource_filter::ActivationScope::NO_SITES)); |
| 268 |
| 269 GURL url("data:text/html,hello world"); |
| 270 SimulateNavigateAndCommit(url, main_rfh()); |
| 271 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); |
| 272 auto* driver_factory = subresource_filter:: |
| 273 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents()); |
| 274 EXPECT_EQ( |
| 275 subresource_filter::ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
| 276 driver_factory->GetActivationDecisionForLastCommittedPageLoad()); |
| 277 |
| 278 // Also don't report UNSUPPORTED_SCHEME if the navigation matches a |
| 279 // configuration with DISABLED activation level. |
| 280 scoped_configuration().ResetConfiguration(subresource_filter::Configuration( |
| 281 subresource_filter::ActivationLevel::DISABLED, |
| 282 subresource_filter::ActivationScope::ALL_SITES)); |
| 283 |
| 284 SimulateNavigateAndCommit(url, main_rfh()); |
| 285 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); |
| 286 EXPECT_EQ(subresource_filter::ActivationDecision::ACTIVATION_DISABLED, |
| 287 driver_factory->GetActivationDecisionForLastCommittedPageLoad()); |
| 288 |
| 289 // Sanity check that UNSUPPORTED_SCHEME is reported if the navigation does |
| 290 // activate. |
| 291 scoped_configuration().ResetConfiguration(subresource_filter::Configuration( |
| 292 subresource_filter::ActivationLevel::ENABLED, |
| 293 subresource_filter::ActivationScope::ALL_SITES)); |
| 294 SimulateNavigateAndCommit(url, main_rfh()); |
| 295 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); |
| 296 EXPECT_EQ(subresource_filter::ActivationDecision::UNSUPPORTED_SCHEME, |
| 297 driver_factory->GetActivationDecisionForLastCommittedPageLoad()); |
| 298 } |
OLD | NEW |