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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // Basic ------------------------------------------------------------------- | 377 // Basic ------------------------------------------------------------------- |
378 void Basic() { | 378 void Basic() { |
379 AppCacheStorage* storage = service_->storage(); | 379 AppCacheStorage* storage = service_->storage(); |
380 net::URLRequest request( | 380 net::URLRequest request( |
381 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL, &empty_context_); | 381 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL, &empty_context_); |
382 scoped_refptr<AppCacheURLRequestJob> job; | 382 scoped_refptr<AppCacheURLRequestJob> job; |
383 | 383 |
384 // Create an instance and see that it looks as expected. | 384 // Create an instance and see that it looks as expected. |
385 | 385 |
386 job = new AppCacheURLRequestJob( | 386 job = new AppCacheURLRequestJob( |
387 &request, NULL, storage, NULL); | 387 &request, NULL, storage, NULL, false); |
388 EXPECT_TRUE(job->is_waiting()); | 388 EXPECT_TRUE(job->is_waiting()); |
389 EXPECT_FALSE(job->is_delivering_appcache_response()); | 389 EXPECT_FALSE(job->is_delivering_appcache_response()); |
390 EXPECT_FALSE(job->is_delivering_network_response()); | 390 EXPECT_FALSE(job->is_delivering_network_response()); |
391 EXPECT_FALSE(job->is_delivering_error_response()); | 391 EXPECT_FALSE(job->is_delivering_error_response()); |
392 EXPECT_FALSE(job->has_been_started()); | 392 EXPECT_FALSE(job->has_been_started()); |
393 EXPECT_FALSE(job->has_been_killed()); | 393 EXPECT_FALSE(job->has_been_killed()); |
394 EXPECT_EQ(GURL(), job->manifest_url()); | 394 EXPECT_EQ(GURL(), job->manifest_url()); |
395 EXPECT_EQ(kNoCacheId, job->cache_id()); | 395 EXPECT_EQ(kNoCacheId, job->cache_id()); |
396 EXPECT_FALSE(job->entry().has_response_id()); | 396 EXPECT_FALSE(job->entry().has_response_id()); |
397 | 397 |
398 TestFinished(); | 398 TestFinished(); |
399 } | 399 } |
400 | 400 |
401 // DeliveryOrders ----------------------------------------------------- | 401 // DeliveryOrders ----------------------------------------------------- |
402 void DeliveryOrders() { | 402 void DeliveryOrders() { |
403 AppCacheStorage* storage = service_->storage(); | 403 AppCacheStorage* storage = service_->storage(); |
404 net::URLRequest request( | 404 net::URLRequest request( |
405 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL, &empty_context_); | 405 GURL("http://blah/"), net::DEFAULT_PRIORITY, NULL, &empty_context_); |
406 scoped_refptr<AppCacheURLRequestJob> job; | 406 scoped_refptr<AppCacheURLRequestJob> job; |
407 | 407 |
408 // Create an instance, give it a delivery order and see that | 408 // Create an instance, give it a delivery order and see that |
409 // it looks as expected. | 409 // it looks as expected. |
410 | 410 |
411 job = new AppCacheURLRequestJob(&request, NULL, storage, NULL); | 411 job = new AppCacheURLRequestJob(&request, NULL, storage, NULL, false); |
412 job->DeliverErrorResponse(); | 412 job->DeliverErrorResponse(); |
413 EXPECT_TRUE(job->is_delivering_error_response()); | 413 EXPECT_TRUE(job->is_delivering_error_response()); |
414 EXPECT_FALSE(job->has_been_started()); | 414 EXPECT_FALSE(job->has_been_started()); |
415 | 415 |
416 job = new AppCacheURLRequestJob(&request, NULL, storage, NULL); | 416 job = new AppCacheURLRequestJob(&request, NULL, storage, NULL, false); |
417 job->DeliverNetworkResponse(); | 417 job->DeliverNetworkResponse(); |
418 EXPECT_TRUE(job->is_delivering_network_response()); | 418 EXPECT_TRUE(job->is_delivering_network_response()); |
419 EXPECT_FALSE(job->has_been_started()); | 419 EXPECT_FALSE(job->has_been_started()); |
420 | 420 |
421 job = new AppCacheURLRequestJob(&request, NULL, storage, NULL); | 421 job = new AppCacheURLRequestJob(&request, NULL, storage, NULL, false); |
422 const GURL kManifestUrl("http://blah/"); | 422 const GURL kManifestUrl("http://blah/"); |
423 const int64 kCacheId(1); | 423 const int64 kCacheId(1); |
424 const int64 kGroupId(1); | 424 const int64 kGroupId(1); |
425 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1); | 425 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1); |
426 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kGroupId, | 426 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kGroupId, |
427 kEntry, false); | 427 kEntry, false); |
428 EXPECT_FALSE(job->is_waiting()); | 428 EXPECT_FALSE(job->is_waiting()); |
429 EXPECT_TRUE(job->is_delivering_appcache_response()); | 429 EXPECT_TRUE(job->is_delivering_appcache_response()); |
430 EXPECT_FALSE(job->has_been_started()); | 430 EXPECT_FALSE(job->has_been_started()); |
431 EXPECT_EQ(kManifestUrl, job->manifest_url()); | 431 EXPECT_EQ(kManifestUrl, job->manifest_url()); |
(...skipping 15 matching lines...) Expand all Loading... |
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 NULL); |
453 | 453 |
454 // Setup to create an AppCacheURLRequestJob with orders to deliver | 454 // Setup to create an AppCacheURLRequestJob with orders to deliver |
455 // a network response. | 455 // a network response. |
456 mock_factory_job_ = new AppCacheURLRequestJob( | 456 mock_factory_job_ = new AppCacheURLRequestJob( |
457 request_.get(), NULL, storage, NULL); | 457 request_.get(), NULL, storage, NULL, false); |
458 mock_factory_job_->DeliverNetworkResponse(); | 458 mock_factory_job_->DeliverNetworkResponse(); |
459 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); | 459 EXPECT_TRUE(mock_factory_job_->is_delivering_network_response()); |
460 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 460 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
461 | 461 |
462 // Start the request. | 462 // Start the request. |
463 request_->Start(); | 463 request_->Start(); |
464 | 464 |
465 // The job should have been picked up. | 465 // The job should have been picked up. |
466 EXPECT_FALSE(mock_factory_job_); | 466 EXPECT_FALSE(mock_factory_job_); |
467 // Completion is async. | 467 // Completion is async. |
(...skipping 15 matching lines...) Expand all Loading... |
483 | 483 |
484 AppCacheStorage* storage = service_->storage(); | 484 AppCacheStorage* storage = service_->storage(); |
485 request_ = empty_context_.CreateRequest(GURL("http://blah/"), | 485 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
486 net::DEFAULT_PRIORITY, | 486 net::DEFAULT_PRIORITY, |
487 url_request_delegate_.get(), | 487 url_request_delegate_.get(), |
488 NULL); | 488 NULL); |
489 | 489 |
490 // Setup to create an AppCacheURLRequestJob with orders to deliver | 490 // Setup to create an AppCacheURLRequestJob with orders to deliver |
491 // a network response. | 491 // a network response. |
492 mock_factory_job_ = new AppCacheURLRequestJob( | 492 mock_factory_job_ = new AppCacheURLRequestJob( |
493 request_.get(), NULL, storage, NULL); | 493 request_.get(), NULL, storage, NULL, false); |
494 mock_factory_job_->DeliverErrorResponse(); | 494 mock_factory_job_->DeliverErrorResponse(); |
495 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); | 495 EXPECT_TRUE(mock_factory_job_->is_delivering_error_response()); |
496 EXPECT_FALSE(mock_factory_job_->has_been_started()); | 496 EXPECT_FALSE(mock_factory_job_->has_been_started()); |
497 | 497 |
498 // Start the request. | 498 // Start the request. |
499 request_->Start(); | 499 request_->Start(); |
500 | 500 |
501 // The job should have been picked up. | 501 // The job should have been picked up. |
502 EXPECT_FALSE(mock_factory_job_); | 502 EXPECT_FALSE(mock_factory_job_); |
503 // Completion is async. | 503 // Completion is async. |
(...skipping 30 matching lines...) Expand all Loading... |
534 void RequestAppCachedResource(bool start_after_delivery_orders) { | 534 void RequestAppCachedResource(bool start_after_delivery_orders) { |
535 AppCacheStorage* storage = service_->storage(); | 535 AppCacheStorage* storage = service_->storage(); |
536 request_ = empty_context_.CreateRequest(GURL("http://blah/"), | 536 request_ = empty_context_.CreateRequest(GURL("http://blah/"), |
537 net::DEFAULT_PRIORITY, | 537 net::DEFAULT_PRIORITY, |
538 url_request_delegate_.get(), | 538 url_request_delegate_.get(), |
539 NULL); | 539 NULL); |
540 | 540 |
541 // Setup to create an AppCacheURLRequestJob with orders to deliver | 541 // Setup to create an AppCacheURLRequestJob with orders to deliver |
542 // a network response. | 542 // a network response. |
543 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 543 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
544 request_.get(), NULL, storage, NULL)); | 544 request_.get(), NULL, storage, NULL, false)); |
545 | 545 |
546 if (start_after_delivery_orders) { | 546 if (start_after_delivery_orders) { |
547 job->DeliverAppCachedResponse( | 547 job->DeliverAppCachedResponse( |
548 GURL(), 0, 111, | 548 GURL(), 0, 111, |
549 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 549 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
550 false); | 550 false); |
551 EXPECT_TRUE(job->is_delivering_appcache_response()); | 551 EXPECT_TRUE(job->is_delivering_appcache_response()); |
552 } | 552 } |
553 | 553 |
554 // Start the request. | 554 // Start the request. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 url_request_delegate_.get(), | 653 url_request_delegate_.get(), |
654 NULL); | 654 NULL); |
655 | 655 |
656 // Request a range, the 3 middle chars out of 'Hello' | 656 // Request a range, the 3 middle chars out of 'Hello' |
657 net::HttpRequestHeaders extra_headers; | 657 net::HttpRequestHeaders extra_headers; |
658 extra_headers.SetHeader("Range", "bytes= 1-3"); | 658 extra_headers.SetHeader("Range", "bytes= 1-3"); |
659 request_->SetExtraRequestHeaders(extra_headers); | 659 request_->SetExtraRequestHeaders(extra_headers); |
660 | 660 |
661 // Create job with orders to deliver an appcached entry. | 661 // Create job with orders to deliver an appcached entry. |
662 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( | 662 scoped_refptr<AppCacheURLRequestJob> job(new AppCacheURLRequestJob( |
663 request_.get(), NULL, storage, NULL)); | 663 request_.get(), NULL, storage, NULL, false)); |
664 job->DeliverAppCachedResponse( | 664 job->DeliverAppCachedResponse( |
665 GURL(), 0, 111, | 665 GURL(), 0, 111, |
666 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), | 666 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), |
667 false); | 667 false); |
668 EXPECT_TRUE(job->is_delivering_appcache_response()); | 668 EXPECT_TRUE(job->is_delivering_appcache_response()); |
669 | 669 |
670 // Start the request. | 670 // Start the request. |
671 EXPECT_FALSE(job->has_been_started()); | 671 EXPECT_FALSE(job->has_been_started()); |
672 mock_factory_job_ = job.get(); | 672 mock_factory_job_ = job.get(); |
673 request_->Start(); | 673 request_->Start(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 | 811 |
812 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { | 812 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { |
813 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); | 813 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); |
814 } | 814 } |
815 | 815 |
816 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 816 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
817 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 817 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
818 } | 818 } |
819 | 819 |
820 } // namespace appcache | 820 } // namespace appcache |
OLD | NEW |