Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Unified Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 15476003: Move TransferNavigationResourceThrottle into CrossSiteResourceHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get tests to pass Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.cc ('k') | content/browser/loader/resource_loader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/loader/resource_dispatcher_host_unittest.cc
diff --git a/content/browser/loader/resource_dispatcher_host_unittest.cc b/content/browser/loader/resource_dispatcher_host_unittest.cc
index 13895b0c61a99531564f87829e6b3a481cb0210b..c5f26de6e0309d1060a6c36decb66f92d8990515 100644
--- a/content/browser/loader/resource_dispatcher_host_unittest.cc
+++ b/content/browser/loader/resource_dispatcher_host_unittest.cc
@@ -1723,7 +1723,23 @@ TEST_F(ResourceDispatcherHostTest, TransferNavigation) {
MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
- // Restore.
+ // Now that we're blocked on the redirect, update the response and unblock by
+ // telling the AsyncResourceHandler to follow the redirect.
+ const std::string kResponseBody = "hello world";
+ SetResponse("HTTP/1.1 200 OK\n"
+ "Content-Type: text/plain\n\n",
+ kResponseBody);
+ ResourceHostMsg_FollowRedirect redirect_msg(
+ render_view_id, request_id, false, GURL());
+ bool msg_was_ok;
+ host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok);
+ 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.
+
+ // Flush all the pending requests to get the response through the
+ // BufferedResourceHandler.
+ while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
+
+ // Restore, now that we've set up a transfer.
SetBrowserClientForTesting(old_client);
// This second filter is used to emulate a second process.
@@ -1733,11 +1749,6 @@ TEST_F(ResourceDispatcherHostTest, TransferNavigation) {
int new_render_view_id = 1;
int new_request_id = 2;
- const std::string kResponseBody = "hello world";
- SetResponse("HTTP/1.1 200 OK\n"
- "Content-Type: text/plain\n\n",
- kResponseBody);
-
ResourceHostMsg_Request request =
CreateResourceRequest("GET", ResourceType::MAIN_FRAME,
GURL("http://other.com/blech"));
@@ -1748,7 +1759,6 @@ TEST_F(ResourceDispatcherHostTest, TransferNavigation) {
child_ids_.insert(second_filter->child_id());
ResourceHostMsg_RequestResource transfer_request_msg(
new_render_view_id, new_request_id, request);
- bool msg_was_ok;
host_.OnMessageReceived(
transfer_request_msg, second_filter.get(), &msg_was_ok);
base::MessageLoop::current()->RunUntilIdle();
@@ -1760,11 +1770,15 @@ TEST_F(ResourceDispatcherHostTest, TransferNavigation) {
ResourceIPCAccumulator::ClassifiedMessages msgs;
accum_.GetClassifiedMessages(&msgs);
- ASSERT_EQ(1U, msgs.size());
- CheckSuccessfulRequest(msgs[0], kResponseBody);
+ // 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
+ // for, since most were handled before the transfer.
+ ASSERT_EQ(2U, msgs.size());
+ ASSERT_EQ(2U, msgs[1].size());
+ EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type());
+ EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type());
}
-TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) {
+TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) {
EXPECT_EQ(0, host_.pending_requests());
int render_view_id = 0;
@@ -1784,6 +1798,30 @@ TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) {
MakeTestRequest(render_view_id, request_id, GURL("http://example.com/blah"));
+ // Now that we're blocked on the redirect, simulate hitting another redirect.
+ SetResponse("HTTP/1.1 302 Found\n"
+ "Location: http://other.com/blerg\n\n");
+ ResourceHostMsg_FollowRedirect redirect_msg(
+ render_view_id, request_id, false, GURL());
+ bool msg_was_ok;
+ host_.OnMessageReceived(redirect_msg, filter_.get(), &msg_was_ok);
+ base::MessageLoop::current()->RunUntilIdle();
+
+ // Now that we're blocked on the second redirect, update the response and
+ // unblock by telling the AsyncResourceHandler to follow the redirect.
+ const std::string kResponseBody = "hello world";
+ SetResponse("HTTP/1.1 200 OK\n"
+ "Content-Type: text/plain\n\n",
+ kResponseBody);
+ ResourceHostMsg_FollowRedirect redirect_msg2(
+ render_view_id, request_id, false, GURL());
+ host_.OnMessageReceived(redirect_msg2, filter_.get(), &msg_was_ok);
+ base::MessageLoop::current()->RunUntilIdle();
+
+ // Flush all the pending requests to get the response through the
+ // BufferedResourceHandler.
+ while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
+
// Restore.
SetBrowserClientForTesting(old_client);
@@ -1794,13 +1832,6 @@ TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) {
int new_render_view_id = 1;
int new_request_id = 2;
- // Delay the start of the next request so that we can setup the response for
- // the next URL.
- SetDelayedStartJobGeneration(true);
-
- SetResponse("HTTP/1.1 302 Found\n"
- "Location: http://other.com/blerg\n\n");
-
ResourceHostMsg_Request request =
CreateResourceRequest("GET", ResourceType::MAIN_FRAME,
GURL("http://other.com/blech"));
@@ -1811,31 +1842,10 @@ TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) {
child_ids_.insert(second_filter->child_id());
ResourceHostMsg_RequestResource transfer_request_msg(
new_render_view_id, new_request_id, request);
- bool msg_was_ok;
host_.OnMessageReceived(
transfer_request_msg, second_filter.get(), &msg_was_ok);
base::MessageLoop::current()->RunUntilIdle();
- // Response data for "http://other.com/blerg":
- const std::string kResponseBody = "hello world";
- SetResponse("HTTP/1.1 200 OK\n"
- "Content-Type: text/plain\n\n",
- kResponseBody);
-
- // OK, let the redirect happen.
- SetDelayedStartJobGeneration(false);
- CompleteStartRequest(second_filter.get(), new_request_id);
- base::MessageLoop::current()->RunUntilIdle();
-
- // Flush all the pending requests.
- while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
-
- // Now, simulate the renderer choosing to follow the redirect.
- ResourceHostMsg_FollowRedirect redirect_msg(
- new_render_view_id, new_request_id, false, GURL());
- host_.OnMessageReceived(redirect_msg, second_filter.get(), &msg_was_ok);
- base::MessageLoop::current()->RunUntilIdle();
-
// Flush all the pending requests.
while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
@@ -1843,12 +1853,12 @@ TEST_F(ResourceDispatcherHostTest, TransferNavigationAndThenRedirect) {
ResourceIPCAccumulator::ClassifiedMessages msgs;
accum_.GetClassifiedMessages(&msgs);
- ASSERT_EQ(1U, msgs.size());
-
- // We should have received a redirect followed by a "normal" payload.
- EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type());
- msgs[0].erase(msgs[0].begin());
- CheckSuccessfulRequest(msgs[0], kResponseBody);
+ // 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.
+ // for, since most were handled before the transfer.
+ ASSERT_EQ(2U, msgs.size());
+ ASSERT_EQ(2U, msgs[1].size());
+ EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[1][0].type());
+ EXPECT_EQ(ResourceMsg_RequestComplete::ID, msgs[1][1].type());
}
TEST_F(ResourceDispatcherHostTest, UnknownURLScheme) {
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.cc ('k') | content/browser/loader/resource_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698