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 bad HTTPS requests. | 394 // Version of URLFetcherTest that tests bad HTTPS requests. |
410 class URLFetcherBadHTTPSTest : public URLFetcherTest { | 395 class URLFetcherBadHTTPSTest : public URLFetcherTest { |
411 public: | 396 public: |
412 URLFetcherBadHTTPSTest(); | 397 URLFetcherBadHTTPSTest(); |
413 | 398 |
414 // URLFetcherTest: | 399 // URLFetcherTest: |
415 void SetUpServer() override; | 400 void SetUpServer() override; |
416 | 401 |
417 // URLFetcherDelegate: | 402 // URLFetcherDelegate: |
418 void OnURLFetchComplete(const URLFetcher* source) override; | 403 void OnURLFetchComplete(const URLFetcher* source) override; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 // Version of URLFetcherTest that tests retying the same request twice. | 494 // Version of URLFetcherTest that tests retying the same request twice. |
510 class URLFetcherMultipleAttemptTest : public URLFetcherTest { | 495 class URLFetcherMultipleAttemptTest : public URLFetcherTest { |
511 public: | 496 public: |
512 // URLFetcherDelegate: | 497 // URLFetcherDelegate: |
513 void OnURLFetchComplete(const URLFetcher* source) override; | 498 void OnURLFetchComplete(const URLFetcher* source) override; |
514 | 499 |
515 private: | 500 private: |
516 std::string data_; | 501 std::string data_; |
517 }; | 502 }; |
518 | 503 |
519 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { | |
520 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | |
521 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
522 io_message_loop_proxy().get(), request_context())); | |
523 fetcher_->Start(); | |
524 } | |
525 | |
526 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( | |
527 const URLFetcher* source, int64 progress, int64 total) { | |
528 // Increasing between 0 and total. | |
529 EXPECT_LE(0, progress); | |
530 EXPECT_GE(total, progress); | |
531 EXPECT_LE(previous_progress_, progress); | |
532 EXPECT_EQ(expected_total_, total); | |
533 previous_progress_ = progress; | |
534 } | |
535 | |
536 void URLFetcherDownloadProgressCancelTest::CreateFetcher(const GURL& url) { | |
537 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | |
538 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
539 io_message_loop_proxy().get(), request_context())); | |
540 cancelled_ = false; | |
541 fetcher_->Start(); | |
542 } | |
543 | |
544 void URLFetcherDownloadProgressCancelTest::OnURLFetchDownloadProgress( | |
545 const URLFetcher* source, int64 current, int64 total) { | |
546 EXPECT_FALSE(cancelled_); | |
547 if (!cancelled_) { | |
548 cancelled_ = true; | |
549 CleanupAfterFetchComplete(); | |
550 } | |
551 } | |
552 | |
553 void URLFetcherDownloadProgressCancelTest::OnURLFetchComplete( | |
554 const URLFetcher* source) { | |
555 // Should have been cancelled. | |
556 ADD_FAILURE(); | |
557 CleanupAfterFetchComplete(); | |
558 } | |
559 | |
560 void URLFetcherUploadProgressTest::CreateFetcher(const GURL& url) { | |
561 fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); | |
562 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
563 io_message_loop_proxy().get(), request_context())); | |
564 previous_progress_ = 0; | |
565 // Large enough data to require more than one read from UploadDataStream. | |
566 chunk_.assign(1<<16, 'a'); | |
567 // Use chunked upload to wait for a timer event of progress notification. | |
568 fetcher_->SetChunkedUpload("application/x-www-form-urlencoded"); | |
569 fetcher_->Start(); | |
570 number_of_chunks_added_ = 1; | |
571 fetcher_->AppendChunkToUpload(chunk_, false); | |
572 } | |
573 | |
574 void URLFetcherUploadProgressTest::OnURLFetchUploadProgress( | |
575 const URLFetcher* source, int64 current, int64 total) { | |
576 // Increasing between 0 and total. | |
577 EXPECT_LE(0, current); | |
578 EXPECT_GE(static_cast<int64>(chunk_.size()) * number_of_chunks_added_, | |
579 current); | |
580 EXPECT_LE(previous_progress_, current); | |
581 previous_progress_ = current; | |
582 EXPECT_EQ(-1, total); | |
583 | |
584 if (number_of_chunks_added_ < 2) { | |
585 number_of_chunks_added_ += 1; | |
586 fetcher_->AppendChunkToUpload(chunk_, true); | |
587 } | |
588 } | |
589 | |
590 URLFetcherBadHTTPSTest::URLFetcherBadHTTPSTest() { | 504 URLFetcherBadHTTPSTest::URLFetcherBadHTTPSTest() { |
591 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); | 505 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); |
592 cert_dir_ = cert_dir_.AppendASCII("chrome"); | 506 cert_dir_ = cert_dir_.AppendASCII("chrome"); |
593 cert_dir_ = cert_dir_.AppendASCII("test"); | 507 cert_dir_ = cert_dir_.AppendASCII("test"); |
594 cert_dir_ = cert_dir_.AppendASCII("data"); | 508 cert_dir_ = cert_dir_.AppendASCII("data"); |
595 cert_dir_ = cert_dir_.AppendASCII("ssl"); | 509 cert_dir_ = cert_dir_.AppendASCII("ssl"); |
596 cert_dir_ = cert_dir_.AppendASCII("certificates"); | 510 cert_dir_ = cert_dir_.AppendASCII("certificates"); |
597 } | 511 } |
598 | 512 |
599 void URLFetcherBadHTTPSTest::SetUpServer() { | 513 void URLFetcherBadHTTPSTest::SetUpServer() { |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
940 delegate.StartFetcherAndWait(); | 854 delegate.StartFetcherAndWait(); |
941 | 855 |
942 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | 856 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); |
943 EXPECT_EQ(500, delegate.fetcher()->GetResponseCode()); | 857 EXPECT_EQ(500, delegate.fetcher()->GetResponseCode()); |
944 std::string data; | 858 std::string data; |
945 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); | 859 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); |
946 EXPECT_EQ(kCreateUploadStreamBody, data); | 860 EXPECT_EQ(kCreateUploadStreamBody, data); |
947 EXPECT_EQ(2u, num_upload_streams_created()); | 861 EXPECT_EQ(2u, num_upload_streams_created()); |
948 } | 862 } |
949 | 863 |
950 TEST_F(URLFetcherUploadProgressTest, Basic) { | 864 // Checks that upload progress increases over time, never exceeds what's already |
951 CreateFetcher(test_server_->GetURL("echo")); | 865 // been sent, and adds a chunk whenever all previously appended chunks have |
952 base::MessageLoop::current()->Run(); | 866 // been uploaded. |
867 class CheckUploadProgressDelegate : public WaitingURLFetcherDelegate { | |
868 public: | |
869 CheckUploadProgressDelegate() | |
870 : chunk_(1 << 16, 'a'), num_chunks_appended_(0), last_seen_progress_(0) {} | |
871 ~CheckUploadProgressDelegate() override {} | |
872 | |
873 void OnURLFetchUploadProgress(const URLFetcher* source, | |
874 int64 current, | |
875 int64 total) override { | |
876 // Run default checks. | |
877 WaitingURLFetcherDelegate::OnURLFetchUploadProgress(source, current, total); | |
878 | |
879 EXPECT_LE(last_seen_progress_, current); | |
880 EXPECT_LE(current, bytes_appended()); | |
881 last_seen_progress_ = current; | |
882 MaybeAppendChunk(); | |
883 } | |
884 | |
885 // Append the next chunk if all previously appended chunks have been sent. | |
886 void MaybeAppendChunk() { | |
887 const int kNumChunks = 5; | |
888 if (last_seen_progress_ == bytes_appended() && | |
889 num_chunks_appended_ < kNumChunks) { | |
890 ++num_chunks_appended_; | |
891 fetcher()->AppendChunkToUpload(chunk_, | |
892 num_chunks_appended_ == kNumChunks); | |
893 } | |
894 } | |
895 | |
896 private: | |
897 int64 bytes_appended() const { return num_chunks_appended_ * chunk_.size(); } | |
898 | |
899 const std::string chunk_; | |
900 | |
901 int64 num_chunks_appended_; | |
902 int64 last_seen_progress_; | |
903 | |
904 DISALLOW_COPY_AND_ASSIGN(CheckUploadProgressDelegate); | |
905 }; | |
906 | |
907 TEST_F(URLFetcherTest, UploadProgress) { | |
908 CheckUploadProgressDelegate delegate; | |
909 delegate.CreateFetcherWithContext(test_server_->GetURL("echo"), | |
910 URLFetcher::POST, request_context()); | |
911 // Use a chunked upload so that the upload can be paused after uploading data. | |
912 // Since upload progress uses a timer, the delegate may not receive any | |
913 // notification, otherwise. | |
davidben
2015/04/16 21:49:54
Nit: I think this comma is superfluous? I dunno, E
mmenke
2015/04/16 21:56:40
I think the rule is it's needed if it's at the sta
| |
914 delegate.fetcher()->SetChunkedUpload("application/x-www-form-urlencoded"); | |
915 | |
916 delegate.fetcher()->Start(); | |
917 // Append the first chunk. Others will be appended automatically in response | |
918 // to OnURLFetchUploadProgress events. | |
919 delegate.MaybeAppendChunk(); | |
920 delegate.WaitForComplete(); | |
921 | |
922 // Make sure there are no pending events that cause problems when run. | |
923 base::RunLoop().RunUntilIdle(); | |
924 | |
925 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | |
926 EXPECT_EQ(200, delegate.fetcher()->GetResponseCode()); | |
927 EXPECT_TRUE(delegate.did_complete()); | |
953 } | 928 } |
954 | 929 |
955 TEST_F(URLFetcherDownloadProgressTest, Basic) { | 930 // Checks that download progress never decreases, never exceeds file size, and |
931 // that file size is correctly reported. | |
932 class CheckDownloadProgressDelegate : public WaitingURLFetcherDelegate { | |
933 public: | |
934 CheckDownloadProgressDelegate(int64 file_size) | |
935 : file_size_(file_size), last_seen_progress_(0) {} | |
936 ~CheckDownloadProgressDelegate() override {} | |
937 | |
938 void OnURLFetchDownloadProgress(const URLFetcher* source, | |
939 int64 current, | |
940 int64 total) override { | |
941 // Run default checks. | |
942 WaitingURLFetcherDelegate::OnURLFetchDownloadProgress(source, current, | |
943 total); | |
944 | |
945 EXPECT_LE(last_seen_progress_, current); | |
946 EXPECT_EQ(file_size_, total); | |
947 last_seen_progress_ = current; | |
948 } | |
949 | |
950 private: | |
951 int64 file_size_; | |
952 int64 last_seen_progress_; | |
953 | |
954 DISALLOW_COPY_AND_ASSIGN(CheckDownloadProgressDelegate); | |
955 }; | |
956 | |
957 TEST_F(URLFetcherTest, DownloadProgress) { | |
958 // Get a file large enough to require more than one read into | |
959 // URLFetcher::Core's IOBuffer. | |
960 const char kFileToFetch[] = "animate1.gif"; | |
961 | |
962 std::string file_contents; | |
963 ASSERT_TRUE(base::ReadFileToString( | |
964 test_server_->GetDocumentRoot().AppendASCII(kFileToFetch), | |
965 &file_contents)); | |
966 | |
967 CheckDownloadProgressDelegate delegate(file_contents.size()); | |
968 delegate.CreateFetcherWithContext( | |
969 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | |
970 URLFetcher::GET, request_context()); | |
971 delegate.StartFetcherAndWait(); | |
972 | |
973 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | |
974 EXPECT_EQ(200, delegate.fetcher()->GetResponseCode()); | |
975 std::string data; | |
976 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); | |
977 EXPECT_EQ(file_contents, data); | |
978 } | |
979 | |
980 class CancelOnUploadProgressDelegate : public WaitingURLFetcherDelegate { | |
981 public: | |
982 CancelOnUploadProgressDelegate() {} | |
983 ~CancelOnUploadProgressDelegate() override {} | |
984 | |
985 void OnURLFetchUploadProgress(const URLFetcher* source, | |
986 int64 current, | |
987 int64 total) override { | |
988 CancelFetch(); | |
989 } | |
990 | |
991 private: | |
992 DISALLOW_COPY_AND_ASSIGN(CancelOnUploadProgressDelegate); | |
993 }; | |
994 | |
995 // Check that a fetch can be safely cancelled/deleted during an upload progress | |
996 // callback. | |
997 TEST_F(URLFetcherTest, CancelInUploadProgressCallback) { | |
998 CancelOnUploadProgressDelegate delegate; | |
999 delegate.CreateFetcherWithContext(test_server_->GetURL("echo"), | |
1000 URLFetcher::POST, request_context()); | |
1001 delegate.fetcher()->SetChunkedUpload("application/x-www-form-urlencoded"); | |
1002 delegate.fetcher()->Start(); | |
1003 // Use a chunked upload so that the upload can be paused after uploading data. | |
1004 // Since uploads progress uses a timer, may not receive any notification, | |
1005 // otherwise. | |
1006 std::string upload_data(1 << 16, 'a'); | |
1007 delegate.fetcher()->AppendChunkToUpload(upload_data, false); | |
1008 delegate.WaitForComplete(); | |
1009 | |
1010 // Make sure there are no pending events that cause problems when run. | |
1011 base::RunLoop().RunUntilIdle(); | |
1012 | |
1013 EXPECT_FALSE(delegate.did_complete()); | |
1014 EXPECT_FALSE(delegate.fetcher()); | |
1015 } | |
1016 | |
1017 class CancelOnDownloadProgressDelegate : public WaitingURLFetcherDelegate { | |
1018 public: | |
1019 CancelOnDownloadProgressDelegate() {} | |
1020 ~CancelOnDownloadProgressDelegate() override {} | |
1021 | |
1022 void OnURLFetchDownloadProgress(const URLFetcher* source, | |
1023 int64 current, | |
1024 int64 total) override { | |
1025 CancelFetch(); | |
1026 } | |
1027 | |
1028 private: | |
1029 DISALLOW_COPY_AND_ASSIGN(CancelOnDownloadProgressDelegate); | |
1030 }; | |
1031 | |
1032 // Check that a fetch can be safely cancelled/deleted during a download progress | |
1033 // callback. | |
1034 TEST_F(URLFetcherTest, CancelInDownloadProgressCallback) { | |
956 // Get a file large enough to require more than one read into | 1035 // Get a file large enough to require more than one read into |
957 // URLFetcher::Core's IOBuffer. | 1036 // URLFetcher::Core's IOBuffer. |
958 static const char kFileToFetch[] = "animate1.gif"; | 1037 static const char kFileToFetch[] = "animate1.gif"; |
959 // Hardcoded file size - it cannot be easily fetched when a remote http server | 1038 CancelOnDownloadProgressDelegate delegate; |
960 // is used for testing. | 1039 delegate.CreateFetcherWithContext( |
961 static const int64 kFileSize = 19021; | 1040 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1041 URLFetcher::GET, request_context()); | |
1042 delegate.StartFetcherAndWait(); | |
962 | 1043 |
963 expected_total_ = kFileSize; | 1044 // Make sure there are no pending events that cause problems when run. |
1045 base::RunLoop().RunUntilIdle(); | |
964 | 1046 |
965 CreateFetcher( | 1047 EXPECT_FALSE(delegate.did_complete()); |
966 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | 1048 EXPECT_FALSE(delegate.fetcher()); |
967 | |
968 base::MessageLoop::current()->Run(); | |
969 } | |
970 | |
971 TEST_F(URLFetcherDownloadProgressCancelTest, CancelWhileProgressReport) { | |
972 // Get a file large enough to require more than one read into | |
973 // URLFetcher::Core's IOBuffer. | |
974 static const char kFileToFetch[] = "animate1.gif"; | |
975 CreateFetcher( | |
976 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | |
977 | |
978 base::MessageLoop::current()->Run(); | |
979 } | 1049 } |
980 | 1050 |
981 TEST_F(URLFetcherTest, Headers) { | 1051 TEST_F(URLFetcherTest, Headers) { |
982 WaitingURLFetcherDelegate delegate; | 1052 WaitingURLFetcherDelegate delegate; |
983 delegate.CreateFetcherWithContext( | 1053 delegate.CreateFetcherWithContext( |
984 test_server_->GetURL("set-header?cache-control: private"), | 1054 test_server_->GetURL("set-header?cache-control: private"), |
985 URLFetcher::GET, request_context()); | 1055 URLFetcher::GET, request_context()); |
986 delegate.StartFetcherAndWait(); | 1056 delegate.StartFetcherAndWait(); |
987 | 1057 |
988 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | 1058 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 | 1347 |
1278 // If the caller takes the ownership of the temp file, check that the file | 1348 // If the caller takes the ownership of the temp file, check that the file |
1279 // persists even after URLFetcher is gone. | 1349 // persists even after URLFetcher is gone. |
1280 TEST_F(URLFetcherTest, TempFileTestTakeOwnership) { | 1350 TEST_F(URLFetcherTest, TempFileTestTakeOwnership) { |
1281 SaveFileTest("simple.html", true, base::FilePath(), true); | 1351 SaveFileTest("simple.html", true, base::FilePath(), true); |
1282 } | 1352 } |
1283 | 1353 |
1284 } // namespace | 1354 } // namespace |
1285 | 1355 |
1286 } // namespace net | 1356 } // namespace net |
OLD | NEW |