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

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

Issue 2834543003: [subresource_filter] SB throttle can send multiple speculative requests. (Closed)
Patch Set: rebase on #468982 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>
9 #include <utility>
8 10
9 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/run_loop.h"
11 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/test/test_mock_time_task_runner.h"
12 #include "components/safe_browsing_db/test_database_manager.h" 16 #include "components/safe_browsing_db/test_database_manager.h"
13 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" 17 #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" 18 #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" 19 #include "components/subresource_filter/content/browser/subresource_filter_clien t.h"
20 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_client.h"
21 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_client_request.h"
16 #include "components/subresource_filter/core/browser/subresource_filter_features .h" 22 #include "components/subresource_filter/core/browser/subresource_filter_features .h"
17 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" 23 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h"
18 #include "components/subresource_filter/core/common/activation_level.h" 24 #include "components/subresource_filter/core/common/activation_level.h"
19 #include "components/subresource_filter/core/common/activation_list.h" 25 #include "components/subresource_filter/core/common/activation_list.h"
20 #include "components/subresource_filter/core/common/activation_state.h" 26 #include "components/subresource_filter/core/common/activation_state.h"
21 #include "components/subresource_filter/core/common/test_ruleset_creator.h" 27 #include "components/subresource_filter/core/common/test_ruleset_creator.h"
22 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/navigation_handle.h" 29 #include "content/public/browser/navigation_handle.h"
24 #include "content/public/browser/web_contents_observer.h" 30 #include "content/public/browser/web_contents_observer.h"
31 #include "content/public/test/cancelling_navigation_throttle.h"
25 #include "content/public/test/navigation_simulator.h" 32 #include "content/public/test/navigation_simulator.h"
26 #include "content/public/test/test_renderer_host.h" 33 #include "content/public/test/test_renderer_host.h"
27 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
29 36
30 namespace subresource_filter { 37 namespace subresource_filter {
31 38
32 namespace { 39 namespace {
33 40
34 char kURL[] = "http://example.test/"; 41 char kURL[] = "http://example.test/";
35 char kRedirectURL[] = "http://foo.test/"; 42 char kRedirectURL[] = "http://redirect.test/";
36 43
37 // Names of navigation chain patterns histogram. 44 // Names of navigation chain patterns histogram.
38 const char kMatchesPatternHistogramNameSubresourceFilterSuffix[] = 45 const char kMatchesPatternHistogramNameSubresourceFilterSuffix[] =
39 "SubresourceFilter.PageLoad.RedirectChainMatchPattern." 46 "SubresourceFilter.PageLoad.RedirectChainMatchPattern."
40 "SubresourceFilterOnly"; 47 "SubresourceFilterOnly";
41 const char kNavigationChainSizeSubresourceFilterSuffix[] = 48 const char kNavigationChainSizeSubresourceFilterSuffix[] =
42 "SubresourceFilter.PageLoad.RedirectChainLength.SubresourceFilterOnly"; 49 "SubresourceFilter.PageLoad.RedirectChainLength.SubresourceFilterOnly";
50 const char kSafeBrowsingNavigationDelay[] =
51 "SubresourceFilter.PageLoad.SafeBrowsingDelay";
52 const char kSafeBrowsingNavigationDelayNoSpeculation[] =
53 "SubresourceFilter.PageLoad.SafeBrowsingDelay.NoRedirectSpeculation";
54 const char kSafeBrowsingCheckTime[] =
55 "SubresourceFilter.SafeBrowsing.CheckTime";
43 56
44 // Human readable representation of expected redirect chain match patterns. 57 // Human readable representation of expected redirect chain match patterns.
45 // The explanations for the buckets given for the following redirect chain: 58 // The explanations for the buckets given for the following redirect chain:
46 // A->B->C->D, where A is initial URL and D is a final URL. 59 // A->B->C->D, where A is initial URL and D is a final URL.
47 enum RedirectChainMatchPattern { 60 enum RedirectChainMatchPattern {
48 EMPTY, // No histograms were recorded. 61 EMPTY, // No histograms were recorded.
49 F0M0L1, // D is a Safe Browsing match. 62 F0M0L1, // D is a Safe Browsing match.
50 F0M1L0, // B or C, or both are Safe Browsing matches. 63 F0M1L0, // B or C, or both are Safe Browsing matches.
51 F0M1L1, // B or C, or both and D are Safe Browsing matches. 64 F0M1L1, // B or C, or both and D are Safe Browsing matches.
52 F1M0L0, // A is Safe Browsing match 65 F1M0L0, // A is Safe Browsing match
(...skipping 19 matching lines...) Expand all
72 MOCK_METHOD0(GetRulesetDealer, VerifiedRulesetDealer::Handle*()); 85 MOCK_METHOD0(GetRulesetDealer, VerifiedRulesetDealer::Handle*());
73 86
74 private: 87 private:
75 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient); 88 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient);
76 }; 89 };
77 90
78 // Throttle to call WillProcessResponse on the factory, which is otherwise 91 // Throttle to call WillProcessResponse on the factory, which is otherwise
79 // called by the ThrottleManager. 92 // called by the ThrottleManager.
80 class TestForwardingNavigationThrottle : public content::NavigationThrottle { 93 class TestForwardingNavigationThrottle : public content::NavigationThrottle {
81 public: 94 public:
82 TestForwardingNavigationThrottle(content::NavigationHandle* handle) 95 explicit TestForwardingNavigationThrottle(content::NavigationHandle* handle)
83 : content::NavigationThrottle(handle) {} 96 : content::NavigationThrottle(handle) {}
84 ~TestForwardingNavigationThrottle() override {} 97 ~TestForwardingNavigationThrottle() override {}
85 98
86 // content::NavigationThrottle: 99 // content::NavigationThrottle:
87 content::NavigationThrottle::ThrottleCheckResult WillProcessResponse() 100 content::NavigationThrottle::ThrottleCheckResult WillProcessResponse()
88 override { 101 override {
89 content::WebContents* web_contents = navigation_handle()->GetWebContents(); 102 content::WebContents* web_contents = navigation_handle()->GetWebContents();
90 ContentSubresourceFilterDriverFactory* factory = 103 ContentSubresourceFilterDriverFactory* factory =
91 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents); 104 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents);
92 factory->WillProcessResponse(navigation_handle()); 105 factory->WillProcessResponse(navigation_handle());
(...skipping 15 matching lines...) Expand all
108 public: 121 public:
109 SubresourceFilterSafeBrowsingActivationThrottleTest() 122 SubresourceFilterSafeBrowsingActivationThrottleTest()
110 : field_trial_list_(nullptr) {} 123 : field_trial_list_(nullptr) {}
111 ~SubresourceFilterSafeBrowsingActivationThrottleTest() override {} 124 ~SubresourceFilterSafeBrowsingActivationThrottleTest() override {}
112 125
113 void SetUp() override { 126 void SetUp() override {
114 content::RenderViewHostTestHarness::SetUp(); 127 content::RenderViewHostTestHarness::SetUp();
115 scoped_configuration_.ResetConfiguration(Configuration( 128 scoped_configuration_.ResetConfiguration(Configuration(
116 ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST, 129 ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST,
117 ActivationList::SUBRESOURCE_FILTER)); 130 ActivationList::SUBRESOURCE_FILTER));
131 test_io_task_runner_ = new base::TestMockTimeTaskRunner();
118 // Note: Using NiceMock to allow uninteresting calls and suppress warnings. 132 // Note: Using NiceMock to allow uninteresting calls and suppress warnings.
119 auto client = 133 auto client =
120 base::MakeUnique<::testing::NiceMock<MockSubresourceFilterClient>>(); 134 base::MakeUnique<::testing::NiceMock<MockSubresourceFilterClient>>();
121 ContentSubresourceFilterDriverFactory::CreateForWebContents( 135 ContentSubresourceFilterDriverFactory::CreateForWebContents(
122 RenderViewHostTestHarness::web_contents(), std::move(client)); 136 RenderViewHostTestHarness::web_contents(), std::move(client));
123 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); 137 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager();
124 NavigateAndCommit(GURL("https://test.com")); 138 NavigateAndCommit(GURL("https://test.com"));
125 Observe(RenderViewHostTestHarness::web_contents()); 139 Observe(RenderViewHostTestHarness::web_contents());
126 } 140 }
127 141
142 void TearDown() override {
143 RunUntilIdle();
144 content::RenderViewHostTestHarness::TearDown();
145 }
146
128 ContentSubresourceFilterDriverFactory* factory() { 147 ContentSubresourceFilterDriverFactory* factory() {
129 return ContentSubresourceFilterDriverFactory::FromWebContents( 148 return ContentSubresourceFilterDriverFactory::FromWebContents(
130 RenderViewHostTestHarness::web_contents()); 149 RenderViewHostTestHarness::web_contents());
131 } 150 }
132 151
133 // content::WebContentsObserver: 152 // content::WebContentsObserver:
134 void DidStartNavigation( 153 void DidStartNavigation(
135 content::NavigationHandle* navigation_handle) override { 154 content::NavigationHandle* navigation_handle) override {
136 ASSERT_TRUE(navigation_handle->IsInMainFrame()); 155 ASSERT_TRUE(navigation_handle->IsInMainFrame());
137 navigation_handle_ = navigation_handle;
138 navigation_handle->RegisterThrottleForTesting( 156 navigation_handle->RegisterThrottleForTesting(
139 base::MakeUnique<SubresourceFilterSafeBrowsingActivationThrottle>( 157 base::MakeUnique<SubresourceFilterSafeBrowsingActivationThrottle>(
140 navigation_handle, fake_safe_browsing_database_)); 158 navigation_handle, test_io_task_runner_,
159 fake_safe_browsing_database_));
141 navigation_handle->RegisterThrottleForTesting( 160 navigation_handle->RegisterThrottleForTesting(
142 base::MakeUnique<TestForwardingNavigationThrottle>(navigation_handle)); 161 base::MakeUnique<TestForwardingNavigationThrottle>(navigation_handle));
143 } 162 }
144 163
164 content::NavigationThrottle::ThrottleCheckResult SimulateStart() {
165 navigation_simulator_->Start();
166 auto result = navigation_simulator_->GetLastThrottleCheckResult();
167 if (result == content::NavigationThrottle::CANCEL)
168 navigation_simulator_.reset();
169 return result;
170 }
171
172 content::NavigationThrottle::ThrottleCheckResult SimulateRedirect(
173 const GURL& new_url) {
174 navigation_simulator_->Redirect(new_url);
175 auto result = navigation_simulator_->GetLastThrottleCheckResult();
176 if (result == content::NavigationThrottle::CANCEL)
177 navigation_simulator_.reset();
178 return result;
179 }
180
181 content::NavigationThrottle::ThrottleCheckResult SimulateCommit() {
182 // Need to post a task to flush the IO thread because calling Commit()
183 // blocks until the throttle checks are complete.
184 // TODO(csharrison): Consider adding finer grained control to the
185 // NavigationSimulator by giving it an option to be driven by a
186 // TestMockTimeTaskRunner. Also see https://crbug.com/703346.
187 base::ThreadTaskRunnerHandle::Get()->PostTask(
188 FROM_HERE, base::Bind(&base::TestMockTimeTaskRunner::RunUntilIdle,
189 base::Unretained(test_io_task_runner_.get())));
190 navigation_simulator_->Commit();
191 auto result = navigation_simulator_->GetLastThrottleCheckResult();
192 if (result == content::NavigationThrottle::CANCEL)
193 navigation_simulator_.reset();
194 return result;
195 }
196
145 void SimulateStartAndExpectProceed() { 197 void SimulateStartAndExpectProceed() {
146 navigation_simulator_->Start(); 198 EXPECT_EQ(content::NavigationThrottle::PROCEED, SimulateStart());
147 EXPECT_EQ(content::NavigationThrottle::PROCEED,
148 navigation_simulator_->GetLastThrottleCheckResult());
149 } 199 }
150 200
151 void SimulateRedirectAndExpectProceed(const GURL& new_url) { 201 void SimulateRedirectAndExpectProceed(const GURL& new_url) {
152 navigation_simulator_->Redirect(new_url); 202 EXPECT_EQ(content::NavigationThrottle::PROCEED, SimulateRedirect(new_url));
153 EXPECT_EQ(content::NavigationThrottle::PROCEED,
154 navigation_simulator_->GetLastThrottleCheckResult());
155 } 203 }
156 204
157 void SimulateCommitAndExpectProceed() { 205 void SimulateCommitAndExpectProceed() {
158 navigation_simulator_->Commit(); 206 EXPECT_EQ(content::NavigationThrottle::PROCEED, SimulateCommit());
159 EXPECT_EQ(content::NavigationThrottle::PROCEED,
160 navigation_simulator_->GetLastThrottleCheckResult());
161 } 207 }
162 208
163 void CreateTestNavigationForMainFrame(const GURL& first_url) { 209 void CreateTestNavigationForMainFrame(const GURL& first_url) {
164 navigation_simulator_ = 210 navigation_simulator_ =
165 content::NavigationSimulator::CreateRendererInitiated(first_url, 211 content::NavigationSimulator::CreateRendererInitiated(first_url,
166 main_rfh()); 212 main_rfh());
167 } 213 }
168 214
169 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) { 215 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) {
170 fake_safe_browsing_database_->AddBlacklistedUrl( 216 fake_safe_browsing_database_->AddBlacklistedUrl(
171 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); 217 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER);
172 } 218 }
173 219
174 void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); } 220 void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); }
175 221
222 void RunUntilIdle() {
223 test_io_task_runner_->RunUntilIdle();
224 base::RunLoop().RunUntilIdle();
225 }
226
176 const base::HistogramTester& tester() const { return tester_; } 227 const base::HistogramTester& tester() const { return tester_; }
177 228
229 base::TestMockTimeTaskRunner* test_io_task_runner() const {
230 return test_io_task_runner_.get();
231 }
232
178 private: 233 private:
179 base::FieldTrialList field_trial_list_; 234 base::FieldTrialList field_trial_list_;
180 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; 235 testing::ScopedSubresourceFilterConfigurator scoped_configuration_;
236 scoped_refptr<base::TestMockTimeTaskRunner> test_io_task_runner_;
181 std::unique_ptr<content::NavigationSimulator> navigation_simulator_; 237 std::unique_ptr<content::NavigationSimulator> navigation_simulator_;
182 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; 238 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_;
183 base::HistogramTester tester_; 239 base::HistogramTester tester_;
184 content::NavigationHandle* navigation_handle_;
185 240
186 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottleTest); 241 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottleTest);
187 }; 242 };
188 243
244 class SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling
245 : public SubresourceFilterSafeBrowsingActivationThrottleTest,
246 public ::testing::WithParamInterface<
247 std::tuple<content::CancellingNavigationThrottle::CancelTime,
248 content::CancellingNavigationThrottle::ResultSynchrony>> {
249 public:
250 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling() {
251 std::tie(cancel_time_, result_sync_) = GetParam();
252 }
253 ~SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling()
254 override {}
255
256 void DidStartNavigation(content::NavigationHandle* handle) override {
257 handle->RegisterThrottleForTesting(
258 base::MakeUnique<content::CancellingNavigationThrottle>(
259 handle, cancel_time_, result_sync_));
260 SubresourceFilterSafeBrowsingActivationThrottleTest::DidStartNavigation(
261 handle);
262 }
263
264 content::CancellingNavigationThrottle::CancelTime cancel_time() {
265 return cancel_time_;
266 }
267
268 content::CancellingNavigationThrottle::ResultSynchrony result_sync() {
269 return result_sync_;
270 }
271
272 private:
273 content::CancellingNavigationThrottle::CancelTime cancel_time_;
274 content::CancellingNavigationThrottle::ResultSynchrony result_sync_;
275
276 DISALLOW_COPY_AND_ASSIGN(
277 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling);
278 };
279
189 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, 280 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
190 ListNotMatched_NoActivation) { 281 ListNotMatched_NoActivation) {
191 const GURL url(kURL); 282 const GURL url(kURL);
192 CreateTestNavigationForMainFrame(url); 283 CreateTestNavigationForMainFrame(url);
193 SimulateStartAndExpectProceed(); 284 SimulateStartAndExpectProceed();
194 SimulateCommitAndExpectProceed(); 285 SimulateCommitAndExpectProceed();
195 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: 286 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision::
196 ACTIVATION_LIST_NOT_MATCHED, 287 ACTIVATION_LIST_NOT_MATCHED,
197 factory()->GetActivationDecisionForLastCommittedPageLoad()); 288 factory()->GetActivationDecisionForLastCommittedPageLoad());
198 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, 289 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix,
199 0); 290 0);
200 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); 291 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0);
292 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 1);
293 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1);
294 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 1);
201 } 295 }
202 296
203 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, 297 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
204 ListMatched_Activation) { 298 ListMatched_Activation) {
205 const GURL url(kURL); 299 const GURL url(kURL);
206 ConfigureAsSubresourceFilterOnlyURL(url); 300 ConfigureAsSubresourceFilterOnlyURL(url);
207 CreateTestNavigationForMainFrame(url); 301 CreateTestNavigationForMainFrame(url);
208 SimulateStartAndExpectProceed(); 302 SimulateStartAndExpectProceed();
209 SimulateCommitAndExpectProceed(); 303 SimulateCommitAndExpectProceed();
210 EXPECT_EQ( 304 EXPECT_EQ(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 2, 341 tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 2,
248 1); 342 1);
249 } 343 }
250 344
251 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, 345 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
252 ListNotMatchedAndTimeout_NoActivation) { 346 ListNotMatchedAndTimeout_NoActivation) {
253 const GURL url(kURL); 347 const GURL url(kURL);
254 SimulateTimeout(); 348 SimulateTimeout();
255 CreateTestNavigationForMainFrame(url); 349 CreateTestNavigationForMainFrame(url);
256 SimulateStartAndExpectProceed(); 350 SimulateStartAndExpectProceed();
351
352 // Flush the pending tasks on the IO thread, so the delayed task surely gets
353 // posted.
354 test_io_task_runner()->RunUntilIdle();
355
356 // Expect one delayed task, and fast forward time.
357 base::TimeDelta expected_delay =
358 SubresourceFilterSafeBrowsingClientRequest::kCheckURLTimeout;
359 EXPECT_EQ(expected_delay, test_io_task_runner()->NextPendingTaskDelay());
360 test_io_task_runner()->FastForwardBy(expected_delay);
257 SimulateCommitAndExpectProceed(); 361 SimulateCommitAndExpectProceed();
258 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: 362 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision::
259 ACTIVATION_LIST_NOT_MATCHED, 363 ACTIVATION_LIST_NOT_MATCHED,
260 factory()->GetActivationDecisionForLastCommittedPageLoad()); 364 factory()->GetActivationDecisionForLastCommittedPageLoad());
261 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, 365 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix,
262 0); 366 0);
263 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); 367 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0);
368 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 1);
369 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1);
370 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 1);
264 } 371 }
265 372
266 // TODO(melandory): Once non-defering check in WillStart is implemented add one 373 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
267 // more test that destroys the Navigation along with corresponding throttles 374 ListMatchedOnStart_NoDelay) {
268 // while the SB check is pending? (To be run by ASAN bots to ensure 375 const GURL url(kURL);
269 // no use-after-free.) 376 ConfigureAsSubresourceFilterOnlyURL(url);
377 CreateTestNavigationForMainFrame(url);
378 SimulateStartAndExpectProceed();
379
380 // Get the database result back before commit.
381 RunUntilIdle();
382
383 SimulateCommitAndExpectProceed();
384 EXPECT_EQ(
385 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED,
386 factory()->GetActivationDecisionForLastCommittedPageLoad());
387 tester().ExpectUniqueSample(
388 kMatchesPatternHistogramNameSubresourceFilterSuffix, NO_REDIRECTS_HIT, 1);
389 tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 1,
390 1);
391 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay,
392 base::TimeDelta::FromMilliseconds(0), 1);
393 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1);
394 }
395
396 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
397 ListMatchedOnRedirect_NoDelay) {
398 const GURL url(kURL);
399 const GURL redirect_url(kRedirectURL);
400 ConfigureAsSubresourceFilterOnlyURL(redirect_url);
401 CreateTestNavigationForMainFrame(url);
402
403 SimulateStartAndExpectProceed();
404 SimulateRedirectAndExpectProceed(redirect_url);
405
406 // Get the database result back before commit.
407 RunUntilIdle();
408
409 SimulateCommitAndExpectProceed();
410 EXPECT_EQ(
411 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED,
412 factory()->GetActivationDecisionForLastCommittedPageLoad());
413 tester().ExpectUniqueSample(
414 kMatchesPatternHistogramNameSubresourceFilterSuffix, F0M0L1, 1);
415 tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 2,
416 1);
417 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay,
418 base::TimeDelta::FromMilliseconds(0), 1);
419 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1);
420 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 2);
421 }
422
423 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
424 ListMatchedOnStartWithRedirect_NoActivation) {
425 const GURL url(kURL);
426 const GURL redirect_url(kRedirectURL);
427 ConfigureAsSubresourceFilterOnlyURL(url);
428 CreateTestNavigationForMainFrame(url);
429
430 // These two lines also test how the database client reacts to two requests
431 // happening one after another.
432 SimulateStartAndExpectProceed();
433 SimulateRedirectAndExpectProceed(redirect_url);
434
435 // Get the database result back before commit.
436 RunUntilIdle();
437
438 SimulateCommitAndExpectProceed();
439 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision::
440 ACTIVATION_LIST_NOT_MATCHED,
441 factory()->GetActivationDecisionForLastCommittedPageLoad());
442 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix,
443 0);
444 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0);
445 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay,
446 base::TimeDelta::FromMilliseconds(0), 1);
447 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1);
448 }
449
450 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling,
451 Cancel) {
452 const GURL url(kURL);
453 SCOPED_TRACE(::testing::Message() << "CancelTime: " << cancel_time()
454 << " ResultSynchrony: " << result_sync());
455 ConfigureAsSubresourceFilterOnlyURL(url);
456 CreateTestNavigationForMainFrame(url);
457
458 content::NavigationThrottle::ThrottleCheckResult result = SimulateStart();
459 if (cancel_time() ==
460 content::CancellingNavigationThrottle::WILL_START_REQUEST) {
461 EXPECT_EQ(content::NavigationThrottle::CANCEL, result);
462 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 0);
463 return;
464 }
465 EXPECT_EQ(content::NavigationThrottle::PROCEED, result);
466
467 result = SimulateRedirect(GURL(kRedirectURL));
468 if (cancel_time() ==
469 content::CancellingNavigationThrottle::WILL_REDIRECT_REQUEST) {
470 EXPECT_EQ(content::NavigationThrottle::CANCEL, result);
471 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 0);
472 return;
473 }
474 EXPECT_EQ(content::NavigationThrottle::PROCEED, result);
475
476 base::RunLoop().RunUntilIdle();
477
478 result = SimulateCommit();
479 EXPECT_EQ(content::NavigationThrottle::CANCEL, result);
480 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 0);
481 }
482
483 INSTANTIATE_TEST_CASE_P(
484 CancelMethod,
485 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling,
486 ::testing::Combine(
487 ::testing::Values(
488 content::CancellingNavigationThrottle::WILL_START_REQUEST,
489 content::CancellingNavigationThrottle::WILL_REDIRECT_REQUEST,
490 content::CancellingNavigationThrottle::WILL_PROCESS_RESPONSE),
491 ::testing::Values(
492 content::CancellingNavigationThrottle::SYNCHRONOUS,
493 content::CancellingNavigationThrottle::ASYNCHRONOUS)));
270 494
271 } // namespace subresource_filter 495 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698