OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "content/browser/frame_host/navigation_handle_impl.h" | 6 #include "content/browser/frame_host/navigation_handle_impl.h" |
7 #include "content/public/browser/navigation_throttle.h" | 7 #include "content/public/browser/navigation_throttle.h" |
8 #include "content/public/browser/ssl_status.h" | 8 #include "content/public/browser/ssl_status.h" |
9 #include "content/public/common/request_context_type.h" | 9 #include "content/public/common/request_context_type.h" |
10 #include "content/test/test_render_frame_host.h" | 10 #include "content/test/test_render_frame_host.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 bool IsDeferringRedirect() { | 87 bool IsDeferringRedirect() { |
88 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; | 88 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; |
89 } | 89 } |
90 | 90 |
91 bool IsDeferringResponse() { | 91 bool IsDeferringResponse() { |
92 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE; | 92 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE; |
93 } | 93 } |
94 | 94 |
95 bool IsCanceling() { | 95 bool IsCancelingRequest() { |
96 return test_handle_->state() == NavigationHandleImpl::CANCELING; | 96 return test_handle_->state() == NavigationHandleImpl::CANCELING_REQUEST; |
| 97 } |
| 98 |
| 99 bool IsCancelingResponse() { |
| 100 return test_handle_->state() == NavigationHandleImpl::CANCELING_RESPONSE; |
97 } | 101 } |
98 | 102 |
99 // Helper function to call WillStartRequest on |handle|. If this function | 103 // Helper function to call WillStartRequest on |handle|. If this function |
100 // returns DEFER, |callback_result_| will be set to the actual result of | 104 // returns DEFER, |callback_result_| will be set to the actual result of |
101 // the throttle checks when they are finished. | 105 // the throttle checks when they are finished. |
102 void SimulateWillStartRequest() { | 106 void SimulateWillStartRequest() { |
103 was_callback_called_ = false; | 107 was_callback_called_ = false; |
104 callback_result_ = NavigationThrottle::DEFER; | 108 callback_result_ = NavigationThrottle::DEFER; |
105 | 109 |
106 // It's safe to use base::Unretained since the NavigationHandle is owned by | 110 // It's safe to use base::Unretained since the NavigationHandle is owned by |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 EXPECT_FALSE(was_callback_called()); | 306 EXPECT_FALSE(was_callback_called()); |
303 EXPECT_EQ(1, test_throttle->will_start_calls()); | 307 EXPECT_EQ(1, test_throttle->will_start_calls()); |
304 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 308 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
305 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 309 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
306 | 310 |
307 // Cancel the request. The callback should have been called. | 311 // Cancel the request. The callback should have been called. |
308 test_handle()->CancelDeferredNavigation( | 312 test_handle()->CancelDeferredNavigation( |
309 NavigationThrottle::CANCEL_AND_IGNORE); | 313 NavigationThrottle::CANCEL_AND_IGNORE); |
310 EXPECT_FALSE(IsDeferringStart()); | 314 EXPECT_FALSE(IsDeferringStart()); |
311 EXPECT_FALSE(IsDeferringRedirect()); | 315 EXPECT_FALSE(IsDeferringRedirect()); |
312 EXPECT_TRUE(IsCanceling()); | 316 EXPECT_TRUE(IsCancelingRequest()); |
313 EXPECT_TRUE(was_callback_called()); | 317 EXPECT_TRUE(was_callback_called()); |
314 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 318 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
315 EXPECT_EQ(1, test_throttle->will_start_calls()); | 319 EXPECT_EQ(1, test_throttle->will_start_calls()); |
316 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 320 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
317 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 321 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
318 } | 322 } |
319 | 323 |
320 // Checks that a navigation deferred during WillRedirectRequest can be properly | 324 // Checks that a navigation deferred during WillRedirectRequest can be properly |
321 // cancelled. | 325 // cancelled. |
322 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { | 326 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { |
(...skipping 13 matching lines...) Expand all Loading... |
336 EXPECT_FALSE(was_callback_called()); | 340 EXPECT_FALSE(was_callback_called()); |
337 EXPECT_EQ(0, test_throttle->will_start_calls()); | 341 EXPECT_EQ(0, test_throttle->will_start_calls()); |
338 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 342 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
339 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 343 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
340 | 344 |
341 // Cancel the request. The callback should have been called. | 345 // Cancel the request. The callback should have been called. |
342 test_handle()->CancelDeferredNavigation( | 346 test_handle()->CancelDeferredNavigation( |
343 NavigationThrottle::CANCEL_AND_IGNORE); | 347 NavigationThrottle::CANCEL_AND_IGNORE); |
344 EXPECT_FALSE(IsDeferringStart()); | 348 EXPECT_FALSE(IsDeferringStart()); |
345 EXPECT_FALSE(IsDeferringRedirect()); | 349 EXPECT_FALSE(IsDeferringRedirect()); |
346 EXPECT_TRUE(IsCanceling()); | 350 EXPECT_TRUE(IsCancelingRequest()); |
347 EXPECT_TRUE(was_callback_called()); | 351 EXPECT_TRUE(was_callback_called()); |
348 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 352 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
349 EXPECT_EQ(0, test_throttle->will_start_calls()); | 353 EXPECT_EQ(0, test_throttle->will_start_calls()); |
350 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 354 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
351 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 355 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
352 } | 356 } |
353 | 357 |
354 // Checks that a navigation deferred can be canceled and not ignored. | 358 // Checks that a navigation deferred can be canceled and not ignored. |
355 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { | 359 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { |
356 TestNavigationThrottle* test_throttle = | 360 TestNavigationThrottle* test_throttle = |
(...skipping 12 matching lines...) Expand all Loading... |
369 EXPECT_FALSE(was_callback_called()); | 373 EXPECT_FALSE(was_callback_called()); |
370 EXPECT_EQ(1, test_throttle->will_start_calls()); | 374 EXPECT_EQ(1, test_throttle->will_start_calls()); |
371 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 375 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
372 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 376 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
373 | 377 |
374 // Cancel the request. The callback should have been called with CANCEL, and | 378 // Cancel the request. The callback should have been called with CANCEL, and |
375 // not CANCEL_AND_IGNORE. | 379 // not CANCEL_AND_IGNORE. |
376 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); | 380 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); |
377 EXPECT_FALSE(IsDeferringStart()); | 381 EXPECT_FALSE(IsDeferringStart()); |
378 EXPECT_FALSE(IsDeferringRedirect()); | 382 EXPECT_FALSE(IsDeferringRedirect()); |
379 EXPECT_TRUE(IsCanceling()); | 383 EXPECT_TRUE(IsCancelingRequest()); |
380 EXPECT_TRUE(was_callback_called()); | 384 EXPECT_TRUE(was_callback_called()); |
381 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); | 385 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); |
382 EXPECT_EQ(1, test_throttle->will_start_calls()); | 386 EXPECT_EQ(1, test_throttle->will_start_calls()); |
383 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 387 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
384 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 388 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
385 } | 389 } |
386 | 390 |
387 // Checks that a NavigationThrottle asking to defer followed by a | 391 // Checks that a NavigationThrottle asking to defer followed by a |
388 // NavigationThrottle asking to proceed behave correctly. | 392 // NavigationThrottle asking to proceed behave correctly. |
389 TEST_F(NavigationHandleImplTest, DeferThenProceed) { | 393 TEST_F(NavigationHandleImplTest, DeferThenProceed) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 483 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
480 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 484 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
481 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 485 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
482 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 486 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
483 | 487 |
484 // Resume the request. The callback should have been called. The second | 488 // Resume the request. The callback should have been called. The second |
485 // throttle should have been notified. | 489 // throttle should have been notified. |
486 test_handle()->Resume(); | 490 test_handle()->Resume(); |
487 EXPECT_FALSE(IsDeferringStart()); | 491 EXPECT_FALSE(IsDeferringStart()); |
488 EXPECT_FALSE(IsDeferringRedirect()); | 492 EXPECT_FALSE(IsDeferringRedirect()); |
489 EXPECT_TRUE(IsCanceling()); | 493 EXPECT_TRUE(IsCancelingRequest()); |
490 EXPECT_TRUE(was_callback_called()); | 494 EXPECT_TRUE(was_callback_called()); |
491 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 495 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
492 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 496 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
493 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 497 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
494 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 498 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
495 EXPECT_EQ(1, cancel_throttle->will_start_calls()); | 499 EXPECT_EQ(1, cancel_throttle->will_start_calls()); |
496 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 500 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
497 } | 501 } |
498 | 502 |
499 // Checks that a NavigationThrottle asking to defer followed by a | 503 // Checks that a NavigationThrottle asking to defer followed by a |
(...skipping 22 matching lines...) Expand all Loading... |
522 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 526 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
523 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 527 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
524 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 528 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
525 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 529 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
526 | 530 |
527 // Resume the request. The callback should have been called. The second | 531 // Resume the request. The callback should have been called. The second |
528 // throttle should have been notified. | 532 // throttle should have been notified. |
529 test_handle()->Resume(); | 533 test_handle()->Resume(); |
530 EXPECT_FALSE(IsDeferringStart()); | 534 EXPECT_FALSE(IsDeferringStart()); |
531 EXPECT_FALSE(IsDeferringRedirect()); | 535 EXPECT_FALSE(IsDeferringRedirect()); |
532 EXPECT_TRUE(IsCanceling()); | 536 EXPECT_TRUE(IsCancelingRequest()); |
533 EXPECT_TRUE(was_callback_called()); | 537 EXPECT_TRUE(was_callback_called()); |
534 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 538 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
535 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 539 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
536 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 540 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
537 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 541 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
538 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 542 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
539 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); | 543 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); |
540 } | 544 } |
541 | 545 |
542 // Checks that a NavigationThrottle asking to cancel followed by a | 546 // Checks that a NavigationThrottle asking to cancel followed by a |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); | 622 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
619 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 623 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
620 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 624 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
621 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 625 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
622 | 626 |
623 // Simulate WillRedirectRequest. The request should not be deferred. The | 627 // Simulate WillRedirectRequest. The request should not be deferred. The |
624 // callback should have been called. | 628 // callback should have been called. |
625 SimulateWillProcessResponse(); | 629 SimulateWillProcessResponse(); |
626 EXPECT_FALSE(IsDeferringStart()); | 630 EXPECT_FALSE(IsDeferringStart()); |
627 EXPECT_FALSE(IsDeferringRedirect()); | 631 EXPECT_FALSE(IsDeferringRedirect()); |
| 632 EXPECT_TRUE(IsCancelingResponse()); |
628 EXPECT_TRUE(was_callback_called()); | 633 EXPECT_TRUE(was_callback_called()); |
629 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 634 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
630 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 635 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
631 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 636 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
632 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 637 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
633 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 638 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
634 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 639 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
635 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); | 640 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); |
636 } | 641 } |
637 | 642 |
(...skipping 24 matching lines...) Expand all Loading... |
662 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 667 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
663 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 668 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
664 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 669 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
665 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 670 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
666 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 671 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
667 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 672 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
668 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 673 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
669 } | 674 } |
670 | 675 |
671 } // namespace content | 676 } // namespace content |
OLD | NEW |