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

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

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

Powered by Google App Engine
This is Rietveld 408576698