| 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/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
| 12 #include "base/run_loop.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" |
| 17 #include "content/browser/loader/resource_message_filter.h" | 18 #include "content/browser/loader/resource_message_filter.h" |
| 18 #include "content/browser/loader/resource_request_info_impl.h" | 19 #include "content/browser/loader/resource_request_info_impl.h" |
| 19 #include "content/browser/worker_host/worker_service_impl.h" | 20 #include "content/browser/worker_host/worker_service_impl.h" |
| 20 #include "content/common/child_process_host_impl.h" | 21 #include "content/common/child_process_host_impl.h" |
| 21 #include "content/common/resource_messages.h" | 22 #include "content/common/resource_messages.h" |
| (...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 | 1692 |
| 1692 // Cancelling by other methods shouldn't work either. | 1693 // Cancelling by other methods shouldn't work either. |
| 1693 host_.CancelRequestsForProcess(render_view_id); | 1694 host_.CancelRequestsForProcess(render_view_id); |
| 1694 EXPECT_EQ(1, host_.pending_requests()); | 1695 EXPECT_EQ(1, host_.pending_requests()); |
| 1695 | 1696 |
| 1696 // Cancelling by context should work. | 1697 // Cancelling by context should work. |
| 1697 host_.CancelRequestsForContext(filter_->resource_context()); | 1698 host_.CancelRequestsForContext(filter_->resource_context()); |
| 1698 EXPECT_EQ(0, host_.pending_requests()); | 1699 EXPECT_EQ(0, host_.pending_requests()); |
| 1699 } | 1700 } |
| 1700 | 1701 |
| 1701 TEST_F(ResourceDispatcherHostTest, TransferNavigation) { | 1702 // Test transferred navigations with text/html, which doesn't trigger any |
| 1703 // content sniffing. |
| 1704 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) { |
| 1702 EXPECT_EQ(0, host_.pending_requests()); | 1705 EXPECT_EQ(0, host_.pending_requests()); |
| 1703 | 1706 |
| 1704 int render_view_id = 0; | 1707 int render_view_id = 0; |
| 1705 int request_id = 1; | 1708 int request_id = 1; |
| 1706 | 1709 |
| 1707 // Configure initial request. | 1710 // Configure initial request. |
| 1708 SetResponse("HTTP/1.1 302 Found\n" | 1711 SetResponse("HTTP/1.1 302 Found\n" |
| 1709 "Location: http://other.com/blech\n\n"); | 1712 "Location: http://other.com/blech\n\n"); |
| 1710 | 1713 |
| 1711 SetResourceType(ResourceType::MAIN_FRAME); | 1714 SetResourceType(ResourceType::MAIN_FRAME); |
| 1712 HandleScheme("http"); | 1715 HandleScheme("http"); |
| 1713 | 1716 |
| 1714 // Temporarily replace ContentBrowserClient with one that will trigger the | 1717 // Temporarily replace ContentBrowserClient with one that will trigger the |
| 1715 // transfer navigation code paths. | 1718 // transfer navigation code paths. |
| 1716 TransfersAllNavigationsContentBrowserClient new_client; | 1719 TransfersAllNavigationsContentBrowserClient new_client; |
| 1717 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1720 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
| 1718 | 1721 |
| 1719 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1722 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
| 1720 | 1723 |
| 1721 // Restore. | 1724 // Now that we're blocked on the redirect, update the response and unblock by |
| 1725 // telling the AsyncResourceHandler to follow the redirect. |
| 1726 const std::string kResponseBody = "hello world"; |
| 1727 SetResponse("HTTP/1.1 200 OK\n" |
| 1728 "Content-Type: text/html\n\n", |
| 1729 kResponseBody); |
| 1730 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
| 1731 bool msg_was_ok; |
| 1732 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); |
| 1733 base::MessageLoop::current()->RunUntilIdle(); |
| 1734 |
| 1735 // Flush all the pending requests to get the response through the |
| 1736 // BufferedResourceHandler. |
| 1737 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1738 |
| 1739 // Restore, now that we've set up a transfer. |
| 1722 SetBrowserClientForTesting(old_client); | 1740 SetBrowserClientForTesting(old_client); |
| 1723 | 1741 |
| 1724 // This second filter is used to emulate a second process. | 1742 // This second filter is used to emulate a second process. |
| 1725 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1743 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
| 1726 this, browser_context_->GetResourceContext()); | 1744 this, browser_context_->GetResourceContext()); |
| 1727 | 1745 |
| 1728 int new_render_view_id = 1; | 1746 int new_render_view_id = 1; |
| 1729 int new_request_id = 2; | 1747 int new_request_id = 2; |
| 1730 | 1748 |
| 1749 ResourceHostMsg_Request request = |
| 1750 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, |
| 1751 GURL("http://other.com/blech")); |
| 1752 request.transferred_request_child_id = filter_->child_id(); |
| 1753 request.transferred_request_request_id = request_id; |
| 1754 |
| 1755 // For cleanup. |
| 1756 child_ids_.insert(second_filter->child_id()); |
| 1757 ResourceHostMsg_RequestResource transfer_request_msg( |
| 1758 new_render_view_id, new_request_id, request); |
| 1759 host_.OnMessageReceived( |
| 1760 transfer_request_msg, second_filter.get(), &msg_was_ok); |
| 1761 base::MessageLoop::current()->RunUntilIdle(); |
| 1762 |
| 1763 // Check generated messages. |
| 1764 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1765 accum_.GetClassifiedMessages(&msgs); |
| 1766 |
| 1767 ASSERT_EQ(2U, msgs.size()); |
| 1768 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 1769 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 1770 } |
| 1771 |
| 1772 // Test transferred navigations with text/plain, which causes |
| 1773 // BufferedResourceHandler to buffer the response to sniff the content |
| 1774 // before the transfer occurs. |
| 1775 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { |
| 1776 EXPECT_EQ(0, host_.pending_requests()); |
| 1777 |
| 1778 int render_view_id = 0; |
| 1779 int request_id = 1; |
| 1780 |
| 1781 // Configure initial request. |
| 1782 SetResponse("HTTP/1.1 302 Found\n" |
| 1783 "Location: http://other.com/blech\n\n"); |
| 1784 |
| 1785 SetResourceType(ResourceType::MAIN_FRAME); |
| 1786 HandleScheme("http"); |
| 1787 |
| 1788 // Temporarily replace ContentBrowserClient with one that will trigger the |
| 1789 // transfer navigation code paths. |
| 1790 TransfersAllNavigationsContentBrowserClient new_client; |
| 1791 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
| 1792 |
| 1793 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
| 1794 |
| 1795 // Now that we're blocked on the redirect, update the response and unblock by |
| 1796 // telling the AsyncResourceHandler to follow the redirect. Use a text/plain |
| 1797 // MIME type, which causes BufferedResourceHandler to buffer it before the |
| 1798 // transfer occurs. |
| 1731 const std::string kResponseBody = "hello world"; | 1799 const std::string kResponseBody = "hello world"; |
| 1732 SetResponse("HTTP/1.1 200 OK\n" | 1800 SetResponse("HTTP/1.1 200 OK\n" |
| 1733 "Content-Type: text/plain\n\n", | 1801 "Content-Type: text/plain\n\n", |
| 1734 kResponseBody); | 1802 kResponseBody); |
| 1803 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
| 1804 bool msg_was_ok; |
| 1805 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); |
| 1806 base::MessageLoop::current()->RunUntilIdle(); |
| 1807 |
| 1808 // Flush all the pending requests to get the response through the |
| 1809 // BufferedResourceHandler. |
| 1810 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1811 |
| 1812 // Restore, now that we've set up a transfer. |
| 1813 SetBrowserClientForTesting(old_client); |
| 1814 |
| 1815 // This second filter is used to emulate a second process. |
| 1816 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
| 1817 this, browser_context_->GetResourceContext()); |
| 1818 |
| 1819 int new_render_view_id = 1; |
| 1820 int new_request_id = 2; |
| 1735 | 1821 |
| 1736 ResourceHostMsg_Request request = | 1822 ResourceHostMsg_Request request = |
| 1737 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, | 1823 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, |
| 1738 GURL("http://other.com/blech")); | 1824 GURL("http://other.com/blech")); |
| 1739 request.transferred_request_child_id = filter_->child_id(); | 1825 request.transferred_request_child_id = filter_->child_id(); |
| 1740 request.transferred_request_request_id = request_id; | 1826 request.transferred_request_request_id = request_id; |
| 1741 | 1827 |
| 1742 // For cleanup. | 1828 // For cleanup. |
| 1743 child_ids_.insert(second_filter->child_id()); | 1829 child_ids_.insert(second_filter->child_id()); |
| 1744 ResourceHostMsg_RequestResource transfer_request_msg( | 1830 ResourceHostMsg_RequestResource transfer_request_msg( |
| 1745 new_render_view_id, new_request_id, request); | 1831 new_render_view_id, new_request_id, request); |
| 1746 bool msg_was_ok; | |
| 1747 host_.OnMessageReceived( | 1832 host_.OnMessageReceived( |
| 1748 transfer_request_msg, second_filter.get(), &msg_was_ok); | 1833 transfer_request_msg, second_filter.get(), &msg_was_ok); |
| 1749 base::MessageLoop::current()->RunUntilIdle(); | 1834 base::MessageLoop::current()->RunUntilIdle(); |
| 1750 | 1835 |
| 1751 // Flush all the pending requests. | |
| 1752 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
| 1753 | |
| 1754 // Check generated messages. | 1836 // Check generated messages. |
| 1755 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1837 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1756 accum_.GetClassifiedMessages(&msgs); | 1838 accum_.GetClassifiedMessages(&msgs); |
| 1757 | 1839 |
| 1758 ASSERT_EQ(1U, msgs.size()); | 1840 ASSERT_EQ(2U, msgs.size()); |
| 1759 CheckSuccessfulRequest(msgs[0], kResponseBody); | 1841 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 1842 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 1760 } | 1843 } |
| 1761 | 1844 |
| 1762 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) { | 1845 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) { |
| 1763 EXPECT_EQ(0, host_.pending_requests()); | 1846 EXPECT_EQ(0, host_.pending_requests()); |
| 1764 | 1847 |
| 1765 int render_view_id = 0; | 1848 int render_view_id = 0; |
| 1766 int request_id = 1; | 1849 int request_id = 1; |
| 1767 int first_child_id = -1; | 1850 int first_child_id = -1; |
| 1768 | 1851 |
| 1769 // Configure initial request. | 1852 // Configure initial request. |
| 1770 SetResponse("HTTP/1.1 302 Found\n" | 1853 SetResponse("HTTP/1.1 302 Found\n" |
| 1771 "Location: http://other.com/blech\n\n"); | 1854 "Location: http://other.com/blech\n\n"); |
| 1855 const std::string kResponseBody = "hello world"; |
| 1772 | 1856 |
| 1773 SetResourceType(ResourceType::MAIN_FRAME); | 1857 SetResourceType(ResourceType::MAIN_FRAME); |
| 1774 HandleScheme("http"); | 1858 HandleScheme("http"); |
| 1775 | 1859 |
| 1776 // Temporarily replace ContentBrowserClient with one that will trigger the | 1860 // Temporarily replace ContentBrowserClient with one that will trigger the |
| 1777 // transfer navigation code paths. | 1861 // transfer navigation code paths. |
| 1778 TransfersAllNavigationsContentBrowserClient new_client; | 1862 TransfersAllNavigationsContentBrowserClient new_client; |
| 1779 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1863 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
| 1780 | 1864 |
| 1781 // Create a first filter that can be deleted before the second one starts. | 1865 // Create a first filter that can be deleted before the second one starts. |
| 1782 { | 1866 { |
| 1783 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter( | 1867 scoped_refptr<ForwardingFilter> first_filter = new ForwardingFilter( |
| 1784 this, browser_context_->GetResourceContext()); | 1868 this, browser_context_->GetResourceContext()); |
| 1785 first_child_id = first_filter->child_id(); | 1869 first_child_id = first_filter->child_id(); |
| 1786 | 1870 |
| 1787 ResourceHostMsg_Request first_request = | 1871 ResourceHostMsg_Request first_request = |
| 1788 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, | 1872 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, |
| 1789 GURL("http://example.com/blah")); | 1873 GURL("http://example.com/blah")); |
| 1790 | 1874 |
| 1791 // For cleanup. | 1875 // For cleanup. |
| 1792 child_ids_.insert(first_child_id); | 1876 child_ids_.insert(first_child_id); |
| 1793 ResourceHostMsg_RequestResource first_request_msg( | 1877 ResourceHostMsg_RequestResource first_request_msg( |
| 1794 render_view_id, request_id, first_request); | 1878 render_view_id, request_id, first_request); |
| 1795 bool msg_was_ok; | 1879 bool msg_was_ok; |
| 1796 host_.OnMessageReceived( | 1880 host_.OnMessageReceived( |
| 1797 first_request_msg, first_filter.get(), &msg_was_ok); | 1881 first_request_msg, first_filter.get(), &msg_was_ok); |
| 1798 base::MessageLoop::current()->RunUntilIdle(); | 1882 base::MessageLoop::current()->RunUntilIdle(); |
| 1883 |
| 1884 // Now that we're blocked on the redirect, update the response and unblock |
| 1885 // by telling the AsyncResourceHandler to follow the redirect. |
| 1886 SetResponse("HTTP/1.1 200 OK\n" |
| 1887 "Content-Type: text/html\n\n", |
| 1888 kResponseBody); |
| 1889 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
| 1890 host_.OnMessageReceived(redirect_msg, first_filter.get(), &msg_was_ok); |
| 1891 base::MessageLoop::current()->RunUntilIdle(); |
| 1892 |
| 1893 // Flush all the pending requests to get the response through the |
| 1894 // BufferedResourceHandler. |
| 1895 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1799 } | 1896 } |
| 1800 // The first filter is now deleted, as if the child process died. | 1897 // The first filter is now deleted, as if the child process died. |
| 1801 | 1898 |
| 1802 // Restore. | 1899 // Restore. |
| 1803 SetBrowserClientForTesting(old_client); | 1900 SetBrowserClientForTesting(old_client); |
| 1804 | 1901 |
| 1805 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. | 1902 // Make sure we don't hold onto the ResourceMessageFilter after it is deleted. |
| 1806 GlobalRequestID first_global_request_id(first_child_id, request_id); | 1903 GlobalRequestID first_global_request_id(first_child_id, request_id); |
| 1807 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 1904 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 1808 host_.GetURLRequest(first_global_request_id)); | 1905 host_.GetURLRequest(first_global_request_id)); |
| 1809 EXPECT_FALSE(info->filter()); | 1906 EXPECT_FALSE(info->filter()); |
| 1810 | 1907 |
| 1811 // This second filter is used to emulate a second process. | 1908 // This second filter is used to emulate a second process. |
| 1812 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1909 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
| 1813 this, browser_context_->GetResourceContext()); | 1910 this, browser_context_->GetResourceContext()); |
| 1814 | 1911 |
| 1815 int new_render_view_id = 1; | 1912 int new_render_view_id = 1; |
| 1816 int new_request_id = 2; | 1913 int new_request_id = 2; |
| 1817 | 1914 |
| 1818 const std::string kResponseBody = "hello world"; | |
| 1819 SetResponse("HTTP/1.1 200 OK\n" | |
| 1820 "Content-Type: text/plain\n\n", | |
| 1821 kResponseBody); | |
| 1822 | |
| 1823 ResourceHostMsg_Request request = | 1915 ResourceHostMsg_Request request = |
| 1824 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, | 1916 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, |
| 1825 GURL("http://other.com/blech")); | 1917 GURL("http://other.com/blech")); |
| 1826 request.transferred_request_child_id = first_child_id; | 1918 request.transferred_request_child_id = first_child_id; |
| 1827 request.transferred_request_request_id = request_id; | 1919 request.transferred_request_request_id = request_id; |
| 1828 | 1920 |
| 1829 // For cleanup. | 1921 // For cleanup. |
| 1830 child_ids_.insert(second_filter->child_id()); | 1922 child_ids_.insert(second_filter->child_id()); |
| 1831 ResourceHostMsg_RequestResource transfer_request_msg( | 1923 ResourceHostMsg_RequestResource transfer_request_msg( |
| 1832 new_render_view_id, new_request_id, request); | 1924 new_render_view_id, new_request_id, request); |
| 1833 bool msg_was_ok; | 1925 bool msg_was_ok; |
| 1834 host_.OnMessageReceived( | 1926 host_.OnMessageReceived( |
| 1835 transfer_request_msg, second_filter.get(), &msg_was_ok); | 1927 transfer_request_msg, second_filter.get(), &msg_was_ok); |
| 1836 base::MessageLoop::current()->RunUntilIdle(); | 1928 base::MessageLoop::current()->RunUntilIdle(); |
| 1837 | 1929 |
| 1838 // Flush all the pending requests. | |
| 1839 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
| 1840 | |
| 1841 // Check generated messages. | 1930 // Check generated messages. |
| 1842 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1931 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1843 accum_.GetClassifiedMessages(&msgs); | 1932 accum_.GetClassifiedMessages(&msgs); |
| 1844 | 1933 |
| 1845 ASSERT_EQ(1U, msgs.size()); | 1934 ASSERT_EQ(2U, msgs.size()); |
| 1846 CheckSuccessfulRequest(msgs[0], kResponseBody); | 1935 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 1936 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 1847 } | 1937 } |
| 1848 | 1938 |
| 1849 TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) { | 1939 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { |
| 1850 EXPECT_EQ(0, host_.pending_requests()); | 1940 EXPECT_EQ(0, host_.pending_requests()); |
| 1851 | 1941 |
| 1852 int render_view_id = 0; | 1942 int render_view_id = 0; |
| 1853 int request_id = 1; | 1943 int request_id = 1; |
| 1854 | 1944 |
| 1855 // Configure initial request. | 1945 // Configure initial request. |
| 1856 SetResponse("HTTP/1.1 302 Found\n" | 1946 SetResponse("HTTP/1.1 302 Found\n" |
| 1857 "Location: http://other.com/blech\n\n"); | 1947 "Location: http://other.com/blech\n\n"); |
| 1858 | 1948 |
| 1859 SetResourceType(ResourceType::MAIN_FRAME); | 1949 SetResourceType(ResourceType::MAIN_FRAME); |
| 1860 HandleScheme("http"); | 1950 HandleScheme("http"); |
| 1861 | 1951 |
| 1862 // Temporarily replace ContentBrowserClient with one that will trigger the | 1952 // Temporarily replace ContentBrowserClient with one that will trigger the |
| 1863 // transfer navigation code paths. | 1953 // transfer navigation code paths. |
| 1864 TransfersAllNavigationsContentBrowserClient new_client; | 1954 TransfersAllNavigationsContentBrowserClient new_client; |
| 1865 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1955 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
| 1866 | 1956 |
| 1867 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1957 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
| 1868 | 1958 |
| 1959 // Now that we're blocked on the redirect, simulate hitting another redirect. |
| 1960 SetResponse("HTTP/1.1 302 Found\n" |
| 1961 "Location: http://other.com/blerg\n\n"); |
| 1962 ResourceHostMsg_FollowRedirect redirect_msg(request_id, false, GURL()); |
| 1963 bool msg_was_ok; |
| 1964 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); |
| 1965 base::MessageLoop::current()->RunUntilIdle(); |
| 1966 |
| 1967 // Now that we're blocked on the second redirect, update the response and |
| 1968 // unblock by telling the AsyncResourceHandler to follow the redirect. |
| 1969 // Again, use text/plain to force BufferedResourceHandler to buffer before |
| 1970 // the transfer. |
| 1971 const std::string kResponseBody = "hello world"; |
| 1972 SetResponse("HTTP/1.1 200 OK\n" |
| 1973 "Content-Type: text/plain\n\n", |
| 1974 kResponseBody); |
| 1975 ResourceHostMsg_FollowRedirect redirect_msg2(request_id, false, GURL()); |
| 1976 host_.OnMessageReceived(redirect_msg2, filter_.get(), &msg_was_ok); |
| 1977 base::MessageLoop::current()->RunUntilIdle(); |
| 1978 |
| 1979 // Flush all the pending requests to get the response through the |
| 1980 // BufferedResourceHandler. |
| 1981 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1982 |
| 1869 // Restore. | 1983 // Restore. |
| 1870 SetBrowserClientForTesting(old_client); | 1984 SetBrowserClientForTesting(old_client); |
| 1871 | 1985 |
| 1872 // This second filter is used to emulate a second process. | 1986 // This second filter is used to emulate a second process. |
| 1873 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1987 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
| 1874 this, browser_context_->GetResourceContext()); | 1988 this, browser_context_->GetResourceContext()); |
| 1875 | 1989 |
| 1876 int new_render_view_id = 1; | 1990 int new_render_view_id = 1; |
| 1877 int new_request_id = 2; | 1991 int new_request_id = 2; |
| 1878 | 1992 |
| 1879 // Delay the start of the next request so that we can setup the response for | |
| 1880 // the next URL. | |
| 1881 SetDelayedStartJobGeneration(true); | |
| 1882 | |
| 1883 SetResponse("HTTP/1.1 302 Found\n" | |
| 1884 "Location: http://other.com/blerg\n\n"); | |
| 1885 | |
| 1886 ResourceHostMsg_Request request = | 1993 ResourceHostMsg_Request request = |
| 1887 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, | 1994 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, |
| 1888 GURL("http://other.com/blech")); | 1995 GURL("http://other.com/blech")); |
| 1889 request.transferred_request_child_id = filter_->child_id(); | 1996 request.transferred_request_child_id = filter_->child_id(); |
| 1890 request.transferred_request_request_id = request_id; | 1997 request.transferred_request_request_id = request_id; |
| 1891 | 1998 |
| 1892 // For cleanup. | 1999 // For cleanup. |
| 1893 child_ids_.insert(second_filter->child_id()); | 2000 child_ids_.insert(second_filter->child_id()); |
| 1894 ResourceHostMsg_RequestResource transfer_request_msg( | 2001 ResourceHostMsg_RequestResource transfer_request_msg( |
| 1895 new_render_view_id, new_request_id, request); | 2002 new_render_view_id, new_request_id, request); |
| 1896 bool msg_was_ok; | |
| 1897 host_.OnMessageReceived( | 2003 host_.OnMessageReceived( |
| 1898 transfer_request_msg, second_filter.get(), &msg_was_ok); | 2004 transfer_request_msg, second_filter.get(), &msg_was_ok); |
| 1899 base::MessageLoop::current()->RunUntilIdle(); | |
| 1900 | |
| 1901 // Response data for "http://other.com/blerg": | |
| 1902 const std::string kResponseBody = "hello world"; | |
| 1903 SetResponse("HTTP/1.1 200 OK\n" | |
| 1904 "Content-Type: text/plain\n\n", | |
| 1905 kResponseBody); | |
| 1906 | |
| 1907 // OK, let the redirect happen. | |
| 1908 SetDelayedStartJobGeneration(false); | |
| 1909 CompleteStartRequest(second_filter.get(), new_request_id); | |
| 1910 base::MessageLoop::current()->RunUntilIdle(); | |
| 1911 | |
| 1912 // Flush all the pending requests. | |
| 1913 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
| 1914 | 2005 |
| 1915 // Verify that we update the ResourceRequestInfo. | 2006 // Verify that we update the ResourceRequestInfo. |
| 1916 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); | 2007 GlobalRequestID global_request_id(second_filter->child_id(), new_request_id); |
| 1917 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 2008 const ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
| 1918 host_.GetURLRequest(global_request_id)); | 2009 host_.GetURLRequest(global_request_id)); |
| 1919 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); | 2010 EXPECT_EQ(second_filter->child_id(), info->GetChildID()); |
| 1920 EXPECT_EQ(new_render_view_id, info->GetRouteID()); | 2011 EXPECT_EQ(new_render_view_id, info->GetRouteID()); |
| 1921 EXPECT_EQ(new_request_id, info->GetRequestID()); | 2012 EXPECT_EQ(new_request_id, info->GetRequestID()); |
| 1922 EXPECT_EQ(second_filter, info->filter()); | 2013 EXPECT_EQ(second_filter, info->filter()); |
| 1923 | 2014 |
| 1924 // Now, simulate the renderer choosing to follow the redirect. | 2015 // Let request complete. |
| 1925 ResourceHostMsg_FollowRedirect redirect_msg( | |
| 1926 new_request_id, false, GURL()); | |
| 1927 host_.OnMessageReceived(redirect_msg, second_filter.get(), &msg_was_ok); | |
| 1928 base::MessageLoop::current()->RunUntilIdle(); | 2016 base::MessageLoop::current()->RunUntilIdle(); |
| 1929 | 2017 |
| 1930 // Flush all the pending requests. | |
| 1931 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
| 1932 | |
| 1933 // Check generated messages. | 2018 // Check generated messages. |
| 1934 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2019 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1935 accum_.GetClassifiedMessages(&msgs); | 2020 accum_.GetClassifiedMessages(&msgs); |
| 1936 | 2021 |
| 1937 ASSERT_EQ(1U, msgs.size()); | 2022 ASSERT_EQ(2U, msgs.size()); |
| 1938 | |
| 1939 // We should have received a redirect followed by a "normal" payload. | |
| 1940 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2023 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 1941 msgs[0].erase(msgs[0].begin()); | 2024 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 1942 CheckSuccessfulRequest(msgs[0], kResponseBody); | |
| 1943 } | 2025 } |
| 1944 | 2026 |
| 1945 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { | 2027 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { |
| 1946 EXPECT_EQ(0, host_.pending_requests()); | 2028 EXPECT_EQ(0, host_.pending_requests()); |
| 1947 | 2029 |
| 1948 SetResourceType(ResourceType::MAIN_FRAME); | 2030 SetResourceType(ResourceType::MAIN_FRAME); |
| 1949 HandleScheme("http"); | 2031 HandleScheme("http"); |
| 1950 | 2032 |
| 1951 MakeTestRequest(0, 1, GURL("foo://bar")); | 2033 MakeTestRequest(0, 1, GURL("foo://bar")); |
| 1952 | 2034 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2089 } | 2171 } |
| 2090 | 2172 |
| 2091 base::MessageLoop::current()->RunUntilIdle(); | 2173 base::MessageLoop::current()->RunUntilIdle(); |
| 2092 | 2174 |
| 2093 msgs.clear(); | 2175 msgs.clear(); |
| 2094 accum_.GetClassifiedMessages(&msgs); | 2176 accum_.GetClassifiedMessages(&msgs); |
| 2095 } | 2177 } |
| 2096 } | 2178 } |
| 2097 | 2179 |
| 2098 } // namespace content | 2180 } // namespace content |
| OLD | NEW |