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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 TestNavigationThrottle* proceed_throttle = | 671 TestNavigationThrottle* proceed_throttle = |
672 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); | 672 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); |
673 EXPECT_FALSE(IsDeferringStart()); | 673 EXPECT_FALSE(IsDeferringStart()); |
674 EXPECT_FALSE(IsDeferringRedirect()); | 674 EXPECT_FALSE(IsDeferringRedirect()); |
675 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 675 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
676 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 676 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
677 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); | 677 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
678 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 678 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
679 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 679 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
680 | 680 |
681 // Simulate WillRedirectRequest. The request should not be deferred. The | 681 // Simulate WillProcessResponse. The request should not be deferred. The |
682 // callback should have been called. The second throttle should not have | 682 // callback should have been called. The second throttle should not have |
683 // been notified. | 683 // been notified. |
684 SimulateWillProcessResponse(); | 684 SimulateWillProcessResponse(); |
685 EXPECT_FALSE(IsDeferringStart()); | 685 EXPECT_FALSE(IsDeferringStart()); |
686 EXPECT_FALSE(IsDeferringRedirect()); | 686 EXPECT_FALSE(IsDeferringRedirect()); |
| 687 EXPECT_FALSE(IsDeferringResponse()); |
687 EXPECT_TRUE(was_callback_called()); | 688 EXPECT_TRUE(was_callback_called()); |
| 689 EXPECT_TRUE(IsCanceling()); |
688 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 690 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
689 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 691 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
690 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 692 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
691 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 693 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
692 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 694 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
693 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 695 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
694 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 696 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
695 } | 697 } |
696 | 698 |
| 699 // Checks that a NavigationThrottle asking to block the response followed by a |
| 700 // NavigationThrottle asking to proceed behave correctly in WillProcessResponse. |
| 701 // The navigation will be canceled directly, and the second throttle will not |
| 702 // be called. |
| 703 TEST_F(NavigationHandleImplTest, BlockResponseThenProceedWillProcessResponse) { |
| 704 TestNavigationThrottle* cancel_throttle = |
| 705 CreateTestNavigationThrottle(NavigationThrottle::BLOCK_RESPONSE); |
| 706 TestNavigationThrottle* proceed_throttle = |
| 707 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); |
| 708 EXPECT_FALSE(IsDeferringStart()); |
| 709 EXPECT_FALSE(IsDeferringRedirect()); |
| 710 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 711 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 712 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
| 713 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 714 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 715 |
| 716 // Simulate WillRedirectRequest. The request should not be deferred. The |
| 717 // callback should have been called. The second throttle should not have |
| 718 // been notified. |
| 719 SimulateWillProcessResponse(); |
| 720 EXPECT_FALSE(IsDeferringStart()); |
| 721 EXPECT_FALSE(IsDeferringRedirect()); |
| 722 EXPECT_FALSE(IsDeferringResponse()); |
| 723 EXPECT_TRUE(was_callback_called()); |
| 724 EXPECT_TRUE(IsCanceling()); |
| 725 EXPECT_EQ(NavigationThrottle::BLOCK_RESPONSE, callback_result()); |
| 726 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 727 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 728 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
| 729 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 730 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 731 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
| 732 } |
| 733 |
697 } // namespace content | 734 } // namespace content |
OLD | NEW |