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

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

Powered by Google App Engine
This is Rietveld 408576698