| 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 373 |
| 374 // Basic ------------------------------------------------------------------- | 374 // Basic ------------------------------------------------------------------- |
| 375 void Basic() { | 375 void Basic() { |
| 376 AppCacheStorage* storage = service_->storage(); | 376 AppCacheStorage* storage = service_->storage(); |
| 377 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_); | 377 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_); |
| 378 scoped_refptr<AppCacheURLRequestJob> job; | 378 scoped_refptr<AppCacheURLRequestJob> job; |
| 379 | 379 |
| 380 // Create an instance and see that it looks as expected. | 380 // Create an instance and see that it looks as expected. |
| 381 | 381 |
| 382 job = new AppCacheURLRequestJob( | 382 job = new AppCacheURLRequestJob( |
| 383 &request, empty_context_.network_delegate(), storage); | 383 &request, NULL, storage); |
| 384 EXPECT_TRUE(job->is_waiting()); | 384 EXPECT_TRUE(job->is_waiting()); |
| 385 EXPECT_FALSE(job->is_delivering_appcache_response()); | 385 EXPECT_FALSE(job->is_delivering_appcache_response()); |
| 386 EXPECT_FALSE(job->is_delivering_network_response()); | 386 EXPECT_FALSE(job->is_delivering_network_response()); |
| 387 EXPECT_FALSE(job->is_delivering_error_response()); | 387 EXPECT_FALSE(job->is_delivering_error_response()); |
| 388 EXPECT_FALSE(job->has_been_started()); | 388 EXPECT_FALSE(job->has_been_started()); |
| 389 EXPECT_FALSE(job->has_been_killed()); | 389 EXPECT_FALSE(job->has_been_killed()); |
| 390 EXPECT_EQ(GURL(), job->manifest_url()); | 390 EXPECT_EQ(GURL(), job->manifest_url()); |
| 391 EXPECT_EQ(kNoCacheId, job->cache_id()); | 391 EXPECT_EQ(kNoCacheId, job->cache_id()); |
| 392 EXPECT_FALSE(job->entry().has_response_id()); | 392 EXPECT_FALSE(job->entry().has_response_id()); |
| 393 | 393 |
| 394 TestFinished(); | 394 TestFinished(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // DeliveryOrders ----------------------------------------------------- | 397 // DeliveryOrders ----------------------------------------------------- |
| 398 void DeliveryOrders() { | 398 void DeliveryOrders() { |
| 399 AppCacheStorage* storage = service_->storage(); | 399 AppCacheStorage* storage = service_->storage(); |
| 400 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_); | 400 net::URLRequest request(GURL("http://blah/"), NULL, &empty_context_); |
| 401 scoped_refptr<AppCacheURLRequestJob> job; | 401 scoped_refptr<AppCacheURLRequestJob> job; |
| 402 | 402 |
| 403 // Create an instance, give it a delivery order and see that | 403 // Create an instance, give it a delivery order and see that |
| 404 // it looks as expected. | 404 // it looks as expected. |
| 405 | 405 |
| 406 job = new AppCacheURLRequestJob( | 406 job = new AppCacheURLRequestJob(&request, NULL, storage); |
| 407 &request, empty_context_.network_delegate(), storage); | |
| 408 job->DeliverErrorResponse(); | 407 job->DeliverErrorResponse(); |
| 409 EXPECT_TRUE(job->is_delivering_error_response()); | 408 EXPECT_TRUE(job->is_delivering_error_response()); |
| 410 EXPECT_FALSE(job->has_been_started()); | 409 EXPECT_FALSE(job->has_been_started()); |
| 411 | 410 |
| 412 job = new AppCacheURLRequestJob( | 411 job = new AppCacheURLRequestJob(&request, NULL, storage); |
| 413 &request, empty_context_.network_delegate(), storage); | |
| 414 job->DeliverNetworkResponse(); | 412 job->DeliverNetworkResponse(); |
| 415 EXPECT_TRUE(job->is_delivering_network_response()); | 413 EXPECT_TRUE(job->is_delivering_network_response()); |
| 416 EXPECT_FALSE(job->has_been_started()); | 414 EXPECT_FALSE(job->has_been_started()); |
| 417 | 415 |
| 418 job = new AppCacheURLRequestJob( | 416 job = new AppCacheURLRequestJob(&request, NULL, storage); |
| 419 &request, empty_context_.network_delegate(), storage); | |
| 420 const GURL kManifestUrl("http://blah/"); | 417 const GURL kManifestUrl("http://blah/"); |
| 421 const int64 kCacheId(1); | 418 const int64 kCacheId(1); |
| 422 const int64 kGroupId(1); | 419 const int64 kGroupId(1); |
| 423 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1); | 420 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1); |
| 424 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kGroupId, | 421 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kGroupId, |
| 425 kEntry, false); | 422 kEntry, false); |
| 426 EXPECT_FALSE(job->is_waiting()); | 423 EXPECT_FALSE(job->is_waiting()); |
| 427 EXPECT_TRUE(job->is_delivering_appcache_response()); | 424 EXPECT_TRUE(job->is_delivering_appcache_response()); |
| 428 EXPECT_FALSE(job->has_been_started()); | 425 EXPECT_FALSE(job->has_been_started()); |
| 429 EXPECT_EQ(kManifestUrl, job->manifest_url()); | 426 EXPECT_EQ(kManifestUrl, job->manifest_url()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 443 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, | 440 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, |
| 444 base::Unretained(this))); | 441 base::Unretained(this))); |
| 445 | 442 |
| 446 AppCacheStorage* storage = service_->storage(); | 443 AppCacheStorage* storage = service_->storage(); |
| 447 request_.reset(empty_context_.CreateRequest( | 444 request_.reset(empty_context_.CreateRequest( |
| 448 GURL("http://blah/"), url_request_delegate_.get())); | 445 GURL("http://blah/"), url_request_delegate_.get())); |
| 449 | 446 |
| 450 // Setup to create an AppCacheURLRequestJob with orders to deliver | 447 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 451 // a network response. | 448 // a network response. |
| 452 mock_factory_job_ = new AppCacheURLRequestJob( | 449 mock_factory_job_ = new AppCacheURLRequestJob( |
| 453 request_.get(), empty_context_.network_delegate(), storage); | 450 request_.get(), NULL, storage); |
| 454 mock_factory_job_->DeliverNetworkResponse(); | 451 mock_factory_job_->DeliverNetworkResponse(); |
| 455 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); | 452 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); |
| 456 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 453 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
| 457 | 454 |
| 458 // Start the request. | 455 // Start the request. |
| 459 request_->Start(); | 456 request_->Start(); |
| 460 | 457 |
| 461 // The job should have been picked up. | 458 // The job should have been picked up. |
| 462 EXPECT_FALSE(mock_factory_job_); | 459 EXPECT_FALSE(mock_factory_job_); |
| 463 // Completion is async. | 460 // Completion is async. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 477 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, | 474 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverErrorResponse, |
| 478 base::Unretained(this))); | 475 base::Unretained(this))); |
| 479 | 476 |
| 480 AppCacheStorage* storage = service_->storage(); | 477 AppCacheStorage* storage = service_->storage(); |
| 481 request_.reset(empty_context_.CreateRequest(GURL( | 478 request_.reset(empty_context_.CreateRequest(GURL( |
| 482 "http://blah/"), url_request_delegate_.get())); | 479 "http://blah/"), url_request_delegate_.get())); |
| 483 | 480 |
| 484 // Setup to create an AppCacheURLRequestJob with orders to deliver | 481 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 485 // a network response. | 482 // a network response. |
| 486 mock_factory_job_ = new AppCacheURLRequestJob( | 483 mock_factory_job_ = new AppCacheURLRequestJob( |
| 487 request_.get(), empty_context_.network_delegate(), storage); | 484 request_.get(), NULL, storage); |
| 488 mock_factory_job_->DeliverErrorResponse(); | 485 mock_factory_job_->DeliverErrorResponse(); |
| 489 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); | 486 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); |
| 490 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 487 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
| 491 | 488 |
| 492 // Start the request. | 489 // Start the request. |
| 493 request_->Start(); | 490 request_->Start(); |
| 494 | 491 |
| 495 // The job should have been picked up. | 492 // The job should have been picked up. |
| 496 EXPECT_FALSE(mock_factory_job_); | 493 EXPECT_FALSE(mock_factory_job_); |
| 497 // Completion is async. | 494 // Completion is async. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 526 } | 523 } |
| 527 | 524 |
| 528 void RequestAppCachedResource(bool start_after_delivery_orders) { | 525 void RequestAppCachedResource(bool start_after_delivery_orders) { |
| 529 AppCacheStorage* storage = service_->storage(); | 526 AppCacheStorage* storage = service_->storage(); |
| 530 request_.reset(empty_context_.CreateRequest( | 527 request_.reset(empty_context_.CreateRequest( |
| 531 GURL("http://blah/"), url_request_delegate_.get())); | 528 GURL("http://blah/"), url_request_delegate_.get())); |
| 532 | 529 |
| 533 // Setup to create an AppCacheURLRequestJob with orders to deliver | 530 // Setup to create an AppCacheURLRequestJob with orders to deliver |
| 534 // a network response. | 531 // a network response. |
| 535 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 532 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
| 536 request_.get(), empty_context_.network_delegate(), storage)); | 533 request_.get(), NULL, storage)); |
| 537 | 534 |
| 538 if (start_after_delivery_orders) { | 535 if (start_after_delivery_orders) { |
| 539 job->DeliverAppCachedResponse( | 536 job->DeliverAppCachedResponse( |
| 540 GURL(), 0, 111, | 537 GURL(), 0, 111, |
| 541 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 538 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
| 542 false); | 539 false); |
| 543 EXPECT_TRUE(job->is_delivering_appcache_response()); | 540 EXPECT_TRUE(job->is_delivering_appcache_response()); |
| 544 } | 541 } |
| 545 | 542 |
| 546 // Start the request. | 543 // Start the request. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 request_.reset(empty_context_.CreateRequest( | 639 request_.reset(empty_context_.CreateRequest( |
| 643 GURL("http://blah/"), url_request_delegate_.get())); | 640 GURL("http://blah/"), url_request_delegate_.get())); |
| 644 | 641 |
| 645 // Request a range, the 3 middle chars out of 'Hello' | 642 // Request a range, the 3 middle chars out of 'Hello' |
| 646 net::HttpRequestHeaders extra_headers; | 643 net::HttpRequestHeaders extra_headers; |
| 647 extra_headers.SetHeader("Range", "bytes= 1-3"); | 644 extra_headers.SetHeader("Range", "bytes= 1-3"); |
| 648 request_->SetExtraRequestHeaders(extra_headers); | 645 request_->SetExtraRequestHeaders(extra_headers); |
| 649 | 646 |
| 650 // Create job with orders to deliver an appcached entry. | 647 // Create job with orders to deliver an appcached entry. |
| 651 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 648 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
| 652 request_.get(), empty_context_.network_delegate(), storage)); | 649 request_.get(), NULL, storage)); |
| 653 job->DeliverAppCachedResponse( | 650 job->DeliverAppCachedResponse( |
| 654 GURL(), 0, 111, | 651 GURL(), 0, 111, |
| 655 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 652 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
| 656 false); | 653 false); |
| 657 EXPECT_TRUE(job->is_delivering_appcache_response()); | 654 EXPECT_TRUE(job->is_delivering_appcache_response()); |
| 658 | 655 |
| 659 // Start the request. | 656 // Start the request. |
| 660 EXPECT_FALSE(job->has_been_started()); | 657 EXPECT_FALSE(job->has_been_started()); |
| 661 mock_factory_job_ = job; | 658 mock_factory_job_ = job; |
| 662 request_->Start(); | 659 request_->Start(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 | 797 |
| 801 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 798 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { |
| 802 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 799 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
| 803 } | 800 } |
| 804 | 801 |
| 805 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 802 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
| 806 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 803 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
| 807 } | 804 } |
| 808 | 805 |
| 809 } // namespace appcache | 806 } // namespace appcache |
| OLD | NEW |