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 | |
110 std::string GetSuffixForList(const ActivationList& type) { | 85 std::string GetSuffixForList(const ActivationList& type) { |
111 switch (type) { | 86 switch (type) { |
112 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: | 87 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: |
113 return "SocialEngineeringAdsInterstitial"; | 88 return "SocialEngineeringAdsInterstitial"; |
114 case ActivationList::PHISHING_INTERSTITIAL: | 89 case ActivationList::PHISHING_INTERSTITIAL: |
115 return "PhishingInterstitial"; | 90 return "PhishingInterstitial"; |
116 case ActivationList::SUBRESOURCE_FILTER: | 91 case ActivationList::SUBRESOURCE_FILTER: |
117 return "SubresourceFilterOnly"; | 92 return "SubresourceFilterOnly"; |
118 case ActivationList::NONE: | 93 case ActivationList::NONE: |
119 return std::string(); | 94 return std::string(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 166 } |
192 | 167 |
193 // content::WebContentsObserver: | 168 // content::WebContentsObserver: |
194 void DidStartNavigation( | 169 void DidStartNavigation( |
195 content::NavigationHandle* navigation_handle) override { | 170 content::NavigationHandle* navigation_handle) override { |
196 ASSERT_TRUE(navigation_handle->IsInMainFrame()); | 171 ASSERT_TRUE(navigation_handle->IsInMainFrame()); |
197 navigation_handle->RegisterThrottleForTesting( | 172 navigation_handle->RegisterThrottleForTesting( |
198 base::MakeUnique<SubresourceFilterSafeBrowsingActivationThrottle>( | 173 base::MakeUnique<SubresourceFilterSafeBrowsingActivationThrottle>( |
199 navigation_handle, test_io_task_runner_, | 174 navigation_handle, test_io_task_runner_, |
200 fake_safe_browsing_database_)); | 175 fake_safe_browsing_database_)); |
201 navigation_handle->RegisterThrottleForTesting( | |
202 base::MakeUnique<TestForwardingNavigationThrottle>(navigation_handle)); | |
203 } | 176 } |
204 | 177 |
205 content::NavigationThrottle::ThrottleCheckResult SimulateStart() { | 178 content::NavigationThrottle::ThrottleCheckResult SimulateStart() { |
206 navigation_simulator_->Start(); | 179 navigation_simulator_->Start(); |
207 auto result = navigation_simulator_->GetLastThrottleCheckResult(); | 180 auto result = navigation_simulator_->GetLastThrottleCheckResult(); |
208 if (result == content::NavigationThrottle::CANCEL) | 181 if (result == content::NavigationThrottle::CANCEL) |
209 navigation_simulator_.reset(); | 182 navigation_simulator_.reset(); |
210 return result; | 183 return result; |
211 } | 184 } |
212 | 185 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 ::testing::Values( | 618 ::testing::Values( |
646 content::CancellingNavigationThrottle::SYNCHRONOUS, | 619 content::CancellingNavigationThrottle::SYNCHRONOUS, |
647 content::CancellingNavigationThrottle::ASYNCHRONOUS))); | 620 content::CancellingNavigationThrottle::ASYNCHRONOUS))); |
648 | 621 |
649 INSTANTIATE_TEST_CASE_P( | 622 INSTANTIATE_TEST_CASE_P( |
650 ActivationLevelTest, | 623 ActivationLevelTest, |
651 SubresourceFilterSafeBrowsingActivationThrottleParamTest, | 624 SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
652 ::testing::ValuesIn(kActivationListTestData)); | 625 ::testing::ValuesIn(kActivationListTestData)); |
653 | 626 |
654 } // namespace subresource_filter | 627 } // namespace subresource_filter |
OLD | NEW |