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

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

Issue 2321543002: Merge CrossSiteResourceHandler and NavigationResourceThrottle (Closed)
Patch Set: Rebase Created 4 years, 3 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"
31 #include "content/browser/loader/detachable_resource_handler.h" 30 #include "content/browser/loader/detachable_resource_handler.h"
31 #include "content/browser/loader/navigation_resource_throttle.h"
32 #include "content/browser/loader/navigation_url_loader.h" 32 #include "content/browser/loader/navigation_url_loader.h"
33 #include "content/browser/loader/resource_dispatcher_host_impl.h" 33 #include "content/browser/loader/resource_dispatcher_host_impl.h"
34 #include "content/browser/loader/resource_loader.h" 34 #include "content/browser/loader/resource_loader.h"
35 #include "content/browser/loader/resource_message_filter.h" 35 #include "content/browser/loader/resource_message_filter.h"
36 #include "content/browser/loader/resource_request_info_impl.h" 36 #include "content/browser/loader/resource_request_info_impl.h"
37 #include "content/browser/loader_delegate_impl.h" 37 #include "content/browser/loader_delegate_impl.h"
38 #include "content/common/appcache_interfaces.h" 38 #include "content/common/appcache_interfaces.h"
39 #include "content/common/child_process_host_impl.h" 39 #include "content/common/child_process_host_impl.h"
40 #include "content/common/navigation_params.h" 40 #include "content/common/navigation_params.h"
41 #include "content/common/resource_messages.h" 41 #include "content/common/resource_messages.h"
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 explicit TestUserData(bool* was_deleted) 616 explicit TestUserData(bool* was_deleted)
617 : was_deleted_(was_deleted) { 617 : was_deleted_(was_deleted) {
618 } 618 }
619 619
620 ~TestUserData() override { *was_deleted_ = true; } 620 ~TestUserData() override { *was_deleted_ = true; }
621 621
622 private: 622 private:
623 bool* was_deleted_; 623 bool* was_deleted_;
624 }; 624 };
625 625
626 class TransfersAllNavigationsContentBrowserClient
627 : public TestContentBrowserClient {
628 public:
629 bool ShouldSwapProcessesForRedirect(ResourceContext* resource_context,
630 const GURL& current_url,
631 const GURL& new_url) override {
632 return true;
633 }
634 };
635
636 enum GenericResourceThrottleFlags { 626 enum GenericResourceThrottleFlags {
637 NONE = 0, 627 NONE = 0,
638 DEFER_STARTING_REQUEST = 1 << 0, 628 DEFER_STARTING_REQUEST = 1 << 0,
639 DEFER_PROCESSING_RESPONSE = 1 << 1, 629 DEFER_PROCESSING_RESPONSE = 1 << 1,
640 CANCEL_BEFORE_START = 1 << 2, 630 CANCEL_BEFORE_START = 1 << 2,
641 CANCEL_PROCESSING_RESPONSE = 1 << 3, 631 CANCEL_PROCESSING_RESPONSE = 1 << 3,
642 MUST_NOT_CACHE_BODY = 1 << 4, 632 MUST_NOT_CACHE_BODY = 1 << 4,
643 }; 633 };
644 634
645 // Throttle that tracks the current throttle blocking a request. Only one 635 // Throttle that tracks the current throttle blocking a request. Only one
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 accum_.GetClassifiedMessages(&msgs); 2465 accum_.GetClassifiedMessages(&msgs);
2476 ASSERT_EQ(1U, msgs.size()); 2466 ASSERT_EQ(1U, msgs.size());
2477 2467
2478 ResourceResponseHead response_head; 2468 ResourceResponseHead response_head;
2479 GetResponseHead(msgs[0], &response_head); 2469 GetResponseHead(msgs[0], &response_head);
2480 ASSERT_EQ("text/plain", response_head.mime_type); 2470 ASSERT_EQ("text/plain", response_head.mime_type);
2481 } 2471 }
2482 2472
2483 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). 2473 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream).
2484 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) { 2474 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) {
2475 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2485 std::string raw_headers("HTTP/1.1 403 Forbidden\n" 2476 std::string raw_headers("HTTP/1.1 403 Forbidden\n"
2486 "Content-disposition: attachment; filename=blah\n" 2477 "Content-disposition: attachment; filename=blah\n"
2487 "Content-type: application/octet-stream\n\n"); 2478 "Content-type: application/octet-stream\n\n");
2488 std::string response_data("<html><title>Test One</title></html>"); 2479 std::string response_data("<html><title>Test One</title></html>");
2489 SetResponse(raw_headers, response_data); 2480 SetResponse(raw_headers, response_data);
2490 2481
2491 HandleScheme("http"); 2482 HandleScheme("http");
2492 2483
2493 int expected_error_code = net::ERR_INVALID_RESPONSE; 2484 int expected_error_code = net::ERR_INVALID_RESPONSE;
2494 GURL forbidden_download_url = GURL("http:bla"); 2485 GURL forbidden_download_url = GURL("http:bla");
2495 2486
2496 CompleteFailingMainResourceRequest(forbidden_download_url, 2487 CompleteFailingMainResourceRequest(forbidden_download_url,
2497 expected_error_code); 2488 expected_error_code);
2498 } 2489 }
2499 2490
2500 // Test for http://crbug.com/76202 . We don't want to destroy a 2491 // Test for http://crbug.com/76202 . We don't want to destroy a
2501 // download request prematurely when processing a cancellation from 2492 // download request prematurely when processing a cancellation from
2502 // the renderer. 2493 // the renderer.
2503 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { 2494 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) {
2504 // PlzNavigate: A request that ends up being a download is a main resource 2495 // PlzNavigate: A request that ends up being a download is a main resource
2505 // request. Hence, it has been initiated by the browser and is not associated 2496 // request. Hence, it has been initiated by the browser and is not associated
2506 // with a renderer. Therefore, it cannot be canceled by a renderer IPC. 2497 // with a renderer. Therefore, it cannot be canceled by a renderer IPC.
2507 if (IsBrowserSideNavigationEnabled()) { 2498 if (IsBrowserSideNavigationEnabled()) {
2508 SUCCEED() << "Not applicable with --enable-browser-side-navigation."; 2499 SUCCEED() << "Not applicable with --enable-browser-side-navigation.";
2509 return; 2500 return;
2510 } 2501 }
2511 2502
2503 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2504
2512 EXPECT_EQ(0, host_.pending_requests()); 2505 EXPECT_EQ(0, host_.pending_requests());
2513 2506
2514 int render_view_id = 0; 2507 int render_view_id = 0;
2515 int request_id = 1; 2508 int request_id = 1;
2516 2509
2517 std::string raw_headers("HTTP\n" 2510 std::string raw_headers("HTTP\n"
2518 "Content-disposition: attachment; filename=foo\n\n"); 2511 "Content-disposition: attachment; filename=foo\n\n");
2519 std::string response_data("01234567890123456789\x01foobar"); 2512 std::string response_data("01234567890123456789\x01foobar");
2520 2513
2521 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that 2514 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that
(...skipping 23 matching lines...) Expand all
2545 // the cancellation above should have been ignored and the request 2538 // the cancellation above should have been ignored and the request
2546 // should still be alive. 2539 // should still be alive.
2547 EXPECT_EQ(1, host_.pending_requests()); 2540 EXPECT_EQ(1, host_.pending_requests());
2548 2541
2549 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2542 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2550 base::RunLoop().RunUntilIdle(); 2543 base::RunLoop().RunUntilIdle();
2551 } 2544 }
2552 2545
2553 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) { 2546 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) {
2554 EXPECT_EQ(0, host_.pending_requests()); 2547 EXPECT_EQ(0, host_.pending_requests());
2548 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2555 2549
2556 int render_view_id = 0; 2550 int render_view_id = 0;
2557 int request_id = 1; 2551 int request_id = 1;
2558 2552
2559 std::string raw_headers("HTTP\n" 2553 std::string raw_headers("HTTP\n"
2560 "Content-disposition: attachment; filename=foo\n\n"); 2554 "Content-disposition: attachment; filename=foo\n\n");
2561 std::string response_data("01234567890123456789\x01foobar"); 2555 std::string response_data("01234567890123456789\x01foobar");
2562 // Get past sniffing metrics. 2556 // Get past sniffing metrics.
2563 response_data.resize(1025, ' '); 2557 response_data.resize(1025, ' ');
2564 2558
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 EXPECT_EQ(0, host_.pending_requests()); 2654 EXPECT_EQ(0, host_.pending_requests());
2661 } 2655 }
2662 2656
2663 // Test the cancelling of requests that are being transferred to a new renderer 2657 // Test the cancelling of requests that are being transferred to a new renderer
2664 // due to a redirection. 2658 // due to a redirection.
2665 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { 2659 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) {
2666 // PlzNavigate: there are no transferred requests in PlzNavigate. 2660 // PlzNavigate: there are no transferred requests in PlzNavigate.
2667 if (IsBrowserSideNavigationEnabled()) 2661 if (IsBrowserSideNavigationEnabled())
2668 return; 2662 return;
2669 2663
2664 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2665
2670 EXPECT_EQ(0, host_.pending_requests()); 2666 EXPECT_EQ(0, host_.pending_requests());
2671 2667
2672 int request_id = 1; 2668 int request_id = 1;
2673 2669
2674 std::string raw_headers("HTTP/1.1 200 OK\n" 2670 std::string raw_headers("HTTP/1.1 200 OK\n"
2675 "Content-Type: text/html; charset=utf-8\n\n"); 2671 "Content-Type: text/html; charset=utf-8\n\n");
2676 std::string response_data("<html>foobar</html>"); 2672 std::string response_data("<html>foobar</html>");
2677 2673
2678 SetResponse(raw_headers, response_data); 2674 SetResponse(raw_headers, response_data);
2679 HandleScheme("http"); 2675 HandleScheme("http");
2680 2676
2681 MakeWebContentsAssociatedTestRequestWithResourceType( 2677 MakeWebContentsAssociatedTestRequestWithResourceType(
2682 request_id, GURL("http://example.com/blah"), RESOURCE_TYPE_MAIN_FRAME); 2678 request_id, GURL("http://example.com/blah"), RESOURCE_TYPE_MAIN_FRAME);
2683 2679
2684 GlobalRequestID global_request_id(web_contents_filter_->child_id(), 2680 GlobalRequestID global_request_id(web_contents_filter_->child_id(),
2685 request_id); 2681 request_id);
2686 host_.MarkAsTransferredNavigation(global_request_id, nullptr); 2682 host_.MarkAsTransferredNavigation(global_request_id, base::Closure());
2687 2683
2688 // And now simulate a cancellation coming from the renderer. 2684 // And now simulate a cancellation coming from the renderer.
2689 ResourceHostMsg_CancelRequest msg(request_id); 2685 ResourceHostMsg_CancelRequest msg(request_id);
2690 host_.OnMessageReceived(msg, web_contents_filter_.get()); 2686 host_.OnMessageReceived(msg, web_contents_filter_.get());
2691 2687
2692 // Since the request is marked as being transferred, 2688 // Since the request is marked as being transferred,
2693 // the cancellation above should have been ignored and the request 2689 // the cancellation above should have been ignored and the request
2694 // should still be alive. 2690 // should still be alive.
2695 EXPECT_EQ(1, host_.pending_requests()); 2691 EXPECT_EQ(1, host_.pending_requests());
2696 2692
2697 // Cancelling by other methods shouldn't work either. 2693 // Cancelling by other methods shouldn't work either.
2698 host_.CancelRequestsForProcess(web_contents_->GetRoutingID()); 2694 host_.CancelRequestsForProcess(web_contents_->GetRoutingID());
2699 EXPECT_EQ(1, host_.pending_requests()); 2695 EXPECT_EQ(1, host_.pending_requests());
2700 2696
2701 // Cancelling by context should work. 2697 // Cancelling by context should work.
2702 host_.CancelRequestsForContext(web_contents_filter_->resource_context()); 2698 host_.CancelRequestsForContext(web_contents_filter_->resource_context());
2703 EXPECT_EQ(0, host_.pending_requests()); 2699 EXPECT_EQ(0, host_.pending_requests());
2704 } 2700 }
2705 2701
2706 // Test transferred navigations with text/html, which doesn't trigger any 2702 // Test transferred navigations with text/html, which doesn't trigger any
2707 // content sniffing. 2703 // content sniffing.
2708 TEST_P(ResourceDispatcherHostTest, TransferNavigationHtml) { 2704 TEST_P(ResourceDispatcherHostTest, TransferNavigationHtml) {
2709 if (IsBrowserSideNavigationEnabled()) { 2705 if (IsBrowserSideNavigationEnabled()) {
2710 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2706 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2711 return; 2707 return;
2712 } 2708 }
2713 // This test expects the cross site request to be leaked, so it can transfer
2714 // the request directly.
2715 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2716 2709
2717 EXPECT_EQ(0, host_.pending_requests()); 2710 EXPECT_EQ(0, host_.pending_requests());
2718 2711
2712 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2713 NavigationResourceThrottle::SetForceTransferForTesting(true);
2714
2719 int render_view_id = 0; 2715 int render_view_id = 0;
2720 int request_id = 1; 2716 int request_id = 1;
2721 2717
2722 // Configure initial request. 2718 // Configure initial request.
2723 SetResponse("HTTP/1.1 302 Found\n" 2719 SetResponse("HTTP/1.1 302 Found\n"
2724 "Location: http://other.com/blech\n\n"); 2720 "Location: http://other.com/blech\n\n");
2725 2721
2726 HandleScheme("http"); 2722 HandleScheme("http");
2727 2723
2728 // Temporarily replace ContentBrowserClient with one that will trigger the
2729 // transfer navigation code paths.
2730 TransfersAllNavigationsContentBrowserClient new_client;
2731 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2732
2733 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2724 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2734 GURL("http://example.com/blah"), 2725 GURL("http://example.com/blah"),
2735 RESOURCE_TYPE_MAIN_FRAME); 2726 RESOURCE_TYPE_MAIN_FRAME);
2736 2727
2737 // Now that we're blocked on the redirect, update the response and unblock by 2728 // Now that we're blocked on the redirect, update the response and unblock by
2738 // telling the AsyncResourceHandler to follow the redirect. 2729 // telling the AsyncResourceHandler to follow the redirect.
2739 const std::string kResponseBody = "hello world"; 2730 const std::string kResponseBody = "hello world";
2740 SetResponse("HTTP/1.1 200 OK\n" 2731 SetResponse("HTTP/1.1 200 OK\n"
2741 "Content-Type: text/html\n\n", 2732 "Content-Type: text/html\n\n",
2742 kResponseBody); 2733 kResponseBody);
2743 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2734 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2744 host_.OnMessageReceived(redirect_msg, filter_.get()); 2735 host_.OnMessageReceived(redirect_msg, filter_.get());
2745 base::RunLoop().RunUntilIdle(); 2736 base::RunLoop().RunUntilIdle();
2746 2737
2747 // Flush all the pending requests to get the response through the 2738 // Flush all the pending requests to get the response through the
2748 // MimeTypeResourceHandler. 2739 // MimeTypeResourceHandler.
2749 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2740 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2750 2741
2751 // Restore, now that we've set up a transfer.
2752 SetBrowserClientForTesting(old_client);
2753
2754 // This second filter is used to emulate a second process. 2742 // This second filter is used to emulate a second process.
2755 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2743 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2756 2744
2757 int new_render_view_id = 1; 2745 int new_render_view_id = 1;
2758 int new_request_id = 2; 2746 int new_request_id = 2;
2759 2747
2760 ResourceRequest request = CreateResourceRequest( 2748 ResourceRequest request = CreateResourceRequest(
2761 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2749 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2762 request.transferred_request_child_id = filter_->child_id(); 2750 request.transferred_request_child_id = filter_->child_id();
2763 request.transferred_request_request_id = request_id; 2751 request.transferred_request_request_id = request_id;
(...skipping 12 matching lines...) Expand all
2776 CheckSuccessfulRequest(msgs[1], kResponseBody); 2764 CheckSuccessfulRequest(msgs[1], kResponseBody);
2777 } 2765 }
2778 2766
2779 // Test transferring two navigations with text/html, to ensure the resource 2767 // Test transferring two navigations with text/html, to ensure the resource
2780 // accounting works. 2768 // accounting works.
2781 TEST_P(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) { 2769 TEST_P(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) {
2782 if (IsBrowserSideNavigationEnabled()) { 2770 if (IsBrowserSideNavigationEnabled()) {
2783 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2771 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2784 return; 2772 return;
2785 } 2773 }
2786 // This test expects the cross site request to be leaked, so it can transfer 2774
2787 // the request directly. 2775 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2788 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2776 NavigationResourceThrottle::SetForceTransferForTesting(true);
2789 2777
2790 EXPECT_EQ(0, host_.pending_requests()); 2778 EXPECT_EQ(0, host_.pending_requests());
2791 2779
2792 int render_view_id = 0; 2780 int render_view_id = 0;
2793 int request_id = 1; 2781 int request_id = 1;
2794 2782
2795 // Configure initial request. 2783 // Configure initial request.
2796 const std::string kResponseBody = "hello world"; 2784 const std::string kResponseBody = "hello world";
2797 SetResponse("HTTP/1.1 200 OK\n" 2785 SetResponse("HTTP/1.1 200 OK\n"
2798 "Content-Type: text/html\n\n", 2786 "Content-Type: text/html\n\n",
2799 kResponseBody); 2787 kResponseBody);
2800 2788
2801 HandleScheme("http"); 2789 HandleScheme("http");
2802 2790
2803 // Temporarily replace ContentBrowserClient with one that will trigger the
2804 // transfer navigation code paths.
2805 TransfersAllNavigationsContentBrowserClient new_client;
2806 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2807
2808 // Make the first request. 2791 // Make the first request.
2809 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2792 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2810 GURL("http://example.com/blah"), 2793 GURL("http://example.com/blah"),
2811 RESOURCE_TYPE_MAIN_FRAME); 2794 RESOURCE_TYPE_MAIN_FRAME);
2812 2795
2813 // Make a second request from the same process. 2796 // Make a second request from the same process.
2814 int second_request_id = 2; 2797 int second_request_id = 2;
2815 MakeTestRequestWithResourceType(filter_.get(), render_view_id, 2798 MakeTestRequestWithResourceType(filter_.get(), render_view_id,
2816 second_request_id, 2799 second_request_id,
2817 GURL("http://example.com/foo"), 2800 GURL("http://example.com/foo"),
2818 RESOURCE_TYPE_MAIN_FRAME); 2801 RESOURCE_TYPE_MAIN_FRAME);
2819 2802
2820 // Flush all the pending requests to get the response through the 2803 // Flush all the pending requests to get the response through the
2821 // MimeTypeResourceHandler. 2804 // MimeTypeResourceHandler.
2822 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2805 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2823 2806
2824 // Restore, now that we've set up a transfer. 2807 NavigationResourceThrottle::SetForceTransferForTesting(false);
2825 SetBrowserClientForTesting(old_client);
2826 2808
2827 // This second filter is used to emulate a second process. 2809 // This second filter is used to emulate a second process.
2828 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2810 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2829 2811
2830 // Transfer the first request. 2812 // Transfer the first request.
2831 int new_render_view_id = 1; 2813 int new_render_view_id = 1;
2832 int new_request_id = 5; 2814 int new_request_id = 5;
2833 ResourceRequest request = CreateResourceRequest( 2815 ResourceRequest request = CreateResourceRequest(
2834 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2816 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2835 request.transferred_request_child_id = filter_->child_id(); 2817 request.transferred_request_child_id = filter_->child_id();
(...skipping 25 matching lines...) Expand all
2861 } 2843 }
2862 2844
2863 // Test transferred navigations with text/plain, which causes 2845 // Test transferred navigations with text/plain, which causes
2864 // MimeTypeResourceHandler to buffer the response to sniff the content before 2846 // MimeTypeResourceHandler to buffer the response to sniff the content before
2865 // the transfer occurs. 2847 // the transfer occurs.
2866 TEST_P(ResourceDispatcherHostTest, TransferNavigationText) { 2848 TEST_P(ResourceDispatcherHostTest, TransferNavigationText) {
2867 if (IsBrowserSideNavigationEnabled()) { 2849 if (IsBrowserSideNavigationEnabled()) {
2868 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2850 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2869 return; 2851 return;
2870 } 2852 }
2871 // This test expects the cross site request to be leaked, so it can transfer 2853
2872 // the request directly. 2854 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2873 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2855 NavigationResourceThrottle::SetForceTransferForTesting(true);
2874 2856
2875 EXPECT_EQ(0, host_.pending_requests()); 2857 EXPECT_EQ(0, host_.pending_requests());
2876 2858
2877 int render_view_id = 0; 2859 int render_view_id = 0;
2878 int request_id = 1; 2860 int request_id = 1;
2879 2861
2880 // Configure initial request. 2862 // Configure initial request.
2881 SetResponse("HTTP/1.1 302 Found\n" 2863 SetResponse("HTTP/1.1 302 Found\n"
2882 "Location: http://other.com/blech\n\n"); 2864 "Location: http://other.com/blech\n\n");
2883 2865
2884 HandleScheme("http"); 2866 HandleScheme("http");
2885 2867
2886 // Temporarily replace ContentBrowserClient with one that will trigger the
2887 // transfer navigation code paths.
2888 TransfersAllNavigationsContentBrowserClient new_client;
2889 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2890
2891 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2868 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2892 GURL("http://example.com/blah"), 2869 GURL("http://example.com/blah"),
2893 RESOURCE_TYPE_MAIN_FRAME); 2870 RESOURCE_TYPE_MAIN_FRAME);
2894 2871
2895 // Now that we're blocked on the redirect, update the response and unblock by 2872 // Now that we're blocked on the redirect, update the response and unblock by
2896 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain 2873 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain
2897 // MIME type, which causes MimeTypeResourceHandler to buffer it before the 2874 // MIME type, which causes MimeTypeResourceHandler to buffer it before the
2898 // transfer occurs. 2875 // transfer occurs.
2899 const std::string kResponseBody = "hello world"; 2876 const std::string kResponseBody = "hello world";
2900 SetResponse("HTTP/1.1 200 OK\n" 2877 SetResponse("HTTP/1.1 200 OK\n"
2901 "Content-Type: text/plain\n\n", 2878 "Content-Type: text/plain\n\n",
2902 kResponseBody); 2879 kResponseBody);
2903 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2880 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2904 host_.OnMessageReceived(redirect_msg, filter_.get()); 2881 host_.OnMessageReceived(redirect_msg, filter_.get());
2905 base::RunLoop().RunUntilIdle(); 2882 base::RunLoop().RunUntilIdle();
2906 2883
2907 // Flush all the pending requests to get the response through the 2884 // Flush all the pending requests to get the response through the
2908 // MimeTypeResourceHandler. 2885 // MimeTypeResourceHandler.
2909 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2886 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2910 base::RunLoop().RunUntilIdle(); 2887 base::RunLoop().RunUntilIdle();
2911 2888
2912 // Restore, now that we've set up a transfer.
2913 SetBrowserClientForTesting(old_client);
2914
2915 // This second filter is used to emulate a second process. 2889 // This second filter is used to emulate a second process.
2916 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2890 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2917 2891
2918 int new_render_view_id = 1; 2892 int new_render_view_id = 1;
2919 int new_request_id = 2; 2893 int new_request_id = 2;
2920 2894
2921 ResourceRequest request = CreateResourceRequest( 2895 ResourceRequest request = CreateResourceRequest(
2922 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2896 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2923 request.transferred_request_child_id = filter_->child_id(); 2897 request.transferred_request_child_id = filter_->child_id();
2924 request.transferred_request_request_id = request_id; 2898 request.transferred_request_request_id = request_id;
(...skipping 10 matching lines...) Expand all
2935 ASSERT_EQ(2U, msgs.size()); 2909 ASSERT_EQ(2U, msgs.size());
2936 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2910 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2937 CheckSuccessfulRequest(msgs[1], kResponseBody); 2911 CheckSuccessfulRequest(msgs[1], kResponseBody);
2938 } 2912 }
2939 2913
2940 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) { 2914 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) {
2941 if (IsBrowserSideNavigationEnabled()) { 2915 if (IsBrowserSideNavigationEnabled()) {
2942 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2916 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2943 return; 2917 return;
2944 } 2918 }
2945 // This test expects the cross site request to be leaked, so it can transfer 2919
2946 // the request directly. 2920 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2947 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2921 NavigationResourceThrottle::SetForceTransferForTesting(true);
2948 2922
2949 EXPECT_EQ(0, host_.pending_requests()); 2923 EXPECT_EQ(0, host_.pending_requests());
2950 2924
2951 int render_view_id = 0; 2925 int render_view_id = 0;
2952 int request_id = 1; 2926 int request_id = 1;
2953 int first_child_id = -1; 2927 int first_child_id = -1;
2954 2928
2955 // Configure initial request. 2929 // Configure initial request.
2956 SetResponse("HTTP/1.1 302 Found\n" 2930 SetResponse("HTTP/1.1 302 Found\n"
2957 "Location: http://other.com/blech\n\n"); 2931 "Location: http://other.com/blech\n\n");
2958 const std::string kResponseBody = "hello world"; 2932 const std::string kResponseBody = "hello world";
2959 2933
2960 HandleScheme("http"); 2934 HandleScheme("http");
2961 2935
2962 // Temporarily replace ContentBrowserClient with one that will trigger the
2963 // transfer navigation code paths.
2964 TransfersAllNavigationsContentBrowserClient new_client;
2965 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2966
2967 // Create a first filter that can be deleted before the second one starts. 2936 // Create a first filter that can be deleted before the second one starts.
2968 { 2937 {
2969 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); 2938 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter();
2970 first_child_id = first_filter->child_id(); 2939 first_child_id = first_filter->child_id();
2971 2940
2972 ResourceRequest first_request = CreateResourceRequest( 2941 ResourceRequest first_request = CreateResourceRequest(
2973 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2942 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2974 2943
2975 ResourceHostMsg_RequestResource first_request_msg( 2944 ResourceHostMsg_RequestResource first_request_msg(
2976 render_view_id, request_id, first_request); 2945 render_view_id, request_id, first_request);
2977 host_.OnMessageReceived(first_request_msg, first_filter.get()); 2946 host_.OnMessageReceived(first_request_msg, first_filter.get());
2978 base::RunLoop().RunUntilIdle(); 2947 base::RunLoop().RunUntilIdle();
2979 2948
2980 // Now that we're blocked on the redirect, update the response and unblock 2949 // Now that we're blocked on the redirect, update the response and unblock
2981 // by telling the AsyncResourceHandler to follow the redirect. 2950 // by telling the AsyncResourceHandler to follow the redirect.
2982 SetResponse("HTTP/1.1 200 OK\n" 2951 SetResponse("HTTP/1.1 200 OK\n"
2983 "Content-Type: text/html\n\n", 2952 "Content-Type: text/html\n\n",
2984 kResponseBody); 2953 kResponseBody);
2985 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2954 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2986 host_.OnMessageReceived(redirect_msg, first_filter.get()); 2955 host_.OnMessageReceived(redirect_msg, first_filter.get());
2987 base::RunLoop().RunUntilIdle(); 2956 base::RunLoop().RunUntilIdle();
2988 2957
2989 // Flush all the pending requests to get the response through the 2958 // Flush all the pending requests to get the response through the
2990 // MimeTypeResourceHandler. 2959 // MimeTypeResourceHandler.
2991 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2960 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2992 } 2961 }
2993 // The first filter is now deleted, as if the child process died. 2962 // The first filter is now deleted, as if the child process died.
2994 2963
2995 // Restore.
2996 SetBrowserClientForTesting(old_client);
2997
2998 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. 2964 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted.
2999 GlobalRequestID first_global_request_id(first_child_id, request_id); 2965 GlobalRequestID first_global_request_id(first_child_id, request_id);
3000 2966
3001 // This second filter is used to emulate a second process. 2967 // This second filter is used to emulate a second process.
3002 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2968 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3003 2969
3004 int new_render_view_id = 1; 2970 int new_render_view_id = 1;
3005 int new_request_id = 2; 2971 int new_request_id = 2;
3006 2972
3007 ResourceRequest request = CreateResourceRequest( 2973 ResourceRequest request = CreateResourceRequest(
(...skipping 15 matching lines...) Expand all
3023 ASSERT_EQ(2U, msgs.size()); 2989 ASSERT_EQ(2U, msgs.size());
3024 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2990 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3025 CheckSuccessfulRequest(msgs[1], kResponseBody); 2991 CheckSuccessfulRequest(msgs[1], kResponseBody);
3026 } 2992 }
3027 2993
3028 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { 2994 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) {
3029 if (IsBrowserSideNavigationEnabled()) { 2995 if (IsBrowserSideNavigationEnabled()) {
3030 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2996 SUCCEED() << "Test is not applicable with browser side navigation enabled";
3031 return; 2997 return;
3032 } 2998 }
3033 // This test expects the cross site request to be leaked, so it can transfer 2999
3034 // the request directly. 3000 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
3035 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 3001 NavigationResourceThrottle::SetForceTransferForTesting(true);
3036 3002
3037 EXPECT_EQ(0, host_.pending_requests()); 3003 EXPECT_EQ(0, host_.pending_requests());
3038 3004
3039 int render_view_id = 0; 3005 int render_view_id = 0;
3040 int request_id = 1; 3006 int request_id = 1;
3041 3007
3042 // Configure initial request. 3008 // Configure initial request.
3043 SetResponse("HTTP/1.1 302 Found\n" 3009 SetResponse("HTTP/1.1 302 Found\n"
3044 "Location: http://other.com/blech\n\n"); 3010 "Location: http://other.com/blech\n\n");
3045 3011
3046 HandleScheme("http"); 3012 HandleScheme("http");
3047 3013
3048 // Temporarily replace ContentBrowserClient with one that will trigger the
3049 // transfer navigation code paths.
3050 TransfersAllNavigationsContentBrowserClient new_client;
3051 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
3052
3053 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 3014 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
3054 GURL("http://example.com/blah"), 3015 GURL("http://example.com/blah"),
3055 RESOURCE_TYPE_MAIN_FRAME); 3016 RESOURCE_TYPE_MAIN_FRAME);
3056 3017
3057 // Now that we're blocked on the redirect, simulate hitting another redirect. 3018 // Now that we're blocked on the redirect, simulate hitting another redirect.
3058 SetResponse("HTTP/1.1 302 Found\n" 3019 SetResponse("HTTP/1.1 302 Found\n"
3059 "Location: http://other.com/blerg\n\n"); 3020 "Location: http://other.com/blerg\n\n");
3060 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3021 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
3061 host_.OnMessageReceived(redirect_msg, filter_.get()); 3022 host_.OnMessageReceived(redirect_msg, filter_.get());
3062 base::RunLoop().RunUntilIdle(); 3023 base::RunLoop().RunUntilIdle();
3063 3024
3064 // Now that we're blocked on the second redirect, update the response and 3025 // Now that we're blocked on the second redirect, update the response and
3065 // unblock by telling the AsyncResourceHandler to follow the redirect. 3026 // unblock by telling the AsyncResourceHandler to follow the redirect.
3066 // Again, use text/plain to force MimeTypeResourceHandler to buffer before 3027 // Again, use text/plain to force MimeTypeResourceHandler to buffer before
3067 // the transfer. 3028 // the transfer.
3068 const std::string kResponseBody = "hello world"; 3029 const std::string kResponseBody = "hello world";
3069 SetResponse("HTTP/1.1 200 OK\n" 3030 SetResponse("HTTP/1.1 200 OK\n"
3070 "Content-Type: text/plain\n\n", 3031 "Content-Type: text/plain\n\n",
3071 kResponseBody); 3032 kResponseBody);
3072 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); 3033 ResourceHostMsg_FollowRedirect redirect_msg2(request_id);
3073 host_.OnMessageReceived(redirect_msg2, filter_.get()); 3034 host_.OnMessageReceived(redirect_msg2, filter_.get());
3074 base::RunLoop().RunUntilIdle(); 3035 base::RunLoop().RunUntilIdle();
3075 3036
3076 // Flush all the pending requests to get the response through the 3037 // Flush all the pending requests to get the response through the
3077 // MimeTypeResourceHandler. 3038 // MimeTypeResourceHandler.
3078 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3039 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3079 base::RunLoop().RunUntilIdle(); 3040 base::RunLoop().RunUntilIdle();
3080 3041
3081 // Restore.
3082 SetBrowserClientForTesting(old_client);
3083
3084 // This second filter is used to emulate a second process. 3042 // This second filter is used to emulate a second process.
3085 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3043 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3086 3044
3087 int new_render_view_id = 1; 3045 int new_render_view_id = 1;
3088 int new_request_id = 2; 3046 int new_request_id = 2;
3089 3047
3090 ResourceRequest request = CreateResourceRequest( 3048 ResourceRequest request = CreateResourceRequest(
3091 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3049 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3092 request.transferred_request_child_id = filter_->child_id(); 3050 request.transferred_request_child_id = filter_->child_id();
3093 request.transferred_request_request_id = request_id; 3051 request.transferred_request_request_id = request_id;
(...skipping 19 matching lines...) Expand all
3113 // Check generated messages. 3071 // Check generated messages.
3114 ResourceIPCAccumulator::ClassifiedMessages msgs; 3072 ResourceIPCAccumulator::ClassifiedMessages msgs;
3115 accum_.GetClassifiedMessages(&msgs); 3073 accum_.GetClassifiedMessages(&msgs);
3116 3074
3117 ASSERT_EQ(2U, msgs.size()); 3075 ASSERT_EQ(2U, msgs.size());
3118 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3076 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3119 CheckSuccessfulRequest(msgs[1], kResponseBody); 3077 CheckSuccessfulRequest(msgs[1], kResponseBody);
3120 } 3078 }
3121 3079
3122 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) { 3080 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) {
3081 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
3123 EXPECT_EQ(0, host_.pending_requests()); 3082 EXPECT_EQ(0, host_.pending_requests());
3124 3083
3125 HandleScheme("http"); 3084 HandleScheme("http");
3126 3085
3127 const GURL invalid_sheme_url = GURL("foo://bar"); 3086 const GURL invalid_sheme_url = GURL("foo://bar");
3128 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME; 3087 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME;
3129 3088
3130 CompleteFailingMainResourceRequest(invalid_sheme_url, expected_error_code); 3089 CompleteFailingMainResourceRequest(invalid_sheme_url, expected_error_code);
3131 } 3090 }
3132 3091
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
3823 return nullptr; 3782 return nullptr;
3824 } 3783 }
3825 3784
3826 INSTANTIATE_TEST_CASE_P( 3785 INSTANTIATE_TEST_CASE_P(
3827 ResourceDispatcherHostTests, 3786 ResourceDispatcherHostTests,
3828 ResourceDispatcherHostTest, 3787 ResourceDispatcherHostTest,
3829 testing::Values(TestConfig::kDefault, 3788 testing::Values(TestConfig::kDefault,
3830 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3789 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3831 3790
3832 } // namespace content 3791 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698