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