OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <utility> | 6 #include <utility> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 child_ids_.insert(filter->child_id()); | 934 child_ids_.insert(filter->child_id()); |
935 return filter; | 935 return filter; |
936 } | 936 } |
937 | 937 |
938 // Creates a request using the current test object as the filter and | 938 // Creates a request using the current test object as the filter and |
939 // SubResource as the resource type. | 939 // SubResource as the resource type. |
940 void MakeTestRequest(int render_view_id, | 940 void MakeTestRequest(int render_view_id, |
941 int request_id, | 941 int request_id, |
942 const GURL& url); | 942 const GURL& url); |
943 | 943 |
| 944 void MakeTestRequestWithRenderFrame(int render_view_id, |
| 945 int render_frame_id, |
| 946 int request_id, |
| 947 const GURL& url, |
| 948 ResourceType type); |
| 949 |
944 // Generates a request using the given filter and resource type. | 950 // Generates a request using the given filter and resource type. |
945 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, | 951 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, |
946 int render_view_id, | 952 int render_view_id, |
947 int request_id, | 953 int request_id, |
948 const GURL& url, | 954 const GURL& url, |
949 ResourceType type); | 955 ResourceType type); |
950 | 956 |
951 void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url); | 957 void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url); |
952 void MakeWebContentsAssociatedTestRequestWithResourceType(int request_id, | 958 void MakeWebContentsAssociatedTestRequestWithResourceType(int request_id, |
953 const GURL& url, | 959 const GURL& url, |
954 ResourceType type); | 960 ResourceType type); |
955 | 961 |
956 // Generates a request with the given priority. | 962 // Generates a request with the given priority. |
957 void MakeTestRequestWithPriority(int render_view_id, | 963 void MakeTestRequestWithPriority(int render_view_id, |
958 int request_id, | 964 int request_id, |
959 net::RequestPriority priority); | 965 net::RequestPriority priority); |
960 | 966 |
| 967 void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id, |
| 968 int render_frame_id, |
| 969 int request_id, |
| 970 net::RequestPriority priority); |
| 971 |
961 void MakeWebContentsAssociatedDownloadRequest(int request_id, | 972 void MakeWebContentsAssociatedDownloadRequest(int request_id, |
962 const GURL& url); | 973 const GURL& url); |
963 | 974 |
964 void CancelRequest(int request_id); | 975 void CancelRequest(int request_id); |
965 void RendererCancelRequest(int request_id) { | 976 void RendererCancelRequest(int request_id) { |
966 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); | 977 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); |
967 host_.OnCancelRequest(request_id); | 978 host_.OnCancelRequest(request_id); |
968 SetFilter(old_filter); | 979 SetFilter(old_filter); |
969 } | 980 } |
970 | 981 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 return old_filter; | 1034 return old_filter; |
1024 } | 1035 } |
1025 | 1036 |
1026 void WaitForRequestComplete() { | 1037 void WaitForRequestComplete() { |
1027 DCHECK(!wait_for_request_complete_loop_); | 1038 DCHECK(!wait_for_request_complete_loop_); |
1028 wait_for_request_complete_loop_.reset(new base::RunLoop); | 1039 wait_for_request_complete_loop_.reset(new base::RunLoop); |
1029 wait_for_request_complete_loop_->Run(); | 1040 wait_for_request_complete_loop_->Run(); |
1030 wait_for_request_complete_loop_.reset(); | 1041 wait_for_request_complete_loop_.reset(); |
1031 } | 1042 } |
1032 | 1043 |
| 1044 void DeleteRenderFrame(const GlobalFrameRoutingId& global_routing_id) { |
| 1045 host_.OnRenderFrameDeleted(global_routing_id); |
| 1046 } |
| 1047 |
1033 scoped_ptr<LoadInfoTestRequestInfo> loader_test_request_info_; | 1048 scoped_ptr<LoadInfoTestRequestInfo> loader_test_request_info_; |
1034 scoped_ptr<base::RunLoop> wait_for_request_create_loop_; | 1049 scoped_ptr<base::RunLoop> wait_for_request_create_loop_; |
1035 | 1050 |
1036 content::TestBrowserThreadBundle thread_bundle_; | 1051 content::TestBrowserThreadBundle thread_bundle_; |
1037 scoped_ptr<TestBrowserContext> browser_context_; | 1052 scoped_ptr<TestBrowserContext> browser_context_; |
1038 scoped_ptr<TestURLRequestJobFactory> job_factory_; | 1053 scoped_ptr<TestURLRequestJobFactory> job_factory_; |
1039 scoped_ptr<WebContents> web_contents_; | 1054 scoped_ptr<WebContents> web_contents_; |
1040 scoped_ptr<TestWebContentsObserver> web_contents_observer_; | 1055 scoped_ptr<TestWebContentsObserver> web_contents_observer_; |
1041 scoped_refptr<ForwardingFilter> filter_; | 1056 scoped_refptr<ForwardingFilter> filter_; |
1042 scoped_refptr<TestFilterSpecifyingChild> web_contents_filter_; | 1057 scoped_refptr<TestFilterSpecifyingChild> web_contents_filter_; |
(...skipping 10 matching lines...) Expand all Loading... |
1053 RenderViewHostTestEnabler render_view_host_test_enabler_; | 1068 RenderViewHostTestEnabler render_view_host_test_enabler_; |
1054 }; | 1069 }; |
1055 | 1070 |
1056 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, | 1071 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, |
1057 int request_id, | 1072 int request_id, |
1058 const GURL& url) { | 1073 const GURL& url) { |
1059 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 1074 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
1060 url, RESOURCE_TYPE_SUB_RESOURCE); | 1075 url, RESOURCE_TYPE_SUB_RESOURCE); |
1061 } | 1076 } |
1062 | 1077 |
| 1078 void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame( |
| 1079 int render_view_id, |
| 1080 int render_frame_id, |
| 1081 int request_id, |
| 1082 const GURL& url, |
| 1083 ResourceType type) { |
| 1084 ResourceHostMsg_Request request = CreateResourceRequest("GET", type, url); |
| 1085 request.render_frame_id = render_frame_id; |
| 1086 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
| 1087 host_.OnMessageReceived(msg, filter_.get()); |
| 1088 KickOffRequest(); |
| 1089 } |
| 1090 |
1063 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( | 1091 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( |
1064 ResourceMessageFilter* filter, | 1092 ResourceMessageFilter* filter, |
1065 int render_view_id, | 1093 int render_view_id, |
1066 int request_id, | 1094 int request_id, |
1067 const GURL& url, | 1095 const GURL& url, |
1068 ResourceType type) { | 1096 ResourceType type) { |
1069 ResourceHostMsg_Request request = | 1097 ResourceHostMsg_Request request = |
1070 CreateResourceRequest("GET", type, url); | 1098 CreateResourceRequest("GET", type, url); |
1071 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); | 1099 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
1072 host_.OnMessageReceived(msg, filter); | 1100 host_.OnMessageReceived(msg, filter); |
(...skipping 17 matching lines...) Expand all Loading... |
1090 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id, | 1118 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id, |
1091 request); | 1119 request); |
1092 host_.OnMessageReceived(msg, web_contents_filter_.get()); | 1120 host_.OnMessageReceived(msg, web_contents_filter_.get()); |
1093 KickOffRequest(); | 1121 KickOffRequest(); |
1094 } | 1122 } |
1095 | 1123 |
1096 void ResourceDispatcherHostTest::MakeTestRequestWithPriority( | 1124 void ResourceDispatcherHostTest::MakeTestRequestWithPriority( |
1097 int render_view_id, | 1125 int render_view_id, |
1098 int request_id, | 1126 int request_id, |
1099 net::RequestPriority priority) { | 1127 net::RequestPriority priority) { |
| 1128 MakeTestRequestWithPriorityAndRenderFrame(render_view_id, -1, request_id, |
| 1129 priority); |
| 1130 } |
| 1131 |
| 1132 void ResourceDispatcherHostTest::MakeTestRequestWithPriorityAndRenderFrame( |
| 1133 int render_view_id, |
| 1134 int render_frame_id, |
| 1135 int request_id, |
| 1136 net::RequestPriority priority) { |
1100 ResourceHostMsg_Request request = CreateResourceRequest( | 1137 ResourceHostMsg_Request request = CreateResourceRequest( |
1101 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority")); | 1138 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority")); |
| 1139 request.render_frame_id = render_frame_id; |
1102 request.priority = priority; | 1140 request.priority = priority; |
1103 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); | 1141 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
1104 host_.OnMessageReceived(msg, filter_.get()); | 1142 host_.OnMessageReceived(msg, filter_.get()); |
1105 } | 1143 } |
1106 | 1144 |
1107 void ResourceDispatcherHostTest::MakeWebContentsAssociatedDownloadRequest( | 1145 void ResourceDispatcherHostTest::MakeWebContentsAssociatedDownloadRequest( |
1108 int request_id, | 1146 int request_id, |
1109 const GURL& url) { | 1147 const GURL& url) { |
1110 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 1148 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
1111 save_info->prompt_for_save_location = false; | 1149 save_info->prompt_for_save_location = false; |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); | 1779 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
1742 CheckRequestCompleteErrorCode(msgs[1][1], net::ERR_ABORTED); | 1780 CheckRequestCompleteErrorCode(msgs[1][1], net::ERR_ABORTED); |
1743 // But it completed anyway. For the network stack, no requests were canceled. | 1781 // But it completed anyway. For the network stack, no requests were canceled. |
1744 EXPECT_EQ(4, network_delegate()->completed_requests()); | 1782 EXPECT_EQ(4, network_delegate()->completed_requests()); |
1745 EXPECT_EQ(0, network_delegate()->canceled_requests()); | 1783 EXPECT_EQ(0, network_delegate()->canceled_requests()); |
1746 EXPECT_EQ(0, network_delegate()->error_count()); | 1784 EXPECT_EQ(0, network_delegate()->error_count()); |
1747 } | 1785 } |
1748 | 1786 |
1749 // Tests whether the correct requests get canceled when a RenderViewHost is | 1787 // Tests whether the correct requests get canceled when a RenderViewHost is |
1750 // deleted. | 1788 // deleted. |
1751 TEST_F(ResourceDispatcherHostTest, CancelRequestsOnRenderViewHostDeleted) { | 1789 TEST_F(ResourceDispatcherHostTest, CancelRequestsOnRenderFrameDeleted) { |
1752 // Requests all hang once started. This prevents requests from being | 1790 // Requests all hang once started. This prevents requests from being |
1753 // destroyed due to completion. | 1791 // destroyed due to completion. |
1754 job_factory_->SetHangAfterStartJobGeneration(true); | 1792 job_factory_->SetHangAfterStartJobGeneration(true); |
1755 HandleScheme("http"); | 1793 HandleScheme("http"); |
1756 | 1794 |
1757 TestResourceDispatcherHostDelegate delegate; | 1795 TestResourceDispatcherHostDelegate delegate; |
1758 host_.SetDelegate(&delegate); | 1796 host_.SetDelegate(&delegate); |
1759 host_.OnRenderViewHostCreated(filter_->child_id(), 0); | 1797 host_.OnRenderViewHostCreated(filter_->child_id(), 0); |
1760 | 1798 |
1761 // One RenderView issues a high priority request and a low priority one. Both | 1799 // One RenderView issues a high priority request and a low priority one. Both |
1762 // should be started. | 1800 // should be started. |
1763 MakeTestRequestWithPriority(0, 1, net::HIGHEST); | 1801 MakeTestRequestWithPriorityAndRenderFrame(0, 10, 1, net::HIGHEST); |
1764 MakeTestRequestWithPriority(0, 2, net::LOWEST); | 1802 MakeTestRequestWithPriorityAndRenderFrame(0, 11, 2, net::LOWEST); |
1765 KickOffRequest(); | 1803 KickOffRequest(); |
1766 EXPECT_EQ(2, network_delegate_.created_requests()); | 1804 EXPECT_EQ(2, network_delegate_.created_requests()); |
1767 EXPECT_EQ(0, network_delegate_.canceled_requests()); | 1805 EXPECT_EQ(0, network_delegate_.canceled_requests()); |
1768 | 1806 |
1769 // The same RenderView issues two more low priority requests. The | 1807 // The same RenderView issues two more low priority requests. The |
1770 // ResourceScheduler shouldn't let them start immediately. | 1808 // ResourceScheduler shouldn't let them start immediately. |
1771 MakeTestRequestWithPriority(0, 3, net::LOWEST); | 1809 MakeTestRequestWithPriorityAndRenderFrame(0, 10, 3, net::LOWEST); |
1772 MakeTestRequestWithPriority(0, 4, net::LOWEST); | 1810 MakeTestRequestWithPriorityAndRenderFrame(0, 11, 4, net::LOWEST); |
1773 KickOffRequest(); | 1811 KickOffRequest(); |
1774 EXPECT_EQ(2, network_delegate_.created_requests()); | 1812 EXPECT_EQ(2, network_delegate_.created_requests()); |
1775 EXPECT_EQ(0, network_delegate_.canceled_requests()); | 1813 EXPECT_EQ(0, network_delegate_.canceled_requests()); |
1776 | 1814 |
1777 // Another RenderView in the same process as the old one issues a request, | 1815 // Another RenderView in the same process as the old one issues a request, |
1778 // which is then started. | 1816 // which is then started. |
1779 MakeTestRequestWithPriority(1, 5, net::LOWEST); | 1817 MakeTestRequestWithPriorityAndRenderFrame(1, 12, 5, net::LOWEST); |
1780 KickOffRequest(); | 1818 KickOffRequest(); |
1781 EXPECT_EQ(3, network_delegate_.created_requests()); | 1819 EXPECT_EQ(3, network_delegate_.created_requests()); |
1782 EXPECT_EQ(0, network_delegate_.canceled_requests()); | 1820 EXPECT_EQ(0, network_delegate_.canceled_requests()); |
1783 | 1821 |
1784 // The first RenderView is destroyed. All 4 of its requests should be | 1822 // The first two RenderFrameHosts are destroyed. All 4 of their requests |
1785 // cancelled, and none of the two deferred requests should be started. | 1823 // should be cancelled, and none of the two deferred requests should be |
| 1824 // started. |
| 1825 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 10)); |
| 1826 DeleteRenderFrame(GlobalFrameRoutingId(filter_->child_id(), 11)); |
1786 host_.OnRenderViewHostDeleted(filter_->child_id(), 0); | 1827 host_.OnRenderViewHostDeleted(filter_->child_id(), 0); |
1787 base::RunLoop().RunUntilIdle(); | 1828 base::RunLoop().RunUntilIdle(); |
1788 EXPECT_EQ(3, network_delegate_.created_requests()); | 1829 EXPECT_EQ(3, network_delegate_.created_requests()); |
1789 EXPECT_EQ(4, network_delegate_.canceled_requests()); | 1830 EXPECT_EQ(4, network_delegate_.canceled_requests()); |
1790 | 1831 |
1791 // No messages should have been sent, since none of the jobs made any | 1832 // No messages should have been sent, since none of the jobs made any |
1792 // progress. | 1833 // progress. |
1793 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1834 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1794 accum_.GetClassifiedMessages(&msgs); | 1835 accum_.GetClassifiedMessages(&msgs); |
1795 EXPECT_EQ(0U, msgs.size()); | 1836 EXPECT_EQ(0U, msgs.size()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 1876 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
1836 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); | 1877 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); |
1837 // And not run to completion. | 1878 // And not run to completion. |
1838 EXPECT_EQ(1, network_delegate()->completed_requests()); | 1879 EXPECT_EQ(1, network_delegate()->completed_requests()); |
1839 EXPECT_EQ(1, network_delegate()->canceled_requests()); | 1880 EXPECT_EQ(1, network_delegate()->canceled_requests()); |
1840 EXPECT_EQ(0, network_delegate()->error_count()); | 1881 EXPECT_EQ(0, network_delegate()->error_count()); |
1841 } | 1882 } |
1842 | 1883 |
1843 // Tests blocking and resuming requests. | 1884 // Tests blocking and resuming requests. |
1844 TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) { | 1885 TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) { |
1845 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1886 host_.BlockRequestsForRoute(GlobalFrameRoutingId(filter_->child_id(), 11)); |
1846 host_.BlockRequestsForRoute(filter_->child_id(), 2); | 1887 host_.BlockRequestsForRoute(GlobalFrameRoutingId(filter_->child_id(), 12)); |
1847 host_.BlockRequestsForRoute(filter_->child_id(), 3); | 1888 host_.BlockRequestsForRoute(GlobalFrameRoutingId(filter_->child_id(), 13)); |
1848 | 1889 |
1849 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1890 MakeTestRequestWithRenderFrame(0, 10, 1, net::URLRequestTestJob::test_url_1(), |
1850 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); | 1891 RESOURCE_TYPE_SUB_RESOURCE); |
1851 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 1892 MakeTestRequestWithRenderFrame(1, 11, 2, net::URLRequestTestJob::test_url_2(), |
1852 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); | 1893 RESOURCE_TYPE_SUB_RESOURCE); |
1853 MakeTestRequest(2, 5, net::URLRequestTestJob::test_url_2()); | 1894 MakeTestRequestWithRenderFrame(0, 10, 3, net::URLRequestTestJob::test_url_3(), |
1854 MakeTestRequest(3, 6, net::URLRequestTestJob::test_url_3()); | 1895 RESOURCE_TYPE_SUB_RESOURCE); |
| 1896 MakeTestRequestWithRenderFrame(1, 11, 4, net::URLRequestTestJob::test_url_1(), |
| 1897 RESOURCE_TYPE_SUB_RESOURCE); |
| 1898 MakeTestRequestWithRenderFrame(2, 12, 5, net::URLRequestTestJob::test_url_2(), |
| 1899 RESOURCE_TYPE_SUB_RESOURCE); |
| 1900 MakeTestRequestWithRenderFrame(3, 13, 6, net::URLRequestTestJob::test_url_3(), |
| 1901 RESOURCE_TYPE_SUB_RESOURCE); |
1855 | 1902 |
1856 // Flush all the pending requests | 1903 // Flush all the pending requests |
1857 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1904 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1858 | 1905 |
1859 // Sort out all the messages we saw by request | 1906 // Sort out all the messages we saw by request |
1860 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1907 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1861 accum_.GetClassifiedMessages(&msgs); | 1908 accum_.GetClassifiedMessages(&msgs); |
1862 | 1909 |
1863 // All requests but the 2 for the RVH 0 should have been blocked. | 1910 // All requests but the 2 for the RFH 0 should have been blocked. |
1864 ASSERT_EQ(2U, msgs.size()); | 1911 ASSERT_EQ(2U, msgs.size()); |
1865 | 1912 |
1866 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1913 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
1867 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); | 1914 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); |
1868 | 1915 |
1869 // Resume requests for RVH 1 and flush pending requests. | 1916 // Resume requests for RFH 11 and flush pending requests. |
1870 host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 1); | 1917 host_.ResumeBlockedRequestsForRoute( |
| 1918 GlobalFrameRoutingId(filter_->child_id(), 11)); |
1871 KickOffRequest(); | 1919 KickOffRequest(); |
1872 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1920 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1873 | 1921 |
1874 msgs.clear(); | 1922 msgs.clear(); |
1875 accum_.GetClassifiedMessages(&msgs); | 1923 accum_.GetClassifiedMessages(&msgs); |
1876 ASSERT_EQ(2U, msgs.size()); | 1924 ASSERT_EQ(2U, msgs.size()); |
1877 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); | 1925 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); |
1878 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_1()); | 1926 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_1()); |
1879 | 1927 |
1880 // Test that new requests are not blocked for RVH 1. | 1928 // Test that new requests are not blocked for RFH 11. |
1881 MakeTestRequest(1, 7, net::URLRequestTestJob::test_url_1()); | 1929 MakeTestRequestWithRenderFrame(1, 11, 7, net::URLRequestTestJob::test_url_1(), |
| 1930 RESOURCE_TYPE_SUB_RESOURCE); |
1882 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1931 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1883 msgs.clear(); | 1932 msgs.clear(); |
1884 accum_.GetClassifiedMessages(&msgs); | 1933 accum_.GetClassifiedMessages(&msgs); |
1885 ASSERT_EQ(1U, msgs.size()); | 1934 ASSERT_EQ(1U, msgs.size()); |
1886 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1935 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
1887 | 1936 |
1888 // Now resumes requests for all RVH (2 and 3). | 1937 // Now resumes requests for all RFH (12 and 13). |
1889 host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 2); | 1938 host_.ResumeBlockedRequestsForRoute( |
1890 host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 3); | 1939 GlobalFrameRoutingId(filter_->child_id(), 12)); |
| 1940 host_.ResumeBlockedRequestsForRoute( |
| 1941 GlobalFrameRoutingId(filter_->child_id(), 13)); |
1891 KickOffRequest(); | 1942 KickOffRequest(); |
1892 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1943 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1893 | 1944 |
1894 msgs.clear(); | 1945 msgs.clear(); |
1895 accum_.GetClassifiedMessages(&msgs); | 1946 accum_.GetClassifiedMessages(&msgs); |
1896 ASSERT_EQ(2U, msgs.size()); | 1947 ASSERT_EQ(2U, msgs.size()); |
1897 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); | 1948 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); |
1898 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); | 1949 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); |
1899 } | 1950 } |
1900 | 1951 |
1901 // Tests blocking and canceling requests. | 1952 // Tests blocking and canceling requests. |
1902 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { | 1953 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { |
1903 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1954 host_.BlockRequestsForRoute(GlobalFrameRoutingId(filter_->child_id(), 11)); |
1904 | 1955 |
1905 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1956 MakeTestRequestWithRenderFrame(0, 10, 1, net::URLRequestTestJob::test_url_1(), |
1906 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); | 1957 RESOURCE_TYPE_SUB_RESOURCE); |
1907 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 1958 MakeTestRequestWithRenderFrame(1, 11, 2, net::URLRequestTestJob::test_url_2(), |
1908 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); | 1959 RESOURCE_TYPE_SUB_RESOURCE); |
| 1960 MakeTestRequestWithRenderFrame(0, 10, 3, net::URLRequestTestJob::test_url_3(), |
| 1961 RESOURCE_TYPE_SUB_RESOURCE); |
| 1962 MakeTestRequestWithRenderFrame(1, 11, 4, net::URLRequestTestJob::test_url_1(), |
| 1963 RESOURCE_TYPE_SUB_RESOURCE); |
1909 // Blocked detachable resources should not delay cancellation. | 1964 // Blocked detachable resources should not delay cancellation. |
1910 MakeTestRequestWithResourceType(filter_.get(), 1, 5, | 1965 // |
1911 net::URLRequestTestJob::test_url_4(), | 1966 MakeTestRequestWithRenderFrame(1, 11, 5, net::URLRequestTestJob::test_url_4(), |
1912 RESOURCE_TYPE_PREFETCH); // detachable type | 1967 RESOURCE_TYPE_PREFETCH); // detachable type |
1913 | 1968 |
1914 // Flush all the pending requests. | 1969 // Flush all the pending requests. |
1915 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1970 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1916 | 1971 |
1917 // Sort out all the messages we saw by request. | 1972 // Sort out all the messages we saw by request. |
1918 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1973 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1919 accum_.GetClassifiedMessages(&msgs); | 1974 accum_.GetClassifiedMessages(&msgs); |
1920 | 1975 |
1921 // The 2 requests for the RVH 0 should have been processed. | 1976 // The 2 requests for the RFH 10 should have been processed. |
1922 ASSERT_EQ(2U, msgs.size()); | 1977 ASSERT_EQ(2U, msgs.size()); |
1923 | 1978 |
1924 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1979 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
1925 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); | 1980 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); |
1926 | 1981 |
1927 // Cancel requests for RVH 1. | 1982 // Cancel requests for RFH 11. |
1928 host_.CancelBlockedRequestsForRoute(filter_->child_id(), 1); | 1983 host_.CancelBlockedRequestsForRoute( |
| 1984 GlobalFrameRoutingId(filter_->child_id(), 11)); |
1929 KickOffRequest(); | 1985 KickOffRequest(); |
1930 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1986 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1931 | 1987 |
1932 msgs.clear(); | 1988 msgs.clear(); |
1933 accum_.GetClassifiedMessages(&msgs); | 1989 accum_.GetClassifiedMessages(&msgs); |
1934 ASSERT_EQ(0U, msgs.size()); | 1990 ASSERT_EQ(0U, msgs.size()); |
1935 } | 1991 } |
1936 | 1992 |
1937 // Tests that blocked requests are canceled if their associated process dies. | 1993 // Tests that blocked requests are canceled if their associated process dies. |
1938 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { | 1994 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { |
1939 // This second filter is used to emulate a second process. | 1995 // This second filter is used to emulate a second process. |
1940 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 1996 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
1941 | 1997 |
1942 host_.BlockRequestsForRoute(second_filter->child_id(), 0); | 1998 host_.BlockRequestsForRoute( |
| 1999 GlobalFrameRoutingId(second_filter->child_id(), 0)); |
1943 | 2000 |
1944 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | 2001 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
1945 net::URLRequestTestJob::test_url_1(), | 2002 net::URLRequestTestJob::test_url_1(), |
1946 RESOURCE_TYPE_SUB_RESOURCE); | 2003 RESOURCE_TYPE_SUB_RESOURCE); |
1947 MakeTestRequestWithResourceType(second_filter.get(), 0, 2, | 2004 MakeTestRequestWithResourceType(second_filter.get(), 0, 2, |
1948 net::URLRequestTestJob::test_url_2(), | 2005 net::URLRequestTestJob::test_url_2(), |
1949 RESOURCE_TYPE_SUB_RESOURCE); | 2006 RESOURCE_TYPE_SUB_RESOURCE); |
1950 MakeTestRequestWithResourceType(filter_.get(), 0, 3, | 2007 MakeTestRequestWithResourceType(filter_.get(), 0, 3, |
1951 net::URLRequestTestJob::test_url_3(), | 2008 net::URLRequestTestJob::test_url_3(), |
1952 RESOURCE_TYPE_SUB_RESOURCE); | 2009 RESOURCE_TYPE_SUB_RESOURCE); |
(...skipping 25 matching lines...) Expand all Loading... |
1978 } | 2035 } |
1979 | 2036 |
1980 // Tests that blocked requests don't leak when the ResourceDispatcherHost goes | 2037 // Tests that blocked requests don't leak when the ResourceDispatcherHost goes |
1981 // away. Note that we rely on Purify for finding the leaks if any. | 2038 // away. Note that we rely on Purify for finding the leaks if any. |
1982 // If this test turns the Purify bot red, check the ResourceDispatcherHost | 2039 // If this test turns the Purify bot red, check the ResourceDispatcherHost |
1983 // destructor to make sure the blocked requests are deleted. | 2040 // destructor to make sure the blocked requests are deleted. |
1984 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { | 2041 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { |
1985 // This second filter is used to emulate a second process. | 2042 // This second filter is used to emulate a second process. |
1986 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 2043 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
1987 | 2044 |
1988 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 2045 host_.BlockRequestsForRoute(GlobalFrameRoutingId(filter_->child_id(), 1)); |
1989 host_.BlockRequestsForRoute(filter_->child_id(), 2); | 2046 host_.BlockRequestsForRoute(GlobalFrameRoutingId(filter_->child_id(), 2)); |
1990 host_.BlockRequestsForRoute(second_filter->child_id(), 1); | 2047 host_.BlockRequestsForRoute( |
| 2048 GlobalFrameRoutingId(second_filter->child_id(), 1)); |
1991 | 2049 |
1992 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | 2050 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
1993 net::URLRequestTestJob::test_url_1(), | 2051 net::URLRequestTestJob::test_url_1(), |
1994 RESOURCE_TYPE_SUB_RESOURCE); | 2052 RESOURCE_TYPE_SUB_RESOURCE); |
1995 MakeTestRequestWithResourceType(filter_.get(), 1, 2, | 2053 MakeTestRequestWithResourceType(filter_.get(), 1, 2, |
1996 net::URLRequestTestJob::test_url_2(), | 2054 net::URLRequestTestJob::test_url_2(), |
1997 RESOURCE_TYPE_SUB_RESOURCE); | 2055 RESOURCE_TYPE_SUB_RESOURCE); |
1998 MakeTestRequestWithResourceType(filter_.get(), 0, 3, | 2056 MakeTestRequestWithResourceType(filter_.get(), 0, 3, |
1999 net::URLRequestTestJob::test_url_3(), | 2057 net::URLRequestTestJob::test_url_3(), |
2000 RESOURCE_TYPE_SUB_RESOURCE); | 2058 RESOURCE_TYPE_SUB_RESOURCE); |
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3537 return nullptr; | 3595 return nullptr; |
3538 } | 3596 } |
3539 | 3597 |
3540 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( | 3598 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( |
3541 net::URLRequest* request, | 3599 net::URLRequest* request, |
3542 net::NetworkDelegate* network_delegate) const { | 3600 net::NetworkDelegate* network_delegate) const { |
3543 return nullptr; | 3601 return nullptr; |
3544 } | 3602 } |
3545 | 3603 |
3546 } // namespace content | 3604 } // namespace content |
OLD | NEW |