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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 } | 253 } |
254 | 254 |
255 // Returns a URL that hangs on DNS resolution. Only hangs when using the | 255 // Returns a URL that hangs on DNS resolution. Only hangs when using the |
256 // request context returned by request_context(). | 256 // request context returned by request_context(). |
257 const GURL& hanging_url() const { return hanging_url_; } | 257 const GURL& hanging_url() const { return hanging_url_; } |
258 | 258 |
259 MockHostResolver* resolver() { return &resolver_; } | 259 MockHostResolver* resolver() { return &resolver_; } |
260 | 260 |
261 // testing::Test: | 261 // testing::Test: |
262 void SetUp() override { | 262 void SetUp() override { |
263 SetUpServer(); | 263 test_server_.reset(new SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, |
264 SpawnedTestServer::kLocalhost, | |
265 base::FilePath(kDocRoot))); | |
264 ASSERT_TRUE(test_server_->Start()); | 266 ASSERT_TRUE(test_server_->Start()); |
265 | 267 |
266 // Set up host resolver so requests for |hanging_url_| block on an async DNS | 268 // Set up host resolver so requests for |hanging_url_| block on an async DNS |
267 // resolver. Calling resolver()->ResolveAllPending() will resume the hung | 269 // resolver. Calling resolver()->ResolveAllPending() will resume the hung |
268 // requests. | 270 // requests. |
269 resolver_.set_ondemand_mode(true); | 271 resolver_.set_ondemand_mode(true); |
270 resolver_.rules()->AddRule("example.com", "127.0.0.1"); | 272 resolver_.rules()->AddRule("example.com", "127.0.0.1"); |
271 hanging_url_ = | 273 hanging_url_ = |
272 GURL(base::StringPrintf("http://example.com:%d/defaultresponse", | 274 GURL(base::StringPrintf("http://example.com:%d/defaultresponse", |
273 test_server_->host_port_pair().port())); | 275 test_server_->host_port_pair().port())); |
274 ASSERT_TRUE(hanging_url_.is_valid()); | 276 ASSERT_TRUE(hanging_url_.is_valid()); |
275 | 277 |
276 context_.reset(new TestURLRequestContext(true)); | 278 context_.reset(new TestURLRequestContext(true)); |
277 context_->set_host_resolver(&resolver_); | 279 context_->set_host_resolver(&resolver_); |
278 context_->set_throttler_manager(&throttler_manager_); | 280 context_->set_throttler_manager(&throttler_manager_); |
279 context_->Init(); | 281 context_->Init(); |
280 | 282 |
281 #if defined(USE_NSS) || defined(OS_IOS) | 283 #if defined(USE_NSS) || defined(OS_IOS) |
282 crypto::EnsureNSSInit(); | 284 crypto::EnsureNSSInit(); |
283 EnsureNSSHttpIOInit(); | 285 EnsureNSSHttpIOInit(); |
284 #endif | 286 #endif |
285 } | 287 } |
286 | 288 |
287 void TearDown() override { | 289 void TearDown() override { |
288 #if defined(USE_NSS) || defined(OS_IOS) | 290 #if defined(USE_NSS) || defined(OS_IOS) |
289 ShutdownNSSHttpIO(); | 291 ShutdownNSSHttpIO(); |
290 #endif | 292 #endif |
291 } | 293 } |
292 | 294 |
293 // Initializes |test_server_| without starting it. Allows subclasses to use | |
294 // their own server configuration. | |
295 virtual void SetUpServer() { | |
296 test_server_.reset(new SpawnedTestServer(SpawnedTestServer::TYPE_HTTP, | |
297 SpawnedTestServer::kLocalhost, | |
298 base::FilePath(kDocRoot))); | |
299 } | |
300 | |
301 // URLFetcher is designed to run on the main UI thread, but in our tests | 295 // URLFetcher is designed to run on the main UI thread, but in our tests |
302 // we assume that the current thread is the IO thread where the URLFetcher | 296 // we assume that the current thread is the IO thread where the URLFetcher |
303 // dispatches its requests to. When we wish to simulate being used from | 297 // dispatches its requests to. When we wish to simulate being used from |
304 // a UI thread, we dispatch a worker thread to do so. | 298 // a UI thread, we dispatch a worker thread to do so. |
305 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 299 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
306 | 300 |
307 scoped_ptr<SpawnedTestServer> test_server_; | 301 scoped_ptr<SpawnedTestServer> test_server_; |
308 GURL hanging_url_; | 302 GURL hanging_url_; |
309 | 303 |
310 size_t num_upload_streams_created_; | 304 size_t num_upload_streams_created_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 void OnURLFetchUploadProgress(const URLFetcher* source, | 393 void OnURLFetchUploadProgress(const URLFetcher* source, |
400 int64 current, | 394 int64 current, |
401 int64 total) override; | 395 int64 total) override; |
402 | 396 |
403 protected: | 397 protected: |
404 int64 previous_progress_; | 398 int64 previous_progress_; |
405 std::string chunk_; | 399 std::string chunk_; |
406 int64 number_of_chunks_added_; | 400 int64 number_of_chunks_added_; |
407 }; | 401 }; |
408 | 402 |
409 // Version of URLFetcherTest that tests bad HTTPS requests. | |
410 class URLFetcherBadHTTPSTest : public URLFetcherTest { | |
411 public: | |
412 URLFetcherBadHTTPSTest(); | |
413 | |
414 // URLFetcherTest: | |
415 void SetUpServer() override; | |
416 | |
417 // URLFetcherDelegate: | |
418 void OnURLFetchComplete(const URLFetcher* source) override; | |
419 | |
420 private: | |
421 base::FilePath cert_dir_; | |
422 }; | |
423 | |
424 // Version of URLFetcherTest that tests request cancellation on shutdown. | 403 // Version of URLFetcherTest that tests request cancellation on shutdown. |
425 class URLFetcherCancelTest : public URLFetcherTest { | 404 class URLFetcherCancelTest : public URLFetcherTest { |
426 public: | 405 public: |
427 // URLFetcherTest: | 406 // URLFetcherTest: |
428 void CreateFetcher(const GURL& url) override; | 407 void CreateFetcher(const GURL& url) override; |
429 | 408 |
430 // URLFetcherDelegate: | 409 // URLFetcherDelegate: |
431 void OnURLFetchComplete(const URLFetcher* source) override; | 410 void OnURLFetchComplete(const URLFetcher* source) override; |
432 | 411 |
433 void CancelRequest(); | 412 void CancelRequest(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 protected: | 478 protected: |
500 ~CancelTestURLRequestContextGetter() override {} | 479 ~CancelTestURLRequestContextGetter() override {} |
501 | 480 |
502 private: | 481 private: |
503 scoped_ptr<TestURLRequestContext> context_; | 482 scoped_ptr<TestURLRequestContext> context_; |
504 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 483 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
505 base::WaitableEvent context_created_; | 484 base::WaitableEvent context_created_; |
506 GURL throttle_for_url_; | 485 GURL throttle_for_url_; |
507 }; | 486 }; |
508 | 487 |
509 // Version of URLFetcherTest that tests retying the same request twice. | |
510 class URLFetcherMultipleAttemptTest : public URLFetcherTest { | |
511 public: | |
512 // URLFetcherDelegate: | |
513 void OnURLFetchComplete(const URLFetcher* source) override; | |
514 | |
515 private: | |
516 std::string data_; | |
517 }; | |
518 | |
519 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { | 488 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { |
520 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 489 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
521 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 490 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
522 io_message_loop_proxy().get(), request_context())); | 491 io_message_loop_proxy().get(), request_context())); |
523 fetcher_->Start(); | 492 fetcher_->Start(); |
524 } | 493 } |
525 | 494 |
526 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( | 495 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( |
527 const URLFetcher* source, int64 progress, int64 total) { | 496 const URLFetcher* source, int64 progress, int64 total) { |
528 // Increasing between 0 and total. | 497 // Increasing between 0 and total. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 EXPECT_LE(previous_progress_, current); | 549 EXPECT_LE(previous_progress_, current); |
581 previous_progress_ = current; | 550 previous_progress_ = current; |
582 EXPECT_EQ(-1, total); | 551 EXPECT_EQ(-1, total); |
583 | 552 |
584 if (number_of_chunks_added_ < 2) { | 553 if (number_of_chunks_added_ < 2) { |
585 number_of_chunks_added_ += 1; | 554 number_of_chunks_added_ += 1; |
586 fetcher_->AppendChunkToUpload(chunk_, true); | 555 fetcher_->AppendChunkToUpload(chunk_, true); |
587 } | 556 } |
588 } | 557 } |
589 | 558 |
590 URLFetcherBadHTTPSTest::URLFetcherBadHTTPSTest() { | |
591 PathService::Get(base::DIR_SOURCE_ROOT, &cert_dir_); | |
592 cert_dir_ = cert_dir_.AppendASCII("chrome"); | |
593 cert_dir_ = cert_dir_.AppendASCII("test"); | |
594 cert_dir_ = cert_dir_.AppendASCII("data"); | |
595 cert_dir_ = cert_dir_.AppendASCII("ssl"); | |
596 cert_dir_ = cert_dir_.AppendASCII("certificates"); | |
mmenke
2015/04/16 19:11:40
Didn't notice this wasn't even being used in my ea
| |
597 } | |
598 | |
599 void URLFetcherBadHTTPSTest::SetUpServer() { | |
600 SpawnedTestServer::SSLOptions ssl_options( | |
601 SpawnedTestServer::SSLOptions::CERT_EXPIRED); | |
602 test_server_.reset(new SpawnedTestServer( | |
603 SpawnedTestServer::TYPE_HTTPS, ssl_options, base::FilePath(kDocRoot))); | |
604 } | |
605 | |
606 // The "server certificate expired" error should result in automatic | |
607 // cancellation of the request by | |
608 // URLRequest::Delegate::OnSSLCertificateError. | |
609 void URLFetcherBadHTTPSTest::OnURLFetchComplete( | |
610 const URLFetcher* source) { | |
611 // This part is different from URLFetcherTest::OnURLFetchComplete | |
612 // because this test expects the request to be cancelled. | |
613 EXPECT_EQ(URLRequestStatus::CANCELED, source->GetStatus().status()); | |
614 EXPECT_EQ(ERR_ABORTED, source->GetStatus().error()); | |
615 EXPECT_EQ(-1, source->GetResponseCode()); | |
616 EXPECT_TRUE(source->GetCookies().empty()); | |
617 std::string data; | |
618 EXPECT_TRUE(source->GetResponseAsString(&data)); | |
619 EXPECT_TRUE(data.empty()); | |
620 CleanupAfterFetchComplete(); | |
621 } | |
622 | |
623 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { | 559 void URLFetcherCancelTest::CreateFetcher(const GURL& url) { |
624 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 560 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
625 CancelTestURLRequestContextGetter* context_getter = | 561 CancelTestURLRequestContextGetter* context_getter = |
626 new CancelTestURLRequestContextGetter(io_message_loop_proxy().get(), url); | 562 new CancelTestURLRequestContextGetter(io_message_loop_proxy().get(), url); |
627 fetcher_->SetRequestContext(context_getter); | 563 fetcher_->SetRequestContext(context_getter); |
628 fetcher_->SetMaxRetriesOn5xx(2); | 564 fetcher_->SetMaxRetriesOn5xx(2); |
629 fetcher_->Start(); | 565 fetcher_->Start(); |
630 // We need to wait for the creation of the URLRequestContext, since we | 566 // We need to wait for the creation of the URLRequestContext, since we |
631 // rely on it being destroyed as a signal to end the test. | 567 // rely on it being destroyed as a signal to end the test. |
632 context_getter->WaitForContextCreation(); | 568 context_getter->WaitForContextCreation(); |
633 CancelRequest(); | 569 CancelRequest(); |
634 } | 570 } |
635 | 571 |
636 void URLFetcherCancelTest::OnURLFetchComplete( | 572 void URLFetcherCancelTest::OnURLFetchComplete( |
637 const URLFetcher* source) { | 573 const URLFetcher* source) { |
638 // We should have cancelled the request before completion. | 574 // We should have cancelled the request before completion. |
639 ADD_FAILURE(); | 575 ADD_FAILURE(); |
640 CleanupAfterFetchComplete(); | 576 CleanupAfterFetchComplete(); |
641 } | 577 } |
642 | 578 |
643 void URLFetcherCancelTest::CancelRequest() { | 579 void URLFetcherCancelTest::CancelRequest() { |
644 delete fetcher_; | 580 delete fetcher_; |
645 // The URLFetcher's test context will post a Quit task once it is | 581 // The URLFetcher's test context will post a Quit task once it is |
646 // deleted. So if this test simply hangs, it means cancellation | 582 // deleted. So if this test simply hangs, it means cancellation |
647 // did not work. | 583 // did not work. |
648 } | 584 } |
649 | 585 |
650 void URLFetcherMultipleAttemptTest::OnURLFetchComplete( | |
651 const URLFetcher* source) { | |
652 EXPECT_TRUE(source->GetStatus().is_success()); | |
653 EXPECT_EQ(200, source->GetResponseCode()); // HTTP OK | |
654 std::string data; | |
655 EXPECT_TRUE(source->GetResponseAsString(&data)); | |
656 EXPECT_FALSE(data.empty()); | |
657 if (!data.empty() && data_.empty()) { | |
658 data_ = data; | |
659 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
660 io_message_loop_proxy().get(), request_context())); | |
661 fetcher_->Start(); | |
662 } else { | |
663 EXPECT_EQ(data, data_); | |
664 CleanupAfterFetchComplete(); | |
665 } | |
666 } | |
667 | |
668 // Create the fetcher on the main thread. Since network IO will happen on the | 586 // Create the fetcher on the main thread. Since network IO will happen on the |
669 // main thread, this will test URLFetcher's ability to do everything on one | 587 // main thread, this will test URLFetcher's ability to do everything on one |
670 // thread. | 588 // thread. |
671 TEST_F(URLFetcherTest, SameThreadTest) { | 589 TEST_F(URLFetcherTest, SameThreadTest) { |
672 WaitingURLFetcherDelegate delegate; | 590 WaitingURLFetcherDelegate delegate; |
673 delegate.CreateFetcherWithContext(test_server_->GetURL(kDefaultResponsePath), | 591 delegate.CreateFetcherWithContext(test_server_->GetURL(kDefaultResponsePath), |
674 URLFetcher::GET, request_context()); | 592 URLFetcher::GET, request_context()); |
675 delegate.StartFetcherAndWait(); | 593 delegate.StartFetcherAndWait(); |
676 | 594 |
677 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | 595 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1120 std::string data; | 1038 std::string data; |
1121 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); | 1039 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); |
1122 EXPECT_FALSE(data.empty()); | 1040 EXPECT_FALSE(data.empty()); |
1123 EXPECT_GT(delegate.fetcher()->GetBackoffDelay().InMicroseconds(), 0); | 1041 EXPECT_GT(delegate.fetcher()->GetBackoffDelay().InMicroseconds(), 0); |
1124 | 1042 |
1125 // The request should not have been retried at all. If it had attempted all | 1043 // The request should not have been retried at all. If it had attempted all |
1126 // 11 retries, that should have taken 2.5 minutes. | 1044 // 11 retries, that should have taken 2.5 minutes. |
1127 EXPECT_TRUE(Time::Now() - start_time < TimeDelta::FromMinutes(1)); | 1045 EXPECT_TRUE(Time::Now() - start_time < TimeDelta::FromMinutes(1)); |
1128 } | 1046 } |
1129 | 1047 |
1130 TEST_F(URLFetcherBadHTTPSTest, BadHTTPSTest) { | 1048 // Test the case of requesting a file from an SSL server with an expired cert. |
1131 CreateFetcher(test_server_->GetURL(kDefaultResponsePath)); | 1049 TEST_F(URLFetcherTest, BadHTTPS) { |
1132 base::MessageLoop::current()->Run(); | 1050 SpawnedTestServer::SSLOptions ssl_options( |
1051 SpawnedTestServer::SSLOptions::CERT_EXPIRED); | |
1052 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTPS, ssl_options, | |
1053 base::FilePath(kDocRoot)); | |
1054 ASSERT_TRUE(test_server.Start()); | |
1055 | |
1056 WaitingURLFetcherDelegate delegate; | |
1057 delegate.CreateFetcherWithContext(test_server.GetURL(kDefaultResponsePath), | |
1058 URLFetcher::GET, request_context()); | |
1059 delegate.StartFetcherAndWait(); | |
1060 | |
1061 EXPECT_EQ(URLRequestStatus::CANCELED, | |
1062 delegate.fetcher()->GetStatus().status()); | |
1063 EXPECT_EQ(ERR_ABORTED, delegate.fetcher()->GetStatus().error()); | |
1064 EXPECT_EQ(-1, delegate.fetcher()->GetResponseCode()); | |
1065 EXPECT_TRUE(delegate.fetcher()->GetCookies().empty()); | |
1066 std::string data; | |
1067 EXPECT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); | |
1068 EXPECT_TRUE(data.empty()); | |
1133 } | 1069 } |
1134 | 1070 |
1135 TEST_F(URLFetcherCancelTest, ReleasesContext) { | 1071 TEST_F(URLFetcherCancelTest, ReleasesContext) { |
1136 GURL url(test_server_->GetURL("files/server-unavailable.html")); | 1072 GURL url(test_server_->GetURL("files/server-unavailable.html")); |
1137 | 1073 |
1138 // Create a separate thread that will create the URLFetcher. The current | 1074 // Create a separate thread that will create the URLFetcher. The current |
1139 // (main) thread will do the IO, and when the fetch is complete it will | 1075 // (main) thread will do the IO, and when the fetch is complete it will |
1140 // terminate the main thread's message loop; then the other thread's | 1076 // terminate the main thread's message loop; then the other thread's |
1141 // message loop will be shut down automatically as the thread goes out of | 1077 // message loop will be shut down automatically as the thread goes out of |
1142 // scope. | 1078 // scope. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1176 | 1112 |
1177 base::Thread t("URLFetcher test thread"); | 1113 base::Thread t("URLFetcher test thread"); |
1178 ASSERT_TRUE(t.Start()); | 1114 ASSERT_TRUE(t.Start()); |
1179 t.message_loop()->PostTask( | 1115 t.message_loop()->PostTask( |
1180 FROM_HERE, | 1116 FROM_HERE, |
1181 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); | 1117 base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url)); |
1182 | 1118 |
1183 base::MessageLoop::current()->Run(); | 1119 base::MessageLoop::current()->Run(); |
1184 } | 1120 } |
1185 | 1121 |
1186 TEST_F(URLFetcherMultipleAttemptTest, SameData) { | 1122 // A URLFetcherDelegate that expects to receive a response body of "request1" |
1187 // Create the fetcher on the main thread. Since IO will happen on the main | 1123 // and then reuses the fetcher for the same URL, setting the "test" request |
1188 // thread, this will test URLFetcher's ability to do everything on one | 1124 // header to "request2". |
1189 // thread. | 1125 class ReuseFetcherDelegate : public WaitingURLFetcherDelegate { |
1190 CreateFetcher(test_server_->GetURL(kDefaultResponsePath)); | 1126 public: |
1127 // |second_request_context_getter| is the context getter used for the second | |
1128 // request. Can't reuse the old one because fetchers release it on completion. | |
1129 ReuseFetcherDelegate( | |
1130 scoped_refptr<URLRequestContextGetter> second_request_context_getter) | |
1131 : first_request_complete_(false), | |
1132 second_request_context_getter_(second_request_context_getter) {} | |
1191 | 1133 |
1192 base::MessageLoop::current()->Run(); | 1134 ~ReuseFetcherDelegate() override {} |
1135 | |
1136 void OnURLFetchComplete(const URLFetcher* source) override { | |
1137 EXPECT_EQ(fetcher(), source); | |
1138 if (!first_request_complete_) { | |
1139 first_request_complete_ = true; | |
1140 EXPECT_TRUE(fetcher()->GetStatus().is_success()); | |
1141 EXPECT_EQ(200, fetcher()->GetResponseCode()); | |
1142 std::string data; | |
1143 ASSERT_TRUE(fetcher()->GetResponseAsString(&data)); | |
1144 EXPECT_EQ("request1", data); | |
1145 | |
1146 fetcher()->SetRequestContext(second_request_context_getter_.get()); | |
1147 fetcher()->SetExtraRequestHeaders("test: request2"); | |
1148 fetcher()->Start(); | |
1149 return; | |
1150 } | |
1151 WaitingURLFetcherDelegate::OnURLFetchComplete(source); | |
1152 } | |
1153 | |
1154 private: | |
1155 bool first_request_complete_; | |
1156 scoped_refptr<URLRequestContextGetter> second_request_context_getter_; | |
1157 | |
1158 DISALLOW_COPY_AND_ASSIGN(ReuseFetcherDelegate); | |
1159 }; | |
1160 | |
1161 TEST_F(URLFetcherTest, ReuseFetcherForSameURL) { | |
1162 // TODO(mmenke): It's really weird that this is supported, particularly | |
1163 // some fields can be modified between requests, but some (Like upload body) | |
1164 // cannot be. Can we get rid of support for this? | |
1165 ReuseFetcherDelegate delegate(new TrivialURLRequestContextGetter( | |
1166 request_context(), base::MessageLoopProxy::current())); | |
1167 delegate.CreateFetcherWithContext(test_server_->GetURL("echoheader?test"), | |
1168 URLFetcher::GET, request_context()); | |
1169 delegate.fetcher()->SetExtraRequestHeaders("test: request1"); | |
1170 delegate.StartFetcherAndWait(); | |
1171 | |
1172 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | |
1173 EXPECT_EQ(200, delegate.fetcher()->GetResponseCode()); | |
1174 std::string data; | |
1175 ASSERT_TRUE(delegate.fetcher()->GetResponseAsString(&data)); | |
1176 EXPECT_EQ("request2", data); | |
1193 } | 1177 } |
1194 | 1178 |
1195 // Get a small file. | 1179 // Get a small file. |
1196 TEST_F(URLFetcherTest, FileTestSmallGet) { | 1180 TEST_F(URLFetcherTest, FileTestSmallGet) { |
1197 const char kFileToFetch[] = "simple.html"; | 1181 const char kFileToFetch[] = "simple.html"; |
1198 | 1182 |
1199 base::ScopedTempDir temp_dir; | 1183 base::ScopedTempDir temp_dir; |
1200 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1184 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1201 base::FilePath out_path = temp_dir.path().AppendASCII(kFileToFetch); | 1185 base::FilePath out_path = temp_dir.path().AppendASCII(kFileToFetch); |
1202 SaveFileTest(kFileToFetch, false, out_path, false); | 1186 SaveFileTest(kFileToFetch, false, out_path, false); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1277 | 1261 |
1278 // If the caller takes the ownership of the temp file, check that the file | 1262 // If the caller takes the ownership of the temp file, check that the file |
1279 // persists even after URLFetcher is gone. | 1263 // persists even after URLFetcher is gone. |
1280 TEST_F(URLFetcherTest, TempFileTestTakeOwnership) { | 1264 TEST_F(URLFetcherTest, TempFileTestTakeOwnership) { |
1281 SaveFileTest("simple.html", true, base::FilePath(), true); | 1265 SaveFileTest("simple.html", true, base::FilePath(), true); |
1282 } | 1266 } |
1283 | 1267 |
1284 } // namespace | 1268 } // namespace |
1285 | 1269 |
1286 } // namespace net | 1270 } // namespace net |
OLD | NEW |