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 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2279 | 2279 |
2280 // Check generated messages. | 2280 // Check generated messages. |
2281 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2281 ResourceIPCAccumulator::ClassifiedMessages msgs; |
2282 accum_.GetClassifiedMessages(&msgs); | 2282 accum_.GetClassifiedMessages(&msgs); |
2283 | 2283 |
2284 ASSERT_EQ(2U, msgs.size()); | 2284 ASSERT_EQ(2U, msgs.size()); |
2285 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2285 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
2286 CheckSuccessfulRequest(msgs[1], kResponseBody); | 2286 CheckSuccessfulRequest(msgs[1], kResponseBody); |
2287 } | 2287 } |
2288 | 2288 |
| 2289 // Test transferring two navigations with text/html, to ensure the resource |
| 2290 // accounting works. |
| 2291 TEST_F(ResourceDispatcherHostTest, TransferTwoNavigationsHtml) { |
| 2292 // This test expects the cross site request to be leaked, so it can transfer |
| 2293 // the request directly. |
| 2294 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); |
| 2295 |
| 2296 EXPECT_EQ(0, host_.pending_requests()); |
| 2297 |
| 2298 int render_view_id = 0; |
| 2299 int request_id = 1; |
| 2300 |
| 2301 // Configure initial request. |
| 2302 const std::string kResponseBody = "hello world"; |
| 2303 SetResponse("HTTP/1.1 200 OK\n" |
| 2304 "Content-Type: text/html\n\n", |
| 2305 kResponseBody); |
| 2306 |
| 2307 HandleScheme("http"); |
| 2308 |
| 2309 // Temporarily replace ContentBrowserClient with one that will trigger the |
| 2310 // transfer navigation code paths. |
| 2311 TransfersAllNavigationsContentBrowserClient new_client; |
| 2312 ContentBrowserClient* old_client = SetBrowserClientForTesting(&new_client); |
| 2313 |
| 2314 // Make the first request. |
| 2315 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
| 2316 GURL("http://example.com/blah"), |
| 2317 RESOURCE_TYPE_MAIN_FRAME); |
| 2318 |
| 2319 // Make a second request from the same process. |
| 2320 int second_request_id = 2; |
| 2321 MakeTestRequestWithResourceType(filter_.get(), render_view_id, |
| 2322 second_request_id, |
| 2323 GURL("http://example.com/foo"), |
| 2324 RESOURCE_TYPE_MAIN_FRAME); |
| 2325 |
| 2326 // Flush all the pending requests to get the response through the |
| 2327 // BufferedResourceHandler. |
| 2328 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2329 |
| 2330 // Restore, now that we've set up a transfer. |
| 2331 SetBrowserClientForTesting(old_client); |
| 2332 |
| 2333 // This second filter is used to emulate a second process. |
| 2334 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
| 2335 |
| 2336 // Transfer the first request. |
| 2337 int new_render_view_id = 1; |
| 2338 int new_request_id = 5; |
| 2339 ResourceHostMsg_Request request = |
| 2340 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME, |
| 2341 GURL("http://example.com/blah")); |
| 2342 request.transferred_request_child_id = filter_->child_id(); |
| 2343 request.transferred_request_request_id = request_id; |
| 2344 |
| 2345 ResourceHostMsg_RequestResource transfer_request_msg( |
| 2346 new_render_view_id, new_request_id, request); |
| 2347 host_.OnMessageReceived(transfer_request_msg, second_filter.get()); |
| 2348 base::MessageLoop::current()->RunUntilIdle(); |
| 2349 |
| 2350 // Transfer the second request. |
| 2351 int new_second_request_id = 6; |
| 2352 ResourceHostMsg_Request second_request = |
| 2353 CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME, |
| 2354 GURL("http://example.com/foo")); |
| 2355 request.transferred_request_child_id = filter_->child_id(); |
| 2356 request.transferred_request_request_id = second_request_id; |
| 2357 |
| 2358 ResourceHostMsg_RequestResource second_transfer_request_msg( |
| 2359 new_render_view_id, new_second_request_id, second_request); |
| 2360 host_.OnMessageReceived(second_transfer_request_msg, second_filter.get()); |
| 2361 base::MessageLoop::current()->RunUntilIdle(); |
| 2362 |
| 2363 // Check generated messages. |
| 2364 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2365 accum_.GetClassifiedMessages(&msgs); |
| 2366 |
| 2367 ASSERT_EQ(2U, msgs.size()); |
| 2368 CheckSuccessfulRequest(msgs[0], kResponseBody); |
| 2369 } |
| 2370 |
2289 // Test transferred navigations with text/plain, which causes | 2371 // Test transferred navigations with text/plain, which causes |
2290 // BufferedResourceHandler to buffer the response to sniff the content | 2372 // BufferedResourceHandler to buffer the response to sniff the content |
2291 // before the transfer occurs. | 2373 // before the transfer occurs. |
2292 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { | 2374 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { |
2293 // This test expects the cross site request to be leaked, so it can transfer | 2375 // This test expects the cross site request to be leaked, so it can transfer |
2294 // the request directly. | 2376 // the request directly. |
2295 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); | 2377 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); |
2296 | 2378 |
2297 EXPECT_EQ(0, host_.pending_requests()); | 2379 EXPECT_EQ(0, host_.pending_requests()); |
2298 | 2380 |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2919 } else { | 3001 } else { |
2920 return new net::URLRequestTestJob( | 3002 return new net::URLRequestTestJob( |
2921 request, network_delegate, | 3003 request, network_delegate, |
2922 test_fixture_->response_headers_, test_fixture_->response_data_, | 3004 test_fixture_->response_headers_, test_fixture_->response_data_, |
2923 false); | 3005 false); |
2924 } | 3006 } |
2925 } | 3007 } |
2926 } | 3008 } |
2927 | 3009 |
2928 } // namespace content | 3010 } // namespace content |
OLD | NEW |