OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/url_request/url_fetcher_impl.h" | 5 #include "net/url_request/url_fetcher_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 protected: | 157 protected: |
158 GURL test_url_; | 158 GURL test_url_; |
159 scoped_ptr<SpawnedTestServer> test_server_; | 159 scoped_ptr<SpawnedTestServer> test_server_; |
160 MockHostResolver resolver_; | 160 MockHostResolver resolver_; |
161 scoped_ptr<URLFetcher> completed_fetcher_; | 161 scoped_ptr<URLFetcher> completed_fetcher_; |
162 }; | 162 }; |
163 | 163 |
164 void URLFetcherTest::CreateFetcher(const GURL& url) { | 164 void URLFetcherTest::CreateFetcher(const GURL& url) { |
165 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 165 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
166 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 166 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
167 io_message_loop_proxy(), request_context())); | 167 io_message_loop_proxy().get(), request_context())); |
168 fetcher_->Start(); | 168 fetcher_->Start(); |
169 } | 169 } |
170 | 170 |
171 void URLFetcherTest::OnURLFetchComplete(const URLFetcher* source) { | 171 void URLFetcherTest::OnURLFetchComplete(const URLFetcher* source) { |
172 EXPECT_TRUE(source->GetStatus().is_success()); | 172 EXPECT_TRUE(source->GetStatus().is_success()); |
173 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK | 173 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK |
174 | 174 |
175 std::string data; | 175 std::string data; |
176 EXPECT_TRUE(source->GetResponseAsString(&data)); | 176 EXPECT_TRUE(source->GetResponseAsString(&data)); |
177 EXPECT_FALSE(data.empty()); | 177 EXPECT_FALSE(data.empty()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // trigger an async resolve. | 210 // trigger an async resolve. |
211 test_url_ = GURL( | 211 test_url_ = GURL( |
212 base::StringPrintf("http://example.com:%d/defaultresponse", | 212 base::StringPrintf("http://example.com:%d/defaultresponse", |
213 test_server_->host_port_pair().port())); | 213 test_server_->host_port_pair().port())); |
214 ASSERT_TRUE(test_url_.is_valid()); | 214 ASSERT_TRUE(test_url_.is_valid()); |
215 } | 215 } |
216 | 216 |
217 void URLFetcherMockDnsTest::CreateFetcher(const GURL& url) { | 217 void URLFetcherMockDnsTest::CreateFetcher(const GURL& url) { |
218 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 218 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
219 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 219 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
220 io_message_loop_proxy(), request_context())); | 220 io_message_loop_proxy().get(), request_context())); |
221 } | 221 } |
222 | 222 |
223 void URLFetcherMockDnsTest::OnURLFetchComplete(const URLFetcher* source) { | 223 void URLFetcherMockDnsTest::OnURLFetchComplete(const URLFetcher* source) { |
224 io_message_loop_proxy()->PostTask(FROM_HERE, | 224 io_message_loop_proxy()->PostTask(FROM_HERE, |
225 base::MessageLoop::QuitClosure()); | 225 base::MessageLoop::QuitClosure()); |
226 ASSERT_EQ(fetcher_, source); | 226 ASSERT_EQ(fetcher_, source); |
227 EXPECT_EQ(test_url_, source->GetOriginalURL()); | 227 EXPECT_EQ(test_url_, source->GetOriginalURL()); |
228 completed_fetcher_.reset(fetcher_); | 228 completed_fetcher_.reset(fetcher_); |
229 } | 229 } |
230 | 230 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 // disowning prevents the file from being deleted. | 515 // disowning prevents the file from being deleted. |
516 bool take_ownership_of_file_; | 516 bool take_ownership_of_file_; |
517 | 517 |
518 // Expected file error code for the test. OK when expecting success. | 518 // Expected file error code for the test. OK when expecting success. |
519 int expected_file_error_; | 519 int expected_file_error_; |
520 }; | 520 }; |
521 | 521 |
522 void URLFetcherPostTest::CreateFetcher(const GURL& url) { | 522 void URLFetcherPostTest::CreateFetcher(const GURL& url) { |
523 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); | 523 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); |
524 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 524 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
525 io_message_loop_proxy(), request_context())); | 525 io_message_loop_proxy().get(), request_context())); |
526 fetcher_->SetUploadData("application/x-www-form-urlencoded", | 526 fetcher_->SetUploadData("application/x-www-form-urlencoded", "bobsyeruncle"); |
527 "bobsyeruncle"); | |
528 fetcher_->Start(); | 527 fetcher_->Start(); |
529 } | 528 } |
530 | 529 |
531 void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) { | 530 void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) { |
532 std::string data; | 531 std::string data; |
533 EXPECT_TRUE(source->GetResponseAsString(&data)); | 532 EXPECT_TRUE(source->GetResponseAsString(&data)); |
534 EXPECT_EQ(std::string("bobsyeruncle"), data); | 533 EXPECT_EQ(std::string("bobsyeruncle"), data); |
535 URLFetcherTest::OnURLFetchComplete(source); | 534 URLFetcherTest::OnURLFetchComplete(source); |
536 } | 535 } |
537 | 536 |
538 URLFetcherPostFileTest::URLFetcherPostFileTest() | 537 URLFetcherPostFileTest::URLFetcherPostFileTest() |
539 : range_offset_(0), | 538 : range_offset_(0), |
540 range_length_(kuint64max) { | 539 range_length_(kuint64max) { |
541 PathService::Get(base::DIR_SOURCE_ROOT, &path_); | 540 PathService::Get(base::DIR_SOURCE_ROOT, &path_); |
542 path_ = path_.Append(FILE_PATH_LITERAL("net")); | 541 path_ = path_.Append(FILE_PATH_LITERAL("net")); |
543 path_ = path_.Append(FILE_PATH_LITERAL("data")); | 542 path_ = path_.Append(FILE_PATH_LITERAL("data")); |
544 path_ = path_.Append(FILE_PATH_LITERAL("url_request_unittest")); | 543 path_ = path_.Append(FILE_PATH_LITERAL("url_request_unittest")); |
545 path_ = path_.Append(FILE_PATH_LITERAL("BullRunSpeech.txt")); | 544 path_ = path_.Append(FILE_PATH_LITERAL("BullRunSpeech.txt")); |
546 } | 545 } |
547 | 546 |
548 void URLFetcherPostFileTest::CreateFetcher(const GURL& url) { | 547 void URLFetcherPostFileTest::CreateFetcher(const GURL& url) { |
549 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); | 548 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); |
550 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 549 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
551 io_message_loop_proxy(), request_context())); | 550 io_message_loop_proxy().get(), request_context())); |
552 fetcher_->SetUploadFilePath("application/x-www-form-urlencoded", | 551 fetcher_->SetUploadFilePath("application/x-www-form-urlencoded", |
553 path_, | 552 path_, |
554 range_offset_, | 553 range_offset_, |
555 range_length_, | 554 range_length_, |
556 base::MessageLoopProxy::current()); | 555 base::MessageLoopProxy::current()); |
557 fetcher_->Start(); | 556 fetcher_->Start(); |
558 } | 557 } |
559 | 558 |
560 void URLFetcherPostFileTest::OnURLFetchComplete(const URLFetcher* source) { | 559 void URLFetcherPostFileTest::OnURLFetchComplete(const URLFetcher* source) { |
561 std::string expected; | 560 std::string expected; |
(...skipping 25 matching lines...) Expand all Loading... |
587 EXPECT_TRUE(data.empty()); | 586 EXPECT_TRUE(data.empty()); |
588 | 587 |
589 CleanupAfterFetchComplete(); | 588 CleanupAfterFetchComplete(); |
590 // Do not call the super class method URLFetcherTest::OnURLFetchComplete, | 589 // Do not call the super class method URLFetcherTest::OnURLFetchComplete, |
591 // since it expects a non-empty response. | 590 // since it expects a non-empty response. |
592 } | 591 } |
593 | 592 |
594 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { | 593 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { |
595 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 594 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
596 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 595 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
597 io_message_loop_proxy(), request_context())); | 596 io_message_loop_proxy().get(), request_context())); |
598 fetcher_->Start(); | 597 fetcher_->Start(); |
599 } | 598 } |
600 | 599 |
601 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( | 600 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( |
602 const URLFetcher* source, int64 progress, int64 total) { | 601 const URLFetcher* source, int64 progress, int64 total) { |
603 // Increasing between 0 and total. | 602 // Increasing between 0 and total. |
604 EXPECT_LE(0, progress); | 603 EXPECT_LE(0, progress); |
605 EXPECT_GE(total, progress); | 604 EXPECT_GE(total, progress); |
606 EXPECT_LE(previous_progress_, progress); | 605 EXPECT_LE(previous_progress_, progress); |
607 EXPECT_EQ(expected_total_, total); | 606 EXPECT_EQ(expected_total_, total); |
608 previous_progress_ = progress; | 607 previous_progress_ = progress; |
609 } | 608 } |
610 | 609 |
611 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { | 610 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { |
612 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 611 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
613 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 612 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
614 io_message_loop_proxy(), request_context())); | 613 io_message_loop_proxy().get(), request_context())); |
615 cancelled_ = false; | 614 cancelled_ = false; |
616 fetcher_->Start(); | 615 fetcher_->Start(); |
617 } | 616 } |
618 | 617 |
619 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( | 618 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( |
620 const URLFetcher* source, int64 current, int64 total) { | 619 const URLFetcher* source, int64 current, int64 total) { |
621 EXPECT_FALSE(cancelled_); | 620 EXPECT_FALSE(cancelled_); |
622 if (!cancelled_) { | 621 if (!cancelled_) { |
623 cancelled_ = true; | 622 cancelled_ = true; |
624 CleanupAfterFetchComplete(); | 623 CleanupAfterFetchComplete(); |
625 } | 624 } |
626 } | 625 } |
627 | 626 |
628 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( | 627 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( |
629 const URLFetcher* source) { | 628 const URLFetcher* source) { |
630 // Should have been cancelled. | 629 // Should have been cancelled. |
631 ADD_FAILURE(); | 630 ADD_FAILURE(); |
632 CleanupAfterFetchComplete(); | 631 CleanupAfterFetchComplete(); |
633 } | 632 } |
634 | 633 |
635 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { | 634 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { |
636 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); | 635 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); |
637 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 636 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
638 io_message_loop_proxy(), request_context())); | 637 io_message_loop_proxy().get(), request_context())); |
639 previous_progress_ = 0; | 638 previous_progress_ = 0; |
640 // Large enough data to require more than one read from UploadDataStream. | 639 // Large enough data to require more than one read from UploadDataStream. |
641 chunk_.assign(1<<16, 'a'); | 640 chunk_.assign(1<<16, 'a'); |
642 // Use chunked upload to wait for a timer event of progress notification. | 641 // Use chunked upload to wait for a timer event of progress notification. |
643 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); | 642 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); |
644 fetcher_->Start(); | 643 fetcher_->Start(); |
645 number_of_chunks_added_ = 1; | 644 number_of_chunks_added_ = 1; |
646 fetcher_->AppendChunkToUpload(chunk_, false); | 645 fetcher_->AppendChunkToUpload(chunk_, false); |
647 } | 646 } |
648 | 647 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 URLFetcherStopOnRedirectTest::URLFetcherStopOnRedirectTest() | 684 URLFetcherStopOnRedirectTest::URLFetcherStopOnRedirectTest() |
686 : callback_called_(false) { | 685 : callback_called_(false) { |
687 } | 686 } |
688 | 687 |
689 URLFetcherStopOnRedirectTest::~URLFetcherStopOnRedirectTest() { | 688 URLFetcherStopOnRedirectTest::~URLFetcherStopOnRedirectTest() { |
690 } | 689 } |
691 | 690 |
692 void URLFetcherStopOnRedirectTest::CreateFetcher(const GURL& url) { | 691 void URLFetcherStopOnRedirectTest::CreateFetcher(const GURL& url) { |
693 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 692 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
694 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 693 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
695 io_message_loop_proxy(), request_context())); | 694 io_message_loop_proxy().get(), request_context())); |
696 fetcher_->SetStopOnRedirect(true); | 695 fetcher_->SetStopOnRedirect(true); |
697 fetcher_->Start(); | 696 fetcher_->Start(); |
698 } | 697 } |
699 | 698 |
700 void URLFetcherStopOnRedirectTest::OnURLFetchComplete( | 699 void URLFetcherStopOnRedirectTest::OnURLFetchComplete( |
701 const URLFetcher* source) { | 700 const URLFetcher* source) { |
702 callback_called_ = true; | 701 callback_called_ = true; |
703 EXPECT_EQ(GURL(kRedirectTarget), source->GetURL()); | 702 EXPECT_EQ(GURL(kRedirectTarget), source->GetURL()); |
704 EXPECT_EQ(URLRequestStatus::CANCELED, source->GetStatus().status()); | 703 EXPECT_EQ(URLRequestStatus::CANCELED, source->GetStatus().status()); |
705 EXPECT_EQ(ERR_ABORTED, source->GetStatus().error()); | 704 EXPECT_EQ(ERR_ABORTED, source->GetStatus().error()); |
706 EXPECT_EQ(301, source->GetResponseCode()); | 705 EXPECT_EQ(301, source->GetResponseCode()); |
707 CleanupAfterFetchComplete(); | 706 CleanupAfterFetchComplete(); |
708 } | 707 } |
709 | 708 |
710 void URLFetcherProtectTest::CreateFetcher(const GURL& url) { | 709 void URLFetcherProtectTest::CreateFetcher(const GURL& url) { |
711 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 710 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
712 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 711 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
713 io_message_loop_proxy(), request_context())); | 712 io_message_loop_proxy().get(), request_context())); |
714 start_time_ = Time::Now(); | 713 start_time_ = Time::Now(); |
715 fetcher_->SetMaxRetriesOn5xx(11); | 714 fetcher_->SetMaxRetriesOn5xx(11); |
716 fetcher_->Start(); | 715 fetcher_->Start(); |
717 } | 716 } |
718 | 717 |
719 void URLFetcherProtectTest::OnURLFetchComplete(const URLFetcher* source) { | 718 void URLFetcherProtectTest::OnURLFetchComplete(const URLFetcher* source) { |
720 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000); | 719 const TimeDelta one_second = TimeDelta::FromMilliseconds(1000); |
721 if (source->GetResponseCode() >= 500) { | 720 if (source->GetResponseCode() >= 500) { |
722 // Now running ServerUnavailable test. | 721 // Now running ServerUnavailable test. |
723 // It takes more than 1 second to finish all 11 requests. | 722 // It takes more than 1 second to finish all 11 requests. |
724 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); | 723 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); |
725 EXPECT_TRUE(source->GetStatus().is_success()); | 724 EXPECT_TRUE(source->GetStatus().is_success()); |
726 std::string data; | 725 std::string data; |
727 EXPECT_TRUE(source->GetResponseAsString(&data)); | 726 EXPECT_TRUE(source->GetResponseAsString(&data)); |
728 EXPECT_FALSE(data.empty()); | 727 EXPECT_FALSE(data.empty()); |
729 CleanupAfterFetchComplete(); | 728 CleanupAfterFetchComplete(); |
730 } else { | 729 } else { |
731 // Now running Overload test. | 730 // Now running Overload test. |
732 static int count = 0; | 731 static int count = 0; |
733 count++; | 732 count++; |
734 if (count < 20) { | 733 if (count < 20) { |
735 fetcher_->SetRequestContext( | 734 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
736 new ThrottlingTestURLRequestContextGetter( | 735 io_message_loop_proxy().get(), request_context())); |
737 io_message_loop_proxy(), request_context())); | |
738 fetcher_->Start(); | 736 fetcher_->Start(); |
739 } else { | 737 } else { |
740 // We have already sent 20 requests continuously. And we expect that | 738 // We have already sent 20 requests continuously. And we expect that |
741 // it takes more than 1 second due to the overload protection settings. | 739 // it takes more than 1 second due to the overload protection settings. |
742 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); | 740 EXPECT_TRUE(Time::Now() - start_time_ >= one_second); |
743 URLFetcherTest::OnURLFetchComplete(source); | 741 URLFetcherTest::OnURLFetchComplete(source); |
744 } | 742 } |
745 } | 743 } |
746 } | 744 } |
747 | 745 |
748 void URLFetcherProtectTestPassedThrough::CreateFetcher(const GURL& url) { | 746 void URLFetcherProtectTestPassedThrough::CreateFetcher(const GURL& url) { |
749 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 747 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
750 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 748 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
751 io_message_loop_proxy(), request_context())); | 749 io_message_loop_proxy().get(), request_context())); |
752 fetcher_->SetAutomaticallyRetryOn5xx(false); | 750 fetcher_->SetAutomaticallyRetryOn5xx(false); |
753 start_time_ = Time::Now(); | 751 start_time_ = Time::Now(); |
754 fetcher_->SetMaxRetriesOn5xx(11); | 752 fetcher_->SetMaxRetriesOn5xx(11); |
755 fetcher_->Start(); | 753 fetcher_->Start(); |
756 } | 754 } |
757 | 755 |
758 void URLFetcherProtectTestPassedThrough::OnURLFetchComplete( | 756 void URLFetcherProtectTestPassedThrough::OnURLFetchComplete( |
759 const URLFetcher* source) { | 757 const URLFetcher* source) { |
760 const TimeDelta one_minute = TimeDelta::FromMilliseconds(60000); | 758 const TimeDelta one_minute = TimeDelta::FromMilliseconds(60000); |
761 if (source->GetResponseCode() >= 500) { | 759 if (source->GetResponseCode() >= 500) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 EXPECT_TRUE(source->GetCookies().empty()); | 798 EXPECT_TRUE(source->GetCookies().empty()); |
801 std::string data; | 799 std::string data; |
802 EXPECT_TRUE(source->GetResponseAsString(&data)); | 800 EXPECT_TRUE(source->GetResponseAsString(&data)); |
803 EXPECT_TRUE(data.empty()); | 801 EXPECT_TRUE(data.empty()); |
804 CleanupAfterFetchComplete(); | 802 CleanupAfterFetchComplete(); |
805 } | 803 } |
806 | 804 |
807 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { | 805 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { |
808 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 806 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
809 CancelTestURLRequestContextGetter* context_getter = | 807 CancelTestURLRequestContextGetter* context_getter = |
810 new CancelTestURLRequestContextGetter(io_message_loop_proxy(), | 808 new CancelTestURLRequestContextGetter(io_message_loop_proxy().get(), url); |
811 url); | |
812 fetcher_->SetRequestContext(context_getter); | 809 fetcher_->SetRequestContext(context_getter); |
813 fetcher_->SetMaxRetriesOn5xx(2); | 810 fetcher_->SetMaxRetriesOn5xx(2); |
814 fetcher_->Start(); | 811 fetcher_->Start(); |
815 // We need to wait for the creation of the URLRequestContext, since we | 812 // We need to wait for the creation of the URLRequestContext, since we |
816 // rely on it being destroyed as a signal to end the test. | 813 // rely on it being destroyed as a signal to end the test. |
817 context_getter->WaitForContextCreation(); | 814 context_getter->WaitForContextCreation(); |
818 CancelRequest(); | 815 CancelRequest(); |
819 } | 816 } |
820 | 817 |
821 void URLFetcherCancelTest::OnURLFetchComplete( | 818 void URLFetcherCancelTest::OnURLFetchComplete( |
(...skipping 13 matching lines...) Expand all Loading... |
835 void URLFetcherMultipleAttemptTest::OnURLFetchComplete( | 832 void URLFetcherMultipleAttemptTest::OnURLFetchComplete( |
836 const URLFetcher* source) { | 833 const URLFetcher* source) { |
837 EXPECT_TRUE(source->GetStatus().is_success()); | 834 EXPECT_TRUE(source->GetStatus().is_success()); |
838 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK | 835 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK |
839 std::string data; | 836 std::string data; |
840 EXPECT_TRUE(source->GetResponseAsString(&data)); | 837 EXPECT_TRUE(source->GetResponseAsString(&data)); |
841 EXPECT_FALSE(data.empty()); | 838 EXPECT_FALSE(data.empty()); |
842 if (!data.empty() && data_.empty()) { | 839 if (!data.empty() && data_.empty()) { |
843 data_ = data; | 840 data_ = data; |
844 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 841 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
845 io_message_loop_proxy(), request_context())); | 842 io_message_loop_proxy().get(), request_context())); |
846 fetcher_->Start(); | 843 fetcher_->Start(); |
847 } else { | 844 } else { |
848 EXPECT_EQ(data, data_); | 845 EXPECT_EQ(data, data_); |
849 CleanupAfterFetchComplete(); | 846 CleanupAfterFetchComplete(); |
850 } | 847 } |
851 } | 848 } |
852 | 849 |
853 void URLFetcherFileTest::CreateFetcherForFile(const GURL& url, | 850 void URLFetcherFileTest::CreateFetcherForFile(const GURL& url, |
854 const base::FilePath& file_path) { | 851 const base::FilePath& file_path) { |
855 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 852 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
856 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 853 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
857 io_message_loop_proxy(), request_context())); | 854 io_message_loop_proxy().get(), request_context())); |
858 | 855 |
859 // Use the IO message loop to do the file operations in this test. | 856 // Use the IO message loop to do the file operations in this test. |
860 fetcher_->SaveResponseToFileAtPath(file_path, io_message_loop_proxy()); | 857 fetcher_->SaveResponseToFileAtPath(file_path, io_message_loop_proxy()); |
861 fetcher_->Start(); | 858 fetcher_->Start(); |
862 } | 859 } |
863 | 860 |
864 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) { | 861 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) { |
865 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 862 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
866 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 863 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
867 io_message_loop_proxy(), request_context())); | 864 io_message_loop_proxy().get(), request_context())); |
868 | 865 |
869 // Use the IO message loop to do the file operations in this test. | 866 // Use the IO message loop to do the file operations in this test. |
870 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); | 867 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); |
871 fetcher_->Start(); | 868 fetcher_->Start(); |
872 } | 869 } |
873 | 870 |
874 void URLFetcherFileTest::OnURLFetchComplete(const URLFetcher* source) { | 871 void URLFetcherFileTest::OnURLFetchComplete(const URLFetcher* source) { |
875 if (expected_file_error_ == OK) { | 872 if (expected_file_error_ == OK) { |
876 EXPECT_TRUE(source->GetStatus().is_success()); | 873 EXPECT_TRUE(source->GetStatus().is_success()); |
877 EXPECT_EQ(source->GetResponseCode(), 200); | 874 EXPECT_EQ(source->GetResponseCode(), 200); |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1523 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). |
1527 | 1524 |
1528 base::MessageLoop::current()->RunUntilIdle(); | 1525 base::MessageLoop::current()->RunUntilIdle(); |
1529 ASSERT_FALSE(file_util::PathExists(file_path_)) << file_path_.value() | 1526 ASSERT_FALSE(file_util::PathExists(file_path_)) << file_path_.value() |
1530 << " not removed."; | 1527 << " not removed."; |
1531 } | 1528 } |
1532 | 1529 |
1533 } // namespace | 1530 } // namespace |
1534 | 1531 |
1535 } // namespace net | 1532 } // namespace net |
OLD | NEW |