| 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/content_subresource_filt
er_throttle_manager.h" | 5 #include "components/subresource_filter/content/browser/content_subresource_filt
er_throttle_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 228 } |
| 229 navigation_simulator_.reset(); | 229 navigation_simulator_.reset(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 void NavigateAndCommitMainFrame(const GURL& url) { | 232 void NavigateAndCommitMainFrame(const GURL& url) { |
| 233 CreateTestNavigation(url, main_rfh()); | 233 CreateTestNavigation(url, main_rfh()); |
| 234 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 234 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 235 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 235 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void SuppressActivationForUrl(const GURL& url) { | |
| 239 urls_to_suppress_activation_.insert(url); | |
| 240 } | |
| 241 | |
| 242 bool ManagerHasRulesetHandle() { | 238 bool ManagerHasRulesetHandle() { |
| 243 return throttle_manager_->ruleset_handle_for_testing(); | 239 return throttle_manager_->ruleset_handle_for_testing(); |
| 244 } | 240 } |
| 245 | 241 |
| 246 int disallowed_notification_count() { return disallowed_notification_count_; } | 242 int disallowed_notification_count() { return disallowed_notification_count_; } |
| 247 | 243 |
| 248 int attempted_frame_activations() { return attempted_frame_activations_; } | |
| 249 | |
| 250 protected: | 244 protected: |
| 251 // content::WebContentsObserver | 245 // content::WebContentsObserver |
| 252 void DidStartNavigation( | 246 void DidStartNavigation( |
| 253 content::NavigationHandle* navigation_handle) override { | 247 content::NavigationHandle* navigation_handle) override { |
| 254 if (navigation_handle->IsSameDocument()) | 248 if (navigation_handle->IsSameDocument()) |
| 255 return; | 249 return; |
| 256 | 250 |
| 257 // Inject the proper throttles at this time. | 251 // Inject the proper throttles at this time. |
| 258 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; | 252 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
| 259 PageActivationNotificationTiming state = | 253 PageActivationNotificationTiming state = |
| 260 ::testing::UnitTest::GetInstance()->current_test_info()->value_param() | 254 ::testing::UnitTest::GetInstance()->current_test_info()->value_param() |
| 261 ? GetParam() | 255 ? GetParam() |
| 262 : WILL_PROCESS_RESPONSE; | 256 : WILL_PROCESS_RESPONSE; |
| 263 throttles.push_back(base::MakeUnique<MockPageStateActivationThrottle>( | 257 throttles.push_back(base::MakeUnique<MockPageStateActivationThrottle>( |
| 264 navigation_handle, state, throttle_manager_.get())); | 258 navigation_handle, state, throttle_manager_.get())); |
| 265 throttle_manager_->MaybeAppendNavigationThrottles(navigation_handle, | 259 throttle_manager_->MaybeAppendNavigationThrottles(navigation_handle, |
| 266 &throttles); | 260 &throttles); |
| 267 for (auto& it : throttles) { | 261 for (auto& it : throttles) { |
| 268 navigation_handle->RegisterThrottleForTesting(std::move(it)); | 262 navigation_handle->RegisterThrottleForTesting(std::move(it)); |
| 269 } | 263 } |
| 270 } | 264 } |
| 271 | 265 |
| 272 // ContentSubresourceFilterThrottleManager::Delegate: | 266 // ContentSubresourceFilterThrottleManager::Delegate: |
| 273 void OnFirstSubresourceLoadDisallowed() override { | 267 void OnFirstSubresourceLoadDisallowed() override { |
| 274 ++disallowed_notification_count_; | 268 ++disallowed_notification_count_; |
| 275 } | 269 } |
| 276 | 270 |
| 277 bool ShouldSuppressActivation( | |
| 278 content::NavigationHandle* navigation_handle) override { | |
| 279 ++attempted_frame_activations_; | |
| 280 return urls_to_suppress_activation_.find(navigation_handle->GetURL()) != | |
| 281 urls_to_suppress_activation_.end(); | |
| 282 } | |
| 283 | |
| 284 private: | 271 private: |
| 285 testing::TestRulesetCreator test_ruleset_creator_; | 272 testing::TestRulesetCreator test_ruleset_creator_; |
| 286 testing::TestRulesetPair test_ruleset_pair_; | 273 testing::TestRulesetPair test_ruleset_pair_; |
| 287 | 274 |
| 288 std::set<GURL> urls_to_suppress_activation_; | |
| 289 | |
| 290 std::unique_ptr<VerifiedRulesetDealer::Handle> dealer_handle_; | 275 std::unique_ptr<VerifiedRulesetDealer::Handle> dealer_handle_; |
| 291 | 276 |
| 292 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; | 277 std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_; |
| 293 | 278 |
| 294 std::unique_ptr<content::NavigationSimulator> navigation_simulator_; | 279 std::unique_ptr<content::NavigationSimulator> navigation_simulator_; |
| 295 | 280 |
| 296 // Incremented on every OnFirstSubresourceLoadDisallowed call. | 281 // Incremented on every OnFirstSubresourceLoadDisallowed call. |
| 297 int disallowed_notification_count_ = 0; | 282 int disallowed_notification_count_ = 0; |
| 298 | 283 |
| 299 // Incremented every time the manager queries the harness for activation | |
| 300 // suppression. | |
| 301 int attempted_frame_activations_ = 0; | |
| 302 | |
| 303 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManagerTest); | 284 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterThrottleManagerTest); |
| 304 }; | 285 }; |
| 305 | 286 |
| 306 INSTANTIATE_TEST_CASE_P(PageActivationNotificationTiming, | 287 INSTANTIATE_TEST_CASE_P(PageActivationNotificationTiming, |
| 307 ContentSubresourceFilterThrottleManagerTest, | 288 ContentSubresourceFilterThrottleManagerTest, |
| 308 ::testing::Values(WILL_START_REQUEST, | 289 ::testing::Values(WILL_START_REQUEST, |
| 309 WILL_PROCESS_RESPONSE)); | 290 WILL_PROCESS_RESPONSE)); |
| 310 | 291 |
| 311 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 292 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 312 ActivateMainFrameAndFilterSubframeNavigation) { | 293 ActivateMainFrameAndFilterSubframeNavigation) { |
| 313 // Commit a navigation that triggers page level activation. | 294 // Commit a navigation that triggers page level activation. |
| 314 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 295 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 315 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 296 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 316 | 297 |
| 317 // A disallowed subframe navigation should be successfully filtered. | 298 // A disallowed subframe navigation should be successfully filtered. |
| 318 CreateSubframeWithTestNavigation( | 299 CreateSubframeWithTestNavigation( |
| 319 GURL("https://www.example.com/disallowed.html"), main_rfh()); | 300 GURL("https://www.example.com/disallowed.html"), main_rfh()); |
| 320 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 301 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 321 | 302 |
| 322 EXPECT_EQ(1, disallowed_notification_count()); | 303 EXPECT_EQ(1, disallowed_notification_count()); |
| 323 EXPECT_EQ(1, attempted_frame_activations()); | |
| 324 } | 304 } |
| 325 | 305 |
| 326 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 306 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 327 ActivateMainFrameAndDoNotFilterDryRun) { | 307 ActivateMainFrameAndDoNotFilterDryRun) { |
| 328 // Commit a navigation that triggers page level activation. | 308 // Commit a navigation that triggers page level activation. |
| 329 NavigateAndCommitMainFrame(GURL(kTestURLWithDryRun)); | 309 NavigateAndCommitMainFrame(GURL(kTestURLWithDryRun)); |
| 330 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 310 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 331 | 311 |
| 332 // A disallowed subframe navigation should not be filtered in dry-run mode. | 312 // A disallowed subframe navigation should not be filtered in dry-run mode. |
| 333 CreateSubframeWithTestNavigation( | 313 CreateSubframeWithTestNavigation( |
| 334 GURL("https://www.example.com/disallowed.html"), main_rfh()); | 314 GURL("https://www.example.com/disallowed.html"), main_rfh()); |
| 335 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 315 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 336 content::RenderFrameHost* child = | 316 content::RenderFrameHost* child = |
| 337 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 317 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 338 // But it should still be activated. | 318 // But it should still be activated. |
| 339 ExpectActivationSignalForFrame(child, true /* expect_activation */); | 319 ExpectActivationSignalForFrame(child, true /* expect_activation */); |
| 340 | 320 |
| 341 EXPECT_EQ(0, disallowed_notification_count()); | 321 EXPECT_EQ(0, disallowed_notification_count()); |
| 342 EXPECT_EQ(2, attempted_frame_activations()); | |
| 343 } | 322 } |
| 344 | 323 |
| 345 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 324 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 346 ActivateMainFrameAndFilterSubframeNavigationOnRedirect) { | 325 ActivateMainFrameAndFilterSubframeNavigationOnRedirect) { |
| 347 // Commit a navigation that triggers page level activation. | 326 // Commit a navigation that triggers page level activation. |
| 348 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 327 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 349 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 328 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 350 | 329 |
| 351 // A disallowed subframe navigation via redirect should be successfully | 330 // A disallowed subframe navigation via redirect should be successfully |
| 352 // filtered. | 331 // filtered. |
| 353 CreateSubframeWithTestNavigation( | 332 CreateSubframeWithTestNavigation( |
| 354 GURL("https://www.example.com/before-redirect.html"), main_rfh()); | 333 GURL("https://www.example.com/before-redirect.html"), main_rfh()); |
| 355 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 334 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 356 SimulateRedirectAndExpectResult( | 335 SimulateRedirectAndExpectResult( |
| 357 GURL("https://www.example.com/disallowed.html"), | 336 GURL("https://www.example.com/disallowed.html"), |
| 358 content::NavigationThrottle::CANCEL); | 337 content::NavigationThrottle::CANCEL); |
| 359 | 338 |
| 360 EXPECT_EQ(1, disallowed_notification_count()); | 339 EXPECT_EQ(1, disallowed_notification_count()); |
| 361 EXPECT_EQ(1, attempted_frame_activations()); | |
| 362 } | 340 } |
| 363 | 341 |
| 364 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 342 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 365 ActivateMainFrameAndDoNotFilterSubframeNavigation) { | 343 ActivateMainFrameAndDoNotFilterSubframeNavigation) { |
| 366 // Commit a navigation that triggers page level activation. | 344 // Commit a navigation that triggers page level activation. |
| 367 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 345 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 368 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 346 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 369 | 347 |
| 370 // An allowed subframe navigation should complete successfully. | 348 // An allowed subframe navigation should complete successfully. |
| 371 CreateSubframeWithTestNavigation( | 349 CreateSubframeWithTestNavigation( |
| 372 GURL("https://www.example.com/allowed1.html"), main_rfh()); | 350 GURL("https://www.example.com/allowed1.html"), main_rfh()); |
| 373 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 351 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 374 SimulateRedirectAndExpectResult(GURL("https://www.example.com/allowed2.html"), | 352 SimulateRedirectAndExpectResult(GURL("https://www.example.com/allowed2.html"), |
| 375 content::NavigationThrottle::PROCEED); | 353 content::NavigationThrottle::PROCEED); |
| 376 content::RenderFrameHost* child = | 354 content::RenderFrameHost* child = |
| 377 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 355 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 378 ExpectActivationSignalForFrame(child, true /* expect_activation */); | 356 ExpectActivationSignalForFrame(child, true /* expect_activation */); |
| 379 | 357 |
| 380 EXPECT_EQ(0, disallowed_notification_count()); | 358 EXPECT_EQ(0, disallowed_notification_count()); |
| 381 EXPECT_EQ(2, attempted_frame_activations()); | |
| 382 } | 359 } |
| 383 | 360 |
| 384 // This should fail if the throttle manager notifies the delegate twice of a | 361 // This should fail if the throttle manager notifies the delegate twice of a |
| 385 // disallowed load for the same page load. | 362 // disallowed load for the same page load. |
| 386 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 363 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 387 ActivateMainFrameAndFilterTwoSubframeNavigations) { | 364 ActivateMainFrameAndFilterTwoSubframeNavigations) { |
| 388 // Commit a navigation that triggers page level activation. | 365 // Commit a navigation that triggers page level activation. |
| 389 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 366 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 390 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 367 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 391 | 368 |
| 392 // A disallowed subframe navigation should be successfully filtered. | 369 // A disallowed subframe navigation should be successfully filtered. |
| 393 CreateSubframeWithTestNavigation( | 370 CreateSubframeWithTestNavigation( |
| 394 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); | 371 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); |
| 395 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 372 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 396 | 373 |
| 397 EXPECT_EQ(1, disallowed_notification_count()); | 374 EXPECT_EQ(1, disallowed_notification_count()); |
| 398 | 375 |
| 399 CreateSubframeWithTestNavigation( | 376 CreateSubframeWithTestNavigation( |
| 400 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); | 377 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); |
| 401 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 378 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 402 | 379 |
| 403 EXPECT_EQ(1, disallowed_notification_count()); | 380 EXPECT_EQ(1, disallowed_notification_count()); |
| 404 EXPECT_EQ(1, attempted_frame_activations()); | |
| 405 } | 381 } |
| 406 | 382 |
| 407 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 383 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 408 ActivateTwoMainFramesAndFilterTwoSubframeNavigations) { | 384 ActivateTwoMainFramesAndFilterTwoSubframeNavigations) { |
| 409 // Commit a navigation that triggers page level activation. | 385 // Commit a navigation that triggers page level activation. |
| 410 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 386 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 411 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 387 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 412 | 388 |
| 413 // A disallowed subframe navigation should be successfully filtered. | 389 // A disallowed subframe navigation should be successfully filtered. |
| 414 CreateSubframeWithTestNavigation( | 390 CreateSubframeWithTestNavigation( |
| 415 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); | 391 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); |
| 416 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 392 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 417 | 393 |
| 418 EXPECT_EQ(1, disallowed_notification_count()); | 394 EXPECT_EQ(1, disallowed_notification_count()); |
| 419 | 395 |
| 420 // Commit another navigation that triggers page level activation. | 396 // Commit another navigation that triggers page level activation. |
| 421 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation2)); | 397 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation2)); |
| 422 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 398 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 423 | 399 |
| 424 CreateSubframeWithTestNavigation( | 400 CreateSubframeWithTestNavigation( |
| 425 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); | 401 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); |
| 426 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 402 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 427 | 403 |
| 428 EXPECT_EQ(2, disallowed_notification_count()); | 404 EXPECT_EQ(2, disallowed_notification_count()); |
| 429 EXPECT_EQ(2, attempted_frame_activations()); | |
| 430 } | 405 } |
| 431 | 406 |
| 432 // Test that the disallow load notification will not be repeated for the first | 407 // Test that the disallow load notification will not be repeated for the first |
| 433 // disallowed load that follows a same-document navigation. | 408 // disallowed load that follows a same-document navigation. |
| 434 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 409 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 435 ActivateMainFrameDoNotNotifyAfterSameDocumentNav) { | 410 ActivateMainFrameDoNotNotifyAfterSameDocumentNav) { |
| 436 // Commit a navigation that triggers page level activation. | 411 // Commit a navigation that triggers page level activation. |
| 437 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 412 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 438 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 413 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 439 | 414 |
| 440 // A disallowed subframe navigation should be successfully filtered. | 415 // A disallowed subframe navigation should be successfully filtered. |
| 441 CreateSubframeWithTestNavigation( | 416 CreateSubframeWithTestNavigation( |
| 442 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); | 417 GURL("https://www.example.com/1/disallowed.html"), main_rfh()); |
| 443 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 418 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 444 | 419 |
| 445 EXPECT_EQ(1, disallowed_notification_count()); | 420 EXPECT_EQ(1, disallowed_notification_count()); |
| 446 | 421 |
| 447 // Commit another navigation that triggers page level activation. | 422 // Commit another navigation that triggers page level activation. |
| 448 GURL url2 = GURL(base::StringPrintf("%s#ref", kTestURLWithActivation)); | 423 GURL url2 = GURL(base::StringPrintf("%s#ref", kTestURLWithActivation)); |
| 449 CreateTestNavigation(url2, main_rfh()); | 424 CreateTestNavigation(url2, main_rfh()); |
| 450 SimulateSameDocumentCommit(); | 425 SimulateSameDocumentCommit(); |
| 451 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); | 426 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); |
| 452 | 427 |
| 453 CreateSubframeWithTestNavigation( | 428 CreateSubframeWithTestNavigation( |
| 454 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); | 429 GURL("https://www.example.com/2/disallowed.html"), main_rfh()); |
| 455 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 430 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 456 | 431 |
| 457 EXPECT_EQ(1, disallowed_notification_count()); | 432 EXPECT_EQ(1, disallowed_notification_count()); |
| 458 EXPECT_EQ(1, attempted_frame_activations()); | |
| 459 } | 433 } |
| 460 | 434 |
| 461 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 435 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 462 DoNotFilterForInactiveFrame) { | 436 DoNotFilterForInactiveFrame) { |
| 463 NavigateAndCommitMainFrame(GURL("https://do-not-activate.html")); | 437 NavigateAndCommitMainFrame(GURL("https://do-not-activate.html")); |
| 464 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); | 438 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); |
| 465 | 439 |
| 466 // A subframe navigation should complete successfully. | 440 // A subframe navigation should complete successfully. |
| 467 CreateSubframeWithTestNavigation(GURL("https://www.example.com/allowed.html"), | 441 CreateSubframeWithTestNavigation(GURL("https://www.example.com/allowed.html"), |
| 468 main_rfh()); | 442 main_rfh()); |
| 469 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 443 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 470 content::RenderFrameHost* child = | 444 content::RenderFrameHost* child = |
| 471 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 445 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 472 ExpectActivationSignalForFrame(child, false /* expect_activation */); | 446 ExpectActivationSignalForFrame(child, false /* expect_activation */); |
| 473 | 447 |
| 474 EXPECT_EQ(0, disallowed_notification_count()); | 448 EXPECT_EQ(0, disallowed_notification_count()); |
| 475 EXPECT_EQ(0, attempted_frame_activations()); | |
| 476 } | |
| 477 | |
| 478 TEST_P(ContentSubresourceFilterThrottleManagerTest, SuppressActivation) { | |
| 479 SuppressActivationForUrl(GURL(kTestURLWithActivation)); | |
| 480 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | |
| 481 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); | |
| 482 | |
| 483 // A subframe navigation should complete successfully. | |
| 484 CreateSubframeWithTestNavigation(GURL("https://www.example.com/allowed.html"), | |
| 485 main_rfh()); | |
| 486 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | |
| 487 content::RenderFrameHost* child = | |
| 488 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | |
| 489 ExpectActivationSignalForFrame(child, false /* expect_activation */); | |
| 490 | |
| 491 EXPECT_EQ(0, disallowed_notification_count()); | |
| 492 EXPECT_EQ(1, attempted_frame_activations()); | |
| 493 } | 449 } |
| 494 | 450 |
| 495 // Once there are no activated frames, the manager drops its ruleset handle. If | 451 // Once there are no activated frames, the manager drops its ruleset handle. If |
| 496 // another frame is activated, make sure the handle is regenerated. | 452 // another frame is activated, make sure the handle is regenerated. |
| 497 TEST_P(ContentSubresourceFilterThrottleManagerTest, RulesetHandleRegeneration) { | 453 TEST_P(ContentSubresourceFilterThrottleManagerTest, RulesetHandleRegeneration) { |
| 498 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 454 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 499 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 455 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 500 | 456 |
| 501 CreateSubframeWithTestNavigation( | 457 CreateSubframeWithTestNavigation( |
| 502 GURL("https://www.example.com/disallowed.html"), main_rfh()); | 458 GURL("https://www.example.com/disallowed.html"), main_rfh()); |
| 503 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 459 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 504 | 460 |
| 505 EXPECT_EQ(1, disallowed_notification_count()); | 461 EXPECT_EQ(1, disallowed_notification_count()); |
| 506 | 462 |
| 507 // Simulate a renderer crash which should delete the frame. | 463 // Simulate a renderer crash which should delete the frame. |
| 508 EXPECT_TRUE(ManagerHasRulesetHandle()); | 464 EXPECT_TRUE(ManagerHasRulesetHandle()); |
| 509 process()->SimulateCrash(); | 465 process()->SimulateCrash(); |
| 510 EXPECT_FALSE(ManagerHasRulesetHandle()); | 466 EXPECT_FALSE(ManagerHasRulesetHandle()); |
| 511 | 467 |
| 512 NavigateAndCommit(GURL("https://example.reset")); | 468 NavigateAndCommit(GURL("https://example.reset")); |
| 513 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 469 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 514 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 470 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 515 | 471 |
| 516 CreateSubframeWithTestNavigation( | 472 CreateSubframeWithTestNavigation( |
| 517 GURL("https://www.example.com/disallowed.html"), main_rfh()); | 473 GURL("https://www.example.com/disallowed.html"), main_rfh()); |
| 518 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 474 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 519 | 475 |
| 520 EXPECT_EQ(2, disallowed_notification_count()); | 476 EXPECT_EQ(2, disallowed_notification_count()); |
| 521 EXPECT_EQ(2, attempted_frame_activations()); | |
| 522 } | 477 } |
| 523 | 478 |
| 524 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 479 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 525 SameSiteNavigation_RulesetGoesAway) { | 480 SameSiteNavigation_RulesetGoesAway) { |
| 526 GURL same_site_inactive_url = | 481 GURL same_site_inactive_url = |
| 527 GURL(base::StringPrintf("%ssuppressed.html", kTestURLWithActivation)); | 482 GURL(base::StringPrintf("%sinactive.html", kTestURLWithActivation)); |
| 528 SuppressActivationForUrl(same_site_inactive_url); | |
| 529 | 483 |
| 530 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 484 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 531 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 485 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 532 EXPECT_TRUE(ManagerHasRulesetHandle()); | 486 EXPECT_TRUE(ManagerHasRulesetHandle()); |
| 533 | 487 |
| 534 NavigateAndCommitMainFrame(same_site_inactive_url); | 488 NavigateAndCommitMainFrame(same_site_inactive_url); |
| 535 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); | 489 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); |
| 536 EXPECT_FALSE(ManagerHasRulesetHandle()); | 490 EXPECT_FALSE(ManagerHasRulesetHandle()); |
| 537 | 491 |
| 538 // A subframe navigation should complete successfully. | 492 // A subframe navigation should complete successfully. |
| 539 CreateSubframeWithTestNavigation( | 493 CreateSubframeWithTestNavigation( |
| 540 GURL("https://www.example.com/disallowed.html"), main_rfh()); | 494 GURL("https://www.example.com/disallowed.html"), main_rfh()); |
| 541 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 495 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 542 content::RenderFrameHost* child = | 496 content::RenderFrameHost* child = |
| 543 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 497 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 544 ExpectActivationSignalForFrame(child, false /* expect_activation */); | 498 ExpectActivationSignalForFrame(child, false /* expect_activation */); |
| 545 | 499 |
| 546 EXPECT_EQ(0, disallowed_notification_count()); | 500 EXPECT_EQ(0, disallowed_notification_count()); |
| 547 EXPECT_EQ(1, attempted_frame_activations()); | |
| 548 } | 501 } |
| 549 | 502 |
| 550 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 503 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 551 SameSiteFailedNavigation_MaintainActivation) { | 504 SameSiteFailedNavigation_MaintainActivation) { |
| 552 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 505 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 553 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 506 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 554 EXPECT_TRUE(ManagerHasRulesetHandle()); | 507 EXPECT_TRUE(ManagerHasRulesetHandle()); |
| 555 | 508 |
| 556 GURL same_site_inactive_url = | 509 GURL same_site_inactive_url = |
| 557 GURL(base::StringPrintf("%ssuppressed.html", kTestURLWithActivation)); | 510 GURL(base::StringPrintf("%sinactive.html", kTestURLWithActivation)); |
| 558 SuppressActivationForUrl(same_site_inactive_url); | |
| 559 | 511 |
| 560 CreateTestNavigation(same_site_inactive_url, main_rfh()); | 512 CreateTestNavigation(same_site_inactive_url, main_rfh()); |
| 561 SimulateFailedNavigation(net::ERR_ABORTED); | 513 SimulateFailedNavigation(net::ERR_ABORTED); |
| 562 EXPECT_TRUE(ManagerHasRulesetHandle()); | 514 EXPECT_TRUE(ManagerHasRulesetHandle()); |
| 563 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); | 515 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); |
| 564 | 516 |
| 565 // A subframe navigation fail. | 517 // A subframe navigation fail. |
| 566 CreateSubframeWithTestNavigation( | 518 CreateSubframeWithTestNavigation( |
| 567 GURL("https://www.example.com/disallowed.html"), main_rfh()); | 519 GURL("https://www.example.com/disallowed.html"), main_rfh()); |
| 568 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 520 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 569 | 521 |
| 570 EXPECT_EQ(1, disallowed_notification_count()); | 522 EXPECT_EQ(1, disallowed_notification_count()); |
| 571 EXPECT_EQ(1, attempted_frame_activations()); | |
| 572 } | 523 } |
| 573 | 524 |
| 574 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 525 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 575 FailedNavigationToErrorPage_NoActivation) { | 526 FailedNavigationToErrorPage_NoActivation) { |
| 576 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 527 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 577 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 528 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 578 EXPECT_TRUE(ManagerHasRulesetHandle()); | 529 EXPECT_TRUE(ManagerHasRulesetHandle()); |
| 579 | 530 |
| 580 GURL same_site_inactive_url = | 531 GURL same_site_inactive_url = |
| 581 GURL(base::StringPrintf("%ssuppressed.html", kTestURLWithActivation)); | 532 GURL(base::StringPrintf("%sinactive.html", kTestURLWithActivation)); |
| 582 SuppressActivationForUrl(same_site_inactive_url); | |
| 583 | 533 |
| 584 CreateTestNavigation(same_site_inactive_url, main_rfh()); | 534 CreateTestNavigation(same_site_inactive_url, main_rfh()); |
| 585 SimulateFailedNavigation(net::ERR_FAILED); | 535 SimulateFailedNavigation(net::ERR_FAILED); |
| 586 EXPECT_FALSE(ManagerHasRulesetHandle()); | 536 EXPECT_FALSE(ManagerHasRulesetHandle()); |
| 587 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); | 537 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); |
| 588 | 538 |
| 589 CreateSubframeWithTestNavigation( | 539 CreateSubframeWithTestNavigation( |
| 590 GURL("https://www.example.com/disallowed.html"), main_rfh()); | 540 GURL("https://www.example.com/disallowed.html"), main_rfh()); |
| 591 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 541 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 592 content::RenderFrameHost* child = | 542 content::RenderFrameHost* child = |
| 593 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 543 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 594 ExpectActivationSignalForFrame(child, false /* expect_activation */); | 544 ExpectActivationSignalForFrame(child, false /* expect_activation */); |
| 595 | 545 |
| 596 EXPECT_EQ(0, disallowed_notification_count()); | 546 EXPECT_EQ(0, disallowed_notification_count()); |
| 597 EXPECT_EQ(1, attempted_frame_activations()); | |
| 598 } | 547 } |
| 599 | 548 |
| 600 // Ensure activation propagates into great-grandchild frames, including cross | 549 // Ensure activation propagates into great-grandchild frames, including cross |
| 601 // process ones. | 550 // process ones. |
| 602 TEST_P(ContentSubresourceFilterThrottleManagerTest, ActivationPropagation) { | 551 TEST_P(ContentSubresourceFilterThrottleManagerTest, ActivationPropagation) { |
| 603 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 552 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 604 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 553 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 605 | 554 |
| 606 // Navigate a subframe to a URL that is not itself disallowed. Subresource | 555 // Navigate a subframe to a URL that is not itself disallowed. Subresource |
| 607 // filtering for this subframe document should still be activated. | 556 // filtering for this subframe document should still be activated. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 620 content::RenderFrameHost* subframe2 = | 569 content::RenderFrameHost* subframe2 = |
| 621 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 570 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 622 ExpectActivationSignalForFrame(subframe2, true /* expect_activation */); | 571 ExpectActivationSignalForFrame(subframe2, true /* expect_activation */); |
| 623 | 572 |
| 624 // A final, nested subframe navigation is filtered. | 573 // A final, nested subframe navigation is filtered. |
| 625 CreateSubframeWithTestNavigation(GURL("https://www.c.com/disallowed.html"), | 574 CreateSubframeWithTestNavigation(GURL("https://www.c.com/disallowed.html"), |
| 626 subframe2); | 575 subframe2); |
| 627 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 576 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 628 | 577 |
| 629 EXPECT_EQ(1, disallowed_notification_count()); | 578 EXPECT_EQ(1, disallowed_notification_count()); |
| 630 EXPECT_EQ(3, attempted_frame_activations()); | |
| 631 } | 579 } |
| 632 | 580 |
| 633 // Ensure activation propagates through whitelisted documents. | 581 // Ensure activation propagates through whitelisted documents. |
| 634 TEST_P(ContentSubresourceFilterThrottleManagerTest, ActivationPropagation2) { | 582 TEST_P(ContentSubresourceFilterThrottleManagerTest, ActivationPropagation2) { |
| 635 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 583 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 636 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 584 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 637 | 585 |
| 638 // Navigate a subframe that is not filtered, but should still activate. | 586 // Navigate a subframe that is not filtered, but should still activate. |
| 639 CreateSubframeWithTestNavigation(GURL("https://whitelist.com"), main_rfh()); | 587 CreateSubframeWithTestNavigation(GURL("https://whitelist.com"), main_rfh()); |
| 640 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 588 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 641 content::RenderFrameHost* subframe1 = | 589 content::RenderFrameHost* subframe1 = |
| 642 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 590 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 643 ExpectActivationSignalForFrame(subframe1, true /* expect_activation */); | 591 ExpectActivationSignalForFrame(subframe1, true /* expect_activation */); |
| 644 | 592 |
| 645 // Navigate a sub-subframe that is not filtered due to the whitelist. | 593 // Navigate a sub-subframe that is not filtered due to the whitelist. |
| 646 CreateSubframeWithTestNavigation( | 594 CreateSubframeWithTestNavigation( |
| 647 GURL("https://www.example.com/disallowed.html"), subframe1); | 595 GURL("https://www.example.com/disallowed.html"), subframe1); |
| 648 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 596 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 649 content::RenderFrameHost* subframe2 = | 597 content::RenderFrameHost* subframe2 = |
| 650 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 598 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 651 ExpectActivationSignalForFrame(subframe2, true /* expect_activation */); | 599 ExpectActivationSignalForFrame(subframe2, true /* expect_activation */); |
| 652 | 600 |
| 653 EXPECT_EQ(3, attempted_frame_activations()); | |
| 654 EXPECT_EQ(0, disallowed_notification_count()); | 601 EXPECT_EQ(0, disallowed_notification_count()); |
| 655 | 602 |
| 656 // An identical series of events that don't match whitelist rules cause | 603 // An identical series of events that don't match whitelist rules cause |
| 657 // filtering. | 604 // filtering. |
| 658 CreateSubframeWithTestNavigation(GURL("https://average-joe.com"), main_rfh()); | 605 CreateSubframeWithTestNavigation(GURL("https://average-joe.com"), main_rfh()); |
| 659 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 606 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 660 content::RenderFrameHost* subframe3 = | 607 content::RenderFrameHost* subframe3 = |
| 661 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 608 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 662 ExpectActivationSignalForFrame(subframe3, true /* expect_activation */); | 609 ExpectActivationSignalForFrame(subframe3, true /* expect_activation */); |
| 663 | 610 |
| 664 // Navigate a sub-subframe that is not filtered due to the whitelist. | 611 // Navigate a sub-subframe that is not filtered due to the whitelist. |
| 665 CreateSubframeWithTestNavigation( | 612 CreateSubframeWithTestNavigation( |
| 666 GURL("https://www.example.com/disallowed.html"), subframe3); | 613 GURL("https://www.example.com/disallowed.html"), subframe3); |
| 667 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 614 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
| 668 | 615 |
| 669 EXPECT_EQ(4, attempted_frame_activations()); | |
| 670 EXPECT_EQ(1, disallowed_notification_count()); | 616 EXPECT_EQ(1, disallowed_notification_count()); |
| 671 } | 617 } |
| 672 | 618 |
| 673 // Same-site navigations within a single RFH do not persist activation. | 619 // Same-site navigations within a single RFH do not persist activation. |
| 674 TEST_P(ContentSubresourceFilterThrottleManagerTest, | 620 TEST_P(ContentSubresourceFilterThrottleManagerTest, |
| 675 SameSiteNavigationStopsActivation) { | 621 SameSiteNavigationStopsActivation) { |
| 676 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); | 622 NavigateAndCommitMainFrame(GURL(kTestURLWithActivation)); |
| 677 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); | 623 ExpectActivationSignalForFrame(main_rfh(), true /* expect_activation */); |
| 678 EXPECT_EQ(1, attempted_frame_activations()); | |
| 679 | 624 |
| 680 // Mock a same-site navigation, in the same RFH, this URL does not trigger | 625 // Mock a same-site navigation, in the same RFH, this URL does not trigger |
| 681 // page level activation. | 626 // page level activation. |
| 682 NavigateAndCommitMainFrame( | 627 NavigateAndCommitMainFrame( |
| 683 GURL(base::StringPrintf("%s/some_path/", kTestURLWithActivation))); | 628 GURL(base::StringPrintf("%s/some_path/", kTestURLWithActivation))); |
| 684 EXPECT_EQ(1, attempted_frame_activations()); | |
| 685 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); | 629 ExpectActivationSignalForFrame(main_rfh(), false /* expect_activation */); |
| 686 | 630 |
| 687 CreateSubframeWithTestNavigation( | 631 CreateSubframeWithTestNavigation( |
| 688 GURL("https://www.example.com/disallowed.html"), main_rfh()); | 632 GURL("https://www.example.com/disallowed.html"), main_rfh()); |
| 689 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); | 633 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 690 content::RenderFrameHost* child = | 634 content::RenderFrameHost* child = |
| 691 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); | 635 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 692 ExpectActivationSignalForFrame(child, false /* expect_activation */); | 636 ExpectActivationSignalForFrame(child, false /* expect_activation */); |
| 693 | 637 |
| 694 EXPECT_EQ(0, disallowed_notification_count()); | 638 EXPECT_EQ(0, disallowed_notification_count()); |
| 695 EXPECT_EQ(1, attempted_frame_activations()); | |
| 696 } | 639 } |
| 697 | 640 |
| 698 // TODO(csharrison): Make sure the following conditions are exercised in tests: | 641 // TODO(csharrison): Make sure the following conditions are exercised in tests: |
| 699 // | 642 // |
| 700 // - Synchronous navigations to about:blank. These hit issues with the | 643 // - Synchronous navigations to about:blank. These hit issues with the |
| 701 // NavigationSimulator currently. | 644 // NavigationSimulator currently. |
| 702 | 645 |
| 703 } // namespace subresource_filter | 646 } // namespace subresource_filter |
| OLD | NEW |