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 #include <tuple> | 8 #include <tuple> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 MOCK_METHOD2(OnPageActivationComputed, | 75 MOCK_METHOD2(OnPageActivationComputed, |
76 bool(content::NavigationHandle*, bool)); | 76 bool(content::NavigationHandle*, bool)); |
77 MOCK_METHOD1(WhitelistByContentSettings, void(const GURL&)); | 77 MOCK_METHOD1(WhitelistByContentSettings, void(const GURL&)); |
78 MOCK_METHOD1(WhitelistInCurrentWebContents, void(const GURL&)); | 78 MOCK_METHOD1(WhitelistInCurrentWebContents, void(const GURL&)); |
79 MOCK_METHOD0(GetRulesetDealer, VerifiedRulesetDealer::Handle*()); | 79 MOCK_METHOD0(GetRulesetDealer, VerifiedRulesetDealer::Handle*()); |
80 | 80 |
81 private: | 81 private: |
82 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient); | 82 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient); |
83 }; | 83 }; |
84 | 84 |
| 85 // Throttle to call WillProcessResponse on the factory, which is otherwise |
| 86 // called by the ThrottleManager. |
| 87 class TestForwardingNavigationThrottle : public content::NavigationThrottle { |
| 88 public: |
| 89 explicit TestForwardingNavigationThrottle(content::NavigationHandle* handle) |
| 90 : content::NavigationThrottle(handle) {} |
| 91 ~TestForwardingNavigationThrottle() override {} |
| 92 |
| 93 // content::NavigationThrottle: |
| 94 content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() |
| 95 override { |
| 96 content::WebContents* web_contents = navigation_handle()->GetWebContents(); |
| 97 ContentSubresourceFilterDriverFactory* factory = |
| 98 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); |
| 99 factory->WillProcessResponse(navigation_handle()); |
| 100 return content::NavigationThrottle::PROCEED; |
| 101 } |
| 102 const char* GetNameForLogging() override { |
| 103 return "TestForwardingNavigationThrottle"; |
| 104 } |
| 105 |
| 106 private: |
| 107 DISALLOW_COPY_AND_ASSIGN(TestForwardingNavigationThrottle); |
| 108 }; |
| 109 |
85 std::string GetSuffixForList(const ActivationList& type) { | 110 std::string GetSuffixForList(const ActivationList& type) { |
86 switch (type) { | 111 switch (type) { |
87 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: | 112 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: |
88 return "SocialEngineeringAdsInterstitial"; | 113 return "SocialEngineeringAdsInterstitial"; |
89 case ActivationList::PHISHING_INTERSTITIAL: | 114 case ActivationList::PHISHING_INTERSTITIAL: |
90 return "PhishingInterstitial"; | 115 return "PhishingInterstitial"; |
91 case ActivationList::SUBRESOURCE_FILTER: | 116 case ActivationList::SUBRESOURCE_FILTER: |
92 return "SubresourceFilterOnly"; | 117 return "SubresourceFilterOnly"; |
93 case ActivationList::NONE: | 118 case ActivationList::NONE: |
94 return std::string(); | 119 return std::string(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 191 } |
167 | 192 |
168 // content::WebContentsObserver: | 193 // content::WebContentsObserver: |
169 void DidStartNavigation( | 194 void DidStartNavigation( |
170 content::NavigationHandle* navigation_handle) override { | 195 content::NavigationHandle* navigation_handle) override { |
171 ASSERT_TRUE(navigation_handle->IsInMainFrame()); | 196 ASSERT_TRUE(navigation_handle->IsInMainFrame()); |
172 navigation_handle->RegisterThrottleForTesting( | 197 navigation_handle->RegisterThrottleForTesting( |
173 base::MakeUnique<SubresourceFilterSafeBrowsingActivationThrottle>( | 198 base::MakeUnique<SubresourceFilterSafeBrowsingActivationThrottle>( |
174 navigation_handle, test_io_task_runner_, | 199 navigation_handle, test_io_task_runner_, |
175 fake_safe_browsing_database_)); | 200 fake_safe_browsing_database_)); |
| 201 navigation_handle->RegisterThrottleForTesting( |
| 202 base::MakeUnique<TestForwardingNavigationThrottle>(navigation_handle)); |
176 } | 203 } |
177 | 204 |
178 content::NavigationThrottle::ThrottleCheckResult SimulateStart() { | 205 content::NavigationThrottle::ThrottleCheckResult SimulateStart() { |
179 navigation_simulator_->Start(); | 206 navigation_simulator_->Start(); |
180 auto result = navigation_simulator_->GetLastThrottleCheckResult(); | 207 auto result = navigation_simulator_->GetLastThrottleCheckResult(); |
181 if (result == content::NavigationThrottle::CANCEL) | 208 if (result == content::NavigationThrottle::CANCEL) |
182 navigation_simulator_.reset(); | 209 navigation_simulator_.reset(); |
183 return result; | 210 return result; |
184 } | 211 } |
185 | 212 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 ::testing::Values( | 645 ::testing::Values( |
619 content::CancellingNavigationThrottle::SYNCHRONOUS, | 646 content::CancellingNavigationThrottle::SYNCHRONOUS, |
620 content::CancellingNavigationThrottle::ASYNCHRONOUS))); | 647 content::CancellingNavigationThrottle::ASYNCHRONOUS))); |
621 | 648 |
622 INSTANTIATE_TEST_CASE_P( | 649 INSTANTIATE_TEST_CASE_P( |
623 ActivationLevelTest, | 650 ActivationLevelTest, |
624 SubresourceFilterSafeBrowsingActivationThrottleParamTest, | 651 SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
625 ::testing::ValuesIn(kActivationListTestData)); | 652 ::testing::ValuesIn(kActivationListTestData)); |
626 | 653 |
627 } // namespace subresource_filter | 654 } // namespace subresource_filter |
OLD | NEW |