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

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

Issue 2847443002: PlzNavigate: make NavigationResourceHandler a LayeredResourceHandler (Closed)
Patch Set: Addressed comments Created 3 years, 7 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 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2552 // Since the request had already started processing as a download, 2552 // Since the request had already started processing as a download,
2553 // the cancellation above should have been ignored and the request 2553 // the cancellation above should have been ignored and the request
2554 // should still be alive. 2554 // should still be alive.
2555 EXPECT_EQ(1, host_.pending_requests()); 2555 EXPECT_EQ(1, host_.pending_requests());
2556 2556
2557 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} 2557 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {}
2558 content::RunAllBlockingPoolTasksUntilIdle(); 2558 content::RunAllBlockingPoolTasksUntilIdle();
2559 } 2559 }
2560 2560
2561 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContext) { 2561 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContext) {
2562 if (IsBrowserSideNavigationEnabled())
2563 return;
2564
2562 EXPECT_EQ(0, host_.pending_requests()); 2565 EXPECT_EQ(0, host_.pending_requests());
2563 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true); 2566 NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(true);
2564 2567
2565 int render_view_id = 0; 2568 int render_view_id = 0;
2566 int request_id = 1; 2569 int request_id = 1;
2567 2570
2568 std::string raw_headers("HTTP\n" 2571 std::string raw_headers("HTTP\n"
2569 "Content-disposition: attachment; filename=foo\n\n"); 2572 "Content-disposition: attachment; filename=foo\n\n");
2570 std::string response_data("01234567890123456789\x01foobar"); 2573 std::string response_data("01234567890123456789\x01foobar");
2571 // Get past sniffing metrics. 2574 // Get past sniffing metrics.
2572 response_data.resize(1025, ' '); 2575 response_data.resize(1025, ' ');
2573 2576
2574 SetResponse(raw_headers, response_data); 2577 SetResponse(raw_headers, response_data);
2575 job_factory_->SetDelayedCompleteJobGeneration(true); 2578 job_factory_->SetDelayedCompleteJobGeneration(true);
2576 HandleScheme("http"); 2579 HandleScheme("http");
2577 2580
2578 const GURL download_url = GURL("http://example.com/blah"); 2581 const GURL download_url = GURL("http://example.com/blah");
2579 2582
2580 if (IsBrowserSideNavigationEnabled()) { 2583 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2581 // Create a NavigationRequest. 2584 download_url, RESOURCE_TYPE_MAIN_FRAME);
2582 TestNavigationURLLoaderDelegate delegate;
2583 BeginNavigationParams begin_params(
2584 std::string(), net::LOAD_NORMAL, false, false,
2585 REQUEST_CONTEXT_TYPE_LOCATION,
2586 blink::WebMixedContentContextType::kBlockable,
2587 false, // is_form_submission
2588 url::Origin(download_url));
2589 CommonNavigationParams common_params;
2590 common_params.url = download_url;
2591 std::unique_ptr<NavigationRequestInfo> request_info(
2592 new NavigationRequestInfo(common_params, begin_params, download_url,
2593 true, false, false, -1, false, false,
2594 blink::kWebPageVisibilityStateVisible));
2595 std::unique_ptr<NavigationURLLoader> loader = NavigationURLLoader::Create(
2596 browser_context_->GetResourceContext(),
2597 BrowserContext::GetDefaultStoragePartition(browser_context_.get()),
2598 std::move(request_info), nullptr, nullptr, nullptr, &delegate);
2599 2585
2600 // Wait until a response has been received and proceed with the response. 2586 // Return some data so that the request is identified as a download
2601 KickOffRequest(); 2587 // and the proper resource handlers are created.
2588 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2589 content::RunAllBlockingPoolTasksUntilIdle();
2602 2590
2603 // Return some data so that the request is identified as a download 2591 // And now simulate a cancellation coming from the renderer.
2604 // and the proper resource handlers are created. 2592 ResourceHostMsg_CancelRequest msg(request_id);
2605 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); 2593 OnMessageReceived(msg, filter_.get());
2606 content::RunAllBlockingPoolTasksUntilIdle();
2607 2594
2608 // The UI thread will be informed that the navigation failed with an error 2595 // Since the request had already started processing as a download,
2609 // code of ERR_ABORTED because the navigation turns out to be a download. 2596 // the cancellation above should have been ignored and the request
2610 // The navigation is aborted, but the request goes on as a download. 2597 // should still be alive.
2611 EXPECT_EQ(delegate.net_error(), net::ERR_ABORTED); 2598 EXPECT_EQ(1, host_.pending_requests());
2612 EXPECT_EQ(1, host_.pending_requests());
2613 2599
2614 // In PlzNavigate, the renderer cannot cancel the request directly. 2600 // Cancelling by other methods shouldn't work either.
2615 // However, cancelling by context should work. 2601 host_.CancelRequestsForProcess(render_view_id);
2616 host_.CancelRequestsForContext(browser_context_->GetResourceContext()); 2602 EXPECT_EQ(1, host_.pending_requests());
2617 EXPECT_EQ(0, host_.pending_requests());
2618 2603
2619 content::RunAllBlockingPoolTasksUntilIdle(); 2604 // Cancelling by context should work.
2620 } else { 2605 host_.CancelRequestsForContext(filter_->resource_context());
2621 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2606 EXPECT_EQ(0, host_.pending_requests());
2622 download_url, RESOURCE_TYPE_MAIN_FRAME);
2623 2607
2624 // Return some data so that the request is identified as a download 2608 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {
2625 // and the proper resource handlers are created.
2626 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage());
2627 content::RunAllBlockingPoolTasksUntilIdle();
2628
2629 // And now simulate a cancellation coming from the renderer.
2630 ResourceHostMsg_CancelRequest msg(request_id);
2631 OnMessageReceived(msg, filter_.get());
2632
2633 // Since the request had already started processing as a download,
2634 // the cancellation above should have been ignored and the request
2635 // should still be alive.
2636 EXPECT_EQ(1, host_.pending_requests());
2637
2638 // Cancelling by other methods shouldn't work either.
2639 host_.CancelRequestsForProcess(render_view_id);
2640 EXPECT_EQ(1, host_.pending_requests());
2641
2642 // Cancelling by context should work.
2643 host_.CancelRequestsForContext(filter_->resource_context());
2644 EXPECT_EQ(0, host_.pending_requests());
2645
2646 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {
2647 }
2648 content::RunAllBlockingPoolTasksUntilIdle();
2649 } 2609 }
2610 content::RunAllBlockingPoolTasksUntilIdle();
2650 } 2611 }
2651 2612
2652 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) { 2613 TEST_F(ResourceDispatcherHostTest, CancelRequestsForContextDetached) {
2653 EXPECT_EQ(0, host_.pending_requests()); 2614 EXPECT_EQ(0, host_.pending_requests());
2654 2615
2655 int render_view_id = 0; 2616 int render_view_id = 0;
2656 int request_id = 1; 2617 int request_id = 1;
2657 2618
2658 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id, 2619 MakeTestRequestWithResourceType(filter_.get(), render_view_id, request_id,
2659 net::URLRequestTestJob::test_url_4(), 2620 net::URLRequestTestJob::test_url_4(),
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after
3928 return nullptr; 3889 return nullptr;
3929 } 3890 }
3930 3891
3931 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( 3892 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse(
3932 net::URLRequest* request, 3893 net::URLRequest* request,
3933 net::NetworkDelegate* network_delegate) const { 3894 net::NetworkDelegate* network_delegate) const {
3934 return nullptr; 3895 return nullptr;
3935 } 3896 }
3936 3897
3937 } // namespace content 3898 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.cc ('k') | content/browser/loader/stream_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698