| 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 436 |
| 437 // DeliverNetworkResponse -------------------------------------------------- | 437 // DeliverNetworkResponse -------------------------------------------------- |
| 438 | 438 |
| 439 void DeliverNetworkResponse() { | 439 void DeliverNetworkResponse() { |
| 440 // This test has async steps. | 440 // This test has async steps. |
| 441 PushNextTask( | 441 PushNextTask( |
| 442 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, | 442 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, |
| 443 base::Unretained(this))); | 443 base::Unretained(this))); |
| 444 | 444 |
| 445 AppCacheStorage* storage = service_->storage(); | 445 AppCacheStorage* storage = service_->storage(); |
| 446 request_.reset( | 446 request_.reset(empty_context_.CreateRequest( |
| 447 new net::URLRequest(GURL("http://blah/"), | 447 GURL("http://blah/"), url_request_delegate_.get())); |
| 448 url_request_delegate_.get(), | |
| 449 &empty_context_)); | |
| 450 | 448 |
| 451 // Setup to create an AppCacheURLRequestJob with orders to deliver | 449 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 452 // a network response. | 450 // a network response. |
| 453 mock_factory_job_ = new AppCacheURLRequestJob( | 451 mock_factory_job_ = new AppCacheURLRequestJob( |
| 454 request_.get(), empty_context_.network_delegate(), storage); | 452 request_.get(), empty_context_.network_delegate(), storage); |
| 455 mock_factory_job_->DeliverNetworkResponse(); | 453 mock_factory_job_->DeliverNetworkResponse(); |
| 456 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); | 454 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); |
| 457 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 455 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
| 458 | 456 |
| 459 // Start the request. | 457 // Start the request. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 472 | 470 |
| 473 // DeliverErrorResponse -------------------------------------------------- | 471 // DeliverErrorResponse -------------------------------------------------- |
| 474 | 472 |
| 475 void DeliverErrorResponse() { | 473 void DeliverErrorResponse() { |
| 476 // This test has async steps. | 474 // This test has async steps. |
| 477 PushNextTask( | 475 PushNextTask( |
| 478 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, | 476 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, |
| 479 base::Unretained(this))); | 477 base::Unretained(this))); |
| 480 | 478 |
| 481 AppCacheStorage* storage = service_->storage(); | 479 AppCacheStorage* storage = service_->storage(); |
| 482 request_.reset( | 480 request_.reset(empty_context_.CreateRequest(GURL( |
| 483 new net::URLRequest(GURL("http://blah/"), | 481 "http://blah/"), url_request_delegate_.get())); |
| 484 url_request_delegate_.get(), | |
| 485 &empty_context_)); | |
| 486 | 482 |
| 487 // Setup to create an AppCacheURLRequestJob with orders to deliver | 483 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 488 // a network response. | 484 // a network response. |
| 489 mock_factory_job_ = new AppCacheURLRequestJob( | 485 mock_factory_job_ = new AppCacheURLRequestJob( |
| 490 request_.get(), empty_context_.network_delegate(), storage); | 486 request_.get(), empty_context_.network_delegate(), storage); |
| 491 mock_factory_job_->DeliverErrorResponse(); | 487 mock_factory_job_->DeliverErrorResponse(); |
| 492 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); | 488 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); |
| 493 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 489 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
| 494 | 490 |
| 495 // Start the request. | 491 // Start the request. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 523 base::Unretained(this), false)); | 519 base::Unretained(this), false)); |
| 524 | 520 |
| 525 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 521 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); |
| 526 written_response_id_ = writer_->response_id(); | 522 written_response_id_ = writer_->response_id(); |
| 527 WriteBasicResponse(); | 523 WriteBasicResponse(); |
| 528 // Continues async | 524 // Continues async |
| 529 } | 525 } |
| 530 | 526 |
| 531 void RequestAppCachedResource(bool start_after_delivery_orders) { | 527 void RequestAppCachedResource(bool start_after_delivery_orders) { |
| 532 AppCacheStorage* storage = service_->storage(); | 528 AppCacheStorage* storage = service_->storage(); |
| 533 request_.reset( | 529 request_.reset(empty_context_.CreateRequest( |
| 534 new net::URLRequest(GURL("http://blah/"), | 530 GURL("http://blah/"), url_request_delegate_.get())); |
| 535 url_request_delegate_.get(), | |
| 536 &empty_context_)); | |
| 537 | 531 |
| 538 // Setup to create an AppCacheURLRequestJob with orders to deliver | 532 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 539 // a network response. | 533 // a network response. |
| 540 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 534 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
| 541 request_.get(), empty_context_.network_delegate(), storage)); | 535 request_.get(), empty_context_.network_delegate(), storage)); |
| 542 | 536 |
| 543 if (start_after_delivery_orders) { | 537 if (start_after_delivery_orders) { |
| 544 job->DeliverAppCachedResponse( | 538 job->DeliverAppCachedResponse( |
| 545 GURL(), 0, 111, | 539 GURL(), 0, 111, |
| 546 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 540 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 PushNextTask(base::Bind( | 631 PushNextTask(base::Bind( |
| 638 &AppCacheURLRequestJobTest::MakeRangeRequest, base::Unretained(this))); | 632 &AppCacheURLRequestJobTest::MakeRangeRequest, base::Unretained(this))); |
| 639 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 633 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); |
| 640 written_response_id_ = writer_->response_id(); | 634 written_response_id_ = writer_->response_id(); |
| 641 WriteBasicResponse(); | 635 WriteBasicResponse(); |
| 642 // Continues async | 636 // Continues async |
| 643 } | 637 } |
| 644 | 638 |
| 645 void MakeRangeRequest() { | 639 void MakeRangeRequest() { |
| 646 AppCacheStorage* storage = service_->storage(); | 640 AppCacheStorage* storage = service_->storage(); |
| 647 request_.reset( | 641 request_.reset(empty_context_.CreateRequest( |
| 648 new net::URLRequest(GURL("http://blah/"), | 642 GURL("http://blah/"), url_request_delegate_.get())); |
| 649 url_request_delegate_.get(), | |
| 650 &empty_context_)); | |
| 651 | 643 |
| 652 // Request a range, the 3 middle chars out of 'Hello' | 644 // Request a range, the 3 middle chars out of 'Hello' |
| 653 net::HttpRequestHeaders extra_headers; | 645 net::HttpRequestHeaders extra_headers; |
| 654 extra_headers.SetHeader("Range", "bytes= 1-3"); | 646 extra_headers.SetHeader("Range", "bytes= 1-3"); |
| 655 request_->SetExtraRequestHeaders(extra_headers); | 647 request_->SetExtraRequestHeaders(extra_headers); |
| 656 | 648 |
| 657 // Create job with orders to deliver an appcached entry. | 649 // Create job with orders to deliver an appcached entry. |
| 658 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 650 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
| 659 request_.get(), empty_context_.network_delegate(), storage)); | 651 request_.get(), empty_context_.network_delegate(), storage)); |
| 660 job->DeliverAppCachedResponse( | 652 job->DeliverAppCachedResponse( |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 | 799 |
| 808 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 800 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { |
| 809 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 801 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
| 810 } | 802 } |
| 811 | 803 |
| 812 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 804 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
| 813 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 805 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
| 814 } | 806 } |
| 815 | 807 |
| 816 } // namespace appcache | 808 } // namespace appcache |
| OLD | NEW |