Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle_unittest.cc

Issue 2889193003: [subresource_filter] Reland: Remove Forwarding NavigationThrottles (Closed)
Patch Set: Fix Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 fake_safe_browsing_database_->AddBlacklistedUrl(url, pattern_type, 234 fake_safe_browsing_database_->AddBlacklistedUrl(url, pattern_type,
262 metadata); 235 metadata);
263 } 236 }
264 237
265 void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); } 238 void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); }
266 239
267 void ClearAllBlacklistedUrls() { 240 void ClearAllBlacklistedUrls() {
268 fake_safe_browsing_database_->RemoveAllBlacklistedUrls(); 241 fake_safe_browsing_database_->RemoveAllBlacklistedUrls();
269 } 242 }
270 243
244 // With a null database the throttle becomes pass-through.
245 void UsePassThroughThrottle() { fake_safe_browsing_database_ = nullptr; }
246
271 void RunUntilIdle() { 247 void RunUntilIdle() {
272 test_io_task_runner_->RunUntilIdle(); 248 test_io_task_runner_->RunUntilIdle();
273 base::RunLoop().RunUntilIdle(); 249 base::RunLoop().RunUntilIdle();
274 } 250 }
275 251
276 const base::HistogramTester& tester() const { return tester_; } 252 const base::HistogramTester& tester() const { return tester_; }
277 253
278 base::TestMockTimeTaskRunner* test_io_task_runner() const { 254 base::TestMockTimeTaskRunner* test_io_task_runner() const {
279 return test_io_task_runner_.get(); 255 return test_io_task_runner_.get();
280 } 256 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 325 }
350 326
351 private: 327 private:
352 content::CancellingNavigationThrottle::CancelTime cancel_time_; 328 content::CancellingNavigationThrottle::CancelTime cancel_time_;
353 content::CancellingNavigationThrottle::ResultSynchrony result_sync_; 329 content::CancellingNavigationThrottle::ResultSynchrony result_sync_;
354 330
355 DISALLOW_COPY_AND_ASSIGN( 331 DISALLOW_COPY_AND_ASSIGN(
356 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling); 332 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling);
357 }; 333 };
358 334
335 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
336 PassThroughThrottle) {
337 UsePassThroughThrottle();
338 CreateTestNavigationForMainFrame(GURL(kURL));
339 SimulateStartAndExpectProceed();
340 SimulateRedirectAndExpectProceed(GURL(kRedirectURL));
341 SimulateCommitAndExpectProceed();
342 EXPECT_EQ(ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET,
343 factory()->GetActivationDecisionForLastCommittedPageLoad());
344
345 scoped_configuration()->ResetConfiguration(
346 Configuration(ActivationLevel::ENABLED, ActivationScope::ALL_SITES));
347 CreateTestNavigationForMainFrame(GURL(kURL));
348 SimulateStartAndExpectProceed();
349 SimulateRedirectAndExpectProceed(GURL(kRedirectURL));
350 SimulateCommitAndExpectProceed();
351 EXPECT_EQ(ActivationDecision::ACTIVATED,
352 factory()->GetActivationDecisionForLastCommittedPageLoad());
353
354 scoped_configuration()->ResetConfiguration(
355 Configuration(ActivationLevel::ENABLED, ActivationScope::NO_SITES));
356 CreateTestNavigationForMainFrame(GURL(kURL));
357 SimulateStartAndExpectProceed();
358 SimulateRedirectAndExpectProceed(GURL(kRedirectURL));
359 SimulateCommitAndExpectProceed();
360 EXPECT_EQ(ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET,
361 factory()->GetActivationDecisionForLastCommittedPageLoad());
362 }
363
359 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, 364 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest,
360 ListNotMatched_NoActivation) { 365 ListNotMatched_NoActivation) {
361 const ActivationListTestData& test_data = GetParam(); 366 const ActivationListTestData& test_data = GetParam();
362 const GURL url(kURL); 367 const GURL url(kURL);
363 const std::string suffix(GetSuffixForList(test_data.activation_list_type)); 368 const std::string suffix(GetSuffixForList(test_data.activation_list_type));
364 CreateTestNavigationForMainFrame(url); 369 CreateTestNavigationForMainFrame(url);
365 SimulateStartAndExpectProceed(); 370 SimulateStartAndExpectProceed();
366 SimulateCommitAndExpectProceed(); 371 SimulateCommitAndExpectProceed();
367 EXPECT_EQ(ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, 372 EXPECT_EQ(ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET,
368 factory()->GetActivationDecisionForLastCommittedPageLoad()); 373 factory()->GetActivationDecisionForLastCommittedPageLoad());
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 ::testing::Values( 650 ::testing::Values(
646 content::CancellingNavigationThrottle::SYNCHRONOUS, 651 content::CancellingNavigationThrottle::SYNCHRONOUS,
647 content::CancellingNavigationThrottle::ASYNCHRONOUS))); 652 content::CancellingNavigationThrottle::ASYNCHRONOUS)));
648 653
649 INSTANTIATE_TEST_CASE_P( 654 INSTANTIATE_TEST_CASE_P(
650 ActivationLevelTest, 655 ActivationLevelTest,
651 SubresourceFilterSafeBrowsingActivationThrottleParamTest, 656 SubresourceFilterSafeBrowsingActivationThrottleParamTest,
652 ::testing::ValuesIn(kActivationListTestData)); 657 ::testing::ValuesIn(kActivationListTestData));
653 658
654 } // namespace subresource_filter 659 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698