| 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/run_loop.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
| 16 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
| 17 #include "content/browser/loader/cross_site_resource_handler.h" |
| 17 #include "content/browser/loader/detachable_resource_handler.h" | 18 #include "content/browser/loader/detachable_resource_handler.h" |
| 18 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 19 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 19 #include "content/browser/loader/resource_loader.h" | 20 #include "content/browser/loader/resource_loader.h" |
| 20 #include "content/browser/loader/resource_message_filter.h" | 21 #include "content/browser/loader/resource_message_filter.h" |
| 21 #include "content/browser/loader/resource_request_info_impl.h" | 22 #include "content/browser/loader/resource_request_info_impl.h" |
| 22 #include "content/browser/worker_host/worker_service_impl.h" | 23 #include "content/browser/worker_host/worker_service_impl.h" |
| 23 #include "content/common/child_process_host_impl.h" | 24 #include "content/common/child_process_host_impl.h" |
| 24 #include "content/common/resource_messages.h" | 25 #include "content/common/resource_messages.h" |
| 25 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
| 26 #include "content/public/browser/global_request_id.h" | 27 #include "content/public/browser/global_request_id.h" |
| (...skipping 2137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 EXPECT_EQ(1, host_.pending_requests()); | 2165 EXPECT_EQ(1, host_.pending_requests()); |
| 2165 | 2166 |
| 2166 // Cancelling by context should work. | 2167 // Cancelling by context should work. |
| 2167 host_.CancelRequestsForContext(filter_->resource_context()); | 2168 host_.CancelRequestsForContext(filter_->resource_context()); |
| 2168 EXPECT_EQ(0, host_.pending_requests()); | 2169 EXPECT_EQ(0, host_.pending_requests()); |
| 2169 } | 2170 } |
| 2170 | 2171 |
| 2171 // Test transferred navigations with text/html, which doesn't trigger any | 2172 // Test transferred navigations with text/html, which doesn't trigger any |
| 2172 // content sniffing. | 2173 // content sniffing. |
| 2173 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) { | 2174 TEST_F(ResourceDispatcherHostTest, TransferNavigationHtml) { |
| 2175 // This test expects the cross site request to be leaked, so it can transfer |
| 2176 // the request directly. |
| 2177 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); |
| 2178 |
| 2174 EXPECT_EQ(0, host_.pending_requests()); | 2179 EXPECT_EQ(0, host_.pending_requests()); |
| 2175 | 2180 |
| 2176 int render_view_id = 0; | 2181 int render_view_id = 0; |
| 2177 int request_id = 1; | 2182 int request_id = 1; |
| 2178 | 2183 |
| 2179 // Configure initial request. | 2184 // Configure initial request. |
| 2180 SetResponse("HTTP/1.1 302 Found\n" | 2185 SetResponse("HTTP/1.1 302 Found\n" |
| 2181 "Location: http://other.com/blech\n\n"); | 2186 "Location: http://other.com/blech\n\n"); |
| 2182 | 2187 |
| 2183 HandleScheme("http"); | 2188 HandleScheme("http"); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2236 | 2241 |
| 2237 ASSERT_EQ(2U, msgs.size()); | 2242 ASSERT_EQ(2U, msgs.size()); |
| 2238 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2243 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 2239 CheckSuccessfulRequest(msgs[1], kResponseBody); | 2244 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 2240 } | 2245 } |
| 2241 | 2246 |
| 2242 // Test transferred navigations with text/plain, which causes | 2247 // Test transferred navigations with text/plain, which causes |
| 2243 // BufferedResourceHandler to buffer the response to sniff the content | 2248 // BufferedResourceHandler to buffer the response to sniff the content |
| 2244 // before the transfer occurs. | 2249 // before the transfer occurs. |
| 2245 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { | 2250 TEST_F(ResourceDispatcherHostTest, TransferNavigationText) { |
| 2251 // This test expects the cross site request to be leaked, so it can transfer |
| 2252 // the request directly. |
| 2253 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); |
| 2254 |
| 2246 EXPECT_EQ(0, host_.pending_requests()); | 2255 EXPECT_EQ(0, host_.pending_requests()); |
| 2247 | 2256 |
| 2248 int render_view_id = 0; | 2257 int render_view_id = 0; |
| 2249 int request_id = 1; | 2258 int request_id = 1; |
| 2250 | 2259 |
| 2251 // Configure initial request. | 2260 // Configure initial request. |
| 2252 SetResponse("HTTP/1.1 302 Found\n" | 2261 SetResponse("HTTP/1.1 302 Found\n" |
| 2253 "Location: http://other.com/blech\n\n"); | 2262 "Location: http://other.com/blech\n\n"); |
| 2254 | 2263 |
| 2255 HandleScheme("http"); | 2264 HandleScheme("http"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2307 // Check generated messages. | 2316 // Check generated messages. |
| 2308 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2317 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2309 accum_.GetClassifiedMessages(&msgs); | 2318 accum_.GetClassifiedMessages(&msgs); |
| 2310 | 2319 |
| 2311 ASSERT_EQ(2U, msgs.size()); | 2320 ASSERT_EQ(2U, msgs.size()); |
| 2312 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2321 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 2313 CheckSuccessfulRequest(msgs[1], kResponseBody); | 2322 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 2314 } | 2323 } |
| 2315 | 2324 |
| 2316 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) { | 2325 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithProcessCrash) { |
| 2326 // This test expects the cross site request to be leaked, so it can transfer |
| 2327 // the request directly. |
| 2328 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); |
| 2329 |
| 2317 EXPECT_EQ(0, host_.pending_requests()); | 2330 EXPECT_EQ(0, host_.pending_requests()); |
| 2318 | 2331 |
| 2319 int render_view_id = 0; | 2332 int render_view_id = 0; |
| 2320 int request_id = 1; | 2333 int request_id = 1; |
| 2321 int first_child_id = -1; | 2334 int first_child_id = -1; |
| 2322 | 2335 |
| 2323 // Configure initial request. | 2336 // Configure initial request. |
| 2324 SetResponse("HTTP/1.1 302 Found\n" | 2337 SetResponse("HTTP/1.1 302 Found\n" |
| 2325 "Location: http://other.com/blech\n\n"); | 2338 "Location: http://other.com/blech\n\n"); |
| 2326 const std::string kResponseBody = "hello world"; | 2339 const std::string kResponseBody = "hello world"; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2397 // Check generated messages. | 2410 // Check generated messages. |
| 2398 ResourceIPCAccumulator::ClassifiedMessages msgs; | 2411 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 2399 accum_.GetClassifiedMessages(&msgs); | 2412 accum_.GetClassifiedMessages(&msgs); |
| 2400 | 2413 |
| 2401 ASSERT_EQ(2U, msgs.size()); | 2414 ASSERT_EQ(2U, msgs.size()); |
| 2402 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); | 2415 EXPECT_EQ(ResourceMsg_ReceivedRedirect::ID, msgs[0][0].type()); |
| 2403 CheckSuccessfulRequest(msgs[1], kResponseBody); | 2416 CheckSuccessfulRequest(msgs[1], kResponseBody); |
| 2404 } | 2417 } |
| 2405 | 2418 |
| 2406 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { | 2419 TEST_F(ResourceDispatcherHostTest, TransferNavigationWithTwoRedirects) { |
| 2420 // This test expects the cross site request to be leaked, so it can transfer |
| 2421 // the request directly. |
| 2422 CrossSiteResourceHandler::SetLeakRequestsForTesting(true); |
| 2423 |
| 2407 EXPECT_EQ(0, host_.pending_requests()); | 2424 EXPECT_EQ(0, host_.pending_requests()); |
| 2408 | 2425 |
| 2409 int render_view_id = 0; | 2426 int render_view_id = 0; |
| 2410 int request_id = 1; | 2427 int request_id = 1; |
| 2411 | 2428 |
| 2412 // Configure initial request. | 2429 // Configure initial request. |
| 2413 SetResponse("HTTP/1.1 302 Found\n" | 2430 SetResponse("HTTP/1.1 302 Found\n" |
| 2414 "Location: http://other.com/blech\n\n"); | 2431 "Location: http://other.com/blech\n\n"); |
| 2415 | 2432 |
| 2416 HandleScheme("http"); | 2433 HandleScheme("http"); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2690 } | 2707 } |
| 2691 | 2708 |
| 2692 base::MessageLoop::current()->RunUntilIdle(); | 2709 base::MessageLoop::current()->RunUntilIdle(); |
| 2693 | 2710 |
| 2694 msgs.clear(); | 2711 msgs.clear(); |
| 2695 accum_.GetClassifiedMessages(&msgs); | 2712 accum_.GetClassifiedMessages(&msgs); |
| 2696 } | 2713 } |
| 2697 } | 2714 } |
| 2698 | 2715 |
| 2699 } // namespace content | 2716 } // namespace content |
| OLD | NEW |