OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
9 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "base/pickle.h" | 12 #include "base/pickle.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
14 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
15 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
16 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 17 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 18 #include "content/browser/loader/resource_loader.h" |
17 #include "content/browser/loader/resource_message_filter.h" | 19 #include "content/browser/loader/resource_message_filter.h" |
18 #include "content/browser/loader/resource_request_info_impl.h" | 20 #include "content/browser/loader/resource_request_info_impl.h" |
19 #include "content/browser/worker_host/worker_service_impl.h" | 21 #include "content/browser/worker_host/worker_service_impl.h" |
20 #include "content/common/child_process_host_impl.h" | 22 #include "content/common/child_process_host_impl.h" |
21 #include "content/common/resource_messages.h" | 23 #include "content/common/resource_messages.h" |
22 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
23 #include "content/public/browser/global_request_id.h" | 25 #include "content/public/browser/global_request_id.h" |
24 #include "content/public/browser/resource_context.h" | 26 #include "content/public/browser/resource_context.h" |
25 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 27 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
26 #include "content/public/browser/resource_request_info.h" | 28 #include "content/public/browser/resource_request_info.h" |
27 #include "content/public/browser/resource_throttle.h" | 29 #include "content/public/browser/resource_throttle.h" |
| 30 #include "content/public/common/content_switches.h" |
28 #include "content/public/common/process_type.h" | 31 #include "content/public/common/process_type.h" |
29 #include "content/public/common/resource_response.h" | 32 #include "content/public/common/resource_response.h" |
30 #include "content/public/test/test_browser_context.h" | 33 #include "content/public/test/test_browser_context.h" |
31 #include "content/test/test_content_browser_client.h" | 34 #include "content/test/test_content_browser_client.h" |
32 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
33 #include "net/base/upload_bytes_element_reader.h" | 36 #include "net/base/upload_bytes_element_reader.h" |
34 #include "net/base/upload_data_stream.h" | 37 #include "net/base/upload_data_stream.h" |
35 #include "net/http/http_util.h" | 38 #include "net/http/http_util.h" |
36 #include "net/url_request/url_request.h" | 39 #include "net/url_request/url_request.h" |
37 #include "net/url_request/url_request_context.h" | 40 #include "net/url_request/url_request_context.h" |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 browser_context_.reset(); | 595 browser_context_.reset(); |
593 message_loop_.RunUntilIdle(); | 596 message_loop_.RunUntilIdle(); |
594 } | 597 } |
595 | 598 |
596 // Creates a request using the current test object as the filter. | 599 // Creates a request using the current test object as the filter. |
597 void MakeTestRequest(int render_view_id, | 600 void MakeTestRequest(int render_view_id, |
598 int request_id, | 601 int request_id, |
599 const GURL& url); | 602 const GURL& url); |
600 | 603 |
601 // Generates a request using the given filter. This will probably be a | 604 // Generates a request using the given filter. This will probably be a |
602 // ForwardingFilter. | 605 // ForwardingFilter. Uses the resource_type_ as the resource type. |
603 void MakeTestRequest(ResourceMessageFilter* filter, | 606 void MakeTestRequest(ResourceMessageFilter* filter, |
604 int render_view_id, | 607 int render_view_id, |
605 int request_id, | 608 int request_id, |
606 const GURL& url); | 609 const GURL& url); |
607 | 610 |
| 611 // Generates a request using the given filter. This will probably be a |
| 612 // ForwardingFilter. |
| 613 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, |
| 614 int render_view_id, int request_id, |
| 615 const GURL& url, |
| 616 ResourceType::Type type); |
| 617 |
608 void CancelRequest(int request_id); | 618 void CancelRequest(int request_id); |
609 | 619 |
610 void CompleteStartRequest(int request_id); | 620 void CompleteStartRequest(int request_id); |
611 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); | 621 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); |
612 | 622 |
613 void EnsureSchemeIsAllowed(const std::string& scheme) { | 623 void EnsureSchemeIsAllowed(const std::string& scheme) { |
614 ChildProcessSecurityPolicyImpl* policy = | 624 ChildProcessSecurityPolicyImpl* policy = |
615 ChildProcessSecurityPolicyImpl::GetInstance(); | 625 ChildProcessSecurityPolicyImpl::GetInstance(); |
616 if (!policy->IsWebSafeScheme(scheme)) | 626 if (!policy->IsWebSafeScheme(scheme)) |
617 policy->RegisterWebSafeScheme(scheme); | 627 policy->RegisterWebSafeScheme(scheme); |
618 } | 628 } |
619 | 629 |
620 void EnsureTestSchemeIsAllowed() { | 630 void EnsureTestSchemeIsAllowed() { |
621 EnsureSchemeIsAllowed("test"); | 631 EnsureSchemeIsAllowed("test"); |
622 } | 632 } |
623 | 633 |
624 // Sets a particular response for any request from now on. To switch back to | 634 // Sets a particular response for any request from now on. To switch back to |
625 // the default bahavior, pass an empty |headers|. |headers| should be raw- | 635 // the default bahavior, pass an empty |headers|. |headers| should be raw- |
626 // formatted (NULLs instead of EOLs). | 636 // formatted (NULLs instead of EOLs). |
627 void SetResponse(const std::string& headers, const std::string& data) { | 637 void SetResponse(const std::string& headers, const std::string& data) { |
628 response_headers_ = net::HttpUtil::AssembleRawHeaders(headers.data(), | 638 response_headers_ = net::HttpUtil::AssembleRawHeaders(headers.data(), |
629 headers.size()); | 639 headers.size()); |
630 response_data_ = data; | 640 response_data_ = data; |
631 } | 641 } |
632 void SetResponse(const std::string& headers) { | 642 void SetResponse(const std::string& headers) { |
633 SetResponse(headers, std::string()); | 643 SetResponse(headers, std::string()); |
634 } | 644 } |
635 | 645 |
636 // Sets a particular resource type for any request from now on. | |
637 void SetResourceType(ResourceType::Type type) { | |
638 resource_type_ = type; | |
639 } | |
640 | |
641 void SendDataReceivedACKs(bool send_acks) { | 646 void SendDataReceivedACKs(bool send_acks) { |
642 send_data_received_acks_ = send_acks; | 647 send_data_received_acks_ = send_acks; |
643 } | 648 } |
644 | 649 |
645 // Intercepts requests for the given protocol. | 650 // Intercepts requests for the given protocol. |
646 void HandleScheme(const std::string& scheme) { | 651 void HandleScheme(const std::string& scheme) { |
647 DCHECK(scheme_.empty()); | 652 DCHECK(scheme_.empty()); |
648 DCHECK(!old_factory_); | 653 DCHECK(!old_factory_); |
649 scheme_ = scheme; | 654 scheme_ = scheme; |
650 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( | 655 old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 int request_id, | 746 int request_id, |
742 const GURL& url) { | 747 const GURL& url) { |
743 MakeTestRequest(filter_.get(), render_view_id, request_id, url); | 748 MakeTestRequest(filter_.get(), render_view_id, request_id, url); |
744 } | 749 } |
745 | 750 |
746 void ResourceDispatcherHostTest::MakeTestRequest( | 751 void ResourceDispatcherHostTest::MakeTestRequest( |
747 ResourceMessageFilter* filter, | 752 ResourceMessageFilter* filter, |
748 int render_view_id, | 753 int render_view_id, |
749 int request_id, | 754 int request_id, |
750 const GURL& url) { | 755 const GURL& url) { |
| 756 MakeTestRequestWithResourceType(filter, render_view_id, request_id, url, |
| 757 resource_type_); |
| 758 } |
| 759 |
| 760 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( |
| 761 ResourceMessageFilter* filter, |
| 762 int render_view_id, |
| 763 int request_id, |
| 764 const GURL& url, |
| 765 ResourceType::Type type) { |
751 // If it's already there, this'll be dropped on the floor, which is fine. | 766 // If it's already there, this'll be dropped on the floor, which is fine. |
752 child_ids_.insert(filter->child_id()); | 767 child_ids_.insert(filter->child_id()); |
753 | 768 |
754 ResourceHostMsg_Request request = | 769 ResourceHostMsg_Request request = |
755 CreateResourceRequest("GET", resource_type_, url); | 770 CreateResourceRequest("GET", type, url); |
756 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); | 771 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
757 bool msg_was_ok; | 772 bool msg_was_ok; |
758 host_.OnMessageReceived(msg, filter, &msg_was_ok); | 773 host_.OnMessageReceived(msg, filter, &msg_was_ok); |
759 KickOffRequest(); | 774 KickOffRequest(); |
760 } | 775 } |
761 | 776 |
762 void ResourceDispatcherHostTest::CancelRequest(int request_id) { | 777 void ResourceDispatcherHostTest::CancelRequest(int request_id) { |
763 host_.CancelRequest(filter_->child_id(), request_id, false); | 778 host_.CancelRequest(filter_->child_id(), request_id, false); |
764 } | 779 } |
765 | 780 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 | 915 |
901 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 916 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
902 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); | 917 CheckSuccessfulRequest(msgs[2], net::URLRequestTestJob::test_data_3()); |
903 | 918 |
904 // Check that request 2 got canceled. | 919 // Check that request 2 got canceled. |
905 ASSERT_EQ(2U, msgs[1].size()); | 920 ASSERT_EQ(2U, msgs[1].size()); |
906 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); | 921 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
907 CheckCancelledRequestCompleteMessage(msgs[1][1]); | 922 CheckCancelledRequestCompleteMessage(msgs[1][1]); |
908 } | 923 } |
909 | 924 |
| 925 // Shows that unlike normal requests, prefetched async requests are not |
| 926 // immediately canceled, and will complete within a timeout period. |
| 927 TEST_F(ResourceDispatcherHostTest, PrefetchIgnoreCancel) { |
| 928 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 929 command_line->AppendSwitch(switches::kDelayPrefetchCancellation); |
| 930 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 931 net::URLRequestTestJob::test_url_1(), |
| 932 ResourceType::PREFETCH); |
| 933 MakeTestRequestWithResourceType(filter_.get(), 0, 2, |
| 934 net::URLRequestTestJob::test_url_2(), |
| 935 ResourceType::PREFETCH); |
| 936 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); |
| 937 |
| 938 // test_url_1 is synchronous and already complete. |
| 939 EXPECT_EQ(2, host_.pending_requests()); |
| 940 // We need to make sure that the request comes from the renderer, else it |
| 941 // won't delay. |
| 942 host_.CancelRequest(filter_->child_id(), 2, true); |
| 943 host_.CancelRequest(filter_->child_id(), 3, true); |
| 944 |
| 945 // Process any completion messages from cancelling. |
| 946 base::MessageLoop::current()->RunUntilIdle(); |
| 947 |
| 948 EXPECT_EQ(1, host_.pending_requests()); |
| 949 |
| 950 // Run the requests to completion. |
| 951 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 952 base::MessageLoop::current()->RunUntilIdle(); |
| 953 |
| 954 EXPECT_EQ(0, host_.pending_requests()); |
| 955 |
| 956 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 957 accum_.GetClassifiedMessages(&msgs); |
| 958 |
| 959 ASSERT_EQ(3U, msgs.size()); |
| 960 |
| 961 // The first fetch was synchronous and should have completed successfully. |
| 962 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 963 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][1].type()); |
| 964 |
| 965 // The prefetch should have ignored the cancel and completed. Note that |
| 966 // prefetches run detached and do not receive data notifications. |
| 967 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
| 968 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type()); |
| 969 // Verify that there was no error. |
| 970 int request_id; |
| 971 int error_code; |
| 972 PickleIterator iter(msgs[1][1]); |
| 973 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &request_id)); |
| 974 ASSERT_TRUE(IPC::ReadParam(&msgs[1][1], &iter, &error_code)); |
| 975 EXPECT_EQ(0, error_code); |
| 976 |
| 977 // Request 3 should have been cancelled immediately. |
| 978 ASSERT_EQ(2U, msgs[2].size()); |
| 979 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[2][0].type()); |
| 980 CheckCancelledRequestCompleteMessage(msgs[2][1]); |
| 981 } |
| 982 |
| 983 // Shows that prefetched requests will timeout if the request takes too long |
| 984 // to complete. |
| 985 TEST_F(ResourceDispatcherHostTest, PrefetchIgnoreCancelTimesOut) { |
| 986 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 987 command_line->AppendSwitchASCII(switches::kDelayPrefetchCancellation, "200"); |
| 988 |
| 989 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 990 net::URLRequestTestJob::test_url_2(), |
| 991 ResourceType::PREFETCH); |
| 992 host_.CancelRequest(filter_->child_id(), 1, true); |
| 993 base::MessageLoop::current()->RunUntilIdle(); |
| 994 EXPECT_EQ(1, host_.pending_requests()); |
| 995 |
| 996 // Wait until after the delay timer times before letting any Reads complete. |
| 997 base::OneShotTimer<base::MessageLoop> timer; |
| 998 timer.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(210), |
| 999 base::MessageLoop::current(), &base::MessageLoop::QuitWhenIdle); |
| 1000 |
| 1001 // We should have cancelled the prefetch by now. |
| 1002 base::MessageLoop::current()->Run(); |
| 1003 EXPECT_EQ(0, host_.pending_requests()); |
| 1004 |
| 1005 // In case any messages are still to be processed. |
| 1006 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1007 base::MessageLoop::current()->RunUntilIdle(); |
| 1008 |
| 1009 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1010 accum_.GetClassifiedMessages(&msgs); |
| 1011 |
| 1012 ASSERT_EQ(1U, msgs.size()); |
| 1013 |
| 1014 // The request should have cancelled. |
| 1015 ASSERT_EQ(2U, msgs[0].size()); |
| 1016 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 1017 CheckCancelledRequestCompleteMessage(msgs[0][1]); |
| 1018 } |
| 1019 |
910 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { | 1020 TEST_F(ResourceDispatcherHostTest, CancelWhileStartIsDeferred) { |
911 bool was_deleted = false; | 1021 bool was_deleted = false; |
912 | 1022 |
913 // Arrange to have requests deferred before starting. | 1023 // Arrange to have requests deferred before starting. |
914 TestResourceDispatcherHostDelegate delegate; | 1024 TestResourceDispatcherHostDelegate delegate; |
915 delegate.set_flags(DEFER_STARTING_REQUEST); | 1025 delegate.set_flags(DEFER_STARTING_REQUEST); |
916 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); | 1026 delegate.set_url_request_user_data(new TestUserData(&was_deleted)); |
917 host_.SetDelegate(&delegate); | 1027 host_.SetDelegate(&delegate); |
918 | 1028 |
919 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1029 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 } | 1646 } |
1537 | 1647 |
1538 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). | 1648 // Tests for crbug.com/31266 (Non-2xx + application/octet-stream). |
1539 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { | 1649 TEST_F(ResourceDispatcherHostTest, ForbiddenDownload) { |
1540 std::string raw_headers("HTTP/1.1 403 Forbidden\n" | 1650 std::string raw_headers("HTTP/1.1 403 Forbidden\n" |
1541 "Content-disposition: attachment; filename=blah\n" | 1651 "Content-disposition: attachment; filename=blah\n" |
1542 "Content-type: application/octet-stream\n\n"); | 1652 "Content-type: application/octet-stream\n\n"); |
1543 std::string response_data("<html><title>Test One</title></html>"); | 1653 std::string response_data("<html><title>Test One</title></html>"); |
1544 SetResponse(raw_headers, response_data); | 1654 SetResponse(raw_headers, response_data); |
1545 | 1655 |
| 1656 HandleScheme("http"); |
| 1657 |
1546 // Only MAIN_FRAMEs can trigger a download. | 1658 // Only MAIN_FRAMEs can trigger a download. |
1547 SetResourceType(ResourceType::MAIN_FRAME); | 1659 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("http:bla"), |
1548 | 1660 ResourceType::MAIN_FRAME); |
1549 HandleScheme("http"); | |
1550 MakeTestRequest(0, 1, GURL("http:bla")); | |
1551 | 1661 |
1552 // Flush all pending requests. | 1662 // Flush all pending requests. |
1553 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1663 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1554 | 1664 |
1555 // Sorts out all the messages we saw by request. | 1665 // Sorts out all the messages we saw by request. |
1556 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1666 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1557 accum_.GetClassifiedMessages(&msgs); | 1667 accum_.GetClassifiedMessages(&msgs); |
1558 | 1668 |
1559 // We should have gotten one RequestComplete message. | 1669 // We should have gotten one RequestComplete message. |
1560 ASSERT_EQ(1U, msgs[0].size()); | 1670 ASSERT_EQ(1U, msgs[0].size()); |
(...skipping 26 matching lines...) Expand all Loading... |
1587 std::string response_data("01234567890123456789\x01foobar"); | 1697 std::string response_data("01234567890123456789\x01foobar"); |
1588 | 1698 |
1589 // Get past sniffing metrics in the BufferedResourceHandler. Note that | 1699 // Get past sniffing metrics in the BufferedResourceHandler. Note that |
1590 // if we don't get past the sniffing metrics, the result will be that | 1700 // if we don't get past the sniffing metrics, the result will be that |
1591 // the BufferedResourceHandler won't have figured out that it's a download, | 1701 // the BufferedResourceHandler won't have figured out that it's a download, |
1592 // won't have constructed a DownloadResourceHandler, and and the request | 1702 // won't have constructed a DownloadResourceHandler, and and the request |
1593 // will be successfully canceled below, failing the test. | 1703 // will be successfully canceled below, failing the test. |
1594 response_data.resize(1025, ' '); | 1704 response_data.resize(1025, ' '); |
1595 | 1705 |
1596 SetResponse(raw_headers, response_data); | 1706 SetResponse(raw_headers, response_data); |
1597 SetResourceType(ResourceType::MAIN_FRAME); | |
1598 SetDelayedCompleteJobGeneration(true); | 1707 SetDelayedCompleteJobGeneration(true); |
1599 HandleScheme("http"); | 1708 HandleScheme("http"); |
1600 | 1709 |
1601 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1710 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1711 GURL("http://example.com/blah"), |
| 1712 ResourceType::MAIN_FRAME); |
1602 // Return some data so that the request is identified as a download | 1713 // Return some data so that the request is identified as a download |
1603 // and the proper resource handlers are created. | 1714 // and the proper resource handlers are created. |
1604 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1715 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1605 | 1716 |
1606 // And now simulate a cancellation coming from the renderer. | 1717 // And now simulate a cancellation coming from the renderer. |
1607 ResourceHostMsg_CancelRequest msg(request_id); | 1718 ResourceHostMsg_CancelRequest msg(request_id); |
1608 bool msg_was_ok; | 1719 bool msg_was_ok; |
1609 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1720 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1610 | 1721 |
1611 // Since the request had already started processing as a download, | 1722 // Since the request had already started processing as a download, |
(...skipping 10 matching lines...) Expand all Loading... |
1622 int render_view_id = 0; | 1733 int render_view_id = 0; |
1623 int request_id = 1; | 1734 int request_id = 1; |
1624 | 1735 |
1625 std::string raw_headers("HTTP\n" | 1736 std::string raw_headers("HTTP\n" |
1626 "Content-disposition: attachment; filename=foo\n\n"); | 1737 "Content-disposition: attachment; filename=foo\n\n"); |
1627 std::string response_data("01234567890123456789\x01foobar"); | 1738 std::string response_data("01234567890123456789\x01foobar"); |
1628 // Get past sniffing metrics. | 1739 // Get past sniffing metrics. |
1629 response_data.resize(1025, ' '); | 1740 response_data.resize(1025, ' '); |
1630 | 1741 |
1631 SetResponse(raw_headers, response_data); | 1742 SetResponse(raw_headers, response_data); |
1632 SetResourceType(ResourceType::MAIN_FRAME); | |
1633 SetDelayedCompleteJobGeneration(true); | 1743 SetDelayedCompleteJobGeneration(true); |
1634 HandleScheme("http"); | 1744 HandleScheme("http"); |
1635 | 1745 |
1636 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1746 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1747 GURL("http://example.com/blah"), |
| 1748 ResourceType::MAIN_FRAME); |
1637 // Return some data so that the request is identified as a download | 1749 // Return some data so that the request is identified as a download |
1638 // and the proper resource handlers are created. | 1750 // and the proper resource handlers are created. |
1639 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1751 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1640 | 1752 |
1641 // And now simulate a cancellation coming from the renderer. | 1753 // And now simulate a cancellation coming from the renderer. |
1642 ResourceHostMsg_CancelRequest msg(request_id); | 1754 ResourceHostMsg_CancelRequest msg(request_id); |
1643 bool msg_was_ok; | 1755 bool msg_was_ok; |
1644 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1756 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1645 | 1757 |
1646 // Since the request had already started processing as a download, | 1758 // Since the request had already started processing as a download, |
(...skipping 16 matching lines...) Expand all Loading... |
1663 EXPECT_EQ(0, host_.pending_requests()); | 1775 EXPECT_EQ(0, host_.pending_requests()); |
1664 | 1776 |
1665 int render_view_id = 0; | 1777 int render_view_id = 0; |
1666 int request_id = 1; | 1778 int request_id = 1; |
1667 | 1779 |
1668 std::string raw_headers("HTTP/1.1 200 OK\n" | 1780 std::string raw_headers("HTTP/1.1 200 OK\n" |
1669 "Content-Type: text/html; charset=utf-8\n\n"); | 1781 "Content-Type: text/html; charset=utf-8\n\n"); |
1670 std::string response_data("<html>foobar</html>"); | 1782 std::string response_data("<html>foobar</html>"); |
1671 | 1783 |
1672 SetResponse(raw_headers, response_data); | 1784 SetResponse(raw_headers, response_data); |
1673 SetResourceType(ResourceType::MAIN_FRAME); | |
1674 HandleScheme("http"); | 1785 HandleScheme("http"); |
1675 | 1786 |
1676 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1787 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1788 GURL("http://example.com/blah"), |
| 1789 ResourceType::MAIN_FRAME); |
| 1790 |
1677 | 1791 |
1678 GlobalRequestID global_request_id(filter_->child_id(), request_id); | 1792 GlobalRequestID global_request_id(filter_->child_id(), request_id); |
1679 host_.MarkAsTransferredNavigation(global_request_id, | 1793 host_.MarkAsTransferredNavigation(global_request_id, |
1680 GURL("http://example.com/blah")); | 1794 GURL("http://example.com/blah")); |
1681 | 1795 |
1682 // And now simulate a cancellation coming from the renderer. | 1796 // And now simulate a cancellation coming from the renderer. |
1683 ResourceHostMsg_CancelRequest msg(request_id); | 1797 ResourceHostMsg_CancelRequest msg(request_id); |
1684 bool msg_was_ok; | 1798 bool msg_was_ok; |
1685 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1799 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1686 | 1800 |
(...skipping 14 matching lines...) Expand all Loading... |
1701 TEST_F(ResourceDispatcherHostTest, TransferNavigation) { | 1815 TEST_F(ResourceDispatcherHostTest, TransferNavigation) { |
1702 EXPECT_EQ(0, host_.pending_requests()); | 1816 EXPECT_EQ(0, host_.pending_requests()); |
1703 | 1817 |
1704 int render_view_id = 0; | 1818 int render_view_id = 0; |
1705 int request_id = 1; | 1819 int request_id = 1; |
1706 | 1820 |
1707 // Configure initial request. | 1821 // Configure initial request. |
1708 SetResponse("HTTP/1.1 302 Found\n" | 1822 SetResponse("HTTP/1.1 302 Found\n" |
1709 "Location: http://other.com/blech\n\n"); | 1823 "Location: http://other.com/blech\n\n"); |
1710 | 1824 |
1711 SetResourceType(ResourceType::MAIN_FRAME); | |
1712 HandleScheme("http"); | 1825 HandleScheme("http"); |
1713 | 1826 |
1714 // Temporarily replace ContentBrowserClient with one that will trigger the | 1827 // Temporarily replace ContentBrowserClient with one that will trigger the |
1715 // transfer navigation code paths. | 1828 // transfer navigation code paths. |
1716 TransfersAllNavigationsContentBrowserClient new_client; | 1829 TransfersAllNavigationsContentBrowserClient new_client; |
1717 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1830 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1718 | 1831 |
1719 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1832 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1833 GURL("http://example.com/blah"), ResourceType::MAIN_FRAME); |
1720 | 1834 |
1721 // Restore. | 1835 // Restore. |
1722 SetBrowserClientForTesting(old_client); | 1836 SetBrowserClientForTesting(old_client); |
1723 | 1837 |
1724 // This second filter is used to emulate a second process. | 1838 // This second filter is used to emulate a second process. |
1725 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1839 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1726 this, browser_context_->GetResourceContext()); | 1840 this, browser_context_->GetResourceContext()); |
1727 | 1841 |
1728 int new_render_view_id = 1; | 1842 int new_render_view_id = 1; |
1729 int new_request_id = 2; | 1843 int new_request_id = 2; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 EXPECT_EQ(0, host_.pending_requests()); | 1877 EXPECT_EQ(0, host_.pending_requests()); |
1764 | 1878 |
1765 int render_view_id = 0; | 1879 int render_view_id = 0; |
1766 int request_id = 1; | 1880 int request_id = 1; |
1767 int first_child_id = -1; | 1881 int first_child_id = -1; |
1768 | 1882 |
1769 // Configure initial request. | 1883 // Configure initial request. |
1770 SetResponse("HTTP/1.1 302 Found\n" | 1884 SetResponse("HTTP/1.1 302 Found\n" |
1771 "Location: http://other.com/blech\n\n"); | 1885 "Location: http://other.com/blech\n\n"); |
1772 | 1886 |
1773 SetResourceType(ResourceType::MAIN_FRAME); | |
1774 HandleScheme("http"); | 1887 HandleScheme("http"); |
1775 | 1888 |
1776 // Temporarily replace ContentBrowserClient with one that will trigger the | 1889 // Temporarily replace ContentBrowserClient with one that will trigger the |
1777 // transfer navigation code paths. | 1890 // transfer navigation code paths. |
1778 TransfersAllNavigationsContentBrowserClient new_client; | 1891 TransfersAllNavigationsContentBrowserClient new_client; |
1779 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1892 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1780 | 1893 |
1781 // Create a first filter that can be deleted before the second one starts. | 1894 // Create a first filter that can be deleted before the second one starts. |
1782 { | 1895 { |
1783 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter( | 1896 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) { | 1959 TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) { |
1847 EXPECT_EQ(0, host_.pending_requests()); | 1960 EXPECT_EQ(0, host_.pending_requests()); |
1848 | 1961 |
1849 int render_view_id = 0; | 1962 int render_view_id = 0; |
1850 int request_id = 1; | 1963 int request_id = 1; |
1851 | 1964 |
1852 // Configure initial request. | 1965 // Configure initial request. |
1853 SetResponse("HTTP/1.1 302 Found\n" | 1966 SetResponse("HTTP/1.1 302 Found\n" |
1854 "Location: http://other.com/blech\n\n"); | 1967 "Location: http://other.com/blech\n\n"); |
1855 | 1968 |
1856 SetResourceType(ResourceType::MAIN_FRAME); | |
1857 HandleScheme("http"); | 1969 HandleScheme("http"); |
1858 | 1970 |
1859 // Temporarily replace ContentBrowserClient with one that will trigger the | 1971 // Temporarily replace ContentBrowserClient with one that will trigger the |
1860 // transfer navigation code paths. | 1972 // transfer navigation code paths. |
1861 TransfersAllNavigationsContentBrowserClient new_client; | 1973 TransfersAllNavigationsContentBrowserClient new_client; |
1862 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1974 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
1863 | 1975 |
1864 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1976 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1977 GURL("http://example.com/blah"), |
| 1978 ResourceType::MAIN_FRAME); |
1865 | 1979 |
1866 // Restore. | 1980 // Restore. |
1867 SetBrowserClientForTesting(old_client); | 1981 SetBrowserClientForTesting(old_client); |
1868 | 1982 |
1869 // This second filter is used to emulate a second process. | 1983 // This second filter is used to emulate a second process. |
1870 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1984 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
1871 this, browser_context_->GetResourceContext()); | 1985 this, browser_context_->GetResourceContext()); |
1872 | 1986 |
1873 int new_render_view_id = 1; | 1987 int new_render_view_id = 1; |
1874 int new_request_id = 2; | 1988 int new_request_id = 2; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1935 | 2049 |
1936 // We should have received a redirect followed by a "normal" payload. | 2050 // We should have received a redirect followed by a "normal" payload. |
1937 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2051 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
1938 msgs[0].erase(msgs[0].begin()); | 2052 msgs[0].erase(msgs[0].begin()); |
1939 CheckSuccessfulRequest(msgs[0], kResponseBody); | 2053 CheckSuccessfulRequest(msgs[0], kResponseBody); |
1940 } | 2054 } |
1941 | 2055 |
1942 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { | 2056 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { |
1943 EXPECT_EQ(0, host_.pending_requests()); | 2057 EXPECT_EQ(0, host_.pending_requests()); |
1944 | 2058 |
1945 SetResourceType(ResourceType::MAIN_FRAME); | |
1946 HandleScheme("http"); | 2059 HandleScheme("http"); |
1947 | 2060 |
1948 MakeTestRequest(0, 1, GURL("foo://bar")); | 2061 MakeTestRequestWithResourceType(filter_.get(), 0, 1, GURL("foo://bar"), |
| 2062 ResourceType::MAIN_FRAME); |
1949 | 2063 |
1950 // Flush all pending requests. | 2064 // Flush all pending requests. |
1951 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2065 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1952 | 2066 |
1953 // Sort all the messages we saw by request. | 2067 // Sort all the messages we saw by request. |
1954 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2068 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1955 accum_.GetClassifiedMessages(&msgs); | 2069 accum_.GetClassifiedMessages(&msgs); |
1956 | 2070 |
1957 // We should have gotten one RequestComplete message. | 2071 // We should have gotten one RequestComplete message. |
1958 ASSERT_EQ(1U, msgs[0].size()); | 2072 ASSERT_EQ(1U, msgs[0].size()); |
(...skipping 26 matching lines...) Expand all Loading... |
1985 | 2099 |
1986 size_t size = msgs[0].size(); | 2100 size_t size = msgs[0].size(); |
1987 | 2101 |
1988 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 2102 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
1989 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); | 2103 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); |
1990 for (size_t i = 2; i < size - 1; ++i) | 2104 for (size_t i = 2; i < size - 1; ++i) |
1991 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 2105 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
1992 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type()); | 2106 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][size - 1].type()); |
1993 } | 2107 } |
1994 | 2108 |
| 2109 // Request a very large prefetch. This tests to make sure that the data |
| 2110 // is not sent to the render process and verifies that the async handler |
| 2111 // doesn't fill up its pending buffers and block. |
| 2112 TEST_F(ResourceDispatcherHostTest, DetachedNoDataSentOrReceived) { |
| 2113 EXPECT_EQ(0, host_.pending_requests()); |
| 2114 |
| 2115 SendDataReceivedACKs(true); |
| 2116 |
| 2117 HandleScheme("big-job"); |
| 2118 |
| 2119 // This request would normally result in many messages (>300). |
| 2120 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 2121 GURL("big-job:0123456789,1000000"), |
| 2122 ResourceType::PREFETCH); |
| 2123 |
| 2124 // Sort all the messages we saw by request. |
| 2125 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2126 accum_.GetClassifiedMessages(&msgs); |
| 2127 |
| 2128 EXPECT_EQ(size_t(2), msgs[0].size()); |
| 2129 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 2130 ASSERT_EQ(ResourceMsg_RequestComplete::ID, msgs[0][1].type()); |
| 2131 } |
| 2132 |
1995 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { | 2133 TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACKs) { |
1996 EXPECT_EQ(0, host_.pending_requests()); | 2134 EXPECT_EQ(0, host_.pending_requests()); |
1997 | 2135 |
1998 HandleScheme("big-job"); | 2136 HandleScheme("big-job"); |
1999 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); | 2137 MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000")); |
2000 | 2138 |
2001 // Sort all the messages we saw by request. | 2139 // Sort all the messages we saw by request. |
2002 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2140 ResourceIPCAccumulator::ClassifiedMessages msgs; |
2003 accum_.GetClassifiedMessages(&msgs); | 2141 accum_.GetClassifiedMessages(&msgs); |
2004 | 2142 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2086 } | 2224 } |
2087 | 2225 |
2088 base::MessageLoop::current()->RunUntilIdle(); | 2226 base::MessageLoop::current()->RunUntilIdle(); |
2089 | 2227 |
2090 msgs.clear(); | 2228 msgs.clear(); |
2091 accum_.GetClassifiedMessages(&msgs); | 2229 accum_.GetClassifiedMessages(&msgs); |
2092 } | 2230 } |
2093 } | 2231 } |
2094 | 2232 |
2095 } // namespace content | 2233 } // namespace content |
OLD | NEW |