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" |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 delay_complete_ = delay_job_complete; | 701 delay_complete_ = delay_job_complete; |
702 } | 702 } |
703 | 703 |
704 void GenerateDataReceivedACK(const IPC::Message& msg) { | 704 void GenerateDataReceivedACK(const IPC::Message& msg) { |
705 EXPECT_EQ(ResourceMsg_DataReceived::ID, msg.type()); | 705 EXPECT_EQ(ResourceMsg_DataReceived::ID, msg.type()); |
706 | 706 |
707 int request_id = -1; | 707 int request_id = -1; |
708 bool result = PickleIterator(msg).ReadInt(&request_id); | 708 bool result = PickleIterator(msg).ReadInt(&request_id); |
709 DCHECK(result); | 709 DCHECK(result); |
710 scoped_ptr<IPC::Message> ack( | 710 scoped_ptr<IPC::Message> ack( |
711 new ResourceHostMsg_DataReceived_ACK(msg.routing_id(), request_id)); | 711 new ResourceHostMsg_DataReceived_ACK(request_id)); |
712 | 712 |
713 base::MessageLoop::current()->PostTask( | 713 base::MessageLoop::current()->PostTask( |
714 FROM_HERE, | 714 FROM_HERE, |
715 base::Bind(&GenerateIPCMessage, filter_, base::Passed(&ack))); | 715 base::Bind(&GenerateIPCMessage, filter_, base::Passed(&ack))); |
716 } | 716 } |
717 | 717 |
718 base::MessageLoopForIO message_loop_; | 718 base::MessageLoopForIO message_loop_; |
719 BrowserThreadImpl ui_thread_; | 719 BrowserThreadImpl ui_thread_; |
720 BrowserThreadImpl file_thread_; | 720 BrowserThreadImpl file_thread_; |
721 BrowserThreadImpl cache_thread_; | 721 BrowserThreadImpl cache_thread_; |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 SetResourceType(ResourceType::MAIN_FRAME); | 1602 SetResourceType(ResourceType::MAIN_FRAME); |
1603 SetDelayedCompleteJobGeneration(true); | 1603 SetDelayedCompleteJobGeneration(true); |
1604 HandleScheme("http"); | 1604 HandleScheme("http"); |
1605 | 1605 |
1606 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1606 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
1607 // Return some data so that the request is identified as a download | 1607 // Return some data so that the request is identified as a download |
1608 // and the proper resource handlers are created. | 1608 // and the proper resource handlers are created. |
1609 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1609 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1610 | 1610 |
1611 // And now simulate a cancellation coming from the renderer. | 1611 // And now simulate a cancellation coming from the renderer. |
1612 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); | 1612 ResourceHostMsg_CancelRequest msg(request_id); |
1613 bool msg_was_ok; | 1613 bool msg_was_ok; |
1614 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1614 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1615 | 1615 |
1616 // Since the request had already started processing as a download, | 1616 // Since the request had already started processing as a download, |
1617 // the cancellation above should have been ignored and the request | 1617 // the cancellation above should have been ignored and the request |
1618 // should still be alive. | 1618 // should still be alive. |
1619 EXPECT_EQ(1, host_.pending_requests()); | 1619 EXPECT_EQ(1, host_.pending_requests()); |
1620 | 1620 |
1621 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1621 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1622 } | 1622 } |
(...skipping 14 matching lines...) Expand all Loading... |
1637 SetResourceType(ResourceType::MAIN_FRAME); | 1637 SetResourceType(ResourceType::MAIN_FRAME); |
1638 SetDelayedCompleteJobGeneration(true); | 1638 SetDelayedCompleteJobGeneration(true); |
1639 HandleScheme("http"); | 1639 HandleScheme("http"); |
1640 | 1640 |
1641 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1641 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
1642 // Return some data so that the request is identified as a download | 1642 // Return some data so that the request is identified as a download |
1643 // and the proper resource handlers are created. | 1643 // and the proper resource handlers are created. |
1644 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 1644 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
1645 | 1645 |
1646 // And now simulate a cancellation coming from the renderer. | 1646 // And now simulate a cancellation coming from the renderer. |
1647 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); | 1647 ResourceHostMsg_CancelRequest msg(request_id); |
1648 bool msg_was_ok; | 1648 bool msg_was_ok; |
1649 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1649 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1650 | 1650 |
1651 // Since the request had already started processing as a download, | 1651 // Since the request had already started processing as a download, |
1652 // the cancellation above should have been ignored and the request | 1652 // the cancellation above should have been ignored and the request |
1653 // should still be alive. | 1653 // should still be alive. |
1654 EXPECT_EQ(1, host_.pending_requests()); | 1654 EXPECT_EQ(1, host_.pending_requests()); |
1655 | 1655 |
1656 // Cancelling by other methods shouldn't work either. | 1656 // Cancelling by other methods shouldn't work either. |
1657 host_.CancelRequestsForProcess(render_view_id); | 1657 host_.CancelRequestsForProcess(render_view_id); |
(...skipping 20 matching lines...) Expand all Loading... |
1678 SetResourceType(ResourceType::MAIN_FRAME); | 1678 SetResourceType(ResourceType::MAIN_FRAME); |
1679 HandleScheme("http"); | 1679 HandleScheme("http"); |
1680 | 1680 |
1681 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); | 1681 MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah")); |
1682 | 1682 |
1683 GlobalRequestID global_request_id(filter_->child_id(), request_id); | 1683 GlobalRequestID global_request_id(filter_->child_id(), request_id); |
1684 host_.MarkAsTransferredNavigation(global_request_id, | 1684 host_.MarkAsTransferredNavigation(global_request_id, |
1685 GURL("http://example.com/blah")); | 1685 GURL("http://example.com/blah")); |
1686 | 1686 |
1687 // And now simulate a cancellation coming from the renderer. | 1687 // And now simulate a cancellation coming from the renderer. |
1688 ResourceHostMsg_CancelRequest msg(filter_->child_id(), request_id); | 1688 ResourceHostMsg_CancelRequest msg(request_id); |
1689 bool msg_was_ok; | 1689 bool msg_was_ok; |
1690 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1690 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1691 | 1691 |
1692 // Since the request is marked as being transferred, | 1692 // Since the request is marked as being transferred, |
1693 // the cancellation above should have been ignored and the request | 1693 // the cancellation above should have been ignored and the request |
1694 // should still be alive. | 1694 // should still be alive. |
1695 EXPECT_EQ(1, host_.pending_requests()); | 1695 EXPECT_EQ(1, host_.pending_requests()); |
1696 | 1696 |
1697 // Cancelling by other methods shouldn't work either. | 1697 // Cancelling by other methods shouldn't work either. |
1698 host_.CancelRequestsForProcess(render_view_id); | 1698 host_.CancelRequestsForProcess(render_view_id); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1825 // OK, let the redirect happen. | 1825 // OK, let the redirect happen. |
1826 SetDelayedStartJobGeneration(false); | 1826 SetDelayedStartJobGeneration(false); |
1827 CompleteStartRequest(second_filter.get(), new_request_id); | 1827 CompleteStartRequest(second_filter.get(), new_request_id); |
1828 base::MessageLoop::current()->RunUntilIdle(); | 1828 base::MessageLoop::current()->RunUntilIdle(); |
1829 | 1829 |
1830 // Flush all the pending requests. | 1830 // Flush all the pending requests. |
1831 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1831 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1832 | 1832 |
1833 // Now, simulate the renderer choosing to follow the redirect. | 1833 // Now, simulate the renderer choosing to follow the redirect. |
1834 ResourceHostMsg_FollowRedirect redirect_msg( | 1834 ResourceHostMsg_FollowRedirect redirect_msg( |
1835 new_render_view_id, new_request_id, false, GURL()); | 1835 new_request_id, false, GURL()); |
1836 host_.OnMessageReceived(redirect_msg, second_filter.get(), &msg_was_ok); | 1836 host_.OnMessageReceived(redirect_msg, second_filter.get(), &msg_was_ok); |
1837 base::MessageLoop::current()->RunUntilIdle(); | 1837 base::MessageLoop::current()->RunUntilIdle(); |
1838 | 1838 |
1839 // Flush all the pending requests. | 1839 // Flush all the pending requests. |
1840 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1840 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
1841 | 1841 |
1842 // Check generated messages. | 1842 // Check generated messages. |
1843 ResourceIPCAccumulator::ClassifiedMessages msgs; | 1843 ResourceIPCAccumulator::ClassifiedMessages msgs; |
1844 accum_.GetClassifiedMessages(&msgs); | 1844 accum_.GetClassifiedMessages(&msgs); |
1845 | 1845 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 bool complete = false; | 1931 bool complete = false; |
1932 while (!complete) { | 1932 while (!complete) { |
1933 for (size_t i = 0; i < msgs[0].size(); ++i) { | 1933 for (size_t i = 0; i < msgs[0].size(); ++i) { |
1934 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) { | 1934 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) { |
1935 complete = true; | 1935 complete = true; |
1936 break; | 1936 break; |
1937 } | 1937 } |
1938 | 1938 |
1939 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 1939 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
1940 | 1940 |
1941 ResourceHostMsg_DataReceived_ACK msg(0, 1); | 1941 ResourceHostMsg_DataReceived_ACK msg(1); |
1942 bool msg_was_ok; | 1942 bool msg_was_ok; |
1943 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1943 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1944 } | 1944 } |
1945 | 1945 |
1946 base::MessageLoop::current()->RunUntilIdle(); | 1946 base::MessageLoop::current()->RunUntilIdle(); |
1947 | 1947 |
1948 msgs.clear(); | 1948 msgs.clear(); |
1949 accum_.GetClassifiedMessages(&msgs); | 1949 accum_.GetClassifiedMessages(&msgs); |
1950 } | 1950 } |
1951 } | 1951 } |
(...skipping 14 matching lines...) Expand all Loading... |
1966 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); | 1966 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type()); |
1967 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); | 1967 EXPECT_EQ(ResourceMsg_SetDataBuffer::ID, msgs[0][1].type()); |
1968 for (size_t i = 2; i < msgs[0].size(); ++i) | 1968 for (size_t i = 2; i < msgs[0].size(); ++i) |
1969 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 1969 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
1970 | 1970 |
1971 // NOTE: If we fail the above checks then it means that we probably didn't | 1971 // NOTE: If we fail the above checks then it means that we probably didn't |
1972 // load a big enough response to trigger the delay mechanism. | 1972 // load a big enough response to trigger the delay mechanism. |
1973 | 1973 |
1974 // Send some unexpected ACKs. | 1974 // Send some unexpected ACKs. |
1975 for (size_t i = 0; i < 128; ++i) { | 1975 for (size_t i = 0; i < 128; ++i) { |
1976 ResourceHostMsg_DataReceived_ACK msg(0, 1); | 1976 ResourceHostMsg_DataReceived_ACK msg(1); |
1977 bool msg_was_ok; | 1977 bool msg_was_ok; |
1978 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1978 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1979 } | 1979 } |
1980 | 1980 |
1981 msgs[0].erase(msgs[0].begin()); | 1981 msgs[0].erase(msgs[0].begin()); |
1982 msgs[0].erase(msgs[0].begin()); | 1982 msgs[0].erase(msgs[0].begin()); |
1983 | 1983 |
1984 // ACK all DataReceived messages until we find a RequestComplete message. | 1984 // ACK all DataReceived messages until we find a RequestComplete message. |
1985 bool complete = false; | 1985 bool complete = false; |
1986 while (!complete) { | 1986 while (!complete) { |
1987 for (size_t i = 0; i < msgs[0].size(); ++i) { | 1987 for (size_t i = 0; i < msgs[0].size(); ++i) { |
1988 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) { | 1988 if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) { |
1989 complete = true; | 1989 complete = true; |
1990 break; | 1990 break; |
1991 } | 1991 } |
1992 | 1992 |
1993 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); | 1993 EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type()); |
1994 | 1994 |
1995 ResourceHostMsg_DataReceived_ACK msg(0, 1); | 1995 ResourceHostMsg_DataReceived_ACK msg(1); |
1996 bool msg_was_ok; | 1996 bool msg_was_ok; |
1997 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); | 1997 host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok); |
1998 } | 1998 } |
1999 | 1999 |
2000 base::MessageLoop::current()->RunUntilIdle(); | 2000 base::MessageLoop::current()->RunUntilIdle(); |
2001 | 2001 |
2002 msgs.clear(); | 2002 msgs.clear(); |
2003 accum_.GetClassifiedMessages(&msgs); | 2003 accum_.GetClassifiedMessages(&msgs); |
2004 } | 2004 } |
2005 } | 2005 } |
2006 | 2006 |
2007 } // namespace content | 2007 } // namespace content |
OLD | NEW |