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

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

Issue 2251643003: Remove the BeginSaveFile and BeginDownload methods from ResourceDispatcherHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move the blob code to RDHI::BeginURLRequest Created 4 years, 3 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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "base/memory/shared_memory.h" 18 #include "base/memory/shared_memory.h"
19 #include "base/pickle.h" 19 #include "base/pickle.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
24 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
25 #include "content/browser/browser_thread_impl.h" 25 #include "content/browser/browser_thread_impl.h"
26 #include "content/browser/cert_store_impl.h" 26 #include "content/browser/cert_store_impl.h"
27 #include "content/browser/child_process_security_policy_impl.h" 27 #include "content/browser/child_process_security_policy_impl.h"
28 #include "content/browser/download/download_resource_handler.h"
28 #include "content/browser/frame_host/navigation_request_info.h" 29 #include "content/browser/frame_host/navigation_request_info.h"
29 #include "content/browser/loader/cross_site_resource_handler.h" 30 #include "content/browser/loader/cross_site_resource_handler.h"
30 #include "content/browser/loader/detachable_resource_handler.h" 31 #include "content/browser/loader/detachable_resource_handler.h"
31 #include "content/browser/loader/navigation_url_loader.h" 32 #include "content/browser/loader/navigation_url_loader.h"
32 #include "content/browser/loader/resource_dispatcher_host_impl.h" 33 #include "content/browser/loader/resource_dispatcher_host_impl.h"
33 #include "content/browser/loader/resource_loader.h" 34 #include "content/browser/loader/resource_loader.h"
34 #include "content/browser/loader/resource_message_filter.h" 35 #include "content/browser/loader/resource_message_filter.h"
35 #include "content/browser/loader/resource_request_info_impl.h" 36 #include "content/browser/loader/resource_request_info_impl.h"
36 #include "content/browser/loader_delegate_impl.h" 37 #include "content/browser/loader_delegate_impl.h"
37 #include "content/common/appcache_interfaces.h" 38 #include "content/common/appcache_interfaces.h"
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 } 848 }
848 849
849 class ResourceDispatcherHostTest : public testing::TestWithParam<TestConfig>, 850 class ResourceDispatcherHostTest : public testing::TestWithParam<TestConfig>,
850 public IPC::Sender { 851 public IPC::Sender {
851 public: 852 public:
852 typedef ResourceDispatcherHostImpl::LoadInfo LoadInfo; 853 typedef ResourceDispatcherHostImpl::LoadInfo LoadInfo;
853 typedef ResourceDispatcherHostImpl::LoadInfoMap LoadInfoMap; 854 typedef ResourceDispatcherHostImpl::LoadInfoMap LoadInfoMap;
854 855
855 ResourceDispatcherHostTest() 856 ResourceDispatcherHostTest()
856 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 857 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
858 host_(base::Bind(base::Bind(&DownloadResourceHandler::Create))),
857 use_test_ssl_certificate_(false), 859 use_test_ssl_certificate_(false),
858 send_data_received_acks_(false), 860 send_data_received_acks_(false),
859 auto_advance_(false) { 861 auto_advance_(false) {
860 host_.SetLoaderDelegate(&loader_delegate_); 862 host_.SetLoaderDelegate(&loader_delegate_);
861 browser_context_.reset(new TestBrowserContext()); 863 browser_context_.reset(new TestBrowserContext());
862 BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); 864 BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
863 base::RunLoop().RunUntilIdle(); 865 base::RunLoop().RunUntilIdle();
864 filter_ = MakeForwardingFilter(); 866 filter_ = MakeForwardingFilter();
865 // TODO(cbentzel): Better way to get URLRequestContext? 867 // TODO(cbentzel): Better way to get URLRequestContext?
866 net::URLRequestContext* request_context = 868 net::URLRequestContext* request_context =
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 // Generates a request with the given priority. 1002 // Generates a request with the given priority.
1001 void MakeTestRequestWithPriority(int render_view_id, 1003 void MakeTestRequestWithPriority(int render_view_id,
1002 int request_id, 1004 int request_id,
1003 net::RequestPriority priority); 1005 net::RequestPriority priority);
1004 1006
1005 void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id, 1007 void MakeTestRequestWithPriorityAndRenderFrame(int render_view_id,
1006 int render_frame_id, 1008 int render_frame_id,
1007 int request_id, 1009 int request_id,
1008 net::RequestPriority priority); 1010 net::RequestPriority priority);
1009 1011
1010 void MakeWebContentsAssociatedDownloadRequest(int request_id,
1011 const GURL& url);
1012
1013 void CancelRequest(int request_id); 1012 void CancelRequest(int request_id);
1014 void RendererCancelRequest(int request_id) { 1013 void RendererCancelRequest(int request_id) {
1015 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); 1014 ResourceMessageFilter* old_filter = SetFilter(filter_.get());
1016 host_.OnCancelRequest(request_id); 1015 host_.OnCancelRequest(request_id);
1017 SetFilter(old_filter); 1016 SetFilter(old_filter);
1018 } 1017 }
1019 1018
1020 void CompleteStartRequest(int request_id); 1019 void CompleteStartRequest(int request_id);
1021 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); 1020 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id);
1022 1021
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 int request_id, 1227 int request_id,
1229 net::RequestPriority priority) { 1228 net::RequestPriority priority) {
1230 ResourceRequest request = CreateResourceRequest( 1229 ResourceRequest request = CreateResourceRequest(
1231 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority")); 1230 "GET", RESOURCE_TYPE_SUB_RESOURCE, GURL("http://example.com/priority"));
1232 request.render_frame_id = render_frame_id; 1231 request.render_frame_id = render_frame_id;
1233 request.priority = priority; 1232 request.priority = priority;
1234 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); 1233 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request);
1235 host_.OnMessageReceived(msg, filter_.get()); 1234 host_.OnMessageReceived(msg, filter_.get());
1236 } 1235 }
1237 1236
1238 void ResourceDispatcherHostTest::MakeWebContentsAssociatedDownloadRequest(
1239 int request_id,
1240 const GURL& url) {
1241 net::URLRequestContext* request_context =
1242 browser_context_->GetResourceContext()->GetRequestContext();
1243 std::unique_ptr<net::URLRequest> request(
1244 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL));
1245 host_.BeginDownload(std::move(request), Referrer(),
1246 false, // is_content_initiated
1247 browser_context_->GetResourceContext(),
1248 web_contents_->GetRenderProcessHost()->GetID(),
1249 web_contents_->GetRoutingID(),
1250 web_contents_->GetMainFrame()->GetRoutingID(), false);
1251 }
1252
1253 void ResourceDispatcherHostTest::CancelRequest(int request_id) { 1237 void ResourceDispatcherHostTest::CancelRequest(int request_id) {
1254 host_.CancelRequest(filter_->child_id(), request_id); 1238 host_.CancelRequest(filter_->child_id(), request_id);
1255 } 1239 }
1256 1240
1257 void ResourceDispatcherHostTest::CompleteStartRequest(int request_id) { 1241 void ResourceDispatcherHostTest::CompleteStartRequest(int request_id) {
1258 CompleteStartRequest(filter_.get(), request_id); 1242 CompleteStartRequest(filter_.get(), request_id);
1259 } 1243 }
1260 1244
1261 void ResourceDispatcherHostTest::CompleteStartRequest( 1245 void ResourceDispatcherHostTest::CompleteStartRequest(
1262 ResourceMessageFilter* filter, 1246 ResourceMessageFilter* filter,
(...skipping 2441 matching lines...) Expand 10 before | Expand all | Expand 10 after
3704 host_.OnMessageReceived(priority_msg, filter_.get()); 3688 host_.OnMessageReceived(priority_msg, filter_.get());
3705 base::RunLoop().RunUntilIdle(); 3689 base::RunLoop().RunUntilIdle();
3706 3690
3707 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count()); 3691 EXPECT_EQ(3, job_factory_->url_request_jobs_created_count());
3708 3692
3709 // Cleanup. 3693 // Cleanup.
3710 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id 3694 host_.OnRenderViewHostDeleted(filter_->child_id(), // child_id
3711 0); // route_id 3695 0); // route_id
3712 } 3696 }
3713 3697
3714 // Confirm that resource response started notifications for downloads are not
3715 // transmitted to the WebContents.
3716 TEST_P(ResourceDispatcherHostTest, TransferResponseStartedDownload) {
3717 int initial_count(web_contents_observer_->resource_response_start_count());
3718
3719 MakeWebContentsAssociatedDownloadRequest(
3720 1, net::URLRequestTestJob::test_url_1());
3721 base::RunLoop().RunUntilIdle();
3722 EXPECT_EQ(initial_count,
3723 web_contents_observer_->resource_response_start_count());
3724 }
3725
3726 // Confirm that request redirected notifications for downloads are not
3727 // transmitted to the WebContents.
3728 TEST_P(ResourceDispatcherHostTest, TransferRequestRedirectedDownload) {
3729 int initial_count(web_contents_observer_->resource_request_redirect_count());
3730
3731 MakeWebContentsAssociatedDownloadRequest(
3732 1, net::URLRequestTestJob::test_url_redirect_to_url_2());
3733 base::RunLoop().RunUntilIdle();
3734 EXPECT_EQ(initial_count,
3735 web_contents_observer_->resource_request_redirect_count());
3736 }
3737
3738 // A URLRequestTestJob that sets a test certificate on the |ssl_info| 3698 // A URLRequestTestJob that sets a test certificate on the |ssl_info|
3739 // field of the response. 3699 // field of the response.
3740 class TestHTTPSURLRequestJob : public net::URLRequestTestJob { 3700 class TestHTTPSURLRequestJob : public net::URLRequestTestJob {
3741 public: 3701 public:
3742 TestHTTPSURLRequestJob(net::URLRequest* request, 3702 TestHTTPSURLRequestJob(net::URLRequest* request,
3743 net::NetworkDelegate* network_delegate, 3703 net::NetworkDelegate* network_delegate,
3744 const std::string& response_headers, 3704 const std::string& response_headers,
3745 const std::string& response_data, 3705 const std::string& response_data,
3746 bool auto_advance) 3706 bool auto_advance)
3747 : net::URLRequestTestJob(request, 3707 : net::URLRequestTestJob(request,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3823 return nullptr; 3783 return nullptr;
3824 } 3784 }
3825 3785
3826 INSTANTIATE_TEST_CASE_P( 3786 INSTANTIATE_TEST_CASE_P(
3827 ResourceDispatcherHostTests, 3787 ResourceDispatcherHostTests,
3828 ResourceDispatcherHostTest, 3788 ResourceDispatcherHostTest,
3829 testing::Values(TestConfig::kDefault, 3789 testing::Values(TestConfig::kDefault,
3830 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3790 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3831 3791
3832 } // namespace content 3792 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698