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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 2484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2495 SetResponse(raw_headers, response_data); | 2495 SetResponse(raw_headers, response_data); |
2496 job_factory_->SetDelayedCompleteJobGeneration(true); | 2496 job_factory_->SetDelayedCompleteJobGeneration(true); |
2497 HandleScheme("http"); | 2497 HandleScheme("http"); |
2498 | 2498 |
2499 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 2499 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
2500 GURL("http://example.com/blah"), | 2500 GURL("http://example.com/blah"), |
2501 RESOURCE_TYPE_MAIN_FRAME); | 2501 RESOURCE_TYPE_MAIN_FRAME); |
2502 // Return some data so that the request is identified as a download | 2502 // Return some data so that the request is identified as a download |
2503 // and the proper resource handlers are created. | 2503 // and the proper resource handlers are created. |
2504 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 2504 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 2505 base::MessageLoop::current()->RunUntilIdle(); |
2505 | 2506 |
2506 // And now simulate a cancellation coming from the renderer. | 2507 // And now simulate a cancellation coming from the renderer. |
2507 ResourceHostMsg_CancelRequest msg(request_id); | 2508 ResourceHostMsg_CancelRequest msg(request_id); |
2508 host_.OnMessageReceived(msg, filter_.get()); | 2509 host_.OnMessageReceived(msg, filter_.get()); |
2509 | 2510 |
2510 // Since the request had already started processing as a download, | 2511 // Since the request had already started processing as a download, |
2511 // the cancellation above should have been ignored and the request | 2512 // the cancellation above should have been ignored and the request |
2512 // should still be alive. | 2513 // should still be alive. |
2513 EXPECT_EQ(1, host_.pending_requests()); | 2514 EXPECT_EQ(1, host_.pending_requests()); |
2514 | 2515 |
2515 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2516 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2517 base::MessageLoop::current()->RunUntilIdle(); |
2516 } | 2518 } |
2517 | 2519 |
2518 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) { | 2520 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) { |
2519 EXPECT_EQ(0, host_.pending_requests()); | 2521 EXPECT_EQ(0, host_.pending_requests()); |
2520 | 2522 |
2521 int render_view_id = 0; | 2523 int render_view_id = 0; |
2522 int request_id = 1; | 2524 int request_id = 1; |
2523 | 2525 |
2524 std::string raw_headers("HTTP\n" | 2526 std::string raw_headers("HTTP\n" |
2525 "Content-disposition: attachment; filename=foo\n\n"); | 2527 "Content-disposition: attachment; filename=foo\n\n"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2566 EXPECT_EQ(0, host_.pending_requests()); | 2568 EXPECT_EQ(0, host_.pending_requests()); |
2567 | 2569 |
2568 base::RunLoop().RunUntilIdle(); | 2570 base::RunLoop().RunUntilIdle(); |
2569 } else { | 2571 } else { |
2570 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 2572 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
2571 download_url, RESOURCE_TYPE_MAIN_FRAME); | 2573 download_url, RESOURCE_TYPE_MAIN_FRAME); |
2572 | 2574 |
2573 // Return some data so that the request is identified as a download | 2575 // Return some data so that the request is identified as a download |
2574 // and the proper resource handlers are created. | 2576 // and the proper resource handlers are created. |
2575 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 2577 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
| 2578 base::MessageLoop::current()->RunUntilIdle(); |
2576 | 2579 |
2577 // And now simulate a cancellation coming from the renderer. | 2580 // And now simulate a cancellation coming from the renderer. |
2578 ResourceHostMsg_CancelRequest msg(request_id); | 2581 ResourceHostMsg_CancelRequest msg(request_id); |
2579 host_.OnMessageReceived(msg, filter_.get()); | 2582 host_.OnMessageReceived(msg, filter_.get()); |
2580 | 2583 |
2581 // Since the request had already started processing as a download, | 2584 // Since the request had already started processing as a download, |
2582 // the cancellation above should have been ignored and the request | 2585 // the cancellation above should have been ignored and the request |
2583 // should still be alive. | 2586 // should still be alive. |
2584 EXPECT_EQ(1, host_.pending_requests()); | 2587 EXPECT_EQ(1, host_.pending_requests()); |
2585 | 2588 |
2586 // Cancelling by other methods shouldn't work either. | 2589 // Cancelling by other methods shouldn't work either. |
2587 host_.CancelRequestsForProcess(render_view_id); | 2590 host_.CancelRequestsForProcess(render_view_id); |
2588 EXPECT_EQ(1, host_.pending_requests()); | 2591 EXPECT_EQ(1, host_.pending_requests()); |
2589 | 2592 |
2590 // Cancelling by context should work. | 2593 // Cancelling by context should work. |
2591 host_.CancelRequestsForContext(filter_->resource_context()); | 2594 host_.CancelRequestsForContext(filter_->resource_context()); |
2592 EXPECT_EQ(0, host_.pending_requests()); | 2595 EXPECT_EQ(0, host_.pending_requests()); |
| 2596 |
| 2597 while (net::URLRequestTestJob::ProcessOnePendingMessage()) { |
| 2598 } |
| 2599 base::RunLoop().RunUntilIdle(); |
2593 } | 2600 } |
2594 } | 2601 } |
2595 | 2602 |
2596 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { | 2603 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { |
2597 EXPECT_EQ(0, host_.pending_requests()); | 2604 EXPECT_EQ(0, host_.pending_requests()); |
2598 | 2605 |
2599 int render_view_id = 0; | 2606 int render_view_id = 0; |
2600 int request_id = 1; | 2607 int request_id = 1; |
2601 | 2608 |
2602 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, | 2609 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2954 SetResponse("HTTP/1.1 200 OK\n" | 2961 SetResponse("HTTP/1.1 200 OK\n" |
2955 "Content-Type: text/plain\n\n", | 2962 "Content-Type: text/plain\n\n", |
2956 kResponseBody); | 2963 kResponseBody); |
2957 ResourceHostMsg_FollowRedirect redirect_msg(request_id); | 2964 ResourceHostMsg_FollowRedirect redirect_msg(request_id); |
2958 host_.OnMessageReceived(redirect_msg, filter_.get()); | 2965 host_.OnMessageReceived(redirect_msg, filter_.get()); |
2959 base::RunLoop().RunUntilIdle(); | 2966 base::RunLoop().RunUntilIdle(); |
2960 | 2967 |
2961 // Flush all the pending requests to get the response through the | 2968 // Flush all the pending requests to get the response through the |
2962 // MimeTypeResourceHandler. | 2969 // MimeTypeResourceHandler. |
2963 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 2970 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 2971 base::MessageLoop::current()->RunUntilIdle(); |
2964 | 2972 |
2965 // Restore, now that we've set up a transfer. | 2973 // Restore, now that we've set up a transfer. |
2966 SetBrowserClientForTesting(old_client); | 2974 SetBrowserClientForTesting(old_client); |
2967 | 2975 |
2968 // This second filter is used to emulate a second process. | 2976 // This second filter is used to emulate a second process. |
2969 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 2977 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
2970 | 2978 |
2971 int new_render_view_id = 1; | 2979 int new_render_view_id = 1; |
2972 int new_request_id = 2; | 2980 int new_request_id = 2; |
2973 | 2981 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3122 SetResponse("HTTP/1.1 200 OK\n" | 3130 SetResponse("HTTP/1.1 200 OK\n" |
3123 "Content-Type: text/plain\n\n", | 3131 "Content-Type: text/plain\n\n", |
3124 kResponseBody); | 3132 kResponseBody); |
3125 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); | 3133 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); |
3126 host_.OnMessageReceived(redirect_msg2, filter_.get()); | 3134 host_.OnMessageReceived(redirect_msg2, filter_.get()); |
3127 base::RunLoop().RunUntilIdle(); | 3135 base::RunLoop().RunUntilIdle(); |
3128 | 3136 |
3129 // Flush all the pending requests to get the response through the | 3137 // Flush all the pending requests to get the response through the |
3130 // MimeTypeResourceHandler. | 3138 // MimeTypeResourceHandler. |
3131 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 3139 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 3140 base::MessageLoop::current()->RunUntilIdle(); |
3132 | 3141 |
3133 // Restore. | 3142 // Restore. |
3134 SetBrowserClientForTesting(old_client); | 3143 SetBrowserClientForTesting(old_client); |
3135 | 3144 |
3136 // This second filter is used to emulate a second process. | 3145 // This second filter is used to emulate a second process. |
3137 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); | 3146 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); |
3138 | 3147 |
3139 int new_render_view_id = 1; | 3148 int new_render_view_id = 1; |
3140 int new_request_id = 2; | 3149 int new_request_id = 2; |
3141 | 3150 |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3823 return nullptr; | 3832 return nullptr; |
3824 } | 3833 } |
3825 | 3834 |
3826 INSTANTIATE_TEST_CASE_P( | 3835 INSTANTIATE_TEST_CASE_P( |
3827 ResourceDispatcherHostTests, | 3836 ResourceDispatcherHostTests, |
3828 ResourceDispatcherHostTest, | 3837 ResourceDispatcherHostTest, |
3829 testing::Values(TestConfig::kDefault, | 3838 testing::Values(TestConfig::kDefault, |
3830 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3839 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
3831 | 3840 |
3832 } // namespace content | 3841 } // namespace content |
OLD | NEW |