| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 423 } |
| 424 | 424 |
| 425 // Individual Tests --------------------------------------------------------- | 425 // Individual Tests --------------------------------------------------------- |
| 426 // Some of the individual tests involve multiple async steps. Each test | 426 // Some of the individual tests involve multiple async steps. Each test |
| 427 // is delineated with a section header. | 427 // is delineated with a section header. |
| 428 | 428 |
| 429 // Basic ------------------------------------------------------------------- | 429 // Basic ------------------------------------------------------------------- |
| 430 void Basic() { | 430 void Basic() { |
| 431 AppCacheStorage* storage = service_->storage(); | 431 AppCacheStorage* storage = service_->storage(); |
| 432 scoped_ptr<net::URLRequest> request(empty_context_->CreateRequest( | 432 scoped_ptr<net::URLRequest> request(empty_context_->CreateRequest( |
| 433 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL, NULL)); | 433 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL)); |
| 434 scoped_refptr<AppCacheURLRequestJob> job; | 434 scoped_refptr<AppCacheURLRequestJob> job; |
| 435 | 435 |
| 436 // Create an instance and see that it looks as expected. | 436 // Create an instance and see that it looks as expected. |
| 437 | 437 |
| 438 job = new AppCacheURLRequestJob(request.get(), NULL, storage, NULL, false); | 438 job = new AppCacheURLRequestJob(request.get(), NULL, storage, NULL, false); |
| 439 EXPECT_TRUE(job->is_waiting()); | 439 EXPECT_TRUE(job->is_waiting()); |
| 440 EXPECT_FALSE(job->is_delivering_appcache_response()); | 440 EXPECT_FALSE(job->is_delivering_appcache_response()); |
| 441 EXPECT_FALSE(job->is_delivering_network_response()); | 441 EXPECT_FALSE(job->is_delivering_network_response()); |
| 442 EXPECT_FALSE(job->is_delivering_error_response()); | 442 EXPECT_FALSE(job->is_delivering_error_response()); |
| 443 EXPECT_FALSE(job->has_been_started()); | 443 EXPECT_FALSE(job->has_been_started()); |
| 444 EXPECT_FALSE(job->has_been_killed()); | 444 EXPECT_FALSE(job->has_been_killed()); |
| 445 EXPECT_EQ(GURL(), job->manifest_url()); | 445 EXPECT_EQ(GURL(), job->manifest_url()); |
| 446 EXPECT_EQ(kAppCacheNoCacheId, job->cache_id()); | 446 EXPECT_EQ(kAppCacheNoCacheId, job->cache_id()); |
| 447 EXPECT_FALSE(job->entry().has_response_id()); | 447 EXPECT_FALSE(job->entry().has_response_id()); |
| 448 | 448 |
| 449 TestFinished(); | 449 TestFinished(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 // DeliveryOrders ----------------------------------------------------- | 452 // DeliveryOrders ----------------------------------------------------- |
| 453 void DeliveryOrders() { | 453 void DeliveryOrders() { |
| 454 AppCacheStorage* storage = service_->storage(); | 454 AppCacheStorage* storage = service_->storage(); |
| 455 scoped_ptr<net::URLRequest> request(empty_context_->CreateRequest( | 455 scoped_ptr<net::URLRequest> request(empty_context_->CreateRequest( |
| 456 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL, NULL)); | 456 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL)); |
| 457 scoped_refptr<AppCacheURLRequestJob> job; | 457 scoped_refptr<AppCacheURLRequestJob> job; |
| 458 | 458 |
| 459 // Create an instance, give it a delivery order and see that | 459 // Create an instance, give it a delivery order and see that |
| 460 // it looks as expected. | 460 // it looks as expected. |
| 461 | 461 |
| 462 job = new AppCacheURLRequestJob(request.get(), NULL, storage, NULL, false); | 462 job = new AppCacheURLRequestJob(request.get(), NULL, storage, NULL, false); |
| 463 job->DeliverErrorResponse(); | 463 job->DeliverErrorResponse(); |
| 464 EXPECT_TRUE(job->is_delivering_error_response()); | 464 EXPECT_TRUE(job->is_delivering_error_response()); |
| 465 EXPECT_FALSE(job->has_been_started()); | 465 EXPECT_FALSE(job->has_been_started()); |
| 466 | 466 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 492 | 492 |
| 493 void DeliverNetworkResponse() { | 493 void DeliverNetworkResponse() { |
| 494 // This test has async steps. | 494 // This test has async steps. |
| 495 PushNextTask( | 495 PushNextTask( |
| 496 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, | 496 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, |
| 497 base::Unretained(this))); | 497 base::Unretained(this))); |
| 498 | 498 |
| 499 AppCacheStorage* storage = service_->storage(); | 499 AppCacheStorage* storage = service_->storage(); |
| 500 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 500 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 501 net::DEFAULT_PRIORITY, | 501 net::DEFAULT_PRIORITY, |
| 502 url_request_delegate_.get(), | 502 url_request_delegate_.get()); |
| 503 NULL); | |
| 504 | 503 |
| 505 // Setup to create an AppCacheURLRequestJob with orders to deliver | 504 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 506 // a network response. | 505 // a network response. |
| 507 AppCacheURLRequestJob* mock_job = new AppCacheURLRequestJob( | 506 AppCacheURLRequestJob* mock_job = new AppCacheURLRequestJob( |
| 508 request_.get(), NULL, storage, NULL, false); | 507 request_.get(), NULL, storage, NULL, false); |
| 509 job_factory_->SetJob(mock_job); | 508 job_factory_->SetJob(mock_job); |
| 510 mock_job->DeliverNetworkResponse(); | 509 mock_job->DeliverNetworkResponse(); |
| 511 EXPECT_TRUE(mock_job->is_delivering_network_response()); | 510 EXPECT_TRUE(mock_job->is_delivering_network_response()); |
| 512 EXPECT_FALSE(mock_job->has_been_started()); | 511 EXPECT_FALSE(mock_job->has_been_started()); |
| 513 | 512 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 529 | 528 |
| 530 void DeliverErrorResponse() { | 529 void DeliverErrorResponse() { |
| 531 // This test has async steps. | 530 // This test has async steps. |
| 532 PushNextTask( | 531 PushNextTask( |
| 533 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, | 532 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, |
| 534 base::Unretained(this))); | 533 base::Unretained(this))); |
| 535 | 534 |
| 536 AppCacheStorage* storage = service_->storage(); | 535 AppCacheStorage* storage = service_->storage(); |
| 537 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 536 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 538 net::DEFAULT_PRIORITY, | 537 net::DEFAULT_PRIORITY, |
| 539 url_request_delegate_.get(), | 538 url_request_delegate_.get()); |
| 540 NULL); | |
| 541 | 539 |
| 542 // Setup to create an AppCacheURLRequestJob with orders to deliver | 540 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 543 // a network response. | 541 // a network response. |
| 544 AppCacheURLRequestJob* mock_job = new AppCacheURLRequestJob( | 542 AppCacheURLRequestJob* mock_job = new AppCacheURLRequestJob( |
| 545 request_.get(), NULL, storage, NULL, false); | 543 request_.get(), NULL, storage, NULL, false); |
| 546 job_factory_->SetJob(mock_job); | 544 job_factory_->SetJob(mock_job); |
| 547 mock_job->DeliverErrorResponse(); | 545 mock_job->DeliverErrorResponse(); |
| 548 EXPECT_TRUE(mock_job->is_delivering_error_response()); | 546 EXPECT_TRUE(mock_job->is_delivering_error_response()); |
| 549 EXPECT_FALSE(mock_job->has_been_started()); | 547 EXPECT_FALSE(mock_job->has_been_started()); |
| 550 | 548 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 581 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 579 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); |
| 582 written_response_id_ = writer_->response_id(); | 580 written_response_id_ = writer_->response_id(); |
| 583 WriteBasicResponse(); | 581 WriteBasicResponse(); |
| 584 // Continues async | 582 // Continues async |
| 585 } | 583 } |
| 586 | 584 |
| 587 void RequestAppCachedResource(bool start_after_delivery_orders) { | 585 void RequestAppCachedResource(bool start_after_delivery_orders) { |
| 588 AppCacheStorage* storage = service_->storage(); | 586 AppCacheStorage* storage = service_->storage(); |
| 589 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 587 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 590 net::DEFAULT_PRIORITY, | 588 net::DEFAULT_PRIORITY, |
| 591 url_request_delegate_.get(), | 589 url_request_delegate_.get()); |
| 592 NULL); | |
| 593 | 590 |
| 594 // Setup to create an AppCacheURLRequestJob with orders to deliver | 591 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 595 // a network response. | 592 // a network response. |
| 596 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 593 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
| 597 request_.get(), NULL, storage, NULL, false)); | 594 request_.get(), NULL, storage, NULL, false)); |
| 598 | 595 |
| 599 if (start_after_delivery_orders) { | 596 if (start_after_delivery_orders) { |
| 600 job->DeliverAppCachedResponse( | 597 job->DeliverAppCachedResponse( |
| 601 GURL(), 0, 111, | 598 GURL(), 0, 111, |
| 602 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 599 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); | 693 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0)); |
| 697 written_response_id_ = writer_->response_id(); | 694 written_response_id_ = writer_->response_id(); |
| 698 WriteBasicResponse(); | 695 WriteBasicResponse(); |
| 699 // Continues async | 696 // Continues async |
| 700 } | 697 } |
| 701 | 698 |
| 702 void MakeRangeRequest() { | 699 void MakeRangeRequest() { |
| 703 AppCacheStorage* storage = service_->storage(); | 700 AppCacheStorage* storage = service_->storage(); |
| 704 request_ = empty_context_->CreateRequest(GURL("http://blah/"), | 701 request_ = empty_context_->CreateRequest(GURL("http://blah/"), |
| 705 net::DEFAULT_PRIORITY, | 702 net::DEFAULT_PRIORITY, |
| 706 url_request_delegate_.get(), | 703 url_request_delegate_.get()); |
| 707 NULL); | |
| 708 | 704 |
| 709 // Request a range, the 3 middle chars out of 'Hello' | 705 // Request a range, the 3 middle chars out of 'Hello' |
| 710 net::HttpRequestHeaders extra_headers; | 706 net::HttpRequestHeaders extra_headers; |
| 711 extra_headers.SetHeader("Range", "bytes= 1-3"); | 707 extra_headers.SetHeader("Range", "bytes= 1-3"); |
| 712 request_->SetExtraRequestHeaders(extra_headers); | 708 request_->SetExtraRequestHeaders(extra_headers); |
| 713 | 709 |
| 714 // Create job with orders to deliver an appcached entry. | 710 // Create job with orders to deliver an appcached entry. |
| 715 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 711 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
| 716 request_.get(), NULL, storage, NULL, false)); | 712 request_.get(), NULL, storage, NULL, false)); |
| 717 job->DeliverAppCachedResponse( | 713 job->DeliverAppCachedResponse( |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 860 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
| 865 } | 861 } |
| 866 | 862 |
| 867 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 863 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
| 868 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 864 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
| 869 } | 865 } |
| 870 | 866 |
| 871 } // namespace | 867 } // namespace |
| 872 | 868 |
| 873 } // namespace content | 869 } // namespace content |
| OLD | NEW |