Chromium Code Reviews| 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.h" | 10 #include "base/message_loop.h" |
| (...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1716 SetResourceType(ResourceType::MAIN_FRAME); | 1716 SetResourceType(ResourceType::MAIN_FRAME); |
| 1717 HandleScheme("http"); | 1717 HandleScheme("http"); |
| 1718 | 1718 |
| 1719 // Temporarily replace ContentBrowserClient with one that will trigger the | 1719 // Temporarily replace ContentBrowserClient with one that will trigger the |
| 1720 // transfer navigation code paths. | 1720 // transfer navigation code paths. |
| 1721 TransfersAllNavigationsContentBrowserClient new_client; | 1721 TransfersAllNavigationsContentBrowserClient new_client; |
| 1722 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1722 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
| 1723 | 1723 |
| 1724 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1724 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
| 1725 | 1725 |
| 1726 // Restore. | 1726 // Now that we're blocked on the redirect, update the response and unblock by |
| 1727 // telling the AsyncResourceHandler to follow the redirect. | |
| 1728 const std::string kResponseBody = "hello world"; | |
| 1729 SetResponse("HTTP/1.1 200 OK\n" | |
| 1730 "Content-Type: text/plain\n\n", | |
| 1731 kResponseBody); | |
| 1732 ResourceHostMsg_FollowRedirect redirect_msg( | |
| 1733 render_view_id, request_id, false, GURL()); | |
| 1734 bool msg_was_ok; | |
| 1735 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); | |
| 1736 base::MessageLoop::current()->RunUntilIdle(); | |
|
Matt Perry
2013/07/08 21:38:57
deprecated - use RunLoop::RunUntilIdle()
Charlie Reis
2013/07/08 22:49:31
Is that recent? I don't see any other tests using
Matt Perry
2013/07/08 22:59:34
Somewhat recent. See message_loop.h for the deprec
Charlie Reis
2013/07/09 00:08:44
Done.
| |
| 1737 | |
| 1738 // Flush all the pending requests to get the response through the | |
| 1739 // BufferedResourceHandler. | |
| 1740 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
| 1741 | |
| 1742 // Restore, now that we've set up a transfer. | |
| 1727 SetBrowserClientForTesting(old_client); | 1743 SetBrowserClientForTesting(old_client); |
| 1728 | 1744 |
| 1729 // This second filter is used to emulate a second process. | 1745 // This second filter is used to emulate a second process. |
| 1730 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1746 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
| 1731 this, browser_context_->GetResourceContext()); | 1747 this, browser_context_->GetResourceContext()); |
| 1732 | 1748 |
| 1733 int new_render_view_id = 1; | 1749 int new_render_view_id = 1; |
| 1734 int new_request_id = 2; | 1750 int new_request_id = 2; |
| 1735 | 1751 |
| 1736 const std::string kResponseBody = "hello world"; | |
| 1737 SetResponse("HTTP/1.1 200 OK\n" | |
| 1738 "Content-Type: text/plain\n\n", | |
| 1739 kResponseBody); | |
| 1740 | |
| 1741 ResourceHostMsg_Request request = | 1752 ResourceHostMsg_Request request = |
| 1742 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, | 1753 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, |
| 1743 GURL("http://other.com/blech")); | 1754 GURL("http://other.com/blech")); |
| 1744 request.transferred_request_child_id = filter_->child_id(); | 1755 request.transferred_request_child_id = filter_->child_id(); |
| 1745 request.transferred_request_request_id = request_id; | 1756 request.transferred_request_request_id = request_id; |
| 1746 | 1757 |
| 1747 // For cleanup. | 1758 // For cleanup. |
| 1748 child_ids_.insert(second_filter->child_id()); | 1759 child_ids_.insert(second_filter->child_id()); |
| 1749 ResourceHostMsg_RequestResource transfer_request_msg( | 1760 ResourceHostMsg_RequestResource transfer_request_msg( |
| 1750 new_render_view_id, new_request_id, request); | 1761 new_render_view_id, new_request_id, request); |
| 1751 bool msg_was_ok; | |
| 1752 host_.OnMessageReceived( | 1762 host_.OnMessageReceived( |
| 1753 transfer_request_msg, second_filter.get(), &msg_was_ok); | 1763 transfer_request_msg, second_filter.get(), &msg_was_ok); |
| 1754 base::MessageLoop::current()->RunUntilIdle(); | 1764 base::MessageLoop::current()->RunUntilIdle(); |
| 1755 | 1765 |
| 1756 // Flush all the pending requests. | 1766 // Flush all the pending requests. |
| 1757 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1767 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1758 | 1768 |
| 1759 // Check generated messages. | 1769 // Check generated messages. |
| 1760 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1770 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1761 accum_.GetClassifiedMessages(&msgs); | 1771 accum_.GetClassifiedMessages(&msgs); |
| 1762 | 1772 |
| 1763 ASSERT_EQ(1U, msgs.size()); | 1773 // We expect fewer messages in this response than CheckSuccessfulRequest looks |
|
Charlie Reis
2013/07/08 18:28:43
I'm not 100% sure on this. It's suspicious to me
Matt Perry
2013/07/08 21:38:57
I don't know much about it, but is it a bug that t
Charlie Reis
2013/07/08 22:49:31
Entirely possible. It looks like we usually send
Matt Perry
2013/07/08 22:59:34
I guess for a redirect, you're going to get a new
Charlie Reis
2013/07/09 00:08:44
Calling SetResponse again before sending the trans
Matt Perry
2013/07/09 00:22:33
I wonder if the bytes have already been transmitte
Charlie Reis
2013/07/09 23:54:43
Ugh, I just confirmed there's a real bug here. Th
| |
| 1764 CheckSuccessfulRequest(msgs[0], kResponseBody); | 1774 // for, since most were handled before the transfer. |
| 1775 ASSERT_EQ(2U, msgs.size()); | |
| 1776 ASSERT_EQ(2U, msgs[1].size()); | |
| 1777 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); | |
| 1778 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type()); | |
| 1765 } | 1779 } |
| 1766 | 1780 |
| 1767 TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) { | 1781 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { |
| 1768 EXPECT_EQ(0, host_.pending_requests()); | 1782 EXPECT_EQ(0, host_.pending_requests()); |
| 1769 | 1783 |
| 1770 int render_view_id = 0; | 1784 int render_view_id = 0; |
| 1771 int request_id = 1; | 1785 int request_id = 1; |
| 1772 | 1786 |
| 1773 // Configure initial request. | 1787 // Configure initial request. |
| 1774 SetResponse("HTTP/1.1 302 Found\n" | 1788 SetResponse("HTTP/1.1 302 Found\n" |
| 1775 "Location: http://other.com/blech\n\n"); | 1789 "Location: http://other.com/blech\n\n"); |
| 1776 | 1790 |
| 1777 SetResourceType(ResourceType::MAIN_FRAME); | 1791 SetResourceType(ResourceType::MAIN_FRAME); |
| 1778 HandleScheme("http"); | 1792 HandleScheme("http"); |
| 1779 | 1793 |
| 1780 // Temporarily replace ContentBrowserClient with one that will trigger the | 1794 // Temporarily replace ContentBrowserClient with one that will trigger the |
| 1781 // transfer navigation code paths. | 1795 // transfer navigation code paths. |
| 1782 TransfersAllNavigationsContentBrowserClient new_client; | 1796 TransfersAllNavigationsContentBrowserClient new_client; |
| 1783 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); | 1797 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
| 1784 | 1798 |
| 1785 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1799 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
| 1786 | 1800 |
| 1801 // Now that we're blocked on the redirect, simulate hitting another redirect. | |
| 1802 SetResponse("HTTP/1.1 302 Found\n" | |
| 1803 "Location: http://other.com/blerg\n\n"); | |
| 1804 ResourceHostMsg_FollowRedirect redirect_msg( | |
| 1805 render_view_id, request_id, false, GURL()); | |
| 1806 bool msg_was_ok; | |
| 1807 host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok); | |
| 1808 base::MessageLoop::current()->RunUntilIdle(); | |
| 1809 | |
| 1810 // Now that we're blocked on the second redirect, update the response and | |
| 1811 // unblock by telling the AsyncResourceHandler to follow the redirect. | |
| 1812 const std::string kResponseBody = "hello world"; | |
| 1813 SetResponse("HTTP/1.1 200 OK\n" | |
| 1814 "Content-Type: text/plain\n\n", | |
| 1815 kResponseBody); | |
| 1816 ResourceHostMsg_FollowRedirect redirect_msg2( | |
| 1817 render_view_id, request_id, false, GURL()); | |
| 1818 host_.OnMessageReceived(redirect_msg2, filter_.get(), &msg_was_ok); | |
| 1819 base::MessageLoop::current()->RunUntilIdle(); | |
| 1820 | |
| 1821 // Flush all the pending requests to get the response through the | |
| 1822 // BufferedResourceHandler. | |
| 1823 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
| 1824 | |
| 1787 // Restore. | 1825 // Restore. |
| 1788 SetBrowserClientForTesting(old_client); | 1826 SetBrowserClientForTesting(old_client); |
| 1789 | 1827 |
| 1790 // This second filter is used to emulate a second process. | 1828 // This second filter is used to emulate a second process. |
| 1791 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( | 1829 scoped_refptr<ForwardingFilter> second_filter = new ForwardingFilter( |
| 1792 this, browser_context_->GetResourceContext()); | 1830 this, browser_context_->GetResourceContext()); |
| 1793 | 1831 |
| 1794 int new_render_view_id = 1; | 1832 int new_render_view_id = 1; |
| 1795 int new_request_id = 2; | 1833 int new_request_id = 2; |
| 1796 | 1834 |
| 1797 // Delay the start of the next request so that we can setup the response for | |
| 1798 // the next URL. | |
| 1799 SetDelayedStartJobGeneration(true); | |
| 1800 | |
| 1801 SetResponse("HTTP/1.1 302 Found\n" | |
| 1802 "Location: http://other.com/blerg\n\n"); | |
| 1803 | |
| 1804 ResourceHostMsg_Request request = | 1835 ResourceHostMsg_Request request = |
| 1805 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, | 1836 CreateResourceRequest("GET", ResourceType::MAIN_FRAME, |
| 1806 GURL("http://other.com/blech")); | 1837 GURL("http://other.com/blech")); |
| 1807 request.transferred_request_child_id = filter_->child_id(); | 1838 request.transferred_request_child_id = filter_->child_id(); |
| 1808 request.transferred_request_request_id = request_id; | 1839 request.transferred_request_request_id = request_id; |
| 1809 | 1840 |
| 1810 // For cleanup. | 1841 // For cleanup. |
| 1811 child_ids_.insert(second_filter->child_id()); | 1842 child_ids_.insert(second_filter->child_id()); |
| 1812 ResourceHostMsg_RequestResource transfer_request_msg( | 1843 ResourceHostMsg_RequestResource transfer_request_msg( |
| 1813 new_render_view_id, new_request_id, request); | 1844 new_render_view_id, new_request_id, request); |
| 1814 bool msg_was_ok; | |
| 1815 host_.OnMessageReceived( | 1845 host_.OnMessageReceived( |
| 1816 transfer_request_msg, second_filter.get(), &msg_was_ok); | 1846 transfer_request_msg, second_filter.get(), &msg_was_ok); |
| 1817 base::MessageLoop::current()->RunUntilIdle(); | 1847 base::MessageLoop::current()->RunUntilIdle(); |
| 1818 | 1848 |
| 1819 // Response data for "http://other.com/blerg": | |
| 1820 const std::string kResponseBody = "hello world"; | |
| 1821 SetResponse("HTTP/1.1 200 OK\n" | |
| 1822 "Content-Type: text/plain\n\n", | |
| 1823 kResponseBody); | |
| 1824 | |
| 1825 // OK, let the redirect happen. | |
| 1826 SetDelayedStartJobGeneration(false); | |
| 1827 CompleteStartRequest(second_filter.get(), new_request_id); | |
| 1828 base::MessageLoop::current()->RunUntilIdle(); | |
| 1829 | |
| 1830 // Flush all the pending requests. | 1849 // Flush all the pending requests. |
| 1831 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1850 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1832 | 1851 |
| 1833 // Now, simulate the renderer choosing to follow the redirect. | |
| 1834 ResourceHostMsg_FollowRedirect redirect_msg( | |
| 1835 new_render_view_id, new_request_id, false, GURL()); | |
| 1836 host_.OnMessageReceived(redirect_msg, second_filter.get(), &msg_was_ok); | |
| 1837 base::MessageLoop::current()->RunUntilIdle(); | |
| 1838 | |
| 1839 // Flush all the pending requests. | |
| 1840 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
| 1841 | |
| 1842 // Check generated messages. | 1852 // Check generated messages. |
| 1843 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1853 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 1844 accum_.GetClassifiedMessages(&msgs); | 1854 accum_.GetClassifiedMessages(&msgs); |
| 1845 | 1855 |
| 1846 ASSERT_EQ(1U, msgs.size()); | 1856 // We expect fewer messages in this response than CheckSuccessfulRequest looks |
|
Charlie Reis
2013/07/08 18:28:43
Again, uncertain if this is the right way to end.
| |
| 1847 | 1857 // for, since most were handled before the transfer. |
| 1848 // We should have received a redirect followed by a "normal" payload. | 1858 ASSERT_EQ(2U, msgs.size()); |
| 1849 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 1859 ASSERT_EQ(2U, msgs[1].size()); |
| 1850 msgs[0].erase(msgs[0].begin()); | 1860 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type()); |
| 1851 CheckSuccessfulRequest(msgs[0], kResponseBody); | 1861 EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type()); |
| 1852 } | 1862 } |
| 1853 | 1863 |
| 1854 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { | 1864 TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) { |
| 1855 EXPECT_EQ(0, host_.pending_requests()); | 1865 EXPECT_EQ(0, host_.pending_requests()); |
| 1856 | 1866 |
| 1857 SetResourceType(ResourceType::MAIN_FRAME); | 1867 SetResourceType(ResourceType::MAIN_FRAME); |
| 1858 HandleScheme("http"); | 1868 HandleScheme("http"); |
| 1859 | 1869 |
| 1860 MakeTestRequest(0, 1, GURL("foo://bar")); | 1870 MakeTestRequest(0, 1, GURL("foo://bar")); |
| 1861 | 1871 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1998 } | 2008 } |
| 1999 | 2009 |
| 2000 base::MessageLoop::current()->RunUntilIdle(); | 2010 base::MessageLoop::current()->RunUntilIdle(); |
| 2001 | 2011 |
| 2002 msgs.clear(); | 2012 msgs.clear(); |
| 2003 accum_.GetClassifiedMessages(&msgs); | 2013 accum_.GetClassifiedMessages(&msgs); |
| 2004 } | 2014 } |
| 2005 } | 2015 } |
| 2006 | 2016 |
| 2007 } // namespace content | 2017 } // namespace content |
| OLD | NEW |