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