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