Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Side by Side Diff: webkit/appcache/appcache_url_request_job_unittest.cc

Issue 8343018: More groundwork for flat file based response storage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/appcache_url_request_job.cc ('k') | webkit/appcache/mock_appcache_storage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 EXPECT_FALSE(job->has_been_started()); 429 EXPECT_FALSE(job->has_been_started());
430 430
431 job = new AppCacheURLRequestJob(&request, storage); 431 job = new AppCacheURLRequestJob(&request, storage);
432 job->DeliverNetworkResponse(); 432 job->DeliverNetworkResponse();
433 EXPECT_TRUE(job->is_delivering_network_response()); 433 EXPECT_TRUE(job->is_delivering_network_response());
434 EXPECT_FALSE(job->has_been_started()); 434 EXPECT_FALSE(job->has_been_started());
435 435
436 job = new AppCacheURLRequestJob(&request, storage); 436 job = new AppCacheURLRequestJob(&request, storage);
437 const GURL kManifestUrl("http://blah/"); 437 const GURL kManifestUrl("http://blah/");
438 const int64 kCacheId(1); 438 const int64 kCacheId(1);
439 const int64 kGroupId(1);
439 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1); 440 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1);
440 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kEntry, false); 441 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kGroupId,
442 kEntry, false);
441 EXPECT_FALSE(job->is_waiting()); 443 EXPECT_FALSE(job->is_waiting());
442 EXPECT_TRUE(job->is_delivering_appcache_response()); 444 EXPECT_TRUE(job->is_delivering_appcache_response());
443 EXPECT_FALSE(job->has_been_started()); 445 EXPECT_FALSE(job->has_been_started());
444 EXPECT_EQ(kManifestUrl, job->manifest_url()); 446 EXPECT_EQ(kManifestUrl, job->manifest_url());
445 EXPECT_EQ(kCacheId, job->cache_id()); 447 EXPECT_EQ(kCacheId, job->cache_id());
448 EXPECT_EQ(kGroupId, job->group_id());
446 EXPECT_EQ(kEntry.types(), job->entry().types()); 449 EXPECT_EQ(kEntry.types(), job->entry().types());
447 EXPECT_EQ(kEntry.response_id(), job->entry().response_id()); 450 EXPECT_EQ(kEntry.response_id(), job->entry().response_id());
448 451
449 TestFinished(); 452 TestFinished();
450 } 453 }
451 454
452 // DeliverNetworkResponse -------------------------------------------------- 455 // DeliverNetworkResponse --------------------------------------------------
453 456
454 void DeliverNetworkResponse() { 457 void DeliverNetworkResponse() {
455 // This test has async steps. 458 // This test has async steps.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 // This test has several async steps. 523 // This test has several async steps.
521 // 1. Write a small response to response storage. 524 // 1. Write a small response to response storage.
522 // 2. Use net::URLRequest to retrieve it. 525 // 2. Use net::URLRequest to retrieve it.
523 // 3. Verify we received what we expected to receive. 526 // 3. Verify we received what we expected to receive.
524 527
525 PushNextTask(NewRunnableMethod( 528 PushNextTask(NewRunnableMethod(
526 this, &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse)); 529 this, &AppCacheURLRequestJobTest::VerifyDeliverSmallAppCachedResponse));
527 PushNextTask(NewRunnableMethod( 530 PushNextTask(NewRunnableMethod(
528 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, false)); 531 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, false));
529 532
530 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); 533 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
531 written_response_id_ = writer_->response_id(); 534 written_response_id_ = writer_->response_id();
532 WriteBasicResponse(); 535 WriteBasicResponse();
533 // Continues async 536 // Continues async
534 } 537 }
535 538
536 void RequestAppCachedResource(bool start_after_delivery_orders) { 539 void RequestAppCachedResource(bool start_after_delivery_orders) {
537 AppCacheStorage* storage = service_->storage(); 540 AppCacheStorage* storage = service_->storage();
538 request_.reset( 541 request_.reset(
539 new net::URLRequest(GURL("http://blah/"), url_request_delegate_.get())); 542 new net::URLRequest(GURL("http://blah/"), url_request_delegate_.get()));
540 543
541 // Setup to create an AppCacheURLRequestJob with orders to deliver 544 // Setup to create an AppCacheURLRequestJob with orders to deliver
542 // a network response. 545 // a network response.
543 scoped_refptr<AppCacheURLRequestJob> job( 546 scoped_refptr<AppCacheURLRequestJob> job(
544 new AppCacheURLRequestJob(request_.get(), storage)); 547 new AppCacheURLRequestJob(request_.get(), storage));
545 548
546 if (start_after_delivery_orders) { 549 if (start_after_delivery_orders) {
547 job->DeliverAppCachedResponse( 550 job->DeliverAppCachedResponse(
548 GURL(), 111, 551 GURL(), 0, 111,
549 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), 552 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_),
550 false); 553 false);
551 EXPECT_TRUE(job->is_delivering_appcache_response()); 554 EXPECT_TRUE(job->is_delivering_appcache_response());
552 } 555 }
553 556
554 // Start the request. 557 // Start the request.
555 EXPECT_FALSE(job->has_been_started()); 558 EXPECT_FALSE(job->has_been_started());
556 mock_factory_job_ = job; 559 mock_factory_job_ = job;
557 request_->Start(); 560 request_->Start();
558 EXPECT_FALSE(mock_factory_job_); 561 EXPECT_FALSE(mock_factory_job_);
559 EXPECT_TRUE(job->has_been_started()); 562 EXPECT_TRUE(job->has_been_started());
560 563
561 if (!start_after_delivery_orders) { 564 if (!start_after_delivery_orders) {
562 job->DeliverAppCachedResponse( 565 job->DeliverAppCachedResponse(
563 GURL(), 111, 566 GURL(), 0, 111,
564 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), 567 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_),
565 false); 568 false);
566 EXPECT_TRUE(job->is_delivering_appcache_response()); 569 EXPECT_TRUE(job->is_delivering_appcache_response());
567 } 570 }
568 571
569 // Completion is async. 572 // Completion is async.
570 } 573 }
571 574
572 void VerifyDeliverSmallAppCachedResponse() { 575 void VerifyDeliverSmallAppCachedResponse() {
573 EXPECT_TRUE(request_->status().is_success()); 576 EXPECT_TRUE(request_->status().is_success());
(...skipping 14 matching lines...) Expand all
588 // This test has several async steps. 591 // This test has several async steps.
589 // 1. Write a large response to response storage. 592 // 1. Write a large response to response storage.
590 // 2. Use net::URLRequest to retrieve it. 593 // 2. Use net::URLRequest to retrieve it.
591 // 3. Verify we received what we expected to receive. 594 // 3. Verify we received what we expected to receive.
592 595
593 PushNextTask(NewRunnableMethod( 596 PushNextTask(NewRunnableMethod(
594 this, &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse)); 597 this, &AppCacheURLRequestJobTest::VerifyDeliverLargeAppCachedResponse));
595 PushNextTask(NewRunnableMethod( 598 PushNextTask(NewRunnableMethod(
596 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); 599 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
597 600
598 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); 601 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
599 written_response_id_ = writer_->response_id(); 602 written_response_id_ = writer_->response_id();
600 WriteLargeResponse(); 603 WriteLargeResponse();
601 // Continues async 604 // Continues async
602 } 605 }
603 606
604 void WriteLargeResponse() { 607 void WriteLargeResponse() {
605 // 3, 1k blocks 608 // 3, 1k blocks
606 static const char kHttpHeaders[] = 609 static const char kHttpHeaders[] =
607 "HTTP/1.0 200 OK\0Content-Length: 3072\0\0"; 610 "HTTP/1.0 200 OK\0Content-Length: 3072\0\0";
608 scoped_refptr<IOBuffer> body(new IOBuffer(kBlockSize * 3)); 611 scoped_refptr<IOBuffer> body(new IOBuffer(kBlockSize * 3));
(...skipping 20 matching lines...) Expand all
629 632
630 void DeliverPartialResponse() { 633 void DeliverPartialResponse() {
631 // This test has several async steps. 634 // This test has several async steps.
632 // 1. Write a small response to response storage. 635 // 1. Write a small response to response storage.
633 // 2. Use net::URLRequest to retrieve it a subset using a range request 636 // 2. Use net::URLRequest to retrieve it a subset using a range request
634 // 3. Verify we received what we expected to receive. 637 // 3. Verify we received what we expected to receive.
635 PushNextTask(NewRunnableMethod( 638 PushNextTask(NewRunnableMethod(
636 this, &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse)); 639 this, &AppCacheURLRequestJobTest::VerifyDeliverPartialResponse));
637 PushNextTask(NewRunnableMethod( 640 PushNextTask(NewRunnableMethod(
638 this, &AppCacheURLRequestJobTest::MakeRangeRequest)); 641 this, &AppCacheURLRequestJobTest::MakeRangeRequest));
639 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); 642 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
640 written_response_id_ = writer_->response_id(); 643 written_response_id_ = writer_->response_id();
641 WriteBasicResponse(); 644 WriteBasicResponse();
642 // Continues async 645 // Continues async
643 } 646 }
644 647
645 void MakeRangeRequest() { 648 void MakeRangeRequest() {
646 AppCacheStorage* storage = service_->storage(); 649 AppCacheStorage* storage = service_->storage();
647 request_.reset( 650 request_.reset(
648 new net::URLRequest(GURL("http://blah/"), url_request_delegate_.get())); 651 new net::URLRequest(GURL("http://blah/"), url_request_delegate_.get()));
649 652
650 // Request a range, the 3 middle chars out of 'Hello' 653 // Request a range, the 3 middle chars out of 'Hello'
651 net::HttpRequestHeaders extra_headers; 654 net::HttpRequestHeaders extra_headers;
652 extra_headers.SetHeader("Range", "bytes= 1-3"); 655 extra_headers.SetHeader("Range", "bytes= 1-3");
653 request_->SetExtraRequestHeaders(extra_headers); 656 request_->SetExtraRequestHeaders(extra_headers);
654 657
655 // Create job with orders to deliver an appcached entry. 658 // Create job with orders to deliver an appcached entry.
656 scoped_refptr<AppCacheURLRequestJob> job( 659 scoped_refptr<AppCacheURLRequestJob> job(
657 new AppCacheURLRequestJob(request_.get(), storage)); 660 new AppCacheURLRequestJob(request_.get(), storage));
658 job->DeliverAppCachedResponse( 661 job->DeliverAppCachedResponse(
659 GURL(), 111, 662 GURL(), 0, 111,
660 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), 663 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_),
661 false); 664 false);
662 EXPECT_TRUE(job->is_delivering_appcache_response()); 665 EXPECT_TRUE(job->is_delivering_appcache_response());
663 666
664 // Start the request. 667 // Start the request.
665 EXPECT_FALSE(job->has_been_started()); 668 EXPECT_FALSE(job->has_been_started());
666 mock_factory_job_ = job; 669 mock_factory_job_ = job;
667 request_->Start(); 670 request_->Start();
668 EXPECT_FALSE(mock_factory_job_); 671 EXPECT_FALSE(mock_factory_job_);
669 EXPECT_TRUE(job->has_been_started()); 672 EXPECT_TRUE(job->has_been_started());
(...skipping 25 matching lines...) Expand all
695 // This test has several async steps. 698 // This test has several async steps.
696 // 1. Write a large response to response storage. 699 // 1. Write a large response to response storage.
697 // 2. Use net::URLRequest to retrieve it. 700 // 2. Use net::URLRequest to retrieve it.
698 // 3. Cancel the request after data starts coming in. 701 // 3. Cancel the request after data starts coming in.
699 702
700 PushNextTask(NewRunnableMethod( 703 PushNextTask(NewRunnableMethod(
701 this, &AppCacheURLRequestJobTest::VerifyCancel)); 704 this, &AppCacheURLRequestJobTest::VerifyCancel));
702 PushNextTask(NewRunnableMethod( 705 PushNextTask(NewRunnableMethod(
703 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); 706 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
704 707
705 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); 708 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
706 written_response_id_ = writer_->response_id(); 709 written_response_id_ = writer_->response_id();
707 WriteLargeResponse(); 710 WriteLargeResponse();
708 711
709 url_request_delegate_->kill_after_amount_received_ = kBlockSize; 712 url_request_delegate_->kill_after_amount_received_ = kBlockSize;
710 url_request_delegate_->kill_with_io_pending_ = false; 713 url_request_delegate_->kill_with_io_pending_ = false;
711 // Continues async 714 // Continues async
712 } 715 }
713 716
714 void VerifyCancel() { 717 void VerifyCancel() {
715 EXPECT_EQ(net::URLRequestStatus::CANCELED, 718 EXPECT_EQ(net::URLRequestStatus::CANCELED,
716 request_->status().status()); 719 request_->status().status());
717 TestFinished(); 720 TestFinished();
718 } 721 }
719 722
720 // CancelRequestWithIOPending -------------------------------------- 723 // CancelRequestWithIOPending --------------------------------------
721 724
722 void CancelRequestWithIOPending() { 725 void CancelRequestWithIOPending() {
723 // This test has several async steps. 726 // This test has several async steps.
724 // 1. Write a large response to response storage. 727 // 1. Write a large response to response storage.
725 // 2. Use net::URLRequest to retrieve it. 728 // 2. Use net::URLRequest to retrieve it.
726 // 3. Cancel the request after data starts coming in. 729 // 3. Cancel the request after data starts coming in.
727 730
728 PushNextTask(NewRunnableMethod( 731 PushNextTask(NewRunnableMethod(
729 this, &AppCacheURLRequestJobTest::VerifyCancel)); 732 this, &AppCacheURLRequestJobTest::VerifyCancel));
730 PushNextTask(NewRunnableMethod( 733 PushNextTask(NewRunnableMethod(
731 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true)); 734 this, &AppCacheURLRequestJobTest::RequestAppCachedResource, true));
732 735
733 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); 736 writer_.reset(service_->storage()->CreateResponseWriter(GURL(), 0));
734 written_response_id_ = writer_->response_id(); 737 written_response_id_ = writer_->response_id();
735 WriteLargeResponse(); 738 WriteLargeResponse();
736 739
737 url_request_delegate_->kill_after_amount_received_ = kBlockSize; 740 url_request_delegate_->kill_after_amount_received_ = kBlockSize;
738 url_request_delegate_->kill_with_io_pending_ = true; 741 url_request_delegate_->kill_with_io_pending_ = true;
739 // Continues async 742 // Continues async
740 } 743 }
741 744
742 745
743 // Data members -------------------------------------------------------- 746 // Data members --------------------------------------------------------
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 817
815 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { 818 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) {
816 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); 819 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending);
817 } 820 }
818 821
819 } // namespace appcache 822 } // namespace appcache
820 823
821 // AppCacheURLRequestJobTest is expected to always live longer than the 824 // AppCacheURLRequestJobTest is expected to always live longer than the
822 // runnable methods. This lets us call NewRunnableMethod on its instances. 825 // runnable methods. This lets us call NewRunnableMethod on its instances.
823 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest); 826 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest);
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_url_request_job.cc ('k') | webkit/appcache/mock_appcache_storage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698