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

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

Issue 859213006: Cancel client auth requests when not promptable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@client-auth-cancel-1
Patch Set: extension test Created 5 years, 10 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
12 #include "content/browser/loader/redirect_to_file_resource_handler.h" 12 #include "content/browser/loader/redirect_to_file_resource_handler.h"
13 #include "content/browser/loader/resource_loader_delegate.h" 13 #include "content/browser/loader/resource_loader_delegate.h"
14 #include "content/public/browser/client_certificate_delegate.h"
14 #include "content/public/browser/resource_request_info.h" 15 #include "content/public/browser/resource_request_info.h"
15 #include "content/public/common/resource_response.h" 16 #include "content/public/common/resource_response.h"
16 #include "content/public/test/mock_resource_context.h" 17 #include "content/public/test/mock_resource_context.h"
18 #include "content/public/test/test_browser_context.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "content/public/test/test_renderer_host.h"
18 #include "content/test/test_content_browser_client.h" 21 #include "content/test/test_content_browser_client.h"
22 #include "content/test/test_web_contents.h"
19 #include "ipc/ipc_message.h" 23 #include "ipc/ipc_message.h"
20 #include "net/base/io_buffer.h" 24 #include "net/base/io_buffer.h"
21 #include "net/base/mock_file_stream.h" 25 #include "net/base/mock_file_stream.h"
22 #include "net/base/request_priority.h" 26 #include "net/base/request_priority.h"
23 #include "net/cert/x509_certificate.h" 27 #include "net/cert/x509_certificate.h"
24 #include "net/ssl/client_cert_store.h" 28 #include "net/ssl/client_cert_store.h"
25 #include "net/ssl/ssl_cert_request_info.h" 29 #include "net/ssl/ssl_cert_request_info.h"
26 #include "net/url_request/url_request.h" 30 #include "net/url_request/url_request.h"
27 #include "net/url_request/url_request_job_factory_impl.h" 31 #include "net/url_request/url_request_job_factory_impl.h"
28 #include "net/url_request/url_request_test_job.h" 32 #include "net/url_request/url_request_test_job.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 int total_bytes_downloaded_; 236 int total_bytes_downloaded_;
233 }; 237 };
234 238
235 // Test browser client that captures calls to SelectClientCertificates and 239 // Test browser client that captures calls to SelectClientCertificates and
236 // records the arguments of the most recent call for later inspection. 240 // records the arguments of the most recent call for later inspection.
237 class SelectCertificateBrowserClient : public TestContentBrowserClient { 241 class SelectCertificateBrowserClient : public TestContentBrowserClient {
238 public: 242 public:
239 SelectCertificateBrowserClient() : call_count_(0) {} 243 SelectCertificateBrowserClient() : call_count_(0) {}
240 244
241 void SelectClientCertificate( 245 void SelectClientCertificate(
242 int render_process_id, 246 WebContents* web_contents,
243 int render_view_id,
244 net::SSLCertRequestInfo* cert_request_info, 247 net::SSLCertRequestInfo* cert_request_info,
245 const base::Callback<void(net::X509Certificate*)>& callback) override { 248 scoped_ptr<ClientCertificateDelegate> delegate) override {
246 ++call_count_; 249 ++call_count_;
247 passed_certs_ = cert_request_info->client_certs; 250 passed_certs_ = cert_request_info->client_certs;
248 } 251 }
249 252
250 int call_count() { 253 int call_count() {
251 return call_count_; 254 return call_count_;
252 } 255 }
253 256
254 net::CertificateList passed_certs() { 257 net::CertificateList passed_certs() {
255 return passed_certs_; 258 return passed_certs_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 return net::URLRequestTestJob::test_data_1(); 313 return net::URLRequestTestJob::test_data_1();
311 } 314 }
312 315
313 virtual scoped_ptr<ResourceHandler> WrapResourceHandler( 316 virtual scoped_ptr<ResourceHandler> WrapResourceHandler(
314 scoped_ptr<ResourceHandlerStub> leaf_handler, 317 scoped_ptr<ResourceHandlerStub> leaf_handler,
315 net::URLRequest* request) { 318 net::URLRequest* request) {
316 return leaf_handler.Pass(); 319 return leaf_handler.Pass();
317 } 320 }
318 321
319 void SetUp() override { 322 void SetUp() override {
320 const int kRenderProcessId = 1; 323 browser_context_.reset(new TestBrowserContext());
321 const int kRenderViewId = 2; 324 scoped_refptr<SiteInstance> site_instance =
325 SiteInstance::Create(browser_context_.get());
326 web_contents_.reset(
327 TestWebContents::Create(browser_context_.get(), site_instance.get()));
mmenke 2015/02/10 17:19:10 I'm confused. Why are these needed? Aren't we ju
davidben 2015/02/10 20:28:49 There's a handful of tests that install a custom o
mmenke 2015/02/11 17:09:16 Ah, somehow I was missing SelectCertificateBrowser
davidben 2015/02/12 22:55:15 Done.
328 RenderFrameHost* rfh = web_contents_->GetMainFrame();
322 329
323 scoped_ptr<net::URLRequest> request( 330 scoped_ptr<net::URLRequest> request(
324 resource_context_.GetRequestContext()->CreateRequest( 331 resource_context_.GetRequestContext()->CreateRequest(
325 test_url(), 332 test_url(),
326 net::DEFAULT_PRIORITY, 333 net::DEFAULT_PRIORITY,
327 NULL /* delegate */, 334 NULL /* delegate */,
328 NULL /* cookie_store */)); 335 NULL /* cookie_store */));
329 raw_ptr_to_request_ = request.get(); 336 raw_ptr_to_request_ = request.get();
330 ResourceRequestInfo::AllocateForTesting(request.get(), 337 ResourceRequestInfo::AllocateForTesting(request.get(),
331 RESOURCE_TYPE_MAIN_FRAME, 338 RESOURCE_TYPE_MAIN_FRAME,
332 &resource_context_, 339 &resource_context_,
333 kRenderProcessId, 340 rfh->GetProcess()->GetID(),
334 kRenderViewId,
335 MSG_ROUTING_NONE, 341 MSG_ROUTING_NONE,
342 rfh->GetRoutingID(),
mmenke 2015/02/10 17:19:10 Think you messed up the order here
davidben 2015/02/10 20:28:49 I'm passing in RFH ID, and not RVH ID. Getting the
336 true, // is_main_frame 343 true, // is_main_frame
337 false, // parent_is_main_frame 344 false, // parent_is_main_frame
338 true, // allow_download 345 true, // allow_download
339 false); // is_async 346 false); // is_async
340 scoped_ptr<ResourceHandlerStub> resource_handler( 347 scoped_ptr<ResourceHandlerStub> resource_handler(
341 new ResourceHandlerStub(request.get())); 348 new ResourceHandlerStub(request.get()));
342 raw_ptr_resource_handler_ = resource_handler.get(); 349 raw_ptr_resource_handler_ = resource_handler.get();
343 loader_.reset(new ResourceLoader( 350 loader_.reset(new ResourceLoader(
344 request.Pass(), 351 request.Pass(),
345 WrapResourceHandler(resource_handler.Pass(), raw_ptr_to_request_), 352 WrapResourceHandler(resource_handler.Pass(), raw_ptr_to_request_),
346 this)); 353 this));
347 } 354 }
348 355
356 void TearDown() override {
357 web_contents_.reset();
358 base::RunLoop().RunUntilIdle();
359 }
360
349 // ResourceLoaderDelegate: 361 // ResourceLoaderDelegate:
350 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate( 362 ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
351 ResourceLoader* loader, 363 ResourceLoader* loader,
352 net::AuthChallengeInfo* auth_info) override { 364 net::AuthChallengeInfo* auth_info) override {
353 return NULL; 365 return NULL;
354 } 366 }
355 bool HandleExternalProtocol(ResourceLoader* loader, 367 bool HandleExternalProtocol(ResourceLoader* loader,
356 const GURL& url) override { 368 const GURL& url) override {
357 return false; 369 return false;
358 } 370 }
359 void DidStartRequest(ResourceLoader* loader) override {} 371 void DidStartRequest(ResourceLoader* loader) override {}
360 void DidReceiveRedirect(ResourceLoader* loader, 372 void DidReceiveRedirect(ResourceLoader* loader,
361 const GURL& new_url) override {} 373 const GURL& new_url) override {}
362 void DidReceiveResponse(ResourceLoader* loader) override {} 374 void DidReceiveResponse(ResourceLoader* loader) override {}
363 void DidFinishLoading(ResourceLoader* loader) override {} 375 void DidFinishLoading(ResourceLoader* loader) override {}
364 376
365 content::TestBrowserThreadBundle thread_bundle_; 377 TestBrowserThreadBundle thread_bundle_;
378 RenderViewHostTestEnabler rvh_test_enabler_;
366 379
367 net::URLRequestJobFactoryImpl job_factory_; 380 net::URLRequestJobFactoryImpl job_factory_;
368 net::TestURLRequestContext test_url_request_context_; 381 net::TestURLRequestContext test_url_request_context_;
369 ResourceContextStub resource_context_; 382 ResourceContextStub resource_context_;
383 scoped_ptr<TestBrowserContext> browser_context_;
384 scoped_ptr<TestWebContents> web_contents_;
370 385
371 // The ResourceLoader owns the URLRequest and the ResourceHandler. 386 // The ResourceLoader owns the URLRequest and the ResourceHandler.
372 ResourceHandlerStub* raw_ptr_resource_handler_; 387 ResourceHandlerStub* raw_ptr_resource_handler_;
373 net::URLRequest* raw_ptr_to_request_; 388 net::URLRequest* raw_ptr_to_request_;
374 scoped_ptr<ResourceLoader> loader_; 389 scoped_ptr<ResourceLoader> loader_;
375 }; 390 };
376 391
377 // Verifies if a call to net::UrlRequest::Delegate::OnCertificateRequested() 392 // Verifies if a call to net::UrlRequest::Delegate::OnCertificateRequested()
378 // causes client cert store to be queried for certificates and if the returned 393 // causes client cert store to be queried for certificates and if the returned
379 // certificates are correctly passed to the content browser client for 394 // certificates are correctly passed to the content browser client for
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 ASSERT_TRUE(base::ReadFileToString(temp_path(), &contents)); 775 ASSERT_TRUE(base::ReadFileToString(temp_path(), &contents));
761 EXPECT_EQ(test_data(), contents); 776 EXPECT_EQ(test_data(), contents);
762 777
763 // Release the loader. The file should be gone now. 778 // Release the loader. The file should be gone now.
764 ReleaseLoader(); 779 ReleaseLoader();
765 base::RunLoop().RunUntilIdle(); 780 base::RunLoop().RunUntilIdle();
766 EXPECT_FALSE(base::PathExists(temp_path())); 781 EXPECT_FALSE(base::PathExists(temp_path()));
767 } 782 }
768 783
769 } // namespace content 784 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698