OLD | NEW |
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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 | 441 |
442 void DeliverNetworkResponse() { | 442 void DeliverNetworkResponse() { |
443 // This test has async steps. | 443 // This test has async steps. |
444 PushNextTask( | 444 PushNextTask( |
445 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, | 445 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, |
446 base::Unretained(this))); | 446 base::Unretained(this))); |
447 | 447 |
448 AppCacheStorage* storage = service_->storage(); | 448 AppCacheStorage* storage = service_->storage(); |
449 request_ = empty_context_.CreateRequest(GURL("http://blah/"), | 449 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
450 net::DEFAULT_PRIORITY, | 450 net::DEFAULT_PRIORITY, |
451 url_request_delegate_.get(), | 451 url_request_delegate_.get()); |
452 NULL); | |
453 | 452 |
454 // Setup to create an AppCacheURLRequestJob with orders to deliver | 453 // Setup to create an AppCacheURLRequestJob with orders to deliver |
455 // a network response. | 454 // a network response. |
456 mock_factory_job_ = new AppCacheURLRequestJob( | 455 mock_factory_job_ = new AppCacheURLRequestJob( |
457 request_.get(), NULL, storage, NULL); | 456 request_.get(), NULL, storage, NULL); |
458 mock_factory_job_->DeliverNetworkResponse(); | 457 mock_factory_job_->DeliverNetworkResponse(); |
459 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); | 458 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); |
460 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 459 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
461 | 460 |
462 // Start the request. | 461 // Start the request. |
(...skipping 14 matching lines...) Expand all Loading... |
477 | 476 |
478 void DeliverErrorResponse() { | 477 void DeliverErrorResponse() { |
479 // This test has async steps. | 478 // This test has async steps. |
480 PushNextTask( | 479 PushNextTask( |
481 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, | 480 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, |
482 base::Unretained(this))); | 481 base::Unretained(this))); |
483 | 482 |
484 AppCacheStorage* storage = service_->storage(); | 483 AppCacheStorage* storage = service_->storage(); |
485 request_ = empty_context_.CreateRequest(GURL("http://blah/"), | 484 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
486 net::DEFAULT_PRIORITY, | 485 net::DEFAULT_PRIORITY, |
487 url_request_delegate_.get(), | 486 url_request_delegate_.get()); |
488 NULL); | |
489 | 487 |
490 // Setup to create an AppCacheURLRequestJob with orders to deliver | 488 // Setup to create an AppCacheURLRequestJob with orders to deliver |
491 // a network response. | 489 // a network response. |
492 mock_factory_job_ = new AppCacheURLRequestJob( | 490 mock_factory_job_ = new AppCacheURLRequestJob( |
493 request_.get(), NULL, storage, NULL); | 491 request_.get(), NULL, storage, NULL); |
494 mock_factory_job_->DeliverErrorResponse(); | 492 mock_factory_job_->DeliverErrorResponse(); |
495 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); | 493 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); |
496 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 494 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
497 | 495 |
498 // Start the request. | 496 // Start the request. |
(...skipping 29 matching lines...) Expand all Loading... |
528 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 526 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); |
529 written_response_id_ = writer_->response_id(); | 527 written_response_id_ = writer_->response_id(); |
530 WriteBasicResponse(); | 528 WriteBasicResponse(); |
531 // Continues async | 529 // Continues async |
532 } | 530 } |
533 | 531 |
534 void RequestAppCachedResource(bool start_after_delivery_orders) { | 532 void RequestAppCachedResource(bool start_after_delivery_orders) { |
535 AppCacheStorage* storage = service_->storage(); | 533 AppCacheStorage* storage = service_->storage(); |
536 request_ = empty_context_.CreateRequest(GURL("http://blah/"), | 534 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
537 net::DEFAULT_PRIORITY, | 535 net::DEFAULT_PRIORITY, |
538 url_request_delegate_.get(), | 536 url_request_delegate_.get()); |
539 NULL); | |
540 | 537 |
541 // Setup to create an AppCacheURLRequestJob with orders to deliver | 538 // Setup to create an AppCacheURLRequestJob with orders to deliver |
542 // a network response. | 539 // a network response. |
543 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 540 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
544 request_.get(), NULL, storage, NULL)); | 541 request_.get(), NULL, storage, NULL)); |
545 | 542 |
546 if (start_after_delivery_orders) { | 543 if (start_after_delivery_orders) { |
547 job->DeliverAppCachedResponse( | 544 job->DeliverAppCachedResponse( |
548 GURL(), 0, 111, | 545 GURL(), 0, 111, |
549 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 546 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 640 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); |
644 written_response_id_ = writer_->response_id(); | 641 written_response_id_ = writer_->response_id(); |
645 WriteBasicResponse(); | 642 WriteBasicResponse(); |
646 // Continues async | 643 // Continues async |
647 } | 644 } |
648 | 645 |
649 void MakeRangeRequest() { | 646 void MakeRangeRequest() { |
650 AppCacheStorage* storage = service_->storage(); | 647 AppCacheStorage* storage = service_->storage(); |
651 request_ = empty_context_.CreateRequest(GURL("http://blah/"), | 648 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
652 net::DEFAULT_PRIORITY, | 649 net::DEFAULT_PRIORITY, |
653 url_request_delegate_.get(), | 650 url_request_delegate_.get()); |
654 NULL); | |
655 | 651 |
656 // Request a range, the 3 middle chars out of 'Hello' | 652 // Request a range, the 3 middle chars out of 'Hello' |
657 net::HttpRequestHeaders extra_headers; | 653 net::HttpRequestHeaders extra_headers; |
658 extra_headers.SetHeader("Range", "bytes= 1-3"); | 654 extra_headers.SetHeader("Range", "bytes= 1-3"); |
659 request_->SetExtraRequestHeaders(extra_headers); | 655 request_->SetExtraRequestHeaders(extra_headers); |
660 | 656 |
661 // Create job with orders to deliver an appcached entry. | 657 // Create job with orders to deliver an appcached entry. |
662 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 658 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
663 request_.get(), NULL, storage, NULL)); | 659 request_.get(), NULL, storage, NULL)); |
664 job->DeliverAppCachedResponse( | 660 job->DeliverAppCachedResponse( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 | 807 |
812 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 808 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { |
813 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 809 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
814 } | 810 } |
815 | 811 |
816 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 812 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
817 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 813 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
818 } | 814 } |
819 | 815 |
820 } // namespace appcache | 816 } // namespace appcache |
OLD | NEW |