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

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

Issue 2321543002: Merge CrossSiteResourceHandler and NavigationResourceThrottle (Closed)
Patch Set: Addressed comments 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 1809 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 accum_.GetClassifiedMessages(&msgs); 2445 accum_.GetClassifiedMessages(&msgs);
2456 ASSERT_EQ(1U, msgs.size()); 2446 ASSERT_EQ(1U, msgs.size());
2457 2447
2458 ResourceResponseHead response_head; 2448 ResourceResponseHead response_head;
2459 GetResponseHead(msgs[0], &response_head); 2449 GetResponseHead(msgs[0], &response_head);
2460 ASSERT_EQ("text/plain", response_head.mime_type); 2450 ASSERT_EQ("text/plain", response_head.mime_type);
2461 } 2451 }
2462 2452
2463 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). 2453 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream).
2464 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) { 2454 TEST_P(ResourceDispatcherHostTest, ForbiddenDownload) {
2455 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2465 std::string raw_headers("HTTP/1.1 403 Forbidden\n" 2456 std::string raw_headers("HTTP/1.1 403 Forbidden\n"
2466 "Content-disposition: attachment; filename=blah\n" 2457 "Content-disposition: attachment; filename=blah\n"
2467 "Content-type: application/octet-stream\n\n"); 2458 "Content-type: application/octet-stream\n\n");
2468 std::string response_data("<html><title>Test One</title></html>"); 2459 std::string response_data("<html><title>Test One</title></html>");
2469 SetResponse(raw_headers, response_data); 2460 SetResponse(raw_headers, response_data);
2470 2461
2471 HandleScheme("http"); 2462 HandleScheme("http");
2472 2463
2473 int expected_error_code = net::ERR_INVALID_RESPONSE; 2464 int expected_error_code = net::ERR_INVALID_RESPONSE;
2474 GURL forbidden_download_url = GURL("http:bla"); 2465 GURL forbidden_download_url = GURL("http:bla");
2475 2466
2476 CompleteFailingMainResourceRequest(forbidden_download_url, 2467 CompleteFailingMainResourceRequest(forbidden_download_url,
2477 expected_error_code); 2468 expected_error_code);
2478 } 2469 }
2479 2470
2480 // Test for http://crbug.com/76202 . We don't want to destroy a 2471 // Test for http://crbug.com/76202 . We don't want to destroy a
2481 // download request prematurely when processing a cancellation from 2472 // download request prematurely when processing a cancellation from
2482 // the renderer. 2473 // the renderer.
2483 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) { 2474 TEST_P(ResourceDispatcherHostTest, IgnoreCancelForDownloads) {
2484 // PlzNavigate: A request that ends up being a download is a main resource 2475 // PlzNavigate: A request that ends up being a download is a main resource
2485 // request. Hence, it has been initiated by the browser and is not associated 2476 // request. Hence, it has been initiated by the browser and is not associated
2486 // with a renderer. Therefore, it cannot be canceled by a renderer IPC. 2477 // with a renderer. Therefore, it cannot be canceled by a renderer IPC.
2487 if (IsBrowserSideNavigationEnabled()) { 2478 if (IsBrowserSideNavigationEnabled()) {
2488 SUCCEED() << "Not applicable with --enable-browser-side-navigation."; 2479 SUCCEED() << "Not applicable with --enable-browser-side-navigation.";
2489 return; 2480 return;
2490 } 2481 }
2491 2482
2483 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2484
2492 EXPECT_EQ(0, host_.pending_requests()); 2485 EXPECT_EQ(0, host_.pending_requests());
2493 2486
2494 int render_view_id = 0; 2487 int render_view_id = 0;
2495 int request_id = 1; 2488 int request_id = 1;
2496 2489
2497 std::string raw_headers("HTTP\n" 2490 std::string raw_headers("HTTP\n"
2498 "Content-disposition: attachment; filename=foo\n\n"); 2491 "Content-disposition: attachment; filename=foo\n\n");
2499 std::string response_data("01234567890123456789\x01foobar"); 2492 std::string response_data("01234567890123456789\x01foobar");
2500 2493
2501 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that 2494 // Get past sniffing metrics in the MimeTypeResourceHandler. Note that
(...skipping 23 matching lines...) Expand all
2525 // the cancellation above should have been ignored and the request 2518 // the cancellation above should have been ignored and the request
2526 // should still be alive. 2519 // should still be alive.
2527 EXPECT_EQ(1, host_.pending_requests()); 2520 EXPECT_EQ(1, host_.pending_requests());
2528 2521
2529 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2522 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2530 base::RunLoop().RunUntilIdle(); 2523 base::RunLoop().RunUntilIdle();
2531 } 2524 }
2532 2525
2533 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) { 2526 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) {
2534 EXPECT_EQ(0, host_.pending_requests()); 2527 EXPECT_EQ(0, host_.pending_requests());
2528 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2535 2529
2536 int render_view_id = 0; 2530 int render_view_id = 0;
2537 int request_id = 1; 2531 int request_id = 1;
2538 2532
2539 std::string raw_headers("HTTP\n" 2533 std::string raw_headers("HTTP\n"
2540 "Content-disposition: attachment; filename=foo\n\n"); 2534 "Content-disposition: attachment; filename=foo\n\n");
2541 std::string response_data("01234567890123456789\x01foobar"); 2535 std::string response_data("01234567890123456789\x01foobar");
2542 // Get past sniffing metrics. 2536 // Get past sniffing metrics.
2543 response_data.resize(1025, ' '); 2537 response_data.resize(1025, ' ');
2544 2538
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2640 EXPECT_EQ(0, host_.pending_requests()); 2634 EXPECT_EQ(0, host_.pending_requests());
2641 } 2635 }
2642 2636
2643 // Test the cancelling of requests that are being transferred to a new renderer 2637 // Test the cancelling of requests that are being transferred to a new renderer
2644 // due to a redirection. 2638 // due to a redirection.
2645 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) { 2639 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextTransferred) {
2646 // PlzNavigate: there are no transferred requests in PlzNavigate. 2640 // PlzNavigate: there are no transferred requests in PlzNavigate.
2647 if (IsBrowserSideNavigationEnabled()) 2641 if (IsBrowserSideNavigationEnabled())
2648 return; 2642 return;
2649 2643
2644 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2645
2650 EXPECT_EQ(0, host_.pending_requests()); 2646 EXPECT_EQ(0, host_.pending_requests());
2651 2647
2652 int request_id = 1; 2648 int request_id = 1;
2653 2649
2654 std::string raw_headers("HTTP/1.1 200 OK\n" 2650 std::string raw_headers("HTTP/1.1 200 OK\n"
2655 "Content-Type: text/html; charset=utf-8\n\n"); 2651 "Content-Type: text/html; charset=utf-8\n\n");
2656 std::string response_data("<html>foobar</html>"); 2652 std::string response_data("<html>foobar</html>");
2657 2653
2658 SetResponse(raw_headers, response_data); 2654 SetResponse(raw_headers, response_data);
2659 HandleScheme("http"); 2655 HandleScheme("http");
2660 2656
2661 MakeWebContentsAssociatedTestRequestWithResourceType( 2657 MakeWebContentsAssociatedTestRequestWithResourceType(
2662 request_id, GURL("http://example.com/blah"), RESOURCE_TYPE_MAIN_FRAME); 2658 request_id, GURL("http://example.com/blah"), RESOURCE_TYPE_MAIN_FRAME);
2663 2659
2664 GlobalRequestID global_request_id(web_contents_filter_->child_id(), 2660 GlobalRequestID global_request_id(web_contents_filter_->child_id(),
2665 request_id); 2661 request_id);
2666 host_.MarkAsTransferredNavigation(global_request_id, nullptr); 2662 host_.MarkAsTransferredNavigation(global_request_id, base::Closure());
2667 2663
2668 // And now simulate a cancellation coming from the renderer. 2664 // And now simulate a cancellation coming from the renderer.
2669 ResourceHostMsg_CancelRequest msg(request_id); 2665 ResourceHostMsg_CancelRequest msg(request_id);
2670 host_.OnMessageReceived(msg, web_contents_filter_.get()); 2666 host_.OnMessageReceived(msg, web_contents_filter_.get());
2671 2667
2672 // Since the request is marked as being transferred, 2668 // Since the request is marked as being transferred,
2673 // the cancellation above should have been ignored and the request 2669 // the cancellation above should have been ignored and the request
2674 // should still be alive. 2670 // should still be alive.
2675 EXPECT_EQ(1, host_.pending_requests()); 2671 EXPECT_EQ(1, host_.pending_requests());
2676 2672
2677 // Cancelling by other methods shouldn't work either. 2673 // Cancelling by other methods shouldn't work either.
2678 host_.CancelRequestsForProcess(web_contents_->GetRoutingID()); 2674 host_.CancelRequestsForProcess(web_contents_->GetRoutingID());
2679 EXPECT_EQ(1, host_.pending_requests()); 2675 EXPECT_EQ(1, host_.pending_requests());
2680 2676
2681 // Cancelling by context should work. 2677 // Cancelling by context should work.
2682 host_.CancelRequestsForContext(web_contents_filter_->resource_context()); 2678 host_.CancelRequestsForContext(web_contents_filter_->resource_context());
2683 EXPECT_EQ(0, host_.pending_requests()); 2679 EXPECT_EQ(0, host_.pending_requests());
2684 } 2680 }
2685 2681
2686 // Test transferred navigations with text/html, which doesn't trigger any 2682 // Test transferred navigations with text/html, which doesn't trigger any
2687 // content sniffing. 2683 // content sniffing.
2688 TEST_P(ResourceDispatcherHostTest, TransferNavigationHtml) { 2684 TEST_P(ResourceDispatcherHostTest, TransferNavigationHtml) {
2689 if (IsBrowserSideNavigationEnabled()) { 2685 if (IsBrowserSideNavigationEnabled()) {
2690 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2686 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2691 return; 2687 return;
2692 } 2688 }
2693 // This test expects the cross site request to be leaked, so it can transfer
2694 // the request directly.
2695 CrossSiteResourceHandler::SetLeakRequestsForTesting(true);
2696 2689
2697 EXPECT_EQ(0, host_.pending_requests()); 2690 EXPECT_EQ(0, host_.pending_requests());
2698 2691
2692 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2693 NavigationResourceThrottle::SetForceTransferForTesting(true);
2694
2699 int render_view_id = 0; 2695 int render_view_id = 0;
2700 int request_id = 1; 2696 int request_id = 1;
2701 2697
2702 // Configure initial request. 2698 // Configure initial request.
2703 SetResponse("HTTP/1.1 302 Found\n" 2699 SetResponse("HTTP/1.1 302 Found\n"
2704 "Location: http://other.com/blech\n\n"); 2700 "Location: http://other.com/blech\n\n");
2705 2701
2706 HandleScheme("http"); 2702 HandleScheme("http");
2707 2703
2708 // Temporarily replace ContentBrowserClient with one that will trigger the
2709 // transfer navigation code paths.
2710 TransfersAllNavigationsContentBrowserClient new_client;
2711 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2712
2713 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2704 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2714 GURL("http://example.com/blah"), 2705 GURL("http://example.com/blah"),
2715 RESOURCE_TYPE_MAIN_FRAME); 2706 RESOURCE_TYPE_MAIN_FRAME);
2716 2707
2717 // Now that we're blocked on the redirect, update the response and unblock by 2708 // Now that we're blocked on the redirect, update the response and unblock by
2718 // telling the AsyncResourceHandler to follow the redirect. 2709 // telling the AsyncResourceHandler to follow the redirect.
2719 const std::string kResponseBody = "hello world"; 2710 const std::string kResponseBody = "hello world";
2720 SetResponse("HTTP/1.1 200 OK\n" 2711 SetResponse("HTTP/1.1 200 OK\n"
2721 "Content-Type: text/html\n\n", 2712 "Content-Type: text/html\n\n",
2722 kResponseBody); 2713 kResponseBody);
2723 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2714 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2724 host_.OnMessageReceived(redirect_msg, filter_.get()); 2715 host_.OnMessageReceived(redirect_msg, filter_.get());
2725 base::RunLoop().RunUntilIdle(); 2716 base::RunLoop().RunUntilIdle();
2726 2717
2727 // Flush all the pending requests to get the response through the 2718 // Flush all the pending requests to get the response through the
2728 // MimeTypeResourceHandler. 2719 // MimeTypeResourceHandler.
2729 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2720 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2730 2721
2731 // Restore, now that we've set up a transfer.
2732 SetBrowserClientForTesting(old_client);
2733
2734 // This second filter is used to emulate a second process. 2722 // This second filter is used to emulate a second process.
2735 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2723 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2736 2724
2737 int new_render_view_id = 1; 2725 int new_render_view_id = 1;
2738 int new_request_id = 2; 2726 int new_request_id = 2;
2739 2727
2740 ResourceRequest request = CreateResourceRequest( 2728 ResourceRequest request = CreateResourceRequest(
2741 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2729 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2742 request.transferred_request_child_id = filter_->child_id(); 2730 request.transferred_request_child_id = filter_->child_id();
2743 request.transferred_request_request_id = request_id; 2731 request.transferred_request_request_id = request_id;
(...skipping 12 matching lines...) Expand all
2756 CheckSuccessfulRequest(msgs[1], kResponseBody); 2744 CheckSuccessfulRequest(msgs[1], kResponseBody);
2757 } 2745 }
2758 2746
2759 // Test transferring two navigations with text/html, to ensure the resource 2747 // Test transferring two navigations with text/html, to ensure the resource
2760 // accounting works. 2748 // accounting works.
2761 TEST_P(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) { 2749 TEST_P(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) {
2762 if (IsBrowserSideNavigationEnabled()) { 2750 if (IsBrowserSideNavigationEnabled()) {
2763 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2751 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2764 return; 2752 return;
2765 } 2753 }
2766 // This test expects the cross site request to be leaked, so it can transfer 2754
2767 // the request directly. 2755 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2768 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2756 NavigationResourceThrottle::SetForceTransferForTesting(true);
2769 2757
2770 EXPECT_EQ(0, host_.pending_requests()); 2758 EXPECT_EQ(0, host_.pending_requests());
2771 2759
2772 int render_view_id = 0; 2760 int render_view_id = 0;
2773 int request_id = 1; 2761 int request_id = 1;
2774 2762
2775 // Configure initial request. 2763 // Configure initial request.
2776 const std::string kResponseBody = "hello world"; 2764 const std::string kResponseBody = "hello world";
2777 SetResponse("HTTP/1.1 200 OK\n" 2765 SetResponse("HTTP/1.1 200 OK\n"
2778 "Content-Type: text/html\n\n", 2766 "Content-Type: text/html\n\n",
2779 kResponseBody); 2767 kResponseBody);
2780 2768
2781 HandleScheme("http"); 2769 HandleScheme("http");
2782 2770
2783 // Temporarily replace ContentBrowserClient with one that will trigger the
2784 // transfer navigation code paths.
2785 TransfersAllNavigationsContentBrowserClient new_client;
2786 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2787
2788 // Make the first request. 2771 // Make the first request.
2789 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2772 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2790 GURL("http://example.com/blah"), 2773 GURL("http://example.com/blah"),
2791 RESOURCE_TYPE_MAIN_FRAME); 2774 RESOURCE_TYPE_MAIN_FRAME);
2792 2775
2793 // Make a second request from the same process. 2776 // Make a second request from the same process.
2794 int second_request_id = 2; 2777 int second_request_id = 2;
2795 MakeTestRequestWithResourceType(filter_.get(), render_view_id, 2778 MakeTestRequestWithResourceType(filter_.get(), render_view_id,
2796 second_request_id, 2779 second_request_id,
2797 GURL("http://example.com/foo"), 2780 GURL("http://example.com/foo"),
2798 RESOURCE_TYPE_MAIN_FRAME); 2781 RESOURCE_TYPE_MAIN_FRAME);
2799 2782
2800 // Flush all the pending requests to get the response through the 2783 // Flush all the pending requests to get the response through the
2801 // MimeTypeResourceHandler. 2784 // MimeTypeResourceHandler.
2802 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2785 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2803 2786
2804 // Restore, now that we've set up a transfer. 2787 NavigationResourceThrottle::SetForceTransferForTesting(false);
2805 SetBrowserClientForTesting(old_client);
2806 2788
2807 // This second filter is used to emulate a second process. 2789 // This second filter is used to emulate a second process.
2808 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2790 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2809 2791
2810 // Transfer the first request. 2792 // Transfer the first request.
2811 int new_render_view_id = 1; 2793 int new_render_view_id = 1;
2812 int new_request_id = 5; 2794 int new_request_id = 5;
2813 ResourceRequest request = CreateResourceRequest( 2795 ResourceRequest request = CreateResourceRequest(
2814 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2796 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2815 request.transferred_request_child_id = filter_->child_id(); 2797 request.transferred_request_child_id = filter_->child_id();
(...skipping 25 matching lines...) Expand all
2841 } 2823 }
2842 2824
2843 // Test transferred navigations with text/plain, which causes 2825 // Test transferred navigations with text/plain, which causes
2844 // MimeTypeResourceHandler to buffer the response to sniff the content before 2826 // MimeTypeResourceHandler to buffer the response to sniff the content before
2845 // the transfer occurs. 2827 // the transfer occurs.
2846 TEST_P(ResourceDispatcherHostTest, TransferNavigationText) { 2828 TEST_P(ResourceDispatcherHostTest, TransferNavigationText) {
2847 if (IsBrowserSideNavigationEnabled()) { 2829 if (IsBrowserSideNavigationEnabled()) {
2848 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2830 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2849 return; 2831 return;
2850 } 2832 }
2851 // This test expects the cross site request to be leaked, so it can transfer 2833
2852 // the request directly. 2834 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2853 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2835 NavigationResourceThrottle::SetForceTransferForTesting(true);
2854 2836
2855 EXPECT_EQ(0, host_.pending_requests()); 2837 EXPECT_EQ(0, host_.pending_requests());
2856 2838
2857 int render_view_id = 0; 2839 int render_view_id = 0;
2858 int request_id = 1; 2840 int request_id = 1;
2859 2841
2860 // Configure initial request. 2842 // Configure initial request.
2861 SetResponse("HTTP/1.1 302 Found\n" 2843 SetResponse("HTTP/1.1 302 Found\n"
2862 "Location: http://other.com/blech\n\n"); 2844 "Location: http://other.com/blech\n\n");
2863 2845
2864 HandleScheme("http"); 2846 HandleScheme("http");
2865 2847
2866 // Temporarily replace ContentBrowserClient with one that will trigger the
2867 // transfer navigation code paths.
2868 TransfersAllNavigationsContentBrowserClient new_client;
2869 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2870
2871 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2848 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2872 GURL("http://example.com/blah"), 2849 GURL("http://example.com/blah"),
2873 RESOURCE_TYPE_MAIN_FRAME); 2850 RESOURCE_TYPE_MAIN_FRAME);
2874 2851
2875 // Now that we're blocked on the redirect, update the response and unblock by 2852 // Now that we're blocked on the redirect, update the response and unblock by
2876 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain 2853 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain
2877 // MIME type, which causes MimeTypeResourceHandler to buffer it before the 2854 // MIME type, which causes MimeTypeResourceHandler to buffer it before the
2878 // transfer occurs. 2855 // transfer occurs.
2879 const std::string kResponseBody = "hello world"; 2856 const std::string kResponseBody = "hello world";
2880 SetResponse("HTTP/1.1 200 OK\n" 2857 SetResponse("HTTP/1.1 200 OK\n"
2881 "Content-Type: text/plain\n\n", 2858 "Content-Type: text/plain\n\n",
2882 kResponseBody); 2859 kResponseBody);
2883 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2860 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2884 host_.OnMessageReceived(redirect_msg, filter_.get()); 2861 host_.OnMessageReceived(redirect_msg, filter_.get());
2885 base::RunLoop().RunUntilIdle(); 2862 base::RunLoop().RunUntilIdle();
2886 2863
2887 // Flush all the pending requests to get the response through the 2864 // Flush all the pending requests to get the response through the
2888 // MimeTypeResourceHandler. 2865 // MimeTypeResourceHandler.
2889 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2866 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2890 base::RunLoop().RunUntilIdle(); 2867 base::RunLoop().RunUntilIdle();
2891 2868
2892 // Restore, now that we've set up a transfer.
2893 SetBrowserClientForTesting(old_client);
2894
2895 // This second filter is used to emulate a second process. 2869 // This second filter is used to emulate a second process.
2896 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2870 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2897 2871
2898 int new_render_view_id = 1; 2872 int new_render_view_id = 1;
2899 int new_request_id = 2; 2873 int new_request_id = 2;
2900 2874
2901 ResourceRequest request = CreateResourceRequest( 2875 ResourceRequest request = CreateResourceRequest(
2902 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 2876 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
2903 request.transferred_request_child_id = filter_->child_id(); 2877 request.transferred_request_child_id = filter_->child_id();
2904 request.transferred_request_request_id = request_id; 2878 request.transferred_request_request_id = request_id;
(...skipping 10 matching lines...) Expand all
2915 ASSERT_EQ(2U, msgs.size()); 2889 ASSERT_EQ(2U, msgs.size());
2916 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2890 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
2917 CheckSuccessfulRequest(msgs[1], kResponseBody); 2891 CheckSuccessfulRequest(msgs[1], kResponseBody);
2918 } 2892 }
2919 2893
2920 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) { 2894 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) {
2921 if (IsBrowserSideNavigationEnabled()) { 2895 if (IsBrowserSideNavigationEnabled()) {
2922 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2896 SUCCEED() << "Test is not applicable with browser side navigation enabled";
2923 return; 2897 return;
2924 } 2898 }
2925 // This test expects the cross site request to be leaked, so it can transfer 2899
2926 // the request directly. 2900 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
2927 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2901 NavigationResourceThrottle::SetForceTransferForTesting(true);
2928 2902
2929 EXPECT_EQ(0, host_.pending_requests()); 2903 EXPECT_EQ(0, host_.pending_requests());
2930 2904
2931 int render_view_id = 0; 2905 int render_view_id = 0;
2932 int request_id = 1; 2906 int request_id = 1;
2933 int first_child_id = -1; 2907 int first_child_id = -1;
2934 2908
2935 // Configure initial request. 2909 // Configure initial request.
2936 SetResponse("HTTP/1.1 302 Found\n" 2910 SetResponse("HTTP/1.1 302 Found\n"
2937 "Location: http://other.com/blech\n\n"); 2911 "Location: http://other.com/blech\n\n");
2938 const std::string kResponseBody = "hello world"; 2912 const std::string kResponseBody = "hello world";
2939 2913
2940 HandleScheme("http"); 2914 HandleScheme("http");
2941 2915
2942 // Temporarily replace ContentBrowserClient with one that will trigger the
2943 // transfer navigation code paths.
2944 TransfersAllNavigationsContentBrowserClient new_client;
2945 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
2946
2947 // Create a first filter that can be deleted before the second one starts. 2916 // Create a first filter that can be deleted before the second one starts.
2948 { 2917 {
2949 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter(); 2918 scoped_refptr<ForwardingFilter> first_filter = MakeForwardingFilter();
2950 first_child_id = first_filter->child_id(); 2919 first_child_id = first_filter->child_id();
2951 2920
2952 ResourceRequest first_request = CreateResourceRequest( 2921 ResourceRequest first_request = CreateResourceRequest(
2953 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah")); 2922 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://example.com/blah"));
2954 2923
2955 ResourceHostMsg_RequestResource first_request_msg( 2924 ResourceHostMsg_RequestResource first_request_msg(
2956 render_view_id, request_id, first_request); 2925 render_view_id, request_id, first_request);
2957 host_.OnMessageReceived(first_request_msg, first_filter.get()); 2926 host_.OnMessageReceived(first_request_msg, first_filter.get());
2958 base::RunLoop().RunUntilIdle(); 2927 base::RunLoop().RunUntilIdle();
2959 2928
2960 // Now that we're blocked on the redirect, update the response and unblock 2929 // Now that we're blocked on the redirect, update the response and unblock
2961 // by telling the AsyncResourceHandler to follow the redirect. 2930 // by telling the AsyncResourceHandler to follow the redirect.
2962 SetResponse("HTTP/1.1 200 OK\n" 2931 SetResponse("HTTP/1.1 200 OK\n"
2963 "Content-Type: text/html\n\n", 2932 "Content-Type: text/html\n\n",
2964 kResponseBody); 2933 kResponseBody);
2965 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 2934 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
2966 host_.OnMessageReceived(redirect_msg, first_filter.get()); 2935 host_.OnMessageReceived(redirect_msg, first_filter.get());
2967 base::RunLoop().RunUntilIdle(); 2936 base::RunLoop().RunUntilIdle();
2968 2937
2969 // Flush all the pending requests to get the response through the 2938 // Flush all the pending requests to get the response through the
2970 // MimeTypeResourceHandler. 2939 // MimeTypeResourceHandler.
2971 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2940 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2972 } 2941 }
2973 // The first filter is now deleted, as if the child process died. 2942 // The first filter is now deleted, as if the child process died.
2974 2943
2975 // Restore.
2976 SetBrowserClientForTesting(old_client);
2977
2978 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. 2944 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted.
2979 GlobalRequestID first_global_request_id(first_child_id, request_id); 2945 GlobalRequestID first_global_request_id(first_child_id, request_id);
2980 2946
2981 // This second filter is used to emulate a second process. 2947 // This second filter is used to emulate a second process.
2982 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 2948 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
2983 2949
2984 int new_render_view_id = 1; 2950 int new_render_view_id = 1;
2985 int new_request_id = 2; 2951 int new_request_id = 2;
2986 2952
2987 ResourceRequest request = CreateResourceRequest( 2953 ResourceRequest request = CreateResourceRequest(
(...skipping 15 matching lines...) Expand all
3003 ASSERT_EQ(2U, msgs.size()); 2969 ASSERT_EQ(2U, msgs.size());
3004 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 2970 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3005 CheckSuccessfulRequest(msgs[1], kResponseBody); 2971 CheckSuccessfulRequest(msgs[1], kResponseBody);
3006 } 2972 }
3007 2973
3008 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { 2974 TEST_P(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) {
3009 if (IsBrowserSideNavigationEnabled()) { 2975 if (IsBrowserSideNavigationEnabled()) {
3010 SUCCEED() << "Test is not applicable with browser side navigation enabled"; 2976 SUCCEED() << "Test is not applicable with browser side navigation enabled";
3011 return; 2977 return;
3012 } 2978 }
3013 // This test expects the cross site request to be leaked, so it can transfer 2979
3014 // the request directly. 2980 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
3015 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); 2981 NavigationResourceThrottle::SetForceTransferForTesting(true);
3016 2982
3017 EXPECT_EQ(0, host_.pending_requests()); 2983 EXPECT_EQ(0, host_.pending_requests());
3018 2984
3019 int render_view_id = 0; 2985 int render_view_id = 0;
3020 int request_id = 1; 2986 int request_id = 1;
3021 2987
3022 // Configure initial request. 2988 // Configure initial request.
3023 SetResponse("HTTP/1.1 302 Found\n" 2989 SetResponse("HTTP/1.1 302 Found\n"
3024 "Location: http://other.com/blech\n\n"); 2990 "Location: http://other.com/blech\n\n");
3025 2991
3026 HandleScheme("http"); 2992 HandleScheme("http");
3027 2993
3028 // Temporarily replace ContentBrowserClient with one that will trigger the
3029 // transfer navigation code paths.
3030 TransfersAllNavigationsContentBrowserClient new_client;
3031 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client);
3032
3033 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2994 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
3034 GURL("http://example.com/blah"), 2995 GURL("http://example.com/blah"),
3035 RESOURCE_TYPE_MAIN_FRAME); 2996 RESOURCE_TYPE_MAIN_FRAME);
3036 2997
3037 // Now that we're blocked on the redirect, simulate hitting another redirect. 2998 // Now that we're blocked on the redirect, simulate hitting another redirect.
3038 SetResponse("HTTP/1.1 302 Found\n" 2999 SetResponse("HTTP/1.1 302 Found\n"
3039 "Location: http://other.com/blerg\n\n"); 3000 "Location: http://other.com/blerg\n\n");
3040 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3001 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
3041 host_.OnMessageReceived(redirect_msg, filter_.get()); 3002 host_.OnMessageReceived(redirect_msg, filter_.get());
3042 base::RunLoop().RunUntilIdle(); 3003 base::RunLoop().RunUntilIdle();
3043 3004
3044 // Now that we're blocked on the second redirect, update the response and 3005 // Now that we're blocked on the second redirect, update the response and
3045 // unblock by telling the AsyncResourceHandler to follow the redirect. 3006 // unblock by telling the AsyncResourceHandler to follow the redirect.
3046 // Again, use text/plain to force MimeTypeResourceHandler to buffer before 3007 // Again, use text/plain to force MimeTypeResourceHandler to buffer before
3047 // the transfer. 3008 // the transfer.
3048 const std::string kResponseBody = "hello world"; 3009 const std::string kResponseBody = "hello world";
3049 SetResponse("HTTP/1.1 200 OK\n" 3010 SetResponse("HTTP/1.1 200 OK\n"
3050 "Content-Type: text/plain\n\n", 3011 "Content-Type: text/plain\n\n",
3051 kResponseBody); 3012 kResponseBody);
3052 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); 3013 ResourceHostMsg_FollowRedirect redirect_msg2(request_id);
3053 host_.OnMessageReceived(redirect_msg2, filter_.get()); 3014 host_.OnMessageReceived(redirect_msg2, filter_.get());
3054 base::RunLoop().RunUntilIdle(); 3015 base::RunLoop().RunUntilIdle();
3055 3016
3056 // Flush all the pending requests to get the response through the 3017 // Flush all the pending requests to get the response through the
3057 // MimeTypeResourceHandler. 3018 // MimeTypeResourceHandler.
3058 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3019 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3059 base::RunLoop().RunUntilIdle(); 3020 base::RunLoop().RunUntilIdle();
3060 3021
3061 // Restore.
3062 SetBrowserClientForTesting(old_client);
3063
3064 // This second filter is used to emulate a second process. 3022 // This second filter is used to emulate a second process.
3065 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3023 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3066 3024
3067 int new_render_view_id = 1; 3025 int new_render_view_id = 1;
3068 int new_request_id = 2; 3026 int new_request_id = 2;
3069 3027
3070 ResourceRequest request = CreateResourceRequest( 3028 ResourceRequest request = CreateResourceRequest(
3071 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech")); 3029 "GET", RESOURCE_TYPE_MAIN_FRAME, GURL("http://other.com/blech"));
3072 request.transferred_request_child_id = filter_->child_id(); 3030 request.transferred_request_child_id = filter_->child_id();
3073 request.transferred_request_request_id = request_id; 3031 request.transferred_request_request_id = request_id;
(...skipping 19 matching lines...) Expand all
3093 // Check generated messages. 3051 // Check generated messages.
3094 ResourceIPCAccumulator::ClassifiedMessages msgs; 3052 ResourceIPCAccumulator::ClassifiedMessages msgs;
3095 accum_.GetClassifiedMessages(&msgs); 3053 accum_.GetClassifiedMessages(&msgs);
3096 3054
3097 ASSERT_EQ(2U, msgs.size()); 3055 ASSERT_EQ(2U, msgs.size());
3098 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); 3056 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
3099 CheckSuccessfulRequest(msgs[1], kResponseBody); 3057 CheckSuccessfulRequest(msgs[1], kResponseBody);
3100 } 3058 }
3101 3059
3102 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) { 3060 TEST_P(ResourceDispatcherHostTest, UnknownURLScheme) {
3061 NavigationResourceThrottle::SetUIChecksAlwaysSuccedForTesting(true);
3103 EXPECT_EQ(0, host_.pending_requests()); 3062 EXPECT_EQ(0, host_.pending_requests());
3104 3063
3105 HandleScheme("http"); 3064 HandleScheme("http");
3106 3065
3107 const GURL invalid_sheme_url = GURL("foo://bar"); 3066 const GURL invalid_sheme_url = GURL("foo://bar");
3108 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME; 3067 const int expected_error_code = net::ERR_UNKNOWN_URL_SCHEME;
3109 3068
3110 CompleteFailingMainResourceRequest(invalid_sheme_url, expected_error_code); 3069 CompleteFailingMainResourceRequest(invalid_sheme_url, expected_error_code);
3111 } 3070 }
3112 3071
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
3787 return nullptr; 3746 return nullptr;
3788 } 3747 }
3789 3748
3790 INSTANTIATE_TEST_CASE_P( 3749 INSTANTIATE_TEST_CASE_P(
3791 ResourceDispatcherHostTests, 3750 ResourceDispatcherHostTests,
3792 ResourceDispatcherHostTest, 3751 ResourceDispatcherHostTest,
3793 testing::Values(TestConfig::kDefault, 3752 testing::Values(TestConfig::kDefault,
3794 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3753 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3795 3754
3796 } // namespace content 3755 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698