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

Side by Side Diff: content/browser/appcache/appcache_url_request_job_unittest.cc

Issue 2865613002: Add an abstraction for a job in the AppCacheRequestHandler class. (Closed)
Patch Set: Fix compile failures Created 3 years, 7 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
« no previous file with comments | « content/browser/appcache/appcache_url_request_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/browser/appcache/appcache_url_request_job.h" 5 #include "content/browser/appcache/appcache_url_request_job.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 void Basic() { 459 void Basic() {
460 AppCacheStorage* storage = service_->storage(); 460 AppCacheStorage* storage = service_->storage();
461 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 461 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
462 net::DEFAULT_PRIORITY, nullptr); 462 net::DEFAULT_PRIORITY, nullptr);
463 463
464 // Create an instance and see that it looks as expected. 464 // Create an instance and see that it looks as expected.
465 465
466 std::unique_ptr<AppCacheURLRequestJob> job( 466 std::unique_ptr<AppCacheURLRequestJob> job(
467 new AppCacheURLRequestJob(request_.get(), nullptr, storage, nullptr, 467 new AppCacheURLRequestJob(request_.get(), nullptr, storage, nullptr,
468 false, base::Bind(&ExpectNotRestarted))); 468 false, base::Bind(&ExpectNotRestarted)));
469 EXPECT_TRUE(job->is_waiting()); 469 EXPECT_TRUE(job->IsWaiting());
470 EXPECT_FALSE(job->is_delivering_appcache_response()); 470 EXPECT_FALSE(job->IsDeliveringAppCacheResponse());
471 EXPECT_FALSE(job->is_delivering_network_response()); 471 EXPECT_FALSE(job->IsDeliveringNetworkResponse());
472 EXPECT_FALSE(job->is_delivering_error_response()); 472 EXPECT_FALSE(job->IsDeliveringErrorResponse());
473 EXPECT_FALSE(job->has_been_started()); 473 EXPECT_FALSE(job->IsStarted());
474 EXPECT_FALSE(job->has_been_killed()); 474 EXPECT_FALSE(job->has_been_killed());
475 EXPECT_EQ(GURL(), job->manifest_url()); 475 EXPECT_EQ(GURL(), job->manifest_url());
476 EXPECT_EQ(kAppCacheNoCacheId, job->cache_id()); 476 EXPECT_EQ(kAppCacheNoCacheId, job->cache_id());
477 EXPECT_FALSE(job->entry().has_response_id()); 477 EXPECT_FALSE(job->entry().has_response_id());
478 478
479 TestFinished(); 479 TestFinished();
480 } 480 }
481 481
482 // DeliveryOrders ----------------------------------------------------- 482 // DeliveryOrders -----------------------------------------------------
483 void DeliveryOrders() { 483 void DeliveryOrders() {
484 AppCacheStorage* storage = service_->storage(); 484 AppCacheStorage* storage = service_->storage();
485 std::unique_ptr<net::URLRequest> request(empty_context_->CreateRequest( 485 std::unique_ptr<net::URLRequest> request(empty_context_->CreateRequest(
486 GURL("http://blah/"), net::DEFAULT_PRIORITY, nullptr)); 486 GURL("http://blah/"), net::DEFAULT_PRIORITY, nullptr));
487 487
488 // Create an instance, give it a delivery order and see that 488 // Create an instance, give it a delivery order and see that
489 // it looks as expected. 489 // it looks as expected.
490 490
491 std::unique_ptr<AppCacheURLRequestJob> job( 491 std::unique_ptr<AppCacheURLRequestJob> job(
492 new AppCacheURLRequestJob(request.get(), nullptr, storage, nullptr, 492 new AppCacheURLRequestJob(request.get(), nullptr, storage, nullptr,
493 false, base::Bind(&ExpectNotRestarted))); 493 false, base::Bind(&ExpectNotRestarted)));
494 job->DeliverErrorResponse(); 494 job->DeliverErrorResponse();
495 EXPECT_TRUE(job->is_delivering_error_response()); 495 EXPECT_TRUE(job->IsDeliveringErrorResponse());
496 EXPECT_FALSE(job->has_been_started()); 496 EXPECT_FALSE(job->IsStarted());
497 497
498 job.reset(new AppCacheURLRequestJob(request.get(), nullptr, storage, 498 job.reset(new AppCacheURLRequestJob(request.get(), nullptr, storage,
499 nullptr, false, 499 nullptr, false,
500 base::Bind(&ExpectNotRestarted))); 500 base::Bind(&ExpectNotRestarted)));
501 job->DeliverNetworkResponse(); 501 job->DeliverNetworkResponse();
502 EXPECT_TRUE(job->is_delivering_network_response()); 502 EXPECT_TRUE(job->IsDeliveringNetworkResponse());
503 EXPECT_FALSE(job->has_been_started()); 503 EXPECT_FALSE(job->IsStarted());
504 504
505 job.reset(new AppCacheURLRequestJob(request.get(), nullptr, storage, 505 job.reset(new AppCacheURLRequestJob(request.get(), nullptr, storage,
506 nullptr, false, 506 nullptr, false,
507 base::Bind(&ExpectNotRestarted))); 507 base::Bind(&ExpectNotRestarted)));
508 const GURL kManifestUrl("http://blah/"); 508 const GURL kManifestUrl("http://blah/");
509 const int64_t kCacheId(1); 509 const int64_t kCacheId(1);
510 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1); 510 const AppCacheEntry kEntry(AppCacheEntry::EXPLICIT, 1);
511 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kEntry, false); 511 job->DeliverAppCachedResponse(kManifestUrl, kCacheId, kEntry, false);
512 EXPECT_FALSE(job->is_waiting()); 512 EXPECT_FALSE(job->IsWaiting());
513 EXPECT_TRUE(job->is_delivering_appcache_response()); 513 EXPECT_TRUE(job->IsDeliveringAppCacheResponse());
514 EXPECT_FALSE(job->has_been_started()); 514 EXPECT_FALSE(job->IsStarted());
515 EXPECT_EQ(kManifestUrl, job->manifest_url()); 515 EXPECT_EQ(kManifestUrl, job->manifest_url());
516 EXPECT_EQ(kCacheId, job->cache_id()); 516 EXPECT_EQ(kCacheId, job->cache_id());
517 EXPECT_EQ(kEntry.types(), job->entry().types()); 517 EXPECT_EQ(kEntry.types(), job->entry().types());
518 EXPECT_EQ(kEntry.response_id(), job->entry().response_id()); 518 EXPECT_EQ(kEntry.response_id(), job->entry().response_id());
519 519
520 TestFinished(); 520 TestFinished();
521 } 521 }
522 522
523 // DeliverNetworkResponse -------------------------------------------------- 523 // DeliverNetworkResponse --------------------------------------------------
524 524
525 void DeliverNetworkResponse() { 525 void DeliverNetworkResponse() {
526 // This test has async steps. 526 // This test has async steps.
527 PushNextTask( 527 PushNextTask(
528 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse, 528 base::Bind(&AppCacheURLRequestJobTest::VerifyDeliverNetworkResponse,
529 base::Unretained(this))); 529 base::Unretained(this)));
530 530
531 AppCacheStorage* storage = service_->storage(); 531 AppCacheStorage* storage = service_->storage();
532 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 532 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
533 net::DEFAULT_PRIORITY, 533 net::DEFAULT_PRIORITY,
534 url_request_delegate_.get()); 534 url_request_delegate_.get());
535 535
536 // Set up to create an AppCacheURLRequestJob with orders to deliver 536 // Set up to create an AppCacheURLRequestJob with orders to deliver
537 // a network response. 537 // a network response.
538 std::unique_ptr<AppCacheURLRequestJob> mock_job(new AppCacheURLRequestJob( 538 std::unique_ptr<AppCacheURLRequestJob> mock_job(new AppCacheURLRequestJob(
539 request_.get(), nullptr, storage, nullptr, false, 539 request_.get(), nullptr, storage, nullptr, false,
540 base::Bind(&SetIfCalled, &restart_callback_invoked_))); 540 base::Bind(&SetIfCalled, &restart_callback_invoked_)));
541 mock_job->DeliverNetworkResponse(); 541 mock_job->DeliverNetworkResponse();
542 EXPECT_TRUE(mock_job->is_delivering_network_response()); 542 EXPECT_TRUE(mock_job->IsDeliveringNetworkResponse());
543 EXPECT_FALSE(mock_job->has_been_started()); 543 EXPECT_FALSE(mock_job->IsStarted());
544 job_factory_->SetJob(std::move(mock_job)); 544 job_factory_->SetJob(std::move(mock_job));
545 545
546 // Start the request. 546 // Start the request.
547 request_->Start(); 547 request_->Start();
548 548
549 // The job should have been picked up. 549 // The job should have been picked up.
550 EXPECT_FALSE(job_factory_->has_job()); 550 EXPECT_FALSE(job_factory_->has_job());
551 // Completion is async. 551 // Completion is async.
552 } 552 }
553 553
(...skipping 16 matching lines...) Expand all
570 request_ = empty_context_->CreateRequest(GURL("http://blah/"), 570 request_ = empty_context_->CreateRequest(GURL("http://blah/"),
571 net::DEFAULT_PRIORITY, 571 net::DEFAULT_PRIORITY,
572 url_request_delegate_.get()); 572 url_request_delegate_.get());
573 573
574 // Setup to create an AppCacheURLRequestJob with orders to deliver 574 // Setup to create an AppCacheURLRequestJob with orders to deliver
575 // a network response. 575 // a network response.
576 std::unique_ptr<AppCacheURLRequestJob> mock_job( 576 std::unique_ptr<AppCacheURLRequestJob> mock_job(
577 new AppCacheURLRequestJob(request_.get(), nullptr, storage, nullptr, 577 new AppCacheURLRequestJob(request_.get(), nullptr, storage, nullptr,
578 false, base::Bind(&ExpectNotRestarted))); 578 false, base::Bind(&ExpectNotRestarted)));
579 mock_job->DeliverErrorResponse(); 579 mock_job->DeliverErrorResponse();
580 EXPECT_TRUE(mock_job->is_delivering_error_response()); 580 EXPECT_TRUE(mock_job->IsDeliveringErrorResponse());
581 EXPECT_FALSE(mock_job->has_been_started()); 581 EXPECT_FALSE(mock_job->IsStarted());
582 job_factory_->SetJob(std::move(mock_job)); 582 job_factory_->SetJob(std::move(mock_job));
583 583
584 // Start the request. 584 // Start the request.
585 request_->Start(); 585 request_->Start();
586 586
587 // The job should have been picked up. 587 // The job should have been picked up.
588 EXPECT_FALSE(job_factory_->has_job()); 588 EXPECT_FALSE(job_factory_->has_job());
589 // Completion is async. 589 // Completion is async.
590 } 590 }
591 591
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // Setup to create an AppCacheURLRequestJob with orders to deliver 626 // Setup to create an AppCacheURLRequestJob with orders to deliver
627 // a network response. 627 // a network response.
628 std::unique_ptr<AppCacheURLRequestJob> job( 628 std::unique_ptr<AppCacheURLRequestJob> job(
629 new AppCacheURLRequestJob(request_.get(), NULL, storage, NULL, false, 629 new AppCacheURLRequestJob(request_.get(), NULL, storage, NULL, false,
630 base::Bind(&ExpectNotRestarted))); 630 base::Bind(&ExpectNotRestarted)));
631 631
632 if (start_after_delivery_orders) { 632 if (start_after_delivery_orders) {
633 job->DeliverAppCachedResponse( 633 job->DeliverAppCachedResponse(
634 GURL(), 111, 634 GURL(), 111,
635 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), false); 635 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), false);
636 EXPECT_TRUE(job->is_delivering_appcache_response()); 636 EXPECT_TRUE(job->IsDeliveringAppCacheResponse());
637 } 637 }
638 638
639 // Start the request. 639 // Start the request.
640 EXPECT_FALSE(job->has_been_started()); 640 EXPECT_FALSE(job->IsStarted());
641 base::WeakPtr<AppCacheURLRequestJob> weak_job = job->GetWeakPtr(); 641 base::WeakPtr<AppCacheJob> weak_job = job->GetWeakPtr();
642 job_factory_->SetJob(std::move(job)); 642 job_factory_->SetJob(std::move(job));
643 request_->Start(); 643 request_->Start();
644 EXPECT_FALSE(job_factory_->has_job()); 644 EXPECT_FALSE(job_factory_->has_job());
645 ASSERT_TRUE(weak_job); 645 ASSERT_TRUE(weak_job);
646 EXPECT_TRUE(weak_job->has_been_started()); 646 EXPECT_TRUE(weak_job->IsStarted());
647 647
648 if (!start_after_delivery_orders) { 648 if (!start_after_delivery_orders) {
649 weak_job->DeliverAppCachedResponse( 649 weak_job->DeliverAppCachedResponse(
650 GURL(), 111, 650 GURL(), 111,
651 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), false); 651 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), false);
652 ASSERT_TRUE(weak_job); 652 ASSERT_TRUE(weak_job);
653 EXPECT_TRUE(weak_job->is_delivering_appcache_response()); 653 EXPECT_TRUE(weak_job->IsDeliveringAppCacheResponse());
654 } 654 }
655 655
656 // Completion is async. 656 // Completion is async.
657 } 657 }
658 658
659 void VerifyDeliverSmallAppCachedResponse() { 659 void VerifyDeliverSmallAppCachedResponse() {
660 EXPECT_EQ(net::OK, url_request_delegate_->request_status()); 660 EXPECT_EQ(net::OK, url_request_delegate_->request_status());
661 EXPECT_TRUE(CompareHttpResponseInfos( 661 EXPECT_TRUE(CompareHttpResponseInfos(
662 write_info_buffer_->http_info.get(), 662 write_info_buffer_->http_info.get(),
663 &url_request_delegate_->received_info_)); 663 &url_request_delegate_->received_info_));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 extra_headers.SetHeader("Range", "bytes= 1-3"); 744 extra_headers.SetHeader("Range", "bytes= 1-3");
745 request_->SetExtraRequestHeaders(extra_headers); 745 request_->SetExtraRequestHeaders(extra_headers);
746 746
747 // Create job with orders to deliver an appcached entry. 747 // Create job with orders to deliver an appcached entry.
748 std::unique_ptr<AppCacheURLRequestJob> job( 748 std::unique_ptr<AppCacheURLRequestJob> job(
749 new AppCacheURLRequestJob(request_.get(), NULL, storage, NULL, false, 749 new AppCacheURLRequestJob(request_.get(), NULL, storage, NULL, false,
750 base::Bind(&ExpectNotRestarted))); 750 base::Bind(&ExpectNotRestarted)));
751 job->DeliverAppCachedResponse( 751 job->DeliverAppCachedResponse(
752 GURL(), 111, 752 GURL(), 111,
753 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), false); 753 AppCacheEntry(AppCacheEntry::EXPLICIT, written_response_id_), false);
754 EXPECT_TRUE(job->is_delivering_appcache_response()); 754 EXPECT_TRUE(job->IsDeliveringAppCacheResponse());
755 755
756 // Start the request. 756 // Start the request.
757 EXPECT_FALSE(job->has_been_started()); 757 EXPECT_FALSE(job->IsStarted());
758 job_factory_->SetJob(std::move(job)); 758 job_factory_->SetJob(std::move(job));
759 request_->Start(); 759 request_->Start();
760 EXPECT_FALSE(job_factory_->has_job()); 760 EXPECT_FALSE(job_factory_->has_job());
761 // Completion is async. 761 // Completion is async.
762 } 762 }
763 763
764 void VerifyDeliverPartialResponse() { 764 void VerifyDeliverPartialResponse() {
765 EXPECT_EQ(net::OK, url_request_delegate_->request_status()); 765 EXPECT_EQ(net::OK, url_request_delegate_->request_status());
766 EXPECT_EQ(3, url_request_delegate_->amount_received_); 766 EXPECT_EQ(3, url_request_delegate_->amount_received_);
767 EXPECT_EQ(0, memcmp(kHttpBasicBody + 1, 767 EXPECT_EQ(0, memcmp(kHttpBasicBody + 1,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 895
896 TEST_F(AppCacheURLRequestJobTest, CancelRequest) { 896 TEST_F(AppCacheURLRequestJobTest, CancelRequest) {
897 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest); 897 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequest);
898 } 898 }
899 899
900 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { 900 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) {
901 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); 901 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending);
902 } 902 }
903 903
904 } // namespace content 904 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/appcache_url_request_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698