| 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 child_ids_.insert(filter->child_id()); | 933 child_ids_.insert(filter->child_id()); |
| 934 return filter; | 934 return filter; |
| 935 } | 935 } |
| 936 | 936 |
| 937 // Creates a request using the current test object as the filter and | 937 // Creates a request using the current test object as the filter and |
| 938 // SubResource as the resource type. | 938 // SubResource as the resource type. |
| 939 void MakeTestRequest(int render_view_id, | 939 void MakeTestRequest(int render_view_id, |
| 940 int request_id, | 940 int request_id, |
| 941 const GURL& url); | 941 const GURL& url); |
| 942 | 942 |
| 943 void MakeTestRequestWithRenderFrame(int render_view_id, |
| 944 int render_frame_id, |
| 945 int request_id, |
| 946 const GURL& url, |
| 947 ResourceType type); |
| 948 |
| 943 // Generates a request using the given filter and resource type. | 949 // Generates a request using the given filter and resource type. |
| 944 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, | 950 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, |
| 945 int render_view_id, | 951 int render_view_id, |
| 946 int request_id, | 952 int request_id, |
| 947 const GURL& url, | 953 const GURL& url, |
| 948 ResourceType type); | 954 ResourceType type); |
| 949 | 955 |
| 950 void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url); | 956 void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url); |
| 951 void MakeWebContentsAssociatedTestRequestWithResourceType(int request_id, | 957 void MakeWebContentsAssociatedTestRequestWithResourceType(int request_id, |
| 952 const GURL& url, | 958 const GURL& url, |
| 953 ResourceType type); | 959 ResourceType type); |
| 954 | 960 |
| 955 // Generates a request with the given priority. | 961 // Generates a request with the given priority. |
| 956 void MakeTestRequestWithPriority(int render_view_id, | 962 void MakeTestRequestWithPriority(int render_view_id, |
| 957 int request_id, | 963 int request_id, |
| 958 net::RequestPriority priority); | 964 net::RequestPriority priority); |
| 959 | 965 |
| 966 void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id, |
| 967 int render_frame_id, |
| 968 int request_id, |
| 969 net::RequestPriority priority); |
| 970 |
| 960 void MakeWebContentsAssociatedDownloadRequest(int request_id, | 971 void MakeWebContentsAssociatedDownloadRequest(int request_id, |
| 961 const GURL& url); | 972 const GURL& url); |
| 962 | 973 |
| 963 void CancelRequest(int request_id); | 974 void CancelRequest(int request_id); |
| 964 void RendererCancelRequest(int request_id) { | 975 void RendererCancelRequest(int request_id) { |
| 965 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); | 976 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); |
| 966 host_.OnCancelRequest(request_id); | 977 host_.OnCancelRequest(request_id); |
| 967 SetFilter(old_filter); | 978 SetFilter(old_filter); |
| 968 } | 979 } |
| 969 | 980 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 RenderViewHostTestEnabler render_view_host_test_enabler_; | 1063 RenderViewHostTestEnabler render_view_host_test_enabler_; |
| 1053 }; | 1064 }; |
| 1054 | 1065 |
| 1055 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, | 1066 void ResourceDispatcherHostTest::MakeTestRequest(int render_view_id, |
| 1056 int request_id, | 1067 int request_id, |
| 1057 const GURL& url) { | 1068 const GURL& url) { |
| 1058 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 1069 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 1059 url, RESOURCE_TYPE_SUB_RESOURCE); | 1070 url, RESOURCE_TYPE_SUB_RESOURCE); |
| 1060 } | 1071 } |
| 1061 | 1072 |
| 1073 void ResourceDispatcherHostTest::MakeTestRequestWithRenderFrame( |
| 1074 int render_view_id, |
| 1075 int render_frame_id, |
| 1076 int request_id, |
| 1077 const GURL& url, |
| 1078 ResourceType type) { |
| 1079 ResourceHostMsg_Request request = CreateResourceRequest("GET", type, url); |
| 1080 request.render_frame_id = render_frame_id; |
| 1081 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
| 1082 host_.OnMessageReceived(msg, filter_.get()); |
| 1083 KickOffRequest(); |
| 1084 } |
| 1085 |
| 1062 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( | 1086 void ResourceDispatcherHostTest::MakeTestRequestWithResourceType( |
| 1063 ResourceMessageFilter* filter, | 1087 ResourceMessageFilter* filter, |
| 1064 int render_view_id, | 1088 int render_view_id, |
| 1065 int request_id, | 1089 int request_id, |
| 1066 const GURL& url, | 1090 const GURL& url, |
| 1067 ResourceType type) { | 1091 ResourceType type) { |
| 1068 ResourceHostMsg_Request request = | 1092 ResourceHostMsg_Request request = |
| 1069 CreateResourceRequest("GET", type, url); | 1093 CreateResourceRequest("GET", type, url); |
| 1070 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); | 1094 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
| 1071 host_.OnMessageReceived(msg, filter); | 1095 host_.OnMessageReceived(msg, filter); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1089 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id, | 1113 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id, |
| 1090 request); | 1114 request); |
| 1091 host_.OnMessageReceived(msg, web_contents_filter_.get()); | 1115 host_.OnMessageReceived(msg, web_contents_filter_.get()); |
| 1092 KickOffRequest(); | 1116 KickOffRequest(); |
| 1093 } | 1117 } |
| 1094 | 1118 |
| 1095 void ResourceDispatcherHostTest::MakeTestRequestWithPriority( | 1119 void ResourceDispatcherHostTest::MakeTestRequestWithPriority( |
| 1096 int render_view_id, | 1120 int render_view_id, |
| 1097 int request_id, | 1121 int request_id, |
| 1098 net::RequestPriority priority) { | 1122 net::RequestPriority priority) { |
| 1123 MakeTestRequestWithPriorityAndRenderFrame(render_view_id, -1, request_id, |
| 1124 priority); |
| 1125 } |
| 1126 |
| 1127 void ResourceDispatcherHostTest::MakeTestRequestWithPriorityAndRenderFrame( |
| 1128 int render_view_id, |
| 1129 int render_frame_id, |
| 1130 int request_id, |
| 1131 net::RequestPriority priority) { |
| 1099 ResourceHostMsg_Request request = CreateResourceRequest( | 1132 ResourceHostMsg_Request request = CreateResourceRequest( |
| 1100 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority")); | 1133 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority")); |
| 1134 request.render_frame_id = render_frame_id; |
| 1101 request.priority = priority; | 1135 request.priority = priority; |
| 1102 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); | 1136 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
| 1103 host_.OnMessageReceived(msg, filter_.get()); | 1137 host_.OnMessageReceived(msg, filter_.get()); |
| 1104 } | 1138 } |
| 1105 | 1139 |
| 1106 void ResourceDispatcherHostTest::MakeWebContentsAssociatedDownloadRequest( | 1140 void ResourceDispatcherHostTest::MakeWebContentsAssociatedDownloadRequest( |
| 1107 int request_id, | 1141 int request_id, |
| 1108 const GURL& url) { | 1142 const GURL& url) { |
| 1109 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 1143 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
| 1110 save_info->prompt_for_save_location = false; | 1144 save_info->prompt_for_save_location = false; |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1745 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); | 1779 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
| 1746 CheckRequestCompleteErrorCode(msgs[1][1], net::ERR_ABORTED); | 1780 CheckRequestCompleteErrorCode(msgs[1][1], net::ERR_ABORTED); |
| 1747 // 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. |
| 1748 EXPECT_EQ(4, network_delegate()->completed_requests()); | 1782 EXPECT_EQ(4, network_delegate()->completed_requests()); |
| 1749 EXPECT_EQ(0, network_delegate()->canceled_requests()); | 1783 EXPECT_EQ(0, network_delegate()->canceled_requests()); |
| 1750 EXPECT_EQ(0, network_delegate()->error_count()); | 1784 EXPECT_EQ(0, network_delegate()->error_count()); |
| 1751 } | 1785 } |
| 1752 | 1786 |
| 1753 // Tests whether the correct requests get canceled when a RenderViewHost is | 1787 // Tests whether the correct requests get canceled when a RenderViewHost is |
| 1754 // deleted. | 1788 // deleted. |
| 1755 TEST_F(ResourceDispatcherHostTest, CancelRequestsOnRenderViewHostDeleted) { | 1789 TEST_F(ResourceDispatcherHostTest, CancelRequestsOnRenderFrameHostDeleted) { |
| 1756 // Requests all hang once started. This prevents requests from being | 1790 // Requests all hang once started. This prevents requests from being |
| 1757 // destroyed due to completion. | 1791 // destroyed due to completion. |
| 1758 job_factory_->SetHangAfterStartJobGeneration(true); | 1792 job_factory_->SetHangAfterStartJobGeneration(true); |
| 1759 HandleScheme("http"); | 1793 HandleScheme("http"); |
| 1760 | 1794 |
| 1761 TestResourceDispatcherHostDelegate delegate; | 1795 TestResourceDispatcherHostDelegate delegate; |
| 1762 host_.SetDelegate(&delegate); | 1796 host_.SetDelegate(&delegate); |
| 1763 host_.OnRenderViewHostCreated(filter_->child_id(), 0, true, false); | 1797 host_.OnRenderViewHostCreated(filter_->child_id(), 0, true, false); |
| 1764 | 1798 |
| 1765 // 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 |
| 1766 // should be started. | 1800 // should be started. |
| 1767 MakeTestRequestWithPriority(0, 1, net::HIGHEST); | 1801 MakeTestRequestWithPriorityAndRenderFrame(0, 10, 1, net::HIGHEST); |
| 1768 MakeTestRequestWithPriority(0, 2, net::LOWEST); | 1802 MakeTestRequestWithPriorityAndRenderFrame(0, 11, 2, net::LOWEST); |
| 1769 KickOffRequest(); | 1803 KickOffRequest(); |
| 1770 EXPECT_EQ(2, network_delegate_.created_requests()); | 1804 EXPECT_EQ(2, network_delegate_.created_requests()); |
| 1771 EXPECT_EQ(0, network_delegate_.canceled_requests()); | 1805 EXPECT_EQ(0, network_delegate_.canceled_requests()); |
| 1772 | 1806 |
| 1773 // The same RenderView issues two more low priority requests. The | 1807 // The same RenderView issues two more low priority requests. The |
| 1774 // ResourceScheduler shouldn't let them start immediately. | 1808 // ResourceScheduler shouldn't let them start immediately. |
| 1775 MakeTestRequestWithPriority(0, 3, net::LOWEST); | 1809 MakeTestRequestWithPriorityAndRenderFrame(0, 10, 3, net::LOWEST); |
| 1776 MakeTestRequestWithPriority(0, 4, net::LOWEST); | 1810 MakeTestRequestWithPriorityAndRenderFrame(0, 11, 4, net::LOWEST); |
| 1777 KickOffRequest(); | 1811 KickOffRequest(); |
| 1778 EXPECT_EQ(2, network_delegate_.created_requests()); | 1812 EXPECT_EQ(2, network_delegate_.created_requests()); |
| 1779 EXPECT_EQ(0, network_delegate_.canceled_requests()); | 1813 EXPECT_EQ(0, network_delegate_.canceled_requests()); |
| 1780 | 1814 |
| 1781 // 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, |
| 1782 // which is then started. | 1816 // which is then started. |
| 1783 MakeTestRequestWithPriority(1, 5, net::LOWEST); | 1817 MakeTestRequestWithPriorityAndRenderFrame(1, 12, 5, net::LOWEST); |
| 1784 KickOffRequest(); | 1818 KickOffRequest(); |
| 1785 EXPECT_EQ(3, network_delegate_.created_requests()); | 1819 EXPECT_EQ(3, network_delegate_.created_requests()); |
| 1786 EXPECT_EQ(0, network_delegate_.canceled_requests()); | 1820 EXPECT_EQ(0, network_delegate_.canceled_requests()); |
| 1787 | 1821 |
| 1788 // The first RenderView is destroyed. All 4 of its requests should be | 1822 // The first two RenderFrameHosts are destroyed. All 4 of their requests |
| 1789 // 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 host_.OnRenderFrameHostDeleted(filter_->child_id(), 10); |
| 1826 host_.OnRenderFrameHostDeleted(filter_->child_id(), 11); |
| 1790 host_.OnRenderViewHostDeleted(filter_->child_id(), 0); | 1827 host_.OnRenderViewHostDeleted(filter_->child_id(), 0); |
| 1791 base::RunLoop().RunUntilIdle(); | 1828 base::RunLoop().RunUntilIdle(); |
| 1792 EXPECT_EQ(3, network_delegate_.created_requests()); | 1829 EXPECT_EQ(3, network_delegate_.created_requests()); |
| 1793 EXPECT_EQ(4, network_delegate_.canceled_requests()); | 1830 EXPECT_EQ(4, network_delegate_.canceled_requests()); |
| 1794 | 1831 |
| 1795 // 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 |
| 1796 // progress. | 1833 // progress. |
| 1797 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1834 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1798 accum_.GetClassifiedMessages(&msgs); | 1835 accum_.GetClassifiedMessages(&msgs); |
| 1799 EXPECT_EQ(0U, msgs.size()); | 1836 EXPECT_EQ(0U, msgs.size()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 1876 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
| 1840 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); | 1877 CheckRequestCompleteErrorCode(msgs[0][1], net::ERR_ABORTED); |
| 1841 // And not run to completion. | 1878 // And not run to completion. |
| 1842 EXPECT_EQ(1, network_delegate()->completed_requests()); | 1879 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 1843 EXPECT_EQ(1, network_delegate()->canceled_requests()); | 1880 EXPECT_EQ(1, network_delegate()->canceled_requests()); |
| 1844 EXPECT_EQ(0, network_delegate()->error_count()); | 1881 EXPECT_EQ(0, network_delegate()->error_count()); |
| 1845 } | 1882 } |
| 1846 | 1883 |
| 1847 // Tests blocking and resuming requests. | 1884 // Tests blocking and resuming requests. |
| 1848 TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) { | 1885 TEST_F(ResourceDispatcherHostTest, TestBlockingResumingRequests) { |
| 1849 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1886 host_.BlockRequestsForFrame(filter_->child_id(), 11); |
| 1850 host_.BlockRequestsForRoute(filter_->child_id(), 2); | 1887 host_.BlockRequestsForFrame(filter_->child_id(), 12); |
| 1851 host_.BlockRequestsForRoute(filter_->child_id(), 3); | 1888 host_.BlockRequestsForFrame(filter_->child_id(), 13); |
| 1852 | 1889 |
| 1853 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1890 MakeTestRequestWithRenderFrame(0, 10, 1, net::URLRequestTestJob::test_url_1(), |
| 1854 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); | 1891 RESOURCE_TYPE_SUB_RESOURCE); |
| 1855 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 1892 MakeTestRequestWithRenderFrame(1, 11, 2, net::URLRequestTestJob::test_url_2(), |
| 1856 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); | 1893 RESOURCE_TYPE_SUB_RESOURCE); |
| 1857 MakeTestRequest(2, 5, net::URLRequestTestJob::test_url_2()); | 1894 MakeTestRequestWithRenderFrame(0, 10, 3, net::URLRequestTestJob::test_url_3(), |
| 1858 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); |
| 1859 | 1902 |
| 1860 // Flush all the pending requests | 1903 // Flush all the pending requests |
| 1861 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1904 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1862 | 1905 |
| 1863 // Sort out all the messages we saw by request | 1906 // Sort out all the messages we saw by request |
| 1864 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1907 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1865 accum_.GetClassifiedMessages(&msgs); | 1908 accum_.GetClassifiedMessages(&msgs); |
| 1866 | 1909 |
| 1867 // 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. |
| 1868 ASSERT_EQ(2U, msgs.size()); | 1911 ASSERT_EQ(2U, msgs.size()); |
| 1869 | 1912 |
| 1870 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1913 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
| 1871 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); | 1914 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); |
| 1872 | 1915 |
| 1873 // Resume requests for RVH 1 and flush pending requests. | 1916 // Resume requests for RFH 11 and flush pending requests. |
| 1874 host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 1); | 1917 host_.ResumeBlockedRequestsForFrame(filter_->child_id(), 11); |
| 1875 KickOffRequest(); | 1918 KickOffRequest(); |
| 1876 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1919 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1877 | 1920 |
| 1878 msgs.clear(); | 1921 msgs.clear(); |
| 1879 accum_.GetClassifiedMessages(&msgs); | 1922 accum_.GetClassifiedMessages(&msgs); |
| 1880 ASSERT_EQ(2U, msgs.size()); | 1923 ASSERT_EQ(2U, msgs.size()); |
| 1881 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); | 1924 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); |
| 1882 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_1()); | 1925 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_1()); |
| 1883 | 1926 |
| 1884 // Test that new requests are not blocked for RVH 1. | 1927 // Test that new requests are not blocked for RFH 11. |
| 1885 MakeTestRequest(1, 7, net::URLRequestTestJob::test_url_1()); | 1928 MakeTestRequestWithRenderFrame(1, 11, 7, net::URLRequestTestJob::test_url_1(), |
| 1929 RESOURCE_TYPE_SUB_RESOURCE); |
| 1886 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1930 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1887 msgs.clear(); | 1931 msgs.clear(); |
| 1888 accum_.GetClassifiedMessages(&msgs); | 1932 accum_.GetClassifiedMessages(&msgs); |
| 1889 ASSERT_EQ(1U, msgs.size()); | 1933 ASSERT_EQ(1U, msgs.size()); |
| 1890 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1934 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
| 1891 | 1935 |
| 1892 // Now resumes requests for all RVH (2 and 3). | 1936 // Now resumes requests for all RFH (12 and 13). |
| 1893 host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 2); | 1937 host_.ResumeBlockedRequestsForFrame(filter_->child_id(), 12); |
| 1894 host_.ResumeBlockedRequestsForRoute(filter_->child_id(), 3); | 1938 host_.ResumeBlockedRequestsForFrame(filter_->child_id(), 13); |
| 1895 KickOffRequest(); | 1939 KickOffRequest(); |
| 1896 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1940 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1897 | 1941 |
| 1898 msgs.clear(); | 1942 msgs.clear(); |
| 1899 accum_.GetClassifiedMessages(&msgs); | 1943 accum_.GetClassifiedMessages(&msgs); |
| 1900 ASSERT_EQ(2U, msgs.size()); | 1944 ASSERT_EQ(2U, msgs.size()); |
| 1901 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); | 1945 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); |
| 1902 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); | 1946 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); |
| 1903 } | 1947 } |
| 1904 | 1948 |
| 1905 // Tests blocking and canceling requests. | 1949 // Tests blocking and canceling requests. |
| 1906 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { | 1950 TEST_F(ResourceDispatcherHostTest, TestBlockingCancelingRequests) { |
| 1907 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 1951 host_.BlockRequestsForFrame(filter_->child_id(), 11); |
| 1908 | 1952 |
| 1909 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1953 MakeTestRequestWithRenderFrame(0, 10, 1, net::URLRequestTestJob::test_url_1(), |
| 1910 MakeTestRequest(1, 2, net::URLRequestTestJob::test_url_2()); | 1954 RESOURCE_TYPE_SUB_RESOURCE); |
| 1911 MakeTestRequest(0, 3, net::URLRequestTestJob::test_url_3()); | 1955 MakeTestRequestWithRenderFrame(1, 11, 2, net::URLRequestTestJob::test_url_2(), |
| 1912 MakeTestRequest(1, 4, net::URLRequestTestJob::test_url_1()); | 1956 RESOURCE_TYPE_SUB_RESOURCE); |
| 1957 MakeTestRequestWithRenderFrame(0, 10, 3, net::URLRequestTestJob::test_url_3(), |
| 1958 RESOURCE_TYPE_SUB_RESOURCE); |
| 1959 MakeTestRequestWithRenderFrame(1, 11, 4, net::URLRequestTestJob::test_url_1(), |
| 1960 RESOURCE_TYPE_SUB_RESOURCE); |
| 1913 // Blocked detachable resources should not delay cancellation. | 1961 // Blocked detachable resources should not delay cancellation. |
| 1914 MakeTestRequestWithResourceType(filter_.get(), 1, 5, | 1962 // |
| 1915 net::URLRequestTestJob::test_url_4(), | 1963 MakeTestRequestWithRenderFrame(1, 11, 5, net::URLRequestTestJob::test_url_4(), |
| 1916 RESOURCE_TYPE_PREFETCH); // detachable type | 1964 RESOURCE_TYPE_PREFETCH); // detachable type |
| 1917 | 1965 |
| 1918 // Flush all the pending requests. | 1966 // Flush all the pending requests. |
| 1919 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1967 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1920 | 1968 |
| 1921 // Sort out all the messages we saw by request. | 1969 // Sort out all the messages we saw by request. |
| 1922 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1970 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1923 accum_.GetClassifiedMessages(&msgs); | 1971 accum_.GetClassifiedMessages(&msgs); |
| 1924 | 1972 |
| 1925 // The 2 requests for the RVH 0 should have been processed. | 1973 // The 2 requests for the RFH 10 should have been processed. |
| 1926 ASSERT_EQ(2U, msgs.size()); | 1974 ASSERT_EQ(2U, msgs.size()); |
| 1927 | 1975 |
| 1928 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); | 1976 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_1()); |
| 1929 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); | 1977 CheckSuccessfulRequest(msgs[1], net::URLRequestTestJob::test_data_3()); |
| 1930 | 1978 |
| 1931 // Cancel requests for RVH 1. | 1979 // Cancel requests for RFH 11. |
| 1932 host_.CancelBlockedRequestsForRoute(filter_->child_id(), 1); | 1980 host_.CancelBlockedRequestsForFrame(filter_->child_id(), 11); |
| 1933 KickOffRequest(); | 1981 KickOffRequest(); |
| 1934 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1982 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1935 | 1983 |
| 1936 msgs.clear(); | 1984 msgs.clear(); |
| 1937 accum_.GetClassifiedMessages(&msgs); | 1985 accum_.GetClassifiedMessages(&msgs); |
| 1938 ASSERT_EQ(0U, msgs.size()); | 1986 ASSERT_EQ(0U, msgs.size()); |
| 1939 } | 1987 } |
| 1940 | 1988 |
| 1941 // Tests that blocked requests are canceled if their associated process dies. | 1989 // Tests that blocked requests are canceled if their associated process dies. |
| 1942 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { | 1990 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies) { |
| 1943 // This second filter is used to emulate a second process. | 1991 // This second filter is used to emulate a second process. |
| 1944 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 1992 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
| 1945 | 1993 |
| 1946 host_.BlockRequestsForRoute(second_filter->child_id(), 0); | 1994 host_.BlockRequestsForFrame(second_filter->child_id(), 0); |
| 1947 | 1995 |
| 1948 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | 1996 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 1949 net::URLRequestTestJob::test_url_1(), | 1997 net::URLRequestTestJob::test_url_1(), |
| 1950 RESOURCE_TYPE_SUB_RESOURCE); | 1998 RESOURCE_TYPE_SUB_RESOURCE); |
| 1951 MakeTestRequestWithResourceType(second_filter.get(), 0, 2, | 1999 MakeTestRequestWithResourceType(second_filter.get(), 0, 2, |
| 1952 net::URLRequestTestJob::test_url_2(), | 2000 net::URLRequestTestJob::test_url_2(), |
| 1953 RESOURCE_TYPE_SUB_RESOURCE); | 2001 RESOURCE_TYPE_SUB_RESOURCE); |
| 1954 MakeTestRequestWithResourceType(filter_.get(), 0, 3, | 2002 MakeTestRequestWithResourceType(filter_.get(), 0, 3, |
| 1955 net::URLRequestTestJob::test_url_3(), | 2003 net::URLRequestTestJob::test_url_3(), |
| 1956 RESOURCE_TYPE_SUB_RESOURCE); | 2004 RESOURCE_TYPE_SUB_RESOURCE); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1982 } | 2030 } |
| 1983 | 2031 |
| 1984 // Tests that blocked requests don't leak when the ResourceDispatcherHost goes | 2032 // Tests that blocked requests don't leak when the ResourceDispatcherHost goes |
| 1985 // away. Note that we rely on Purify for finding the leaks if any. | 2033 // away. Note that we rely on Purify for finding the leaks if any. |
| 1986 // If this test turns the Purify bot red, check the ResourceDispatcherHost | 2034 // If this test turns the Purify bot red, check the ResourceDispatcherHost |
| 1987 // destructor to make sure the blocked requests are deleted. | 2035 // destructor to make sure the blocked requests are deleted. |
| 1988 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { | 2036 TEST_F(ResourceDispatcherHostTest, TestBlockedRequestsDontLeak) { |
| 1989 // This second filter is used to emulate a second process. | 2037 // This second filter is used to emulate a second process. |
| 1990 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 2038 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
| 1991 | 2039 |
| 1992 host_.BlockRequestsForRoute(filter_->child_id(), 1); | 2040 host_.BlockRequestsForFrame(filter_->child_id(), 1); |
| 1993 host_.BlockRequestsForRoute(filter_->child_id(), 2); | 2041 host_.BlockRequestsForFrame(filter_->child_id(), 2); |
| 1994 host_.BlockRequestsForRoute(second_filter->child_id(), 1); | 2042 host_.BlockRequestsForFrame(second_filter->child_id(), 1); |
| 1995 | 2043 |
| 1996 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | 2044 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
| 1997 net::URLRequestTestJob::test_url_1(), | 2045 net::URLRequestTestJob::test_url_1(), |
| 1998 RESOURCE_TYPE_SUB_RESOURCE); | 2046 RESOURCE_TYPE_SUB_RESOURCE); |
| 1999 MakeTestRequestWithResourceType(filter_.get(), 1, 2, | 2047 MakeTestRequestWithResourceType(filter_.get(), 1, 2, |
| 2000 net::URLRequestTestJob::test_url_2(), | 2048 net::URLRequestTestJob::test_url_2(), |
| 2001 RESOURCE_TYPE_SUB_RESOURCE); | 2049 RESOURCE_TYPE_SUB_RESOURCE); |
| 2002 MakeTestRequestWithResourceType(filter_.get(), 0, 3, | 2050 MakeTestRequestWithResourceType(filter_.get(), 0, 3, |
| 2003 net::URLRequestTestJob::test_url_3(), | 2051 net::URLRequestTestJob::test_url_3(), |
| 2004 RESOURCE_TYPE_SUB_RESOURCE); | 2052 RESOURCE_TYPE_SUB_RESOURCE); |
| (...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3450 | 3498 |
| 3451 // Increase the priority of the second idle priority request. It was | 3499 // Increase the priority of the second idle priority request. It was |
| 3452 // scheduled later, so it is not currently running. | 3500 // scheduled later, so it is not currently running. |
| 3453 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0); | 3501 ResourceHostMsg_DidChangePriority priority_msg(3, net::MAXIMUM_PRIORITY, 0); |
| 3454 host_.OnMessageReceived(priority_msg, filter_.get()); | 3502 host_.OnMessageReceived(priority_msg, filter_.get()); |
| 3455 base::MessageLoop::current()->RunUntilIdle(); | 3503 base::MessageLoop::current()->RunUntilIdle(); |
| 3456 | 3504 |
| 3457 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count()); | 3505 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count()); |
| 3458 | 3506 |
| 3459 // Cleanup. | 3507 // Cleanup. |
| 3508 |
| 3460 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id | 3509 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id |
| 3461 0); // route_id | 3510 0); // route_id |
| 3462 } | 3511 } |
| 3463 | 3512 |
| 3464 // Confirm that resource response started notifications for downloads are not | 3513 // Confirm that resource response started notifications for downloads are not |
| 3465 // transmitted to the WebContents. | 3514 // transmitted to the WebContents. |
| 3466 TEST_F(ResourceDispatcherHostTest, TransferResponseStartedDownload) { | 3515 TEST_F(ResourceDispatcherHostTest, TransferResponseStartedDownload) { |
| 3467 int initial_count(web_contents_observer_->resource_response_start_count()); | 3516 int initial_count(web_contents_observer_->resource_response_start_count()); |
| 3468 | 3517 |
| 3469 MakeWebContentsAssociatedDownloadRequest( | 3518 MakeWebContentsAssociatedDownloadRequest( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3543 return nullptr; | 3592 return nullptr; |
| 3544 } | 3593 } |
| 3545 | 3594 |
| 3546 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( | 3595 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( |
| 3547 net::URLRequest* request, | 3596 net::URLRequest* request, |
| 3548 net::NetworkDelegate* network_delegate) const { | 3597 net::NetworkDelegate* network_delegate) const { |
| 3549 return nullptr; | 3598 return nullptr; |
| 3550 } | 3599 } |
| 3551 | 3600 |
| 3552 } // namespace content | 3601 } // namespace content |
| OLD | NEW |