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

Side by Side Diff: webkit/appcache/appcache_url_request_job_unittest.cc

Issue 10855209: Refactoring: ProtocolHandler::MaybeCreateJob takes NetworkDelegate as argument (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest merge Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stack> 5 #include <stack>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 AppCacheURLRequestJobTest* test_; 121 AppCacheURLRequestJobTest* test_;
122 net::HttpResponseInfo received_info_; 122 net::HttpResponseInfo received_info_;
123 scoped_refptr<net::IOBuffer> received_data_; 123 scoped_refptr<net::IOBuffer> received_data_;
124 bool did_receive_headers_; 124 bool did_receive_headers_;
125 int amount_received_; 125 int amount_received_;
126 int kill_after_amount_received_; 126 int kill_after_amount_received_;
127 bool kill_with_io_pending_; 127 bool kill_with_io_pending_;
128 }; 128 };
129 129
130 static net::URLRequestJob* MockHttpJobFactory(net::URLRequest* request, 130 static net::URLRequestJob* MockHttpJobFactory(
131 const std::string& scheme) { 131 net::URLRequest* request,
132 net::NetworkDelegate* network_delegate,
133 const std::string& scheme) {
132 if (mock_factory_job_) { 134 if (mock_factory_job_) {
133 net::URLRequestJob* temp = mock_factory_job_; 135 net::URLRequestJob* temp = mock_factory_job_;
134 mock_factory_job_ = NULL; 136 mock_factory_job_ = NULL;
135 return temp; 137 return temp;
136 } else { 138 } else {
137 return new net::URLRequestErrorJob(request, 139 return new net::URLRequestErrorJob(request,
140 network_delegate,
138 net::ERR_INTERNET_DISCONNECTED); 141 net::ERR_INTERNET_DISCONNECTED);
139 } 142 }
140 } 143 }
141 144
142 // Helper callback to run a test on our io_thread. The io_thread is spun up 145 // Helper callback to run a test on our io_thread. The io_thread is spun up
143 // once and reused for all tests. 146 // once and reused for all tests.
144 template <class Method> 147 template <class Method>
145 void MethodWrapper(Method method) { 148 void MethodWrapper(Method method) {
146 SetUpTest(); 149 SetUpTest();
147 (this->*method)(); 150 (this->*method)();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // is delineated with a section header. 371 // is delineated with a section header.
369 372
370 // Basic ------------------------------------------------------------------- 373 // Basic -------------------------------------------------------------------
371 void Basic() { 374 void Basic() {
372 AppCacheStorage* storage = service_->storage(); 375 AppCacheStorage* storage = service_->storage();
373 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_); 376 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_);
374 scoped_refptr<AppCacheURLRequestJob> job; 377 scoped_refptr<AppCacheURLRequestJob> job;
375 378
376 // Create an instance and see that it looks as expected. 379 // Create an instance and see that it looks as expected.
377 380
378 job = new AppCacheURLRequestJob(&request, storage); 381 job = new AppCacheURLRequestJob(
382 &request, empty_context_.network_delegate(), storage);
379 EXPECT_TRUE(job->is_waiting()); 383 EXPECT_TRUE(job->is_waiting());
380 EXPECT_FALSE(job->is_delivering_appcache_response()); 384 EXPECT_FALSE(job->is_delivering_appcache_response());
381 EXPECT_FALSE(job->is_delivering_network_response()); 385 EXPECT_FALSE(job->is_delivering_network_response());
382 EXPECT_FALSE(job->is_delivering_error_response()); 386 EXPECT_FALSE(job->is_delivering_error_response());
383 EXPECT_FALSE(job->has_been_started()); 387 EXPECT_FALSE(job->has_been_started());
384 EXPECT_FALSE(job->has_been_killed()); 388 EXPECT_FALSE(job->has_been_killed());
385 EXPECT_EQ(GURL(), job->manifest_url()); 389 EXPECT_EQ(GURL(), job->manifest_url());
386 EXPECT_EQ(kNoCacheId, job->cache_id()); 390 EXPECT_EQ(kNoCacheId, job->cache_id());
387 EXPECT_FALSE(job->entry().has_response_id()); 391 EXPECT_FALSE(job->entry().has_response_id());
388 392
389 TestFinished(); 393 TestFinished();
390 } 394 }
391 395
392 // DeliveryOrders ----------------------------------------------------- 396 // DeliveryOrders -----------------------------------------------------
393 void DeliveryOrders() { 397 void DeliveryOrders() {
394 AppCacheStorage* storage = service_->storage(); 398 AppCacheStorage* storage = service_->storage();
395 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_); 399 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_);
396 scoped_refptr<AppCacheURLRequestJob> job; 400 scoped_refptr<AppCacheURLRequestJob> job;
397 401
398 // Create an instance, give it a delivery order and see that 402 // Create an instance, give it a delivery order and see that
399 // it looks as expected. 403 // it looks as expected.
400 404
401 job = new AppCacheURLRequestJob(&request, storage); 405 job = new AppCacheURLRequestJob(
406 &request, empty_context_.network_delegate(), storage);
402 job->DeliverErrorResponse(); 407 job->DeliverErrorResponse();
403 EXPECT_TRUE(job->is_delivering_error_response()); 408 EXPECT_TRUE(job->is_delivering_error_response());
404 EXPECT_FALSE(job->has_been_started()); 409 EXPECT_FALSE(job->has_been_started());
405 410
406 job = new AppCacheURLRequestJob(&request, storage); 411 job = new AppCacheURLRequestJob(
412 &request, empty_context_.network_delegate(), storage);
407 job->DeliverNetworkResponse(); 413 job->DeliverNetworkResponse();
408 EXPECT_TRUE(job->is_delivering_network_response()); 414 EXPECT_TRUE(job->is_delivering_network_response());
409 EXPECT_FALSE(job->has_been_started()); 415 EXPECT_FALSE(job->has_been_started());
410 416
411 job = new AppCacheURLRequestJob(&request, storage); 417 job = new AppCacheURLRequestJob(
418 &request, empty_context_.network_delegate(), storage);
412 const GURL kManifestUrl("http://blah/"); 419 const GURL kManifestUrl("http://blah/");
413 const int64 kCacheId(1); 420 const int64 kCacheId(1);
414 const int64 kGroupId(1); 421 const int64 kGroupId(1);
415 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1); 422 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1);
416 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kGroupId, 423 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kGroupId,
417 kEntry, false); 424 kEntry, false);
418 EXPECT_FALSE(job->is_waiting()); 425 EXPECT_FALSE(job->is_waiting());
419 EXPECT_TRUE(job->is_delivering_appcache_response()); 426 EXPECT_TRUE(job->is_delivering_appcache_response());
420 EXPECT_FALSE(job->has_been_started()); 427 EXPECT_FALSE(job->has_been_started());
421 EXPECT_EQ(kManifestUrl, job->manifest_url()); 428 EXPECT_EQ(kManifestUrl, job->manifest_url());
(...skipping 14 matching lines...) Expand all
436 base::Unretained(this))); 443 base::Unretained(this)));
437 444
438 AppCacheStorage* storage = service_->storage(); 445 AppCacheStorage* storage = service_->storage();
439 request_.reset( 446 request_.reset(
440 new net::URLRequest(GURL("http://blah/"), 447 new net::URLRequest(GURL("http://blah/"),
441 url_request_delegate_.get(), 448 url_request_delegate_.get(),
442 &empty_context_)); 449 &empty_context_));
443 450
444 // Setup to create an AppCacheURLRequestJob with orders to deliver 451 // Setup to create an AppCacheURLRequestJob with orders to deliver
445 // a network response. 452 // a network response.
446 mock_factory_job_ = new AppCacheURLRequestJob(request_.get(), storage); 453 mock_factory_job_ = new AppCacheURLRequestJob(
454 request_.get(), empty_context_.network_delegate(), storage);
447 mock_factory_job_->DeliverNetworkResponse(); 455 mock_factory_job_->DeliverNetworkResponse();
448 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); 456 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response());
449 EXPECT_FALSE(mock_factory_job_->has_been_started()); 457 EXPECT_FALSE(mock_factory_job_->has_been_started());
450 458
451 // Start the request. 459 // Start the request.
452 request_->Start(); 460 request_->Start();
453 461
454 // The job should have been picked up. 462 // The job should have been picked up.
455 EXPECT_FALSE(mock_factory_job_); 463 EXPECT_FALSE(mock_factory_job_);
456 // Completion is async. 464 // Completion is async.
(...skipping 14 matching lines...) Expand all
471 base::Unretained(this))); 479 base::Unretained(this)));
472 480
473 AppCacheStorage* storage = service_->storage(); 481 AppCacheStorage* storage = service_->storage();
474 request_.reset( 482 request_.reset(
475 new net::URLRequest(GURL("http://blah/"), 483 new net::URLRequest(GURL("http://blah/"),
476 url_request_delegate_.get(), 484 url_request_delegate_.get(),
477 &empty_context_)); 485 &empty_context_));
478 486
479 // Setup to create an AppCacheURLRequestJob with orders to deliver 487 // Setup to create an AppCacheURLRequestJob with orders to deliver
480 // a network response. 488 // a network response.
481 mock_factory_job_ = new AppCacheURLRequestJob(request_.get(), storage); 489 mock_factory_job_ = new AppCacheURLRequestJob(
490 request_.get(), empty_context_.network_delegate(), storage);
482 mock_factory_job_->DeliverErrorResponse(); 491 mock_factory_job_->DeliverErrorResponse();
483 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); 492 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response());
484 EXPECT_FALSE(mock_factory_job_->has_been_started()); 493 EXPECT_FALSE(mock_factory_job_->has_been_started());
485 494
486 // Start the request. 495 // Start the request.
487 request_->Start(); 496 request_->Start();
488 497
489 // The job should have been picked up. 498 // The job should have been picked up.
490 EXPECT_FALSE(mock_factory_job_); 499 EXPECT_FALSE(mock_factory_job_);
491 // Completion is async. 500 // Completion is async.
(...skipping 29 matching lines...) Expand all
521 530
522 void RequestAppCachedResource(bool start_after_delivery_orders) { 531 void RequestAppCachedResource(bool start_after_delivery_orders) {
523 AppCacheStorage* storage = service_->storage(); 532 AppCacheStorage* storage = service_->storage();
524 request_.reset( 533 request_.reset(
525 new net::URLRequest(GURL("http://blah/"), 534 new net::URLRequest(GURL("http://blah/"),
526 url_request_delegate_.get(), 535 url_request_delegate_.get(),
527 &empty_context_)); 536 &empty_context_));
528 537
529 // Setup to create an AppCacheURLRequestJob with orders to deliver 538 // Setup to create an AppCacheURLRequestJob with orders to deliver
530 // a network response. 539 // a network response.
531 scoped_refptr<AppCacheURLRequestJob> job( 540 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob(
532 new AppCacheURLRequestJob(request_.get(), storage)); 541 request_.get(), empty_context_.network_delegate(), storage));
533 542
534 if (start_after_delivery_orders) { 543 if (start_after_delivery_orders) {
535 job->DeliverAppCachedResponse( 544 job->DeliverAppCachedResponse(
536 GURL(), 0, 111, 545 GURL(), 0, 111,
537 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), 546 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_),
538 false); 547 false);
539 EXPECT_TRUE(job->is_delivering_appcache_response()); 548 EXPECT_TRUE(job->is_delivering_appcache_response());
540 } 549 }
541 550
542 // Start the request. 551 // Start the request.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 new net::URLRequest(GURL("http://blah/"), 648 new net::URLRequest(GURL("http://blah/"),
640 url_request_delegate_.get(), 649 url_request_delegate_.get(),
641 &empty_context_)); 650 &empty_context_));
642 651
643 // Request a range, the 3 middle chars out of 'Hello' 652 // Request a range, the 3 middle chars out of 'Hello'
644 net::HttpRequestHeaders extra_headers; 653 net::HttpRequestHeaders extra_headers;
645 extra_headers.SetHeader("Range", "bytes= 1-3"); 654 extra_headers.SetHeader("Range", "bytes= 1-3");
646 request_->SetExtraRequestHeaders(extra_headers); 655 request_->SetExtraRequestHeaders(extra_headers);
647 656
648 // Create job with orders to deliver an appcached entry. 657 // Create job with orders to deliver an appcached entry.
649 scoped_refptr<AppCacheURLRequestJob> job( 658 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob(
650 new AppCacheURLRequestJob(request_.get(), storage)); 659 request_.get(), empty_context_.network_delegate(), storage));
651 job->DeliverAppCachedResponse( 660 job->DeliverAppCachedResponse(
652 GURL(), 0, 111, 661 GURL(), 0, 111,
653 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), 662 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_),
654 false); 663 false);
655 EXPECT_TRUE(job->is_delivering_appcache_response()); 664 EXPECT_TRUE(job->is_delivering_appcache_response());
656 665
657 // Start the request. 666 // Start the request.
658 EXPECT_FALSE(job->has_been_started()); 667 EXPECT_FALSE(job->has_been_started());
659 mock_factory_job_ = job; 668 mock_factory_job_ = job;
660 request_->Start(); 669 request_->Start();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 807
799 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { 808 TEST_F(AppCacheURLRequestJobTest, CancelRequest) {
800 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); 809 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest);
801 } 810 }
802 811
803 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { 812 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) {
804 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); 813 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending);
805 } 814 }
806 815
807 } // namespace appcache 816 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_url_request_job.cc ('k') | webkit/appcache/view_appcache_internals_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698