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

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

Issue 2397893002: Revert the merge of CrossSiteResourceHandler and NavigationResourceThrottle. (Closed)
Patch Set: Add back initialization of started_from_context_menu_. 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "base/memory/shared_memory.h" 18 #include "base/memory/shared_memory.h"
19 #include "base/pickle.h" 19 #include "base/pickle.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
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/detachable_resource_handler.h" 31 #include "content/browser/loader/detachable_resource_handler.h"
31 #include "content/browser/loader/navigation_resource_throttle.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"
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 explicit TestUserData(bool* was_deleted) 612 explicit TestUserData(bool* was_deleted)
612 : was_deleted_(was_deleted) { 613 : was_deleted_(was_deleted) {
613 } 614 }
614 615
615 ~TestUserData() override { *was_deleted_ = true; } 616 ~TestUserData() override { *was_deleted_ = true; }
616 617
617 private: 618 private:
618 bool* was_deleted_; 619 bool* was_deleted_;
619 }; 620 };
620 621
622 class TransfersAllNavigationsContentBrowserClient
623 : public TestContentBrowserClient {
624 public:
625 bool ShouldSwapProcessesForRedirect(ResourceContext* resource_context,
626 const GURL& current_url,
627 const GURL& new_url) override {
628 return true;
629 }
630 };
631
621 enum GenericResourceThrottleFlags { 632 enum GenericResourceThrottleFlags {
622 NONE = 0, 633 NONE = 0,
623 DEFER_STARTING_REQUEST = 1 << 0, 634 DEFER_STARTING_REQUEST = 1 << 0,
624 DEFER_PROCESSING_RESPONSE = 1 << 1, 635 DEFER_PROCESSING_RESPONSE = 1 << 1,
625 CANCEL_BEFORE_START = 1 << 2, 636 CANCEL_BEFORE_START = 1 << 2,
626 CANCEL_PROCESSING_RESPONSE = 1 << 3, 637 CANCEL_PROCESSING_RESPONSE = 1 << 3,
627 MUST_NOT_CACHE_BODY = 1 << 4, 638 MUST_NOT_CACHE_BODY = 1 << 4,
628 }; 639 };
629 640
630 // Throttle that tracks the current throttle blocking a request. Only one 641 // Throttle that tracks the current throttle blocking a request. Only one
(...skipping 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after
2669 std::string response_data("<html>foobar</html>"); 2680 std::string response_data("<html>foobar</html>");
2670 2681
2671 SetResponse(raw_headers, response_data); 2682 SetResponse(raw_headers, response_data);
2672 HandleScheme("http"); 2683 HandleScheme("http");
2673 2684
2674 MakeWebContentsAssociatedTestRequestWithResourceType( 2685 MakeWebContentsAssociatedTestRequestWithResourceType(
2675 request_id, GURL("http://example.com/blah"), RESOURCE_TYPE_MAIN_FRAME); 2686 request_id, GURL("http://example.com/blah"), RESOURCE_TYPE_MAIN_FRAME);
2676 2687
2677 GlobalRequestID global_request_id(web_contents_filter_->child_id(), 2688 GlobalRequestID global_request_id(web_contents_filter_->child_id(),
2678 request_id); 2689 request_id);
2679 host_.MarkAsTransferredNavigation(global_request_id, base::Closure()); 2690 host_.MarkAsTransferredNavigation(global_request_id, nullptr);
2680 2691
2681 // And now simulate a cancellation coming from the renderer. 2692 // And now simulate a cancellation coming from the renderer.
2682 ResourceHostMsg_CancelRequest msg(request_id); 2693 ResourceHostMsg_CancelRequest msg(request_id);
2683 host_.OnMessageReceived(msg, web_contents_filter_.get()); 2694 host_.OnMessageReceived(msg, web_contents_filter_.get());
2684 2695
2685 // Since the request is marked as being transferred, 2696 // Since the request is marked as being transferred,
2686 // the cancellation above should have been ignored and the request 2697 // the cancellation above should have been ignored and the request
2687 // should still be alive. 2698 // should still be alive.
2688 EXPECT_EQ(1, host_.pending_requests()); 2699 EXPECT_EQ(1, host_.pending_requests());
2689 2700
2690 // Cancelling by other methods shouldn't work either. 2701 // Cancelling by other methods shouldn't work either.
2691 host_.CancelRequestsForProcess(web_contents_->GetRoutingID()); 2702 host_.CancelRequestsForProcess(web_contents_->GetRoutingID());
2692 EXPECT_EQ(1, host_.pending_requests()); 2703 EXPECT_EQ(1, host_.pending_requests());
2693 2704
2694 // Cancelling by context should work. 2705 // Cancelling by context should work.
2695 host_.CancelRequestsForContext(web_contents_filter_->resource_context()); 2706 host_.CancelRequestsForContext(web_contents_filter_->resource_context());
2696 EXPECT_EQ(0, host_.pending_requests()); 2707 EXPECT_EQ(0, host_.pending_requests());
2697 } 2708 }
2698 2709
2699 // Test transferred navigations with text/html, which doesn't trigger any 2710 // Test transferred navigations with text/html, which doesn't trigger any
2700 // content sniffing. 2711 // content sniffing.
2701 TEST_P(ResourceDispatcherHostTest, TransferNavigationHtml) { 2712 TEST_P(ResourceDispatcherHostTest, TransferNavigationHtml) {
2702 if (IsBrowserSideNavigationEnabled()) { 2713 if (IsBrowserSideNavigationEnabled()) {
2703 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2714 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2704 return; 2715 return;
2705 } 2716 }
2717 // This test expects the cross site request to be leaked, so it can transfer
2718 // the request directly.
2719 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2706 2720
2707 EXPECT_EQ(0, host_.pending_requests()); 2721 EXPECT_EQ(0, host_.pending_requests());
2708 2722
2709 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 2723 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2710 NavigationResourceThrottle::set_force_transfer_for_testing(true);
2711 2724
2712 int render_view_id = 0; 2725 int render_view_id = 0;
2713 int request_id = 1; 2726 int request_id = 1;
2714 2727
2715 // Configure initial request. 2728 // Configure initial request.
2716 SetResponse("HTTP/1.1 302 Found\n" 2729 SetResponse("HTTP/1.1 302 Found\n"
2717 "Location: http://other.com/blech\n\n"); 2730 "Location: http://other.com/blech\n\n");
2718 2731
2719 HandleScheme("http"); 2732 HandleScheme("http");
2720 2733
2734 // Temporarily replace ContentBrowserClient with one that will trigger the
2735 // transfer navigation code paths.
2736 TransfersAllNavigationsContentBrowserClient new_client;
2737 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2738
2721 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2739 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2722 GURL("http://example.com/blah"), 2740 GURL("http://example.com/blah"),
2723 RESOURCE_TYPE_MAIN_FRAME); 2741 RESOURCE_TYPE_MAIN_FRAME);
2724 2742
2725 // Now that we're blocked on the redirect, update the response and unblock by 2743 // Now that we're blocked on the redirect, update the response and unblock by
2726 // telling the AsyncResourceHandler to follow the redirect. 2744 // telling the AsyncResourceHandler to follow the redirect.
2727 const std::string kResponseBody = "hello world"; 2745 const std::string kResponseBody = "hello world";
2728 SetResponse("HTTP/1.1 200 OK\n" 2746 SetResponse("HTTP/1.1 200 OK\n"
2729 "Content-Type: text/html\n\n", 2747 "Content-Type: text/html\n\n",
2730 kResponseBody); 2748 kResponseBody);
2731 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2749 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2732 host_.OnMessageReceived(redirect_msg, filter_.get()); 2750 host_.OnMessageReceived(redirect_msg, filter_.get());
2733 base::RunLoop().RunUntilIdle(); 2751 base::RunLoop().RunUntilIdle();
2734 2752
2735 // Flush all the pending requests to get the response through the 2753 // Flush all the pending requests to get the response through the
2736 // MimeTypeResourceHandler. 2754 // MimeTypeResourceHandler.
2737 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2755 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2738 2756
2757 // Restore, now that we've set up a transfer.
2758 SetBrowserClientForTesting(old_client);
2759
2739 // This second filter is used to emulate a second process. 2760 // This second filter is used to emulate a second process.
2740 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2761 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2741 2762
2742 int new_render_view_id = 1; 2763 int new_render_view_id = 1;
2743 int new_request_id = 2; 2764 int new_request_id = 2;
2744 2765
2745 ResourceRequest request = CreateResourceRequest( 2766 ResourceRequest request = CreateResourceRequest(
2746 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2767 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2747 request.transferred_request_child_id = filter_->child_id(); 2768 request.transferred_request_child_id = filter_->child_id();
2748 request.transferred_request_request_id = request_id; 2769 request.transferred_request_request_id = request_id;
(...skipping 12 matching lines...) Expand all
2761 CheckSuccessfulRequest(msgs[1], kResponseBody); 2782 CheckSuccessfulRequest(msgs[1], kResponseBody);
2762 } 2783 }
2763 2784
2764 // Test transferring two navigations with text/html, to ensure the resource 2785 // Test transferring two navigations with text/html, to ensure the resource
2765 // accounting works. 2786 // accounting works.
2766 TEST_P(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) { 2787 TEST_P(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) {
2767 if (IsBrowserSideNavigationEnabled()) { 2788 if (IsBrowserSideNavigationEnabled()) {
2768 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2789 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2769 return; 2790 return;
2770 } 2791 }
2792 // This test expects the cross site request to be leaked, so it can transfer
2793 // the request directly.
2794 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2771 2795
2772 NavigationResourceThrottle::set_force_transfer_for_testing(true);
2773 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 2796 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2774 2797
2775 EXPECT_EQ(0, host_.pending_requests()); 2798 EXPECT_EQ(0, host_.pending_requests());
2776 2799
2777 int render_view_id = 0; 2800 int render_view_id = 0;
2778 int request_id = 1; 2801 int request_id = 1;
2779 2802
2780 // Configure initial request. 2803 // Configure initial request.
2781 const std::string kResponseBody = "hello world"; 2804 const std::string kResponseBody = "hello world";
2782 SetResponse("HTTP/1.1 200 OK\n" 2805 SetResponse("HTTP/1.1 200 OK\n"
2783 "Content-Type: text/html\n\n", 2806 "Content-Type: text/html\n\n",
2784 kResponseBody); 2807 kResponseBody);
2785 2808
2786 HandleScheme("http"); 2809 HandleScheme("http");
2787 2810
2811 // Temporarily replace ContentBrowserClient with one that will trigger the
2812 // transfer navigation code paths.
2813 TransfersAllNavigationsContentBrowserClient new_client;
2814 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2815
2788 // Make the first request. 2816 // Make the first request.
2789 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2817 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2790 GURL("http://example.com/blah"), 2818 GURL("http://example.com/blah"),
2791 RESOURCE_TYPE_MAIN_FRAME); 2819 RESOURCE_TYPE_MAIN_FRAME);
2792 2820
2793 // Make a second request from the same process. 2821 // Make a second request from the same process.
2794 int second_request_id = 2; 2822 int second_request_id = 2;
2795 MakeTestRequestWithResourceType(filter_.get(), render_view_id, 2823 MakeTestRequestWithResourceType(filter_.get(), render_view_id,
2796 second_request_id, 2824 second_request_id,
2797 GURL("http://example.com/foo"), 2825 GURL("http://example.com/foo"),
2798 RESOURCE_TYPE_MAIN_FRAME); 2826 RESOURCE_TYPE_MAIN_FRAME);
2799 2827
2800 // Flush all the pending requests to get the response through the 2828 // Flush all the pending requests to get the response through the
2801 // MimeTypeResourceHandler. 2829 // MimeTypeResourceHandler.
2802 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2830 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2803 2831
2804 NavigationResourceThrottle::set_force_transfer_for_testing(false); 2832 // Restore, now that we've set up a transfer.
2833 SetBrowserClientForTesting(old_client);
2805 2834
2806 // This second filter is used to emulate a second process. 2835 // This second filter is used to emulate a second process.
2807 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2836 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2808 2837
2809 // Transfer the first request. 2838 // Transfer the first request.
2810 int new_render_view_id = 1; 2839 int new_render_view_id = 1;
2811 int new_request_id = 5; 2840 int new_request_id = 5;
2812 ResourceRequest request = CreateResourceRequest( 2841 ResourceRequest request = CreateResourceRequest(
2813 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2842 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2814 request.transferred_request_child_id = filter_->child_id(); 2843 request.transferred_request_child_id = filter_->child_id();
(...skipping 25 matching lines...) Expand all
2840 } 2869 }
2841 2870
2842 // Test transferred navigations with text/plain, which causes 2871 // Test transferred navigations with text/plain, which causes
2843 // MimeTypeResourceHandler to buffer the response to sniff the content before 2872 // MimeTypeResourceHandler to buffer the response to sniff the content before
2844 // the transfer occurs. 2873 // the transfer occurs.
2845 TEST_P(ResourceDispatcherHostTest, TransferNavigationText) { 2874 TEST_P(ResourceDispatcherHostTest, TransferNavigationText) {
2846 if (IsBrowserSideNavigationEnabled()) { 2875 if (IsBrowserSideNavigationEnabled()) {
2847 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2876 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2848 return; 2877 return;
2849 } 2878 }
2879 // This test expects the cross site request to be leaked, so it can transfer
2880 // the request directly.
2881 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2850 2882
2851 NavigationResourceThrottle::set_force_transfer_for_testing(true);
2852 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 2883 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2853 2884
2854 EXPECT_EQ(0, host_.pending_requests()); 2885 EXPECT_EQ(0, host_.pending_requests());
2855 2886
2856 int render_view_id = 0; 2887 int render_view_id = 0;
2857 int request_id = 1; 2888 int request_id = 1;
2858 2889
2859 // Configure initial request. 2890 // Configure initial request.
2860 SetResponse("HTTP/1.1 302 Found\n" 2891 SetResponse("HTTP/1.1 302 Found\n"
2861 "Location: http://other.com/blech\n\n"); 2892 "Location: http://other.com/blech\n\n");
2862 2893
2863 HandleScheme("http"); 2894 HandleScheme("http");
2864 2895
2896 // Temporarily replace ContentBrowserClient with one that will trigger the
2897 // transfer navigation code paths.
2898 TransfersAllNavigationsContentBrowserClient new_client;
2899 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2900
2865 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2901 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2866 GURL("http://example.com/blah"), 2902 GURL("http://example.com/blah"),
2867 RESOURCE_TYPE_MAIN_FRAME); 2903 RESOURCE_TYPE_MAIN_FRAME);
2868 2904
2869 // Now that we're blocked on the redirect, update the response and unblock by 2905 // Now that we're blocked on the redirect, update the response and unblock by
2870 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain 2906 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain
2871 // MIME type, which causes MimeTypeResourceHandler to buffer it before the 2907 // MIME type, which causes MimeTypeResourceHandler to buffer it before the
2872 // transfer occurs. 2908 // transfer occurs.
2873 const std::string kResponseBody = "hello world"; 2909 const std::string kResponseBody = "hello world";
2874 SetResponse("HTTP/1.1 200 OK\n" 2910 SetResponse("HTTP/1.1 200 OK\n"
2875 "Content-Type: text/plain\n\n", 2911 "Content-Type: text/plain\n\n",
2876 kResponseBody); 2912 kResponseBody);
2877 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2913 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2878 host_.OnMessageReceived(redirect_msg, filter_.get()); 2914 host_.OnMessageReceived(redirect_msg, filter_.get());
2879 base::RunLoop().RunUntilIdle(); 2915 base::RunLoop().RunUntilIdle();
2880 2916
2881 // Flush all the pending requests to get the response through the 2917 // Flush all the pending requests to get the response through the
2882 // MimeTypeResourceHandler. 2918 // MimeTypeResourceHandler.
2883 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2919 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2884 base::RunLoop().RunUntilIdle(); 2920 base::RunLoop().RunUntilIdle();
2885 2921
2922 // Restore, now that we've set up a transfer.
2923 SetBrowserClientForTesting(old_client);
2924
2886 // This second filter is used to emulate a second process. 2925 // This second filter is used to emulate a second process.
2887 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2926 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2888 2927
2889 int new_render_view_id = 1; 2928 int new_render_view_id = 1;
2890 int new_request_id = 2; 2929 int new_request_id = 2;
2891 2930
2892 ResourceRequest request = CreateResourceRequest( 2931 ResourceRequest request = CreateResourceRequest(
2893 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2932 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2894 request.transferred_request_child_id = filter_->child_id(); 2933 request.transferred_request_child_id = filter_->child_id();
2895 request.transferred_request_request_id = request_id; 2934 request.transferred_request_request_id = request_id;
(...skipping 10 matching lines...) Expand all
2906 ASSERT_EQ(2U, msgs.size()); 2945 ASSERT_EQ(2U, msgs.size());
2907 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2946 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2908 CheckSuccessfulRequest(msgs[1], kResponseBody); 2947 CheckSuccessfulRequest(msgs[1], kResponseBody);
2909 } 2948 }
2910 2949
2911 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) { 2950 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) {
2912 if (IsBrowserSideNavigationEnabled()) { 2951 if (IsBrowserSideNavigationEnabled()) {
2913 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2952 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2914 return; 2953 return;
2915 } 2954 }
2955 // This test expects the cross site request to be leaked, so it can transfer
2956 // the request directly.
2957 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2916 2958
2917 NavigationResourceThrottle::set_force_transfer_for_testing(true);
2918 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 2959 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2919 2960
2920 EXPECT_EQ(0, host_.pending_requests()); 2961 EXPECT_EQ(0, host_.pending_requests());
2921 2962
2922 int render_view_id = 0; 2963 int render_view_id = 0;
2923 int request_id = 1; 2964 int request_id = 1;
2924 int first_child_id = -1; 2965 int first_child_id = -1;
2925 2966
2926 // Configure initial request. 2967 // Configure initial request.
2927 SetResponse("HTTP/1.1 302 Found\n" 2968 SetResponse("HTTP/1.1 302 Found\n"
2928 "Location: http://other.com/blech\n\n"); 2969 "Location: http://other.com/blech\n\n");
2929 const std::string kResponseBody = "hello world"; 2970 const std::string kResponseBody = "hello world";
2930 2971
2931 HandleScheme("http"); 2972 HandleScheme("http");
2932 2973
2974 // Temporarily replace ContentBrowserClient with one that will trigger the
2975 // transfer navigation code paths.
2976 TransfersAllNavigationsContentBrowserClient new_client;
2977 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2978
2933 // Create a first filter that can be deleted before the second one starts. 2979 // Create a first filter that can be deleted before the second one starts.
2934 { 2980 {
2935 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); 2981 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter();
2936 first_child_id = first_filter->child_id(); 2982 first_child_id = first_filter->child_id();
2937 2983
2938 ResourceRequest first_request = CreateResourceRequest( 2984 ResourceRequest first_request = CreateResourceRequest(
2939 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2985 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2940 2986
2941 ResourceHostMsg_RequestResource first_request_msg( 2987 ResourceHostMsg_RequestResource first_request_msg(
2942 render_view_id, request_id, first_request); 2988 render_view_id, request_id, first_request);
2943 host_.OnMessageReceived(first_request_msg, first_filter.get()); 2989 host_.OnMessageReceived(first_request_msg, first_filter.get());
2944 base::RunLoop().RunUntilIdle(); 2990 base::RunLoop().RunUntilIdle();
2945 2991
2946 // Now that we're blocked on the redirect, update the response and unblock 2992 // Now that we're blocked on the redirect, update the response and unblock
2947 // by telling the AsyncResourceHandler to follow the redirect. 2993 // by telling the AsyncResourceHandler to follow the redirect.
2948 SetResponse("HTTP/1.1 200 OK\n" 2994 SetResponse("HTTP/1.1 200 OK\n"
2949 "Content-Type: text/html\n\n", 2995 "Content-Type: text/html\n\n",
2950 kResponseBody); 2996 kResponseBody);
2951 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2997 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2952 host_.OnMessageReceived(redirect_msg, first_filter.get()); 2998 host_.OnMessageReceived(redirect_msg, first_filter.get());
2953 base::RunLoop().RunUntilIdle(); 2999 base::RunLoop().RunUntilIdle();
2954 3000
2955 // Flush all the pending requests to get the response through the 3001 // Flush all the pending requests to get the response through the
2956 // MimeTypeResourceHandler. 3002 // MimeTypeResourceHandler.
2957 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3003 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2958 } 3004 }
2959 // The first filter is now deleted, as if the child process died. 3005 // The first filter is now deleted, as if the child process died.
2960 3006
3007 // Restore.
3008 SetBrowserClientForTesting(old_client);
3009
2961 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. 3010 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted.
2962 GlobalRequestID first_global_request_id(first_child_id, request_id); 3011 GlobalRequestID first_global_request_id(first_child_id, request_id);
2963 3012
2964 // This second filter is used to emulate a second process. 3013 // This second filter is used to emulate a second process.
2965 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3014 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2966 3015
2967 int new_render_view_id = 1; 3016 int new_render_view_id = 1;
2968 int new_request_id = 2; 3017 int new_request_id = 2;
2969 3018
2970 ResourceRequest request = CreateResourceRequest( 3019 ResourceRequest request = CreateResourceRequest(
(...skipping 15 matching lines...) Expand all
2986 ASSERT_EQ(2U, msgs.size()); 3035 ASSERT_EQ(2U, msgs.size());
2987 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3036 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2988 CheckSuccessfulRequest(msgs[1], kResponseBody); 3037 CheckSuccessfulRequest(msgs[1], kResponseBody);
2989 } 3038 }
2990 3039
2991 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { 3040 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) {
2992 if (IsBrowserSideNavigationEnabled()) { 3041 if (IsBrowserSideNavigationEnabled()) {
2993 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 3042 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2994 return; 3043 return;
2995 } 3044 }
3045 // This test expects the cross site request to be leaked, so it can transfer
3046 // the request directly.
3047 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2996 3048
2997 NavigationResourceThrottle::set_force_transfer_for_testing(true);
2998 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 3049 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2999 3050
3000 EXPECT_EQ(0, host_.pending_requests()); 3051 EXPECT_EQ(0, host_.pending_requests());
3001 3052
3002 int render_view_id = 0; 3053 int render_view_id = 0;
3003 int request_id = 1; 3054 int request_id = 1;
3004 3055
3005 // Configure initial request. 3056 // Configure initial request.
3006 SetResponse("HTTP/1.1 302 Found\n" 3057 SetResponse("HTTP/1.1 302 Found\n"
3007 "Location: http://other.com/blech\n\n"); 3058 "Location: http://other.com/blech\n\n");
3008 3059
3009 HandleScheme("http"); 3060 HandleScheme("http");
3010 3061
3062 // Temporarily replace ContentBrowserClient with one that will trigger the
3063 // transfer navigation code paths.
3064 TransfersAllNavigationsContentBrowserClient new_client;
3065 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
3066
3011 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 3067 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
3012 GURL("http://example.com/blah"), 3068 GURL("http://example.com/blah"),
3013 RESOURCE_TYPE_MAIN_FRAME); 3069 RESOURCE_TYPE_MAIN_FRAME);
3014 3070
3015 // Now that we're blocked on the redirect, simulate hitting another redirect. 3071 // Now that we're blocked on the redirect, simulate hitting another redirect.
3016 SetResponse("HTTP/1.1 302 Found\n" 3072 SetResponse("HTTP/1.1 302 Found\n"
3017 "Location: http://other.com/blerg\n\n"); 3073 "Location: http://other.com/blerg\n\n");
3018 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3074 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
3019 host_.OnMessageReceived(redirect_msg, filter_.get()); 3075 host_.OnMessageReceived(redirect_msg, filter_.get());
3020 base::RunLoop().RunUntilIdle(); 3076 base::RunLoop().RunUntilIdle();
3021 3077
3022 // Now that we're blocked on the second redirect, update the response and 3078 // Now that we're blocked on the second redirect, update the response and
3023 // unblock by telling the AsyncResourceHandler to follow the redirect. 3079 // unblock by telling the AsyncResourceHandler to follow the redirect.
3024 // Again, use text/plain to force MimeTypeResourceHandler to buffer before 3080 // Again, use text/plain to force MimeTypeResourceHandler to buffer before
3025 // the transfer. 3081 // the transfer.
3026 const std::string kResponseBody = "hello world"; 3082 const std::string kResponseBody = "hello world";
3027 SetResponse("HTTP/1.1 200 OK\n" 3083 SetResponse("HTTP/1.1 200 OK\n"
3028 "Content-Type: text/plain\n\n", 3084 "Content-Type: text/plain\n\n",
3029 kResponseBody); 3085 kResponseBody);
3030 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); 3086 ResourceHostMsg_FollowRedirect redirect_msg2(request_id);
3031 host_.OnMessageReceived(redirect_msg2, filter_.get()); 3087 host_.OnMessageReceived(redirect_msg2, filter_.get());
3032 base::RunLoop().RunUntilIdle(); 3088 base::RunLoop().RunUntilIdle();
3033 3089
3034 // Flush all the pending requests to get the response through the 3090 // Flush all the pending requests to get the response through the
3035 // MimeTypeResourceHandler. 3091 // MimeTypeResourceHandler.
3036 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3092 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3037 base::RunLoop().RunUntilIdle(); 3093 base::RunLoop().RunUntilIdle();
3038 3094
3095 // Restore.
3096 SetBrowserClientForTesting(old_client);
3097
3039 // This second filter is used to emulate a second process. 3098 // This second filter is used to emulate a second process.
3040 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3099 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3041 3100
3042 int new_render_view_id = 1; 3101 int new_render_view_id = 1;
3043 int new_request_id = 2; 3102 int new_request_id = 2;
3044 3103
3045 ResourceRequest request = CreateResourceRequest( 3104 ResourceRequest request = CreateResourceRequest(
3046 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3105 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3047 request.transferred_request_child_id = filter_->child_id(); 3106 request.transferred_request_child_id = filter_->child_id();
3048 request.transferred_request_request_id = request_id; 3107 request.transferred_request_request_id = request_id;
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
3779 return nullptr; 3838 return nullptr;
3780 } 3839 }
3781 3840
3782 INSTANTIATE_TEST_CASE_P( 3841 INSTANTIATE_TEST_CASE_P(
3783 ResourceDispatcherHostTests, 3842 ResourceDispatcherHostTests,
3784 ResourceDispatcherHostTest, 3843 ResourceDispatcherHostTest,
3785 testing::Values(TestConfig::kDefault, 3844 testing::Values(TestConfig::kDefault,
3786 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3845 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3787 3846
3788 } // namespace content 3847 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.cc ('k') | content/browser/loader/resource_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698