| 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 "components/subresource_filter/content/browser/subresource_filter_safe_
browsing_activation_throttle.h" | 5 #include "components/subresource_filter/content/browser/subresource_filter_safe_
browsing_activation_throttle.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 12 #include "components/safe_browsing_db/test_database_manager.h" | 12 #include "components/safe_browsing_db/test_database_manager.h" |
| 13 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" | 13 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" |
| 14 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab
ase_manager.h" | 14 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab
ase_manager.h" |
| 15 #include "components/subresource_filter/content/browser/subresource_filter_clien
t.h" | 15 #include "components/subresource_filter/content/browser/subresource_filter_clien
t.h" |
| 16 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" | 16 #include "components/subresource_filter/core/browser/subresource_filter_features
.h" |
| 17 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" | 17 #include "components/subresource_filter/core/browser/subresource_filter_features
_test_support.h" |
| 18 #include "components/subresource_filter/core/common/activation_level.h" |
| 19 #include "components/subresource_filter/core/common/activation_list.h" |
| 20 #include "components/subresource_filter/core/common/activation_state.h" |
| 18 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | 21 #include "components/subresource_filter/core/common/test_ruleset_creator.h" |
| 19 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/navigation_handle.h" | 23 #include "content/public/browser/navigation_handle.h" |
| 21 #include "content/public/browser/web_contents_observer.h" | 24 #include "content/public/browser/web_contents_observer.h" |
| 22 #include "content/public/test/navigation_simulator.h" | 25 #include "content/public/test/navigation_simulator.h" |
| 23 #include "content/public/test/test_renderer_host.h" | 26 #include "content/public/test/test_renderer_host.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 29 |
| 27 namespace subresource_filter { | 30 namespace subresource_filter { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 class SubresourceFilterSafeBrowsingActivationThrottleTest | 105 class SubresourceFilterSafeBrowsingActivationThrottleTest |
| 103 : public content::RenderViewHostTestHarness, | 106 : public content::RenderViewHostTestHarness, |
| 104 public content::WebContentsObserver { | 107 public content::WebContentsObserver { |
| 105 public: | 108 public: |
| 106 SubresourceFilterSafeBrowsingActivationThrottleTest() | 109 SubresourceFilterSafeBrowsingActivationThrottleTest() |
| 107 : field_trial_list_(nullptr) {} | 110 : field_trial_list_(nullptr) {} |
| 108 ~SubresourceFilterSafeBrowsingActivationThrottleTest() override {} | 111 ~SubresourceFilterSafeBrowsingActivationThrottleTest() override {} |
| 109 | 112 |
| 110 void SetUp() override { | 113 void SetUp() override { |
| 111 content::RenderViewHostTestHarness::SetUp(); | 114 content::RenderViewHostTestHarness::SetUp(); |
| 112 scoped_feature_toggle_.reset( | 115 scoped_configuration_.ResetConfiguration(Configuration( |
| 113 new testing::ScopedSubresourceFilterFeatureToggle( | 116 ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST, |
| 114 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 117 ActivationList::SUBRESOURCE_FILTER)); |
| 115 kActivationScopeActivationList, kActivationListSubresourceFilter)); | |
| 116 // Note: Using NiceMock to allow uninteresting calls and suppress warnings. | 118 // Note: Using NiceMock to allow uninteresting calls and suppress warnings. |
| 117 auto client = | 119 auto client = |
| 118 base::MakeUnique<::testing::NiceMock<MockSubresourceFilterClient>>(); | 120 base::MakeUnique<::testing::NiceMock<MockSubresourceFilterClient>>(); |
| 119 ContentSubresourceFilterDriverFactory::CreateForWebContents( | 121 ContentSubresourceFilterDriverFactory::CreateForWebContents( |
| 120 RenderViewHostTestHarness::web_contents(), std::move(client)); | 122 RenderViewHostTestHarness::web_contents(), std::move(client)); |
| 121 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); | 123 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); |
| 122 NavigateAndCommit(GURL("https://test.com")); | 124 NavigateAndCommit(GURL("https://test.com")); |
| 123 Observe(RenderViewHostTestHarness::web_contents()); | 125 Observe(RenderViewHostTestHarness::web_contents()); |
| 124 } | 126 } |
| 125 | 127 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 fake_safe_browsing_database_->AddBlacklistedUrl( | 170 fake_safe_browsing_database_->AddBlacklistedUrl( |
| 169 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); | 171 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); } | 174 void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); } |
| 173 | 175 |
| 174 const base::HistogramTester& tester() const { return tester_; } | 176 const base::HistogramTester& tester() const { return tester_; } |
| 175 | 177 |
| 176 private: | 178 private: |
| 177 base::FieldTrialList field_trial_list_; | 179 base::FieldTrialList field_trial_list_; |
| 178 std::unique_ptr<testing::ScopedSubresourceFilterFeatureToggle> | 180 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; |
| 179 scoped_feature_toggle_; | |
| 180 std::unique_ptr<content::NavigationSimulator> navigation_simulator_; | 181 std::unique_ptr<content::NavigationSimulator> navigation_simulator_; |
| 181 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; | 182 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; |
| 182 base::HistogramTester tester_; | 183 base::HistogramTester tester_; |
| 183 content::NavigationHandle* navigation_handle_; | 184 content::NavigationHandle* navigation_handle_; |
| 184 | 185 |
| 185 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottleTest); | 186 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottleTest); |
| 186 }; | 187 }; |
| 187 | 188 |
| 188 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 189 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, |
| 189 ListNotMatched_NoActivation) { | 190 ListNotMatched_NoActivation) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 0); | 262 0); |
| 262 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); | 263 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); |
| 263 } | 264 } |
| 264 | 265 |
| 265 // TODO(melandory): Once non-defering check in WillStart is implemented add one | 266 // TODO(melandory): Once non-defering check in WillStart is implemented add one |
| 266 // more test that destroys the Navigation along with corresponding throttles | 267 // more test that destroys the Navigation along with corresponding throttles |
| 267 // while the SB check is pending? (To be run by ASAN bots to ensure | 268 // while the SB check is pending? (To be run by ASAN bots to ensure |
| 268 // no use-after-free.) | 269 // no use-after-free.) |
| 269 | 270 |
| 270 } // namespace subresource_filter | 271 } // namespace subresource_filter |
| OLD | NEW |