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 "content/browser/frame_host/navigation_handle_impl.h" |
5 #include "base/macros.h" | 6 #include "base/macros.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/browser_side_navigation_policy.h" |
9 #include "content/public/common/request_context_type.h" | 10 #include "content/public/common/request_context_type.h" |
10 #include "content/test/test_render_frame_host.h" | 11 #include "content/test/test_render_frame_host.h" |
11 #include "content/test/test_web_contents.h" | 12 #include "content/test/test_web_contents.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 | 15 |
15 // Test version of a NavigationThrottle. It will always return the current | 16 // Test version of a NavigationThrottle. It will always return the current |
16 // NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the | 17 // NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the |
17 // number of times WillStartRequest, WillRedirectRequest, and | 18 // number of times WillStartRequest, WillRedirectRequest, and |
18 // WillProcessResponse were called. | 19 // WillProcessResponse were called. |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 EXPECT_TRUE(IsCanceling()); | 730 EXPECT_TRUE(IsCanceling()); |
730 EXPECT_EQ(NavigationThrottle::BLOCK_RESPONSE, callback_result()); | 731 EXPECT_EQ(NavigationThrottle::BLOCK_RESPONSE, callback_result()); |
731 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 732 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
732 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 733 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
733 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 734 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
734 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 735 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
735 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 736 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
736 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 737 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
737 } | 738 } |
738 | 739 |
| 740 TEST_F(NavigationHandleImplTest, BlockRequestCustomNetError) { |
| 741 TestNavigationThrottle* blocked_throttle = CreateTestNavigationThrottle( |
| 742 {NavigationThrottle::BLOCK_REQUEST, net::ERR_BLOCKED_BY_ADMINISTRATOR}); |
| 743 |
| 744 EXPECT_EQ(0, blocked_throttle->will_start_calls()); |
| 745 EXPECT_EQ(0, blocked_throttle->will_redirect_calls()); |
| 746 EXPECT_EQ(0, blocked_throttle->will_process_response_calls()); |
| 747 |
| 748 // Simulate WillRedirectRequest. The request should not be deferred. The |
| 749 // callback should have been called. The second throttle should not have |
| 750 // been notified. |
| 751 SimulateWillStartRequest(); |
| 752 EXPECT_FALSE(IsDeferringStart()); |
| 753 EXPECT_FALSE(IsDeferringRedirect()); |
| 754 EXPECT_FALSE(IsDeferringResponse()); |
| 755 EXPECT_TRUE(was_callback_called()); |
| 756 EXPECT_TRUE(IsCanceling()); |
| 757 EXPECT_NE(NavigationThrottle::ThrottleCheckResult( |
| 758 NavigationThrottle::BLOCK_REQUEST), |
| 759 callback_result()); |
| 760 EXPECT_EQ(NavigationThrottle::BLOCK_REQUEST, callback_result().action()); |
| 761 EXPECT_EQ(net::ERR_BLOCKED_BY_ADMINISTRATOR, |
| 762 callback_result().net_error_code()); |
| 763 EXPECT_EQ(1, blocked_throttle->will_start_calls()); |
| 764 EXPECT_EQ(0, blocked_throttle->will_redirect_calls()); |
| 765 EXPECT_EQ(0, blocked_throttle->will_process_response_calls()); |
| 766 } |
| 767 |
| 768 TEST_F(NavigationHandleImplTest, BlockRequestCustomNetErrorInRedirect) { |
| 769 // BLOCK_REQUEST on redirect requires PlzNavigate. |
| 770 if (!IsBrowserSideNavigationEnabled()) |
| 771 return; |
| 772 |
| 773 TestNavigationThrottle* blocked_throttle = CreateTestNavigationThrottle( |
| 774 {NavigationThrottle::BLOCK_REQUEST, net::ERR_FILE_NOT_FOUND}); |
| 775 |
| 776 EXPECT_EQ(0, blocked_throttle->will_start_calls()); |
| 777 EXPECT_EQ(0, blocked_throttle->will_redirect_calls()); |
| 778 EXPECT_EQ(0, blocked_throttle->will_process_response_calls()); |
| 779 |
| 780 // Simulate WillRedirectRequest. The request should not be deferred. The |
| 781 // callback should have been called. The second throttle should not have |
| 782 // been notified. |
| 783 SimulateWillRedirectRequest(); |
| 784 EXPECT_FALSE(IsDeferringStart()); |
| 785 EXPECT_FALSE(IsDeferringRedirect()); |
| 786 EXPECT_FALSE(IsDeferringResponse()); |
| 787 EXPECT_TRUE(was_callback_called()); |
| 788 EXPECT_TRUE(IsCanceling()); |
| 789 EXPECT_NE(NavigationThrottle::ThrottleCheckResult( |
| 790 NavigationThrottle::BLOCK_REQUEST), |
| 791 callback_result()); |
| 792 EXPECT_EQ(NavigationThrottle::BLOCK_REQUEST, callback_result().action()); |
| 793 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, callback_result().net_error_code()); |
| 794 EXPECT_EQ(0, blocked_throttle->will_start_calls()); |
| 795 EXPECT_EQ(1, blocked_throttle->will_redirect_calls()); |
| 796 EXPECT_EQ(0, blocked_throttle->will_process_response_calls()); |
| 797 } |
| 798 |
| 799 TEST_F(NavigationHandleImplTest, BlockResponseCustomNetError) { |
| 800 TestNavigationThrottle* block_throttle = CreateTestNavigationThrottle( |
| 801 {NavigationThrottle::BLOCK_RESPONSE, net::ERR_FILE_VIRUS_INFECTED}); |
| 802 |
| 803 EXPECT_EQ(0, block_throttle->will_start_calls()); |
| 804 EXPECT_EQ(0, block_throttle->will_redirect_calls()); |
| 805 EXPECT_EQ(0, block_throttle->will_process_response_calls()); |
| 806 |
| 807 // Simulate WillRedirectRequest. The request should not be deferred. The |
| 808 // callback should have been called. The second throttle should not have |
| 809 // been notified. |
| 810 SimulateWillProcessResponse(); |
| 811 EXPECT_FALSE(IsDeferringStart()); |
| 812 EXPECT_FALSE(IsDeferringRedirect()); |
| 813 EXPECT_FALSE(IsDeferringResponse()); |
| 814 EXPECT_TRUE(was_callback_called()); |
| 815 EXPECT_TRUE(IsCanceling()); |
| 816 EXPECT_NE(NavigationThrottle::ThrottleCheckResult( |
| 817 NavigationThrottle::BLOCK_RESPONSE), |
| 818 callback_result()); |
| 819 EXPECT_EQ(NavigationThrottle::BLOCK_RESPONSE, callback_result().action()); |
| 820 EXPECT_EQ(net::ERR_FILE_VIRUS_INFECTED, callback_result().net_error_code()); |
| 821 EXPECT_EQ(0, block_throttle->will_start_calls()); |
| 822 EXPECT_EQ(0, block_throttle->will_redirect_calls()); |
| 823 EXPECT_EQ(1, block_throttle->will_process_response_calls()); |
| 824 } |
| 825 |
739 } // namespace content | 826 } // namespace content |
OLD | NEW |