OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/renderer/subresource_filter_agen
t.h" | 5 #include "components/subresource_filter/content/renderer/subresource_filter_agen
t.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "components/subresource_filter/content/common/document_load_statistics.
h" | 15 #include "components/subresource_filter/content/common/document_load_statistics.
h" |
16 #include "components/subresource_filter/content/common/subresource_filter_messag
es.h" | 16 #include "components/subresource_filter/content/common/subresource_filter_messag
es.h" |
17 #include "components/subresource_filter/content/renderer/unverified_ruleset_deal
er.h" | 17 #include "components/subresource_filter/content/renderer/unverified_ruleset_deal
er.h" |
18 #include "components/subresource_filter/core/common/scoped_timers.h" | 18 #include "components/subresource_filter/core/common/scoped_timers.h" |
19 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | 19 #include "components/subresource_filter/core/common/test_ruleset_creator.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "third_party/WebKit/public/platform/WebDocumentSubresourceFilter.h" | 22 #include "third_party/WebKit/public/platform/WebDocumentSubresourceFilter.h" |
| 23 #include "third_party/WebKit/public/platform/WebDocumentSubresourceFilterLoadPol
icy.h" |
23 #include "third_party/WebKit/public/platform/WebURL.h" | 24 #include "third_party/WebKit/public/platform/WebURL.h" |
24 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 25 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
26 | 27 |
27 namespace subresource_filter { | 28 namespace subresource_filter { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 // The SubresourceFilterAgent with its dependencies on Blink mocked out. | 32 // The SubresourceFilterAgent with its dependencies on Blink mocked out. |
32 // | 33 // |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 EXPECT_CALL(*agent(), SignalFirstSubresourceDisallowedForCommittedLoad()) | 166 EXPECT_CALL(*agent(), SignalFirstSubresourceDisallowedForCommittedLoad()) |
166 .Times(0); | 167 .Times(0); |
167 } | 168 } |
168 | 169 |
169 void ExpectDocumentLoadStatisticsSent() { | 170 void ExpectDocumentLoadStatisticsSent() { |
170 EXPECT_CALL(*agent(), SendDocumentLoadStatistics(::testing::_)); | 171 EXPECT_CALL(*agent(), SendDocumentLoadStatistics(::testing::_)); |
171 } | 172 } |
172 | 173 |
173 void ExpectLoadPolicy( | 174 void ExpectLoadPolicy( |
174 base::StringPiece url_spec, | 175 base::StringPiece url_spec, |
175 blink::WebDocumentSubresourceFilter::LoadPolicy expected_policy) { | 176 blink::WebDocumentSubresourceFilterLoadPolicy expected_policy) { |
176 blink::WebURL url = GURL(url_spec); | 177 blink::WebURL url = GURL(url_spec); |
177 blink::WebURLRequest::RequestContext request_context = | 178 blink::WebURLRequest::RequestContext request_context = |
178 blink::WebURLRequest::RequestContextImage; | 179 blink::WebURLRequest::RequestContextImage; |
179 blink::WebDocumentSubresourceFilter::LoadPolicy actual_policy = | 180 blink::WebDocumentSubresourceFilterLoadPolicy actual_policy = |
180 agent()->filter()->getLoadPolicy(url, request_context); | 181 agent()->filter()->getLoadPolicy(url, request_context); |
181 EXPECT_EQ(expected_policy, actual_policy); | 182 EXPECT_EQ(expected_policy, actual_policy); |
182 | 183 |
183 // If the load policy indicated the load was filtered, simulate a filtered | 184 // If the load policy indicated the load was filtered, simulate a filtered |
184 // load callback. In production, this will be called in FrameFetchContext, | 185 // load callback. In production, this will be called in FrameFetchContext, |
185 // but we simulate the call here. | 186 // but we simulate the call here. |
186 if (actual_policy == blink::WebDocumentSubresourceFilter::Disallow) | 187 if (actual_policy == |
| 188 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow) |
187 agent()->filter()->reportDisallowedLoad(); | 189 agent()->filter()->reportDisallowedLoad(); |
188 } | 190 } |
189 | 191 |
190 SubresourceFilterAgentUnderTest* agent() { return agent_.get(); } | 192 SubresourceFilterAgentUnderTest* agent() { return agent_.get(); } |
191 content::RenderFrameObserver* agent_as_rfo() { | 193 content::RenderFrameObserver* agent_as_rfo() { |
192 return static_cast<content::RenderFrameObserver*>(agent_.get()); | 194 return static_cast<content::RenderFrameObserver*>(agent_.get()); |
193 } | 195 } |
194 | 196 |
195 private: | 197 private: |
196 testing::TestRulesetCreator test_ruleset_creator_; | 198 testing::TestRulesetCreator test_ruleset_creator_; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 base::HistogramTester histogram_tester; | 279 base::HistogramTester histogram_tester; |
278 ASSERT_NO_FATAL_FAILURE( | 280 ASSERT_NO_FATAL_FAILURE( |
279 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); | 281 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); |
280 | 282 |
281 ExpectSubresourceFilterGetsInjected(); | 283 ExpectSubresourceFilterGetsInjected(); |
282 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); | 284 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); |
283 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 285 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
284 | 286 |
285 ExpectSignalAboutFirstSubresourceDisallowed(); | 287 ExpectSignalAboutFirstSubresourceDisallowed(); |
286 ExpectLoadPolicy(kTestFirstURL, | 288 ExpectLoadPolicy(kTestFirstURL, |
287 blink::WebDocumentSubresourceFilter::Disallow); | 289 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
288 ExpectLoadPolicy(kTestSecondURL, blink::WebDocumentSubresourceFilter::Allow); | 290 ExpectLoadPolicy(kTestSecondURL, |
| 291 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
289 ExpectDocumentLoadStatisticsSent(); | 292 ExpectDocumentLoadStatisticsSent(); |
290 FinishLoad(); | 293 FinishLoad(); |
291 | 294 |
292 // In-page navigation should not count as a new load. | 295 // In-page navigation should not count as a new load. |
293 ExpectNoSubresourceFilterGetsInjected(); | 296 ExpectNoSubresourceFilterGetsInjected(); |
294 ExpectNoSignalAboutFirstSubresourceDisallowed(); | 297 ExpectNoSignalAboutFirstSubresourceDisallowed(); |
295 PerformSamePageNavigationWithoutSettingActivationLevel(); | 298 PerformSamePageNavigationWithoutSettingActivationLevel(); |
296 ExpectLoadPolicy(kTestFirstURL, | 299 ExpectLoadPolicy(kTestFirstURL, |
297 blink::WebDocumentSubresourceFilter::Disallow); | 300 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
298 ExpectLoadPolicy(kTestSecondURL, blink::WebDocumentSubresourceFilter::Allow); | 301 ExpectLoadPolicy(kTestSecondURL, |
| 302 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
299 | 303 |
300 ExpectNoSubresourceFilterGetsInjected(); | 304 ExpectNoSubresourceFilterGetsInjected(); |
301 StartLoadWithoutSettingActivationLevel(); | 305 StartLoadWithoutSettingActivationLevel(); |
302 FinishLoad(); | 306 FinishLoad(); |
303 | 307 |
304 // Resource loads after the in-page navigation should not be counted toward | 308 // Resource loads after the in-page navigation should not be counted toward |
305 // the figures below, as they came after the original page load event. | 309 // the figures below, as they came after the original page load event. |
306 histogram_tester.ExpectUniqueSample(kSubresourcesTotal, 2, 1); | 310 histogram_tester.ExpectUniqueSample(kSubresourcesTotal, 2, 1); |
307 histogram_tester.ExpectUniqueSample(kSubresourcesEvaluated, 2, 1); | 311 histogram_tester.ExpectUniqueSample(kSubresourcesEvaluated, 2, 1); |
308 histogram_tester.ExpectUniqueSample(kSubresourcesMatchedRules, 1, 1); | 312 histogram_tester.ExpectUniqueSample(kSubresourcesMatchedRules, 1, 1); |
(...skipping 10 matching lines...) Expand all Loading... |
319 base::HistogramTester histogram_tester; | 323 base::HistogramTester histogram_tester; |
320 ASSERT_NO_FATAL_FAILURE( | 324 ASSERT_NO_FATAL_FAILURE( |
321 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); | 325 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); |
322 ExpectSubresourceFilterGetsInjected(); | 326 ExpectSubresourceFilterGetsInjected(); |
323 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED, | 327 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED, |
324 measure_performance); | 328 measure_performance); |
325 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 329 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
326 | 330 |
327 ExpectSignalAboutFirstSubresourceDisallowed(); | 331 ExpectSignalAboutFirstSubresourceDisallowed(); |
328 ExpectLoadPolicy(kTestFirstURL, | 332 ExpectLoadPolicy(kTestFirstURL, |
329 blink::WebDocumentSubresourceFilter::Disallow); | 333 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
330 ExpectNoSignalAboutFirstSubresourceDisallowed(); | 334 ExpectNoSignalAboutFirstSubresourceDisallowed(); |
331 ExpectLoadPolicy(kTestFirstURL, | 335 ExpectLoadPolicy(kTestFirstURL, |
332 blink::WebDocumentSubresourceFilter::Disallow); | 336 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
333 ExpectNoSignalAboutFirstSubresourceDisallowed(); | 337 ExpectNoSignalAboutFirstSubresourceDisallowed(); |
334 ExpectLoadPolicy(kTestSecondURL, | 338 ExpectLoadPolicy(kTestSecondURL, |
335 blink::WebDocumentSubresourceFilter::Allow); | 339 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
336 ExpectDocumentLoadStatisticsSent(); | 340 ExpectDocumentLoadStatisticsSent(); |
337 FinishLoad(); | 341 FinishLoad(); |
338 | 342 |
339 ExpectSubresourceFilterGetsInjected(); | 343 ExpectSubresourceFilterGetsInjected(); |
340 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED, | 344 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED, |
341 measure_performance); | 345 measure_performance); |
342 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 346 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
343 | 347 |
344 ExpectNoSignalAboutFirstSubresourceDisallowed(); | 348 ExpectNoSignalAboutFirstSubresourceDisallowed(); |
345 ExpectLoadPolicy(kTestSecondURL, | 349 ExpectLoadPolicy(kTestSecondURL, |
346 blink::WebDocumentSubresourceFilter::Allow); | 350 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
347 ExpectSignalAboutFirstSubresourceDisallowed(); | 351 ExpectSignalAboutFirstSubresourceDisallowed(); |
348 ExpectLoadPolicy(kTestFirstURL, | 352 ExpectLoadPolicy(kTestFirstURL, |
349 blink::WebDocumentSubresourceFilter::Disallow); | 353 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
350 ExpectDocumentLoadStatisticsSent(); | 354 ExpectDocumentLoadStatisticsSent(); |
351 FinishLoad(); | 355 FinishLoad(); |
352 | 356 |
353 histogram_tester.ExpectUniqueSample( | 357 histogram_tester.ExpectUniqueSample( |
354 kDocumentLoadActivationLevel, | 358 kDocumentLoadActivationLevel, |
355 static_cast<int>(ActivationLevel::ENABLED), 2); | 359 static_cast<int>(ActivationLevel::ENABLED), 2); |
356 histogram_tester.ExpectUniqueSample(kDocumentLoadRulesetIsAvailable, 1, 2); | 360 histogram_tester.ExpectUniqueSample(kDocumentLoadRulesetIsAvailable, 1, 2); |
357 | 361 |
358 EXPECT_THAT(histogram_tester.GetAllSamples(kSubresourcesTotal), | 362 EXPECT_THAT(histogram_tester.GetAllSamples(kSubresourcesTotal), |
359 ::testing::ElementsAre(base::Bucket(2, 1), base::Bucket(3, 1))); | 363 ::testing::ElementsAre(base::Bucket(2, 1), base::Bucket(3, 1))); |
(...skipping 20 matching lines...) Expand all Loading... |
380 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); | 384 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); |
381 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 385 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
382 | 386 |
383 // Set the new ruleset just after the deadline for being used for the current | 387 // Set the new ruleset just after the deadline for being used for the current |
384 // load, to exercises doing filtering based on obseleted rulesets. | 388 // load, to exercises doing filtering based on obseleted rulesets. |
385 ASSERT_NO_FATAL_FAILURE( | 389 ASSERT_NO_FATAL_FAILURE( |
386 SetTestRulesetToDisallowURLsWithPathSuffix(kTestSecondURLPathSuffix)); | 390 SetTestRulesetToDisallowURLsWithPathSuffix(kTestSecondURLPathSuffix)); |
387 | 391 |
388 ExpectSignalAboutFirstSubresourceDisallowed(); | 392 ExpectSignalAboutFirstSubresourceDisallowed(); |
389 ExpectLoadPolicy(kTestFirstURL, | 393 ExpectLoadPolicy(kTestFirstURL, |
390 blink::WebDocumentSubresourceFilter::Disallow); | 394 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
391 ExpectLoadPolicy(kTestSecondURL, blink::WebDocumentSubresourceFilter::Allow); | 395 ExpectLoadPolicy(kTestSecondURL, |
| 396 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
392 ExpectDocumentLoadStatisticsSent(); | 397 ExpectDocumentLoadStatisticsSent(); |
393 FinishLoad(); | 398 FinishLoad(); |
394 | 399 |
395 ExpectSubresourceFilterGetsInjected(); | 400 ExpectSubresourceFilterGetsInjected(); |
396 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); | 401 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); |
397 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 402 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
398 | 403 |
399 ExpectSignalAboutFirstSubresourceDisallowed(); | 404 ExpectSignalAboutFirstSubresourceDisallowed(); |
400 ExpectLoadPolicy(kTestFirstURL, blink::WebDocumentSubresourceFilter::Allow); | 405 ExpectLoadPolicy(kTestFirstURL, |
| 406 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
401 ExpectLoadPolicy(kTestSecondURL, | 407 ExpectLoadPolicy(kTestSecondURL, |
402 blink::WebDocumentSubresourceFilter::Disallow); | 408 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
403 ExpectDocumentLoadStatisticsSent(); | 409 ExpectDocumentLoadStatisticsSent(); |
404 FinishLoad(); | 410 FinishLoad(); |
405 } | 411 } |
406 | 412 |
407 // If a provisional load is aborted, the RenderFrameObservers might not receive | 413 // If a provisional load is aborted, the RenderFrameObservers might not receive |
408 // any further notifications about that load. It is thus possible that there | 414 // any further notifications about that load. It is thus possible that there |
409 // will be two RenderFrameObserver::DidStartProvisionalLoad in a row. Make sure | 415 // will be two RenderFrameObserver::DidStartProvisionalLoad in a row. Make sure |
410 // that the activation decision does not outlive the first provisional load. | 416 // that the activation decision does not outlive the first provisional load. |
411 TEST_F(SubresourceFilterAgentTest, | 417 TEST_F(SubresourceFilterAgentTest, |
412 Enabled_FilteringNoLongerEffectAfterProvisionalLoadIsCancelled) { | 418 Enabled_FilteringNoLongerEffectAfterProvisionalLoadIsCancelled) { |
(...skipping 14 matching lines...) Expand all Loading... |
427 base::HistogramTester histogram_tester; | 433 base::HistogramTester histogram_tester; |
428 ASSERT_NO_FATAL_FAILURE( | 434 ASSERT_NO_FATAL_FAILURE( |
429 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); | 435 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); |
430 ExpectSubresourceFilterGetsInjected(); | 436 ExpectSubresourceFilterGetsInjected(); |
431 StartLoadAndSetActivationLevel(ActivationLevel::DRYRUN); | 437 StartLoadAndSetActivationLevel(ActivationLevel::DRYRUN); |
432 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 438 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
433 | 439 |
434 // In dry-run mode, loads to the first URL should be recorded as | 440 // In dry-run mode, loads to the first URL should be recorded as |
435 // `MatchedRules`, but still be allowed to proceed and not recorded as | 441 // `MatchedRules`, but still be allowed to proceed and not recorded as |
436 // `Disallowed`. | 442 // `Disallowed`. |
437 ExpectLoadPolicy(kTestFirstURL, | 443 ExpectLoadPolicy( |
438 blink::WebDocumentSubresourceFilter::WouldDisallow); | 444 kTestFirstURL, |
439 ExpectLoadPolicy(kTestFirstURL, | 445 blink::WebDocumentSubresourceFilterLoadPolicy::WouldDisallow); |
440 blink::WebDocumentSubresourceFilter::WouldDisallow); | 446 ExpectLoadPolicy( |
441 ExpectLoadPolicy(kTestSecondURL, blink::WebDocumentSubresourceFilter::Allow); | 447 kTestFirstURL, |
| 448 blink::WebDocumentSubresourceFilterLoadPolicy::WouldDisallow); |
| 449 ExpectLoadPolicy(kTestSecondURL, |
| 450 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
442 ExpectDocumentLoadStatisticsSent(); | 451 ExpectDocumentLoadStatisticsSent(); |
443 FinishLoad(); | 452 FinishLoad(); |
444 | 453 |
445 histogram_tester.ExpectUniqueSample(kDocumentLoadActivationLevel, | 454 histogram_tester.ExpectUniqueSample(kDocumentLoadActivationLevel, |
446 static_cast<int>(ActivationLevel::DRYRUN), | 455 static_cast<int>(ActivationLevel::DRYRUN), |
447 1); | 456 1); |
448 histogram_tester.ExpectUniqueSample(kDocumentLoadRulesetIsAvailable, 1, 1); | 457 histogram_tester.ExpectUniqueSample(kDocumentLoadRulesetIsAvailable, 1, 1); |
449 | 458 |
450 histogram_tester.ExpectUniqueSample(kSubresourcesTotal, 3, 1); | 459 histogram_tester.ExpectUniqueSample(kSubresourcesTotal, 3, 1); |
451 histogram_tester.ExpectUniqueSample(kSubresourcesEvaluated, 3, 1); | 460 histogram_tester.ExpectUniqueSample(kSubresourcesEvaluated, 3, 1); |
452 histogram_tester.ExpectUniqueSample(kSubresourcesMatchedRules, 2, 1); | 461 histogram_tester.ExpectUniqueSample(kSubresourcesMatchedRules, 2, 1); |
453 histogram_tester.ExpectUniqueSample(kSubresourcesDisallowed, 0, 1); | 462 histogram_tester.ExpectUniqueSample(kSubresourcesDisallowed, 0, 1); |
454 | 463 |
455 // Performance measurement is switched off. | 464 // Performance measurement is switched off. |
456 histogram_tester.ExpectTotalCount(kEvaluationTotalWallDuration, 0); | 465 histogram_tester.ExpectTotalCount(kEvaluationTotalWallDuration, 0); |
457 histogram_tester.ExpectTotalCount(kEvaluationTotalCPUDuration, 0); | 466 histogram_tester.ExpectTotalCount(kEvaluationTotalCPUDuration, 0); |
458 } | 467 } |
459 | 468 |
460 TEST_F(SubresourceFilterAgentTest, | 469 TEST_F(SubresourceFilterAgentTest, |
461 SignalFirstSubresourceDisallowed_OncePerDocumentLoad) { | 470 SignalFirstSubresourceDisallowed_OncePerDocumentLoad) { |
462 ASSERT_NO_FATAL_FAILURE( | 471 ASSERT_NO_FATAL_FAILURE( |
463 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); | 472 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); |
464 ExpectSubresourceFilterGetsInjected(); | 473 ExpectSubresourceFilterGetsInjected(); |
465 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); | 474 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); |
466 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 475 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
467 | 476 |
468 ExpectSignalAboutFirstSubresourceDisallowed(); | 477 ExpectSignalAboutFirstSubresourceDisallowed(); |
469 ExpectLoadPolicy(kTestFirstURL, | 478 ExpectLoadPolicy(kTestFirstURL, |
470 blink::WebDocumentSubresourceFilter::Disallow); | 479 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
471 ExpectNoSignalAboutFirstSubresourceDisallowed(); | 480 ExpectNoSignalAboutFirstSubresourceDisallowed(); |
472 ExpectLoadPolicy(kTestFirstURL, | 481 ExpectLoadPolicy(kTestFirstURL, |
473 blink::WebDocumentSubresourceFilter::Disallow); | 482 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
474 ExpectLoadPolicy(kTestSecondURL, blink::WebDocumentSubresourceFilter::Allow); | 483 ExpectLoadPolicy(kTestSecondURL, |
| 484 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
475 ExpectDocumentLoadStatisticsSent(); | 485 ExpectDocumentLoadStatisticsSent(); |
476 FinishLoad(); | 486 FinishLoad(); |
477 | 487 |
478 ExpectSubresourceFilterGetsInjected(); | 488 ExpectSubresourceFilterGetsInjected(); |
479 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); | 489 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); |
480 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 490 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
481 | 491 |
482 ExpectLoadPolicy(kTestSecondURL, blink::WebDocumentSubresourceFilter::Allow); | 492 ExpectLoadPolicy(kTestSecondURL, |
| 493 blink::WebDocumentSubresourceFilterLoadPolicy::Allow); |
483 ExpectSignalAboutFirstSubresourceDisallowed(); | 494 ExpectSignalAboutFirstSubresourceDisallowed(); |
484 ExpectLoadPolicy(kTestFirstURL, | 495 ExpectLoadPolicy(kTestFirstURL, |
485 blink::WebDocumentSubresourceFilter::Disallow); | 496 blink::WebDocumentSubresourceFilterLoadPolicy::Disallow); |
486 ExpectDocumentLoadStatisticsSent(); | 497 ExpectDocumentLoadStatisticsSent(); |
487 FinishLoad(); | 498 FinishLoad(); |
488 } | 499 } |
489 | 500 |
490 TEST_F(SubresourceFilterAgentTest, | 501 TEST_F(SubresourceFilterAgentTest, |
491 SignalFirstSubresourceDisallowed_ComesAfterAgentDestroyed) { | 502 SignalFirstSubresourceDisallowed_ComesAfterAgentDestroyed) { |
492 ASSERT_NO_FATAL_FAILURE( | 503 ASSERT_NO_FATAL_FAILURE( |
493 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); | 504 SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix)); |
494 ExpectSubresourceFilterGetsInjected(); | 505 ExpectSubresourceFilterGetsInjected(); |
495 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); | 506 StartLoadAndSetActivationLevel(ActivationLevel::ENABLED); |
496 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); | 507 ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent())); |
497 | 508 |
498 auto filter = agent()->TakeFilter(); | 509 auto filter = agent()->TakeFilter(); |
499 ResetAgent(); | 510 ResetAgent(); |
500 | 511 |
501 // The filter has been disconnected from the agent, so a call to | 512 // The filter has been disconnected from the agent, so a call to |
502 // reportDisallowedLoad() should not signal a first resource disallowed call | 513 // reportDisallowedLoad() should not signal a first resource disallowed call |
503 // to the agent, nor should it cause a crash. | 514 // to the agent, nor should it cause a crash. |
504 ExpectNoSignalAboutFirstSubresourceDisallowed(); | 515 ExpectNoSignalAboutFirstSubresourceDisallowed(); |
505 | 516 |
506 filter->reportDisallowedLoad(); | 517 filter->reportDisallowedLoad(); |
507 } | 518 } |
508 | 519 |
509 } // namespace subresource_filter | 520 } // namespace subresource_filter |
OLD | NEW |