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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 2005273002: Move MimeTypeResourceHandler before ThrottlingResourceHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed issue in ResourceDispatcherHostTests Created 4 years, 6 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 unified diff | Download patch
OLDNEW
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 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 SetResponse(raw_headers, response_data); 2562 SetResponse(raw_headers, response_data);
2563 job_factory_->SetDelayedCompleteJobGeneration(true); 2563 job_factory_->SetDelayedCompleteJobGeneration(true);
2564 HandleScheme("http"); 2564 HandleScheme("http");
2565 2565
2566 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2566 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2567 GURL("http://example.com/blah"), 2567 GURL("http://example.com/blah"),
2568 RESOURCE_TYPE_MAIN_FRAME); 2568 RESOURCE_TYPE_MAIN_FRAME);
2569 // Return some data so that the request is identified as a download 2569 // Return some data so that the request is identified as a download
2570 // and the proper resource handlers are created. 2570 // and the proper resource handlers are created.
2571 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2571 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2572 base::MessageLoop::current()->RunUntilIdle();
2572 2573
2573 // And now simulate a cancellation coming from the renderer. 2574 // And now simulate a cancellation coming from the renderer.
2574 ResourceHostMsg_CancelRequest msg(request_id); 2575 ResourceHostMsg_CancelRequest msg(request_id);
2575 host_.OnMessageReceived(msg, filter_.get()); 2576 host_.OnMessageReceived(msg, filter_.get());
2576 2577
2577 // Since the request had already started processing as a download, 2578 // Since the request had already started processing as a download,
2578 // the cancellation above should have been ignored and the request 2579 // the cancellation above should have been ignored and the request
2579 // should still be alive. 2580 // should still be alive.
2580 EXPECT_EQ(1, host_.pending_requests()); 2581 EXPECT_EQ(1, host_.pending_requests());
2581 2582
2582 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2583 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2584 base::MessageLoop::current()->RunUntilIdle();
2583 } 2585 }
2584 2586
2585 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) { 2587 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContext) {
2586 EXPECT_EQ(0, host_.pending_requests()); 2588 EXPECT_EQ(0, host_.pending_requests());
2587 2589
2588 int render_view_id = 0; 2590 int render_view_id = 0;
2589 int request_id = 1; 2591 int request_id = 1;
2590 2592
2591 std::string raw_headers("HTTP\n" 2593 std::string raw_headers("HTTP\n"
2592 "Content-disposition: attachment; filename=foo\n\n"); 2594 "Content-disposition: attachment; filename=foo\n\n");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 EXPECT_EQ(0, host_.pending_requests()); 2635 EXPECT_EQ(0, host_.pending_requests());
2634 2636
2635 base::RunLoop().RunUntilIdle(); 2637 base::RunLoop().RunUntilIdle();
2636 } else { 2638 } else {
2637 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2639 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2638 download_url, RESOURCE_TYPE_MAIN_FRAME); 2640 download_url, RESOURCE_TYPE_MAIN_FRAME);
2639 2641
2640 // Return some data so that the request is identified as a download 2642 // Return some data so that the request is identified as a download
2641 // and the proper resource handlers are created. 2643 // and the proper resource handlers are created.
2642 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2644 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2645 base::MessageLoop::current()->RunUntilIdle();
2643 2646
2644 // And now simulate a cancellation coming from the renderer. 2647 // And now simulate a cancellation coming from the renderer.
2645 ResourceHostMsg_CancelRequest msg(request_id); 2648 ResourceHostMsg_CancelRequest msg(request_id);
2646 host_.OnMessageReceived(msg, filter_.get()); 2649 host_.OnMessageReceived(msg, filter_.get());
2647 2650
2648 // Since the request had already started processing as a download, 2651 // Since the request had already started processing as a download,
2649 // the cancellation above should have been ignored and the request 2652 // the cancellation above should have been ignored and the request
2650 // should still be alive. 2653 // should still be alive.
2651 EXPECT_EQ(1, host_.pending_requests()); 2654 EXPECT_EQ(1, host_.pending_requests());
2652 2655
2653 // Cancelling by other methods shouldn't work either. 2656 // Cancelling by other methods shouldn't work either.
2654 host_.CancelRequestsForProcess(render_view_id); 2657 host_.CancelRequestsForProcess(render_view_id);
2655 EXPECT_EQ(1, host_.pending_requests()); 2658 EXPECT_EQ(1, host_.pending_requests());
2656 2659
2657 // Cancelling by context should work. 2660 // Cancelling by context should work.
2658 host_.CancelRequestsForContext(filter_->resource_context()); 2661 host_.CancelRequestsForContext(filter_->resource_context());
2659 EXPECT_EQ(0, host_.pending_requests()); 2662 EXPECT_EQ(0, host_.pending_requests());
2663
2664 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2665 base::RunLoop().RunUntilIdle();
2660 } 2666 }
2661 } 2667 }
2662 2668
2663 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { 2669 TEST_P(ResourceDispatcherHostTest, CancelRequestsForContextDetached) {
2664 EXPECT_EQ(0, host_.pending_requests()); 2670 EXPECT_EQ(0, host_.pending_requests());
2665 2671
2666 int render_view_id = 0; 2672 int render_view_id = 0;
2667 int request_id = 1; 2673 int request_id = 1;
2668 2674
2669 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2675 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
3021 SetResponse("HTTP/1.1 200 OK\n" 3027 SetResponse("HTTP/1.1 200 OK\n"
3022 "Content-Type: text/plain\n\n", 3028 "Content-Type: text/plain\n\n",
3023 kResponseBody); 3029 kResponseBody);
3024 ResourceHostMsg_FollowRedirect redirect_msg(request_id); 3030 ResourceHostMsg_FollowRedirect redirect_msg(request_id);
3025 host_.OnMessageReceived(redirect_msg, filter_.get()); 3031 host_.OnMessageReceived(redirect_msg, filter_.get());
3026 base::RunLoop().RunUntilIdle(); 3032 base::RunLoop().RunUntilIdle();
3027 3033
3028 // Flush all the pending requests to get the response through the 3034 // Flush all the pending requests to get the response through the
3029 // MimeTypeResourceHandler. 3035 // MimeTypeResourceHandler.
3030 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3036 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3037 base::MessageLoop::current()->RunUntilIdle();
3031 3038
3032 // Restore, now that we've set up a transfer. 3039 // Restore, now that we've set up a transfer.
3033 SetBrowserClientForTesting(old_client); 3040 SetBrowserClientForTesting(old_client);
3034 3041
3035 // This second filter is used to emulate a second process. 3042 // This second filter is used to emulate a second process.
3036 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3043 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3037 3044
3038 int new_render_view_id = 1; 3045 int new_render_view_id = 1;
3039 int new_request_id = 2; 3046 int new_request_id = 2;
3040 3047
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
3189 SetResponse("HTTP/1.1 200 OK\n" 3196 SetResponse("HTTP/1.1 200 OK\n"
3190 "Content-Type: text/plain\n\n", 3197 "Content-Type: text/plain\n\n",
3191 kResponseBody); 3198 kResponseBody);
3192 ResourceHostMsg_FollowRedirect redirect_msg2(request_id); 3199 ResourceHostMsg_FollowRedirect redirect_msg2(request_id);
3193 host_.OnMessageReceived(redirect_msg2, filter_.get()); 3200 host_.OnMessageReceived(redirect_msg2, filter_.get());
3194 base::RunLoop().RunUntilIdle(); 3201 base::RunLoop().RunUntilIdle();
3195 3202
3196 // Flush all the pending requests to get the response through the 3203 // Flush all the pending requests to get the response through the
3197 // MimeTypeResourceHandler. 3204 // MimeTypeResourceHandler.
3198 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 3205 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
3206 base::MessageLoop::current()->RunUntilIdle();
3199 3207
3200 // Restore. 3208 // Restore.
3201 SetBrowserClientForTesting(old_client); 3209 SetBrowserClientForTesting(old_client);
3202 3210
3203 // This second filter is used to emulate a second process. 3211 // This second filter is used to emulate a second process.
3204 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter(); 3212 scoped_refptr<ForwardingFilter> second_filter = MakeForwardingFilter();
3205 3213
3206 int new_render_view_id = 1; 3214 int new_render_view_id = 1;
3207 int new_request_id = 2; 3215 int new_request_id = 2;
3208 3216
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
3896 return nullptr; 3904 return nullptr;
3897 } 3905 }
3898 3906
3899 INSTANTIATE_TEST_CASE_P( 3907 INSTANTIATE_TEST_CASE_P(
3900 ResourceDispatcherHostTests, 3908 ResourceDispatcherHostTests,
3901 ResourceDispatcherHostTest, 3909 ResourceDispatcherHostTest,
3902 testing::Values(TestConfig::kDefault, 3910 testing::Values(TestConfig::kDefault,
3903 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3911 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3904 3912
3905 } // namespace content 3913 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698