Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 2364943002: Create NavigationHandles for interstitials if needed (Closed)
Patch Set: Fixed Android issue Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 11 matching lines...) Expand all
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
24 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
25 #include "content/browser/browser_thread_impl.h" 25 #include "content/browser/browser_thread_impl.h"
26 #include "content/browser/child_process_security_policy_impl.h" 26 #include "content/browser/child_process_security_policy_impl.h"
27 #include "content/browser/download/download_manager_impl.h" 27 #include "content/browser/download/download_manager_impl.h"
28 #include "content/browser/download/download_resource_handler.h" 28 #include "content/browser/download/download_resource_handler.h"
29 #include "content/browser/frame_host/navigation_request_info.h" 29 #include "content/browser/frame_host/navigation_request_info.h"
30 #include "content/browser/loader/cross_site_resource_handler.h" 30 #include "content/browser/loader/cross_site_resource_handler.h"
31 #include "content/browser/loader/detachable_resource_handler.h" 31 #include "content/browser/loader/detachable_resource_handler.h"
32 #include "content/browser/loader/navigation_resource_throttle.h"
32 #include "content/browser/loader/navigation_url_loader.h" 33 #include "content/browser/loader/navigation_url_loader.h"
33 #include "content/browser/loader/resource_dispatcher_host_impl.h" 34 #include "content/browser/loader/resource_dispatcher_host_impl.h"
34 #include "content/browser/loader/resource_loader.h" 35 #include "content/browser/loader/resource_loader.h"
35 #include "content/browser/loader/resource_message_filter.h" 36 #include "content/browser/loader/resource_message_filter.h"
36 #include "content/browser/loader/resource_request_info_impl.h" 37 #include "content/browser/loader/resource_request_info_impl.h"
37 #include "content/browser/loader_delegate_impl.h" 38 #include "content/browser/loader_delegate_impl.h"
38 #include "content/common/appcache_interfaces.h" 39 #include "content/common/appcache_interfaces.h"
39 #include "content/common/child_process_host_impl.h" 40 #include "content/common/child_process_host_impl.h"
40 #include "content/common/navigation_params.h" 41 #include "content/common/navigation_params.h"
41 #include "content/common/resource_messages.h" 42 #include "content/common/resource_messages.h"
(...skipping 2428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 accum_.GetClassifiedMessages(&msgs); 2471 accum_.GetClassifiedMessages(&msgs);
2471 ASSERT_EQ(1U, msgs.size()); 2472 ASSERT_EQ(1U, msgs.size());
2472 2473
2473 ResourceResponseHead response_head; 2474 ResourceResponseHead response_head;
2474 GetResponseHead(msgs[0], &response_head); 2475 GetResponseHead(msgs[0], &response_head);
2475 ASSERT_EQ("text/plain", response_head.mime_type); 2476 ASSERT_EQ("text/plain", response_head.mime_type);
2476 } 2477 }
2477 2478
2478 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). 2479 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream).
2479 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) { 2480 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) {
2481 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2480 std::string raw_headers("HTTP/1.1 403 Forbidden\n" 2482 std::string raw_headers("HTTP/1.1 403 Forbidden\n"
2481 "Content-disposition: attachment; filename=blah\n" 2483 "Content-disposition: attachment; filename=blah\n"
2482 "Content-type: application/octet-stream\n\n"); 2484 "Content-type: application/octet-stream\n\n");
2483 std::string response_data("<html><title>Test One</title></html>"); 2485 std::string response_data("<html><title>Test One</title></html>");
2484 SetResponse(raw_headers, response_data); 2486 SetResponse(raw_headers, response_data);
2485 2487
2486 HandleScheme("http"); 2488 HandleScheme("http");
2487 2489
2488 int expected_error_code = net::ERR_INVALID_RESPONSE; 2490 int expected_error_code = net::ERR_INVALID_RESPONSE;
2489 GURL forbidden_download_url = GURL("http:bla"); 2491 GURL forbidden_download_url = GURL("http:bla");
2490 2492
2491 CompleteFailingMainResourceRequest(forbidden_download_url, 2493 CompleteFailingMainResourceRequest(forbidden_download_url,
2492 expected_error_code); 2494 expected_error_code);
2493 } 2495 }
2494 2496
2495 // Test for http://crbug.com/76202 . We don't want to destroy a 2497 // Test for http://crbug.com/76202 . We don't want to destroy a
2496 // download request prematurely when processing a cancellation from 2498 // download request prematurely when processing a cancellation from
2497 // the renderer. 2499 // the renderer.
2498 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { 2500 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) {
2499 // PlzNavigate: A request that ends up being a download is a main resource 2501 // PlzNavigate: A request that ends up being a download is a main resource
2500 // request. Hence, it has been initiated by the browser and is not associated 2502 // request. Hence, it has been initiated by the browser and is not associated
2501 // with a renderer. Therefore, it cannot be canceled by a renderer IPC. 2503 // with a renderer. Therefore, it cannot be canceled by a renderer IPC.
2502 if (IsBrowserSideNavigationEnabled()) { 2504 if (IsBrowserSideNavigationEnabled()) {
2503 SUCCEED() << "Not applicable with --enable-browser-side-navigation."; 2505 SUCCEED() << "Not applicable with --enable-browser-side-navigation.";
2504 return; 2506 return;
2505 } 2507 }
2506 2508
2509 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2510
2507 EXPECT_EQ(0, host_.pending_requests()); 2511 EXPECT_EQ(0, host_.pending_requests());
2508 2512
2509 int render_view_id = 0; 2513 int render_view_id = 0;
2510 int request_id = 1; 2514 int request_id = 1;
2511 2515
2512 std::string raw_headers("HTTP\n" 2516 std::string raw_headers("HTTP\n"
2513 "Content-disposition: attachment; filename=foo\n\n"); 2517 "Content-disposition: attachment; filename=foo\n\n");
2514 std::string response_data("01234567890123456789\x01foobar"); 2518 std::string response_data("01234567890123456789\x01foobar");
2515 2519
2516 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that 2520 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that
(...skipping 23 matching lines...) Expand all
2540 // the cancellation above should have been ignored and the request 2544 // the cancellation above should have been ignored and the request
2541 // should still be alive. 2545 // should still be alive.
2542 EXPECT_EQ(1, host_.pending_requests()); 2546 EXPECT_EQ(1, host_.pending_requests());
2543 2547
2544 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2548 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2545 base::RunLoop().RunUntilIdle(); 2549 base::RunLoop().RunUntilIdle();
2546 } 2550 }
2547 2551
2548 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) { 2552 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) {
2549 EXPECT_EQ(0, host_.pending_requests()); 2553 EXPECT_EQ(0, host_.pending_requests());
2554 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2550 2555
2551 int render_view_id = 0; 2556 int render_view_id = 0;
2552 int request_id = 1; 2557 int request_id = 1;
2553 2558
2554 std::string raw_headers("HTTP\n" 2559 std::string raw_headers("HTTP\n"
2555 "Content-disposition: attachment; filename=foo\n\n"); 2560 "Content-disposition: attachment; filename=foo\n\n");
2556 std::string response_data("01234567890123456789\x01foobar"); 2561 std::string response_data("01234567890123456789\x01foobar");
2557 // Get past sniffing metrics. 2562 // Get past sniffing metrics.
2558 response_data.resize(1025, ' '); 2563 response_data.resize(1025, ' ');
2559 2564
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 EXPECT_EQ(0, host_.pending_requests()); 2661 EXPECT_EQ(0, host_.pending_requests());
2657 } 2662 }
2658 2663
2659 // Test the cancelling of requests that are being transferred to a new renderer 2664 // Test the cancelling of requests that are being transferred to a new renderer
2660 // due to a redirection. 2665 // due to a redirection.
2661 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { 2666 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) {
2662 // PlzNavigate: there are no transferred requests in PlzNavigate. 2667 // PlzNavigate: there are no transferred requests in PlzNavigate.
2663 if (IsBrowserSideNavigationEnabled()) 2668 if (IsBrowserSideNavigationEnabled())
2664 return; 2669 return;
2665 2670
2671 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2672
2666 EXPECT_EQ(0, host_.pending_requests()); 2673 EXPECT_EQ(0, host_.pending_requests());
2667 2674
2668 int request_id = 1; 2675 int request_id = 1;
2669 2676
2670 std::string raw_headers("HTTP/1.1 200 OK\n" 2677 std::string raw_headers("HTTP/1.1 200 OK\n"
2671 "Content-Type: text/html; charset=utf-8\n\n"); 2678 "Content-Type: text/html; charset=utf-8\n\n");
2672 std::string response_data("<html>foobar</html>"); 2679 std::string response_data("<html>foobar</html>");
2673 2680
2674 SetResponse(raw_headers, response_data); 2681 SetResponse(raw_headers, response_data);
2675 HandleScheme("http"); 2682 HandleScheme("http");
(...skipping 29 matching lines...) Expand all
2705 if (IsBrowserSideNavigationEnabled()) { 2712 if (IsBrowserSideNavigationEnabled()) {
2706 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2713 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2707 return; 2714 return;
2708 } 2715 }
2709 // This test expects the cross site request to be leaked, so it can transfer 2716 // This test expects the cross site request to be leaked, so it can transfer
2710 // the request directly. 2717 // the request directly.
2711 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2718 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2712 2719
2713 EXPECT_EQ(0, host_.pending_requests()); 2720 EXPECT_EQ(0, host_.pending_requests());
2714 2721
2722 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2723
2715 int render_view_id = 0; 2724 int render_view_id = 0;
2716 int request_id = 1; 2725 int request_id = 1;
2717 2726
2718 // Configure initial request. 2727 // Configure initial request.
2719 SetResponse("HTTP/1.1 302 Found\n" 2728 SetResponse("HTTP/1.1 302 Found\n"
2720 "Location: http://other.com/blech\n\n"); 2729 "Location: http://other.com/blech\n\n");
2721 2730
2722 HandleScheme("http"); 2731 HandleScheme("http");
2723 2732
2724 // Temporarily replace ContentBrowserClient with one that will trigger the 2733 // Temporarily replace ContentBrowserClient with one that will trigger the
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 // accounting works. 2785 // accounting works.
2777 TEST_P(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) { 2786 TEST_P(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) {
2778 if (IsBrowserSideNavigationEnabled()) { 2787 if (IsBrowserSideNavigationEnabled()) {
2779 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2788 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2780 return; 2789 return;
2781 } 2790 }
2782 // This test expects the cross site request to be leaked, so it can transfer 2791 // This test expects the cross site request to be leaked, so it can transfer
2783 // the request directly. 2792 // the request directly.
2784 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2793 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2785 2794
2795 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2796
2786 EXPECT_EQ(0, host_.pending_requests()); 2797 EXPECT_EQ(0, host_.pending_requests());
2787 2798
2788 int render_view_id = 0; 2799 int render_view_id = 0;
2789 int request_id = 1; 2800 int request_id = 1;
2790 2801
2791 // Configure initial request. 2802 // Configure initial request.
2792 const std::string kResponseBody = "hello world"; 2803 const std::string kResponseBody = "hello world";
2793 SetResponse("HTTP/1.1 200 OK\n" 2804 SetResponse("HTTP/1.1 200 OK\n"
2794 "Content-Type: text/html\n\n", 2805 "Content-Type: text/html\n\n",
2795 kResponseBody); 2806 kResponseBody);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 // the transfer occurs. 2872 // the transfer occurs.
2862 TEST_P(ResourceDispatcherHostTest, TransferNavigationText) { 2873 TEST_P(ResourceDispatcherHostTest, TransferNavigationText) {
2863 if (IsBrowserSideNavigationEnabled()) { 2874 if (IsBrowserSideNavigationEnabled()) {
2864 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2875 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2865 return; 2876 return;
2866 } 2877 }
2867 // This test expects the cross site request to be leaked, so it can transfer 2878 // This test expects the cross site request to be leaked, so it can transfer
2868 // the request directly. 2879 // the request directly.
2869 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2880 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2870 2881
2882 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2883
2871 EXPECT_EQ(0, host_.pending_requests()); 2884 EXPECT_EQ(0, host_.pending_requests());
2872 2885
2873 int render_view_id = 0; 2886 int render_view_id = 0;
2874 int request_id = 1; 2887 int request_id = 1;
2875 2888
2876 // Configure initial request. 2889 // Configure initial request.
2877 SetResponse("HTTP/1.1 302 Found\n" 2890 SetResponse("HTTP/1.1 302 Found\n"
2878 "Location: http://other.com/blech\n\n"); 2891 "Location: http://other.com/blech\n\n");
2879 2892
2880 HandleScheme("http"); 2893 HandleScheme("http");
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 2948
2936 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) { 2949 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) {
2937 if (IsBrowserSideNavigationEnabled()) { 2950 if (IsBrowserSideNavigationEnabled()) {
2938 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2951 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2939 return; 2952 return;
2940 } 2953 }
2941 // This test expects the cross site request to be leaked, so it can transfer 2954 // This test expects the cross site request to be leaked, so it can transfer
2942 // the request directly. 2955 // the request directly.
2943 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2956 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2944 2957
2958 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2959
2945 EXPECT_EQ(0, host_.pending_requests()); 2960 EXPECT_EQ(0, host_.pending_requests());
2946 2961
2947 int render_view_id = 0; 2962 int render_view_id = 0;
2948 int request_id = 1; 2963 int request_id = 1;
2949 int first_child_id = -1; 2964 int first_child_id = -1;
2950 2965
2951 // Configure initial request. 2966 // Configure initial request.
2952 SetResponse("HTTP/1.1 302 Found\n" 2967 SetResponse("HTTP/1.1 302 Found\n"
2953 "Location: http://other.com/blech\n\n"); 2968 "Location: http://other.com/blech\n\n");
2954 const std::string kResponseBody = "hello world"; 2969 const std::string kResponseBody = "hello world";
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3023 3038
3024 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { 3039 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) {
3025 if (IsBrowserSideNavigationEnabled()) { 3040 if (IsBrowserSideNavigationEnabled()) {
3026 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 3041 SUCCEED() << "Test is not applicable with browser side navigation enabled";
3027 return; 3042 return;
3028 } 3043 }
3029 // This test expects the cross site request to be leaked, so it can transfer 3044 // This test expects the cross site request to be leaked, so it can transfer
3030 // the request directly. 3045 // the request directly.
3031 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 3046 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
3032 3047
3048 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
3049
3033 EXPECT_EQ(0, host_.pending_requests()); 3050 EXPECT_EQ(0, host_.pending_requests());
3034 3051
3035 int render_view_id = 0; 3052 int render_view_id = 0;
3036 int request_id = 1; 3053 int request_id = 1;
3037 3054
3038 // Configure initial request. 3055 // Configure initial request.
3039 SetResponse("HTTP/1.1 302 Found\n" 3056 SetResponse("HTTP/1.1 302 Found\n"
3040 "Location: http://other.com/blech\n\n"); 3057 "Location: http://other.com/blech\n\n");
3041 3058
3042 HandleScheme("http"); 3059 HandleScheme("http");
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3109 // Check generated messages. 3126 // Check generated messages.
3110 ResourceIPCAccumulator::ClassifiedMessages msgs; 3127 ResourceIPCAccumulator::ClassifiedMessages msgs;
3111 accum_.GetClassifiedMessages(&msgs); 3128 accum_.GetClassifiedMessages(&msgs);
3112 3129
3113 ASSERT_EQ(2U, msgs.size()); 3130 ASSERT_EQ(2U, msgs.size());
3114 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3131 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3115 CheckSuccessfulRequest(msgs[1], kResponseBody); 3132 CheckSuccessfulRequest(msgs[1], kResponseBody);
3116 } 3133 }
3117 3134
3118 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) { 3135 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) {
3136 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
3119 EXPECT_EQ(0, host_.pending_requests()); 3137 EXPECT_EQ(0, host_.pending_requests());
3120 3138
3121 HandleScheme("http"); 3139 HandleScheme("http");
3122 3140
3123 const GURL invalid_sheme_url = GURL("foo://bar"); 3141 const GURL invalid_sheme_url = GURL("foo://bar");
3124 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME; 3142 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME;
3125 3143
3126 CompleteFailingMainResourceRequest(invalid_sheme_url, expected_error_code); 3144 CompleteFailingMainResourceRequest(invalid_sheme_url, expected_error_code);
3127 } 3145 }
3128 3146
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
3819 return nullptr; 3837 return nullptr;
3820 } 3838 }
3821 3839
3822 INSTANTIATE_TEST_CASE_P( 3840 INSTANTIATE_TEST_CASE_P(
3823 ResourceDispatcherHostTests, 3841 ResourceDispatcherHostTests,
3824 ResourceDispatcherHostTest, 3842 ResourceDispatcherHostTest,
3825 testing::Values(TestConfig::kDefault, 3843 testing::Values(TestConfig::kDefault,
3826 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3844 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3827 3845
3828 } // namespace content 3846 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/navigation_resource_throttle.cc ('k') | content/browser/loader/url_loader_factory_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698