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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 void CreateFetcherWithContextGetter( | 85 void CreateFetcherWithContextGetter( |
86 const GURL& url, | 86 const GURL& url, |
87 URLFetcher::RequestType request_type, | 87 URLFetcher::RequestType request_type, |
88 net::URLRequestContextGetter* context_getter) { | 88 net::URLRequestContextGetter* context_getter) { |
89 fetcher_.reset(new URLFetcherImpl(url, request_type, this)); | 89 fetcher_.reset(new URLFetcherImpl(url, request_type, this)); |
90 fetcher_->SetRequestContext(context_getter); | 90 fetcher_->SetRequestContext(context_getter); |
91 } | 91 } |
92 | 92 |
93 URLFetcher* fetcher() const { return fetcher_.get(); } | 93 URLFetcher* fetcher() const { return fetcher_.get(); } |
94 | 94 |
| 95 // Wait until the request has completed or been canceled. |
95 void StartFetcherAndWait() { | 96 void StartFetcherAndWait() { |
96 fetcher_->Start(); | 97 fetcher_->Start(); |
97 WaitForComplete(); | 98 WaitForComplete(); |
98 } | 99 } |
99 | 100 |
100 // Wait until the request has completed, if it's already been started. | 101 // Wait until the request has completed or been canceled. Does not start the |
| 102 // request. |
101 void WaitForComplete() { run_loop_.Run(); } | 103 void WaitForComplete() { run_loop_.Run(); } |
102 | 104 |
| 105 // Cancels the fetch by deleting the fetcher. |
| 106 void CancelFetch() { |
| 107 EXPECT_TRUE(fetcher_); |
| 108 fetcher_.reset(); |
| 109 run_loop_.Quit(); |
| 110 } |
| 111 |
| 112 // URLFetcherDelegate: |
103 void OnURLFetchComplete(const URLFetcher* source) override { | 113 void OnURLFetchComplete(const URLFetcher* source) override { |
| 114 EXPECT_FALSE(did_complete_); |
| 115 EXPECT_TRUE(fetcher_); |
104 EXPECT_EQ(fetcher_.get(), source); | 116 EXPECT_EQ(fetcher_.get(), source); |
105 did_complete_ = true; | 117 did_complete_ = true; |
106 run_loop_.Quit(); | 118 run_loop_.Quit(); |
107 } | 119 } |
108 | 120 |
| 121 void OnURLFetchDownloadProgress(const URLFetcher* source, |
| 122 int64 current, |
| 123 int64 total) override { |
| 124 // Note that the current progress may be greater than the previous progress, |
| 125 // in the case of retrying the request. |
| 126 EXPECT_FALSE(did_complete_); |
| 127 EXPECT_TRUE(fetcher_); |
| 128 EXPECT_EQ(source, fetcher_.get()); |
| 129 |
| 130 EXPECT_LE(0, current); |
| 131 // If file size is not known, |total| is -1. |
| 132 if (total >= 0) |
| 133 EXPECT_LE(current, total); |
| 134 } |
| 135 |
| 136 void OnURLFetchUploadProgress(const URLFetcher* source, |
| 137 int64 current, |
| 138 int64 total) override { |
| 139 // Note that the current progress may be greater than the previous progress, |
| 140 // in the case of retrying the request. |
| 141 EXPECT_FALSE(did_complete_); |
| 142 EXPECT_TRUE(fetcher_); |
| 143 EXPECT_EQ(source, fetcher_.get()); |
| 144 |
| 145 EXPECT_LE(0, current); |
| 146 // If file size is not known, |total| is -1. |
| 147 if (total >= 0) |
| 148 EXPECT_LE(current, total); |
| 149 } |
| 150 |
109 bool did_complete() const { return did_complete_; } | 151 bool did_complete() const { return did_complete_; } |
110 | 152 |
111 private: | 153 private: |
112 bool did_complete_; | 154 bool did_complete_; |
113 | 155 |
114 scoped_ptr<URLFetcherImpl> fetcher_; | 156 scoped_ptr<URLFetcherImpl> fetcher_; |
115 base::RunLoop run_loop_; | 157 base::RunLoop run_loop_; |
116 | 158 |
117 DISALLOW_COPY_AND_ASSIGN(WaitingURLFetcherDelegate); | 159 DISALLOW_COPY_AND_ASSIGN(WaitingURLFetcherDelegate); |
118 }; | 160 }; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // same thread that CreateFetcher() did. | 384 // same thread that CreateFetcher() did. |
343 | 385 |
344 io_message_loop_proxy()->PostTask(FROM_HERE, | 386 io_message_loop_proxy()->PostTask(FROM_HERE, |
345 base::MessageLoop::QuitClosure()); | 387 base::MessageLoop::QuitClosure()); |
346 // If the current message loop is not the IO loop, it will be shut down when | 388 // If the current message loop is not the IO loop, it will be shut down when |
347 // the main loop returns and this thread subsequently goes out of scope. | 389 // the main loop returns and this thread subsequently goes out of scope. |
348 } | 390 } |
349 | 391 |
350 namespace { | 392 namespace { |
351 | 393 |
352 // Version of URLFetcherTest that tests download progress reports. | |
353 class URLFetcherDownloadProgressTest : public URLFetcherTest { | |
354 public: | |
355 URLFetcherDownloadProgressTest() | |
356 : previous_progress_(0), | |
357 expected_total_(0) { | |
358 } | |
359 | |
360 // URLFetcherTest: | |
361 void CreateFetcher(const GURL& url) override; | |
362 | |
363 // URLFetcherDelegate: | |
364 void OnURLFetchDownloadProgress(const URLFetcher* source, | |
365 int64 current, | |
366 int64 total) override; | |
367 | |
368 protected: | |
369 // Download progress returned by the previous callback. | |
370 int64 previous_progress_; | |
371 // Size of the file being downloaded, known in advance (provided by each test | |
372 // case). | |
373 int64 expected_total_; | |
374 }; | |
375 | |
376 // Version of URLFetcherTest that tests progress reports at cancellation. | |
377 class URLFetcherDownloadProgressCancelTest : public URLFetcherTest { | |
378 public: | |
379 // URLFetcherTest: | |
380 void CreateFetcher(const GURL& url) override; | |
381 | |
382 // URLFetcherDelegate: | |
383 void OnURLFetchComplete(const URLFetcher* source) override; | |
384 void OnURLFetchDownloadProgress(const URLFetcher* source, | |
385 int64 current, | |
386 int64 total) override; | |
387 | |
388 protected: | |
389 bool cancelled_; | |
390 }; | |
391 | |
392 // Version of URLFetcherTest that tests upload progress reports. | |
393 class URLFetcherUploadProgressTest : public URLFetcherTest { | |
394 public: | |
395 // URLFetcherTest: | |
396 void CreateFetcher(const GURL& url) override; | |
397 | |
398 // URLFetcherDelegate: | |
399 void OnURLFetchUploadProgress(const URLFetcher* source, | |
400 int64 current, | |
401 int64 total) override; | |
402 | |
403 protected: | |
404 int64 previous_progress_; | |
405 std::string chunk_; | |
406 int64 number_of_chunks_added_; | |
407 }; | |
408 | |
409 // Version of URLFetcherTest that tests request cancellation on shutdown. | 394 // Version of URLFetcherTest that tests request cancellation on shutdown. |
410 class URLFetcherCancelTest : public URLFetcherTest { | 395 class URLFetcherCancelTest : public URLFetcherTest { |
411 public: | 396 public: |
412 // URLFetcherTest: | 397 // URLFetcherTest: |
413 void CreateFetcher(const GURL& url) override; | 398 void CreateFetcher(const GURL& url) override; |
414 | 399 |
415 // URLFetcherDelegate: | 400 // URLFetcherDelegate: |
416 void OnURLFetchComplete(const URLFetcher* source) override; | 401 void OnURLFetchComplete(const URLFetcher* source) override; |
417 | 402 |
418 void CancelRequest(); | 403 void CancelRequest(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 483 |
499 // URLFetcherTest: | 484 // URLFetcherTest: |
500 void SetUpServer() override { | 485 void SetUpServer() override { |
501 SpawnedTestServer::SSLOptions ssl_options( | 486 SpawnedTestServer::SSLOptions ssl_options( |
502 SpawnedTestServer::SSLOptions::CERT_EXPIRED); | 487 SpawnedTestServer::SSLOptions::CERT_EXPIRED); |
503 test_server_.reset(new SpawnedTestServer( | 488 test_server_.reset(new SpawnedTestServer( |
504 SpawnedTestServer::TYPE_HTTPS, ssl_options, base::FilePath(kDocRoot))); | 489 SpawnedTestServer::TYPE_HTTPS, ssl_options, base::FilePath(kDocRoot))); |
505 } | 490 } |
506 }; | 491 }; |
507 | 492 |
508 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { | |
509 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | |
510 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
511 io_message_loop_proxy().get(), request_context())); | |
512 fetcher_->Start(); | |
513 } | |
514 | |
515 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( | |
516 const URLFetcher* source, int64 progress, int64 total) { | |
517 // Increasing between 0 and total. | |
518 EXPECT_LE(0, progress); | |
519 EXPECT_GE(total, progress); | |
520 EXPECT_LE(previous_progress_, progress); | |
521 EXPECT_EQ(expected_total_, total); | |
522 previous_progress_ = progress; | |
523 } | |
524 | |
525 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { | |
526 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | |
527 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
528 io_message_loop_proxy().get(), request_context())); | |
529 cancelled_ = false; | |
530 fetcher_->Start(); | |
531 } | |
532 | |
533 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( | |
534 const URLFetcher* source, int64 current, int64 total) { | |
535 EXPECT_FALSE(cancelled_); | |
536 if (!cancelled_) { | |
537 cancelled_ = true; | |
538 CleanupAfterFetchComplete(); | |
539 } | |
540 } | |
541 | |
542 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( | |
543 const URLFetcher* source) { | |
544 // Should have been cancelled. | |
545 ADD_FAILURE(); | |
546 CleanupAfterFetchComplete(); | |
547 } | |
548 | |
549 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { | |
550 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); | |
551 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
552 io_message_loop_proxy().get(), request_context())); | |
553 previous_progress_ = 0; | |
554 // Large enough data to require more than one read from UploadDataStream. | |
555 chunk_.assign(1<<16, 'a'); | |
556 // Use chunked upload to wait for a timer event of progress notification. | |
557 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); | |
558 fetcher_->Start(); | |
559 number_of_chunks_added_ = 1; | |
560 fetcher_->AppendChunkToUpload(chunk_, false); | |
561 } | |
562 | |
563 void URLFetcherUploadProgressTest::OnURLFetchUploadProgress( | |
564 const URLFetcher* source, int64 current, int64 total) { | |
565 // Increasing between 0 and total. | |
566 EXPECT_LE(0, current); | |
567 EXPECT_GE(static_cast<int64>(chunk_.size()) * number_of_chunks_added_, | |
568 current); | |
569 EXPECT_LE(previous_progress_, current); | |
570 previous_progress_ = current; | |
571 EXPECT_EQ(-1, total); | |
572 | |
573 if (number_of_chunks_added_ < 2) { | |
574 number_of_chunks_added_ += 1; | |
575 fetcher_->AppendChunkToUpload(chunk_, true); | |
576 } | |
577 } | |
578 | |
579 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { | 493 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { |
580 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 494 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
581 CancelTestURLRequestContextGetter* context_getter = | 495 CancelTestURLRequestContextGetter* context_getter = |
582 new CancelTestURLRequestContextGetter(io_message_loop_proxy().get(), url); | 496 new CancelTestURLRequestContextGetter(io_message_loop_proxy().get(), url); |
583 fetcher_->SetRequestContext(context_getter); | 497 fetcher_->SetRequestContext(context_getter); |
584 fetcher_->SetMaxRetriesOn5xx(2); | 498 fetcher_->SetMaxRetriesOn5xx(2); |
585 fetcher_->Start(); | 499 fetcher_->Start(); |
586 // We need to wait for the creation of the URLRequestContext, since we | 500 // We need to wait for the creation of the URLRequestContext, since we |
587 // rely on it being destroyed as a signal to end the test. | 501 // rely on it being destroyed as a signal to end the test. |
588 context_getter->WaitForContextCreation(); | 502 context_getter->WaitForContextCreation(); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 delegate.StartFetcherAndWait(); | 792 delegate.StartFetcherAndWait(); |
879 | 793 |
880 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | 794 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); |
881 EXPECT_EQ(500, delegate.fetcher()->GetResponseCode()); | 795 EXPECT_EQ(500, delegate.fetcher()->GetResponseCode()); |
882 std::string data; | 796 std::string data; |
883 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); | 797 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); |
884 EXPECT_EQ(kCreateUploadStreamBody, data); | 798 EXPECT_EQ(kCreateUploadStreamBody, data); |
885 EXPECT_EQ(2u, num_upload_streams_created()); | 799 EXPECT_EQ(2u, num_upload_streams_created()); |
886 } | 800 } |
887 | 801 |
888 TEST_F(URLFetcherUploadProgressTest, Basic) { | 802 // Checks that upload progress increases over time, never exceeds what's already |
889 CreateFetcher(test_server_->GetURL("echo")); | 803 // been sent, and adds a chunk whenever all previously appended chunks have |
890 base::MessageLoop::current()->Run(); | 804 // been uploaded. |
| 805 class CheckUploadProgressDelegate : public WaitingURLFetcherDelegate { |
| 806 public: |
| 807 CheckUploadProgressDelegate() |
| 808 : chunk_(1 << 16, 'a'), num_chunks_appended_(0), last_seen_progress_(0) {} |
| 809 ~CheckUploadProgressDelegate() override {} |
| 810 |
| 811 void OnURLFetchUploadProgress(const URLFetcher* source, |
| 812 int64 current, |
| 813 int64 total) override { |
| 814 // Run default checks. |
| 815 WaitingURLFetcherDelegate::OnURLFetchUploadProgress(source, current, total); |
| 816 |
| 817 EXPECT_LE(last_seen_progress_, current); |
| 818 EXPECT_LE(current, bytes_appended()); |
| 819 last_seen_progress_ = current; |
| 820 MaybeAppendChunk(); |
| 821 } |
| 822 |
| 823 // Append the next chunk if all previously appended chunks have been sent. |
| 824 void MaybeAppendChunk() { |
| 825 const int kNumChunks = 5; |
| 826 if (last_seen_progress_ == bytes_appended() && |
| 827 num_chunks_appended_ < kNumChunks) { |
| 828 ++num_chunks_appended_; |
| 829 fetcher()->AppendChunkToUpload(chunk_, |
| 830 num_chunks_appended_ == kNumChunks); |
| 831 } |
| 832 } |
| 833 |
| 834 private: |
| 835 int64 bytes_appended() const { return num_chunks_appended_ * chunk_.size(); } |
| 836 |
| 837 const std::string chunk_; |
| 838 |
| 839 int64 num_chunks_appended_; |
| 840 int64 last_seen_progress_; |
| 841 |
| 842 DISALLOW_COPY_AND_ASSIGN(CheckUploadProgressDelegate); |
| 843 }; |
| 844 |
| 845 TEST_F(URLFetcherTest, UploadProgress) { |
| 846 CheckUploadProgressDelegate delegate; |
| 847 delegate.CreateFetcherWithContext(test_server_->GetURL("echo"), |
| 848 URLFetcher::POST, request_context()); |
| 849 // Use a chunked upload so that the upload can be paused after uploading data. |
| 850 // Since upload progress uses a timer, the delegate may not receive any |
| 851 // notification otherwise. |
| 852 delegate.fetcher()->SetChunkedUpload("application/x-www-form-urlencoded"); |
| 853 |
| 854 delegate.fetcher()->Start(); |
| 855 // Append the first chunk. Others will be appended automatically in response |
| 856 // to OnURLFetchUploadProgress events. |
| 857 delegate.MaybeAppendChunk(); |
| 858 delegate.WaitForComplete(); |
| 859 |
| 860 // Make sure there are no pending events that cause problems when run. |
| 861 base::RunLoop().RunUntilIdle(); |
| 862 |
| 863 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); |
| 864 EXPECT_EQ(200, delegate.fetcher()->GetResponseCode()); |
| 865 EXPECT_TRUE(delegate.did_complete()); |
891 } | 866 } |
892 | 867 |
893 TEST_F(URLFetcherDownloadProgressTest, Basic) { | 868 // Checks that download progress never decreases, never exceeds file size, and |
| 869 // that file size is correctly reported. |
| 870 class CheckDownloadProgressDelegate : public WaitingURLFetcherDelegate { |
| 871 public: |
| 872 CheckDownloadProgressDelegate(int64 file_size) |
| 873 : file_size_(file_size), last_seen_progress_(0) {} |
| 874 ~CheckDownloadProgressDelegate() override {} |
| 875 |
| 876 void OnURLFetchDownloadProgress(const URLFetcher* source, |
| 877 int64 current, |
| 878 int64 total) override { |
| 879 // Run default checks. |
| 880 WaitingURLFetcherDelegate::OnURLFetchDownloadProgress(source, current, |
| 881 total); |
| 882 |
| 883 EXPECT_LE(last_seen_progress_, current); |
| 884 EXPECT_EQ(file_size_, total); |
| 885 last_seen_progress_ = current; |
| 886 } |
| 887 |
| 888 private: |
| 889 int64 file_size_; |
| 890 int64 last_seen_progress_; |
| 891 |
| 892 DISALLOW_COPY_AND_ASSIGN(CheckDownloadProgressDelegate); |
| 893 }; |
| 894 |
| 895 TEST_F(URLFetcherTest, DownloadProgress) { |
| 896 // Get a file large enough to require more than one read into |
| 897 // URLFetcher::Core's IOBuffer. |
| 898 const char kFileToFetch[] = "animate1.gif"; |
| 899 |
| 900 std::string file_contents; |
| 901 ASSERT_TRUE(base::ReadFileToString( |
| 902 test_server_->GetDocumentRoot().AppendASCII(kFileToFetch), |
| 903 &file_contents)); |
| 904 |
| 905 CheckDownloadProgressDelegate delegate(file_contents.size()); |
| 906 delegate.CreateFetcherWithContext( |
| 907 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
| 908 URLFetcher::GET, request_context()); |
| 909 delegate.StartFetcherAndWait(); |
| 910 |
| 911 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); |
| 912 EXPECT_EQ(200, delegate.fetcher()->GetResponseCode()); |
| 913 std::string data; |
| 914 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); |
| 915 EXPECT_EQ(file_contents, data); |
| 916 } |
| 917 |
| 918 class CancelOnUploadProgressDelegate : public WaitingURLFetcherDelegate { |
| 919 public: |
| 920 CancelOnUploadProgressDelegate() {} |
| 921 ~CancelOnUploadProgressDelegate() override {} |
| 922 |
| 923 void OnURLFetchUploadProgress(const URLFetcher* source, |
| 924 int64 current, |
| 925 int64 total) override { |
| 926 CancelFetch(); |
| 927 } |
| 928 |
| 929 private: |
| 930 DISALLOW_COPY_AND_ASSIGN(CancelOnUploadProgressDelegate); |
| 931 }; |
| 932 |
| 933 // Check that a fetch can be safely cancelled/deleted during an upload progress |
| 934 // callback. |
| 935 TEST_F(URLFetcherTest, CancelInUploadProgressCallback) { |
| 936 CancelOnUploadProgressDelegate delegate; |
| 937 delegate.CreateFetcherWithContext(test_server_->GetURL("echo"), |
| 938 URLFetcher::POST, request_context()); |
| 939 delegate.fetcher()->SetChunkedUpload("application/x-www-form-urlencoded"); |
| 940 delegate.fetcher()->Start(); |
| 941 // Use a chunked upload so that the upload can be paused after uploading data. |
| 942 // Since uploads progress uses a timer, may not receive any notification, |
| 943 // otherwise. |
| 944 std::string upload_data(1 << 16, 'a'); |
| 945 delegate.fetcher()->AppendChunkToUpload(upload_data, false); |
| 946 delegate.WaitForComplete(); |
| 947 |
| 948 // Make sure there are no pending events that cause problems when run. |
| 949 base::RunLoop().RunUntilIdle(); |
| 950 |
| 951 EXPECT_FALSE(delegate.did_complete()); |
| 952 EXPECT_FALSE(delegate.fetcher()); |
| 953 } |
| 954 |
| 955 class CancelOnDownloadProgressDelegate : public WaitingURLFetcherDelegate { |
| 956 public: |
| 957 CancelOnDownloadProgressDelegate() {} |
| 958 ~CancelOnDownloadProgressDelegate() override {} |
| 959 |
| 960 void OnURLFetchDownloadProgress(const URLFetcher* source, |
| 961 int64 current, |
| 962 int64 total) override { |
| 963 CancelFetch(); |
| 964 } |
| 965 |
| 966 private: |
| 967 DISALLOW_COPY_AND_ASSIGN(CancelOnDownloadProgressDelegate); |
| 968 }; |
| 969 |
| 970 // Check that a fetch can be safely cancelled/deleted during a download progress |
| 971 // callback. |
| 972 TEST_F(URLFetcherTest, CancelInDownloadProgressCallback) { |
894 // Get a file large enough to require more than one read into | 973 // Get a file large enough to require more than one read into |
895 // URLFetcher::Core's IOBuffer. | 974 // URLFetcher::Core's IOBuffer. |
896 static const char kFileToFetch[] = "animate1.gif"; | 975 static const char kFileToFetch[] = "animate1.gif"; |
897 // Hardcoded file size - it cannot be easily fetched when a remote http server | 976 CancelOnDownloadProgressDelegate delegate; |
898 // is used for testing. | 977 delegate.CreateFetcherWithContext( |
899 static const int64 kFileSize = 19021; | 978 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
| 979 URLFetcher::GET, request_context()); |
| 980 delegate.StartFetcherAndWait(); |
900 | 981 |
901 expected_total_ = kFileSize; | 982 // Make sure there are no pending events that cause problems when run. |
| 983 base::RunLoop().RunUntilIdle(); |
902 | 984 |
903 CreateFetcher( | 985 EXPECT_FALSE(delegate.did_complete()); |
904 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | 986 EXPECT_FALSE(delegate.fetcher()); |
905 | |
906 base::MessageLoop::current()->Run(); | |
907 } | |
908 | |
909 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) { | |
910 // Get a file large enough to require more than one read into | |
911 // URLFetcher::Core's IOBuffer. | |
912 static const char kFileToFetch[] = "animate1.gif"; | |
913 CreateFetcher( | |
914 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | |
915 | |
916 base::MessageLoop::current()->Run(); | |
917 } | 987 } |
918 | 988 |
919 TEST_F(URLFetcherTest, Headers) { | 989 TEST_F(URLFetcherTest, Headers) { |
920 WaitingURLFetcherDelegate delegate; | 990 WaitingURLFetcherDelegate delegate; |
921 delegate.CreateFetcherWithContext( | 991 delegate.CreateFetcherWithContext( |
922 test_server_->GetURL("set-header?cache-control: private"), | 992 test_server_->GetURL("set-header?cache-control: private"), |
923 URLFetcher::GET, request_context()); | 993 URLFetcher::GET, request_context()); |
924 delegate.StartFetcherAndWait(); | 994 delegate.StartFetcherAndWait(); |
925 | 995 |
926 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | 996 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 EXPECT_EQ(-1, delegate.fetcher()->GetResponseCode()); | 1344 EXPECT_EQ(-1, delegate.fetcher()->GetResponseCode()); |
1275 EXPECT_TRUE(delegate.fetcher()->GetCookies().empty()); | 1345 EXPECT_TRUE(delegate.fetcher()->GetCookies().empty()); |
1276 std::string data; | 1346 std::string data; |
1277 EXPECT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); | 1347 EXPECT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); |
1278 EXPECT_TRUE(data.empty()); | 1348 EXPECT_TRUE(data.empty()); |
1279 } | 1349 } |
1280 | 1350 |
1281 } // namespace | 1351 } // namespace |
1282 | 1352 |
1283 } // namespace net | 1353 } // namespace net |
OLD | NEW |