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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 scoped_ptr<UploadElementReader>( | 193 scoped_ptr<UploadElementReader>( |
194 new UploadOwnedBytesElementReader(&buffer)), | 194 new UploadOwnedBytesElementReader(&buffer)), |
195 0); | 195 0); |
196 } | 196 } |
197 | 197 |
198 // Number of streams created by CreateUploadStream. | 198 // Number of streams created by CreateUploadStream. |
199 size_t num_upload_streams_created() const { | 199 size_t num_upload_streams_created() const { |
200 return num_upload_streams_created_; | 200 return num_upload_streams_created_; |
201 } | 201 } |
202 | 202 |
203 // Downloads |file_to_fetch| to |out_path|, and checks the contents. Takes | |
204 // ownership of the file if |take_ownership| is true. Caller is epected to | |
205 // cleanup the resulting file. | |
206 void SaveFileTest(const char* file_to_fetch, | |
207 const base::FilePath& out_path, | |
208 bool take_ownership) { | |
209 base::FilePath expected_file = | |
210 test_server_->GetDocumentRoot().AppendASCII(file_to_fetch); | |
211 scoped_ptr<WaitingURLFetcherDelegate> delegate( | |
212 new WaitingURLFetcherDelegate()); | |
213 delegate->CreateFetcherWithContext( | |
214 test_server_->GetURL(std::string(kTestServerFilePrefix) + | |
215 file_to_fetch), | |
216 URLFetcher::GET, request_context()); | |
217 delegate->fetcher()->SaveResponseToFileAtPath( | |
218 out_path, scoped_refptr<base::MessageLoopProxy>( | |
219 base::MessageLoopProxy::current())); | |
220 delegate->StartFetcherAndWait(); | |
221 | |
222 EXPECT_TRUE(delegate->fetcher()->GetStatus().is_success()); | |
223 EXPECT_EQ(200, delegate->fetcher()->GetResponseCode()); | |
224 | |
225 base::FilePath actual_out_path; | |
226 EXPECT_TRUE(delegate->fetcher()->GetResponseAsFilePath(take_ownership, | |
227 &actual_out_path)); | |
228 EXPECT_EQ(out_path, actual_out_path); | |
229 | |
230 EXPECT_TRUE(base::ContentsEqual( | |
231 test_server_->GetDocumentRoot().AppendASCII(file_to_fetch), | |
232 actual_out_path)); | |
233 | |
234 // Delete the delegate and run the message loop to give the fetcher's | |
235 // destructor a chance to delete the file. | |
236 delegate.reset(); | |
237 base::RunLoop().RunUntilIdle(); | |
238 | |
239 // File should only exist if |take_ownership| was true. | |
240 EXPECT_EQ(take_ownership, base::PathExists(actual_out_path)); | |
241 } | |
242 | |
243 // Downloads |file_to_fetch| to a temporary file, and checks the contents. | |
244 // Takes ownership of the file if |take_ownership| is true. Cleans up the | |
245 // temp file when the test is complete. | |
246 void SaveTempFileTest(const char* file_to_fetch, bool take_ownership) { | |
davidben
2015/04/15 18:21:10
These two functions are almost completely identica
mmenke
2015/04/15 18:43:41
Done. Considered this, but was thinking they were
| |
247 base::FilePath expected_file = | |
248 test_server_->GetDocumentRoot().AppendASCII(file_to_fetch); | |
249 scoped_ptr<WaitingURLFetcherDelegate> delegate( | |
250 new WaitingURLFetcherDelegate()); | |
251 delegate->CreateFetcherWithContext( | |
252 test_server_->GetURL(std::string(kTestServerFilePrefix) + | |
253 file_to_fetch), | |
254 URLFetcher::GET, request_context()); | |
255 delegate->fetcher()->SaveResponseToTemporaryFile( | |
256 scoped_refptr<base::MessageLoopProxy>( | |
257 base::MessageLoopProxy::current())); | |
258 delegate->StartFetcherAndWait(); | |
259 | |
260 EXPECT_TRUE(delegate->fetcher()->GetStatus().is_success()); | |
261 EXPECT_EQ(200, delegate->fetcher()->GetResponseCode()); | |
262 | |
263 base::FilePath out_path; | |
264 EXPECT_TRUE( | |
265 delegate->fetcher()->GetResponseAsFilePath(take_ownership, &out_path)); | |
266 | |
267 EXPECT_TRUE(base::ContentsEqual( | |
268 test_server_->GetDocumentRoot().AppendASCII(file_to_fetch), out_path)); | |
269 | |
270 // Delete the delegate and run the message loop to give the fetcher's | |
271 // destructor a chance to delete the file. | |
272 delegate.reset(); | |
273 base::RunLoop().RunUntilIdle(); | |
274 | |
275 // File should only exist if |take_ownership| was true. | |
276 EXPECT_EQ(take_ownership, base::PathExists(out_path)); | |
277 | |
278 // Cleanup. | |
279 if (base::PathExists(out_path)) | |
280 base::DeleteFile(out_path, false); | |
281 } | |
282 | |
203 // Returns a URL that hangs on DNS resolution. Only hangs when using the | 283 // Returns a URL that hangs on DNS resolution. Only hangs when using the |
204 // request context returned by request_context(). | 284 // request context returned by request_context(). |
205 const GURL& hanging_url() const { return hanging_url_; } | 285 const GURL& hanging_url() const { return hanging_url_; } |
206 | 286 |
207 MockHostResolver* resolver() { return &resolver_; } | 287 MockHostResolver* resolver() { return &resolver_; } |
208 | 288 |
209 // testing::Test: | 289 // testing::Test: |
210 void SetUp() override { | 290 void SetUp() override { |
211 SetUpServer(); | 291 SetUpServer(); |
212 ASSERT_TRUE(test_server_->Start()); | 292 ASSERT_TRUE(test_server_->Start()); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 // Version of URLFetcherTest that tests retying the same request twice. | 537 // Version of URLFetcherTest that tests retying the same request twice. |
458 class URLFetcherMultipleAttemptTest : public URLFetcherTest { | 538 class URLFetcherMultipleAttemptTest : public URLFetcherTest { |
459 public: | 539 public: |
460 // URLFetcherDelegate: | 540 // URLFetcherDelegate: |
461 void OnURLFetchComplete(const URLFetcher* source) override; | 541 void OnURLFetchComplete(const URLFetcher* source) override; |
462 | 542 |
463 private: | 543 private: |
464 std::string data_; | 544 std::string data_; |
465 }; | 545 }; |
466 | 546 |
467 class URLFetcherFileTest : public URLFetcherTest { | |
468 public: | |
469 URLFetcherFileTest() : take_ownership_of_file_(false), | |
470 expected_file_error_(OK) {} | |
471 | |
472 void CreateFetcherForFile(const GURL& url, const base::FilePath& file_path); | |
473 void CreateFetcherForTempFile(const GURL& url); | |
474 | |
475 // URLFetcherDelegate: | |
476 void OnURLFetchComplete(const URLFetcher* source) override; | |
477 | |
478 protected: | |
479 base::FilePath expected_file_; | |
480 base::FilePath file_path_; | |
481 | |
482 // Set by the test. Used in OnURLFetchComplete() to decide if | |
483 // the URLFetcher should own the temp file, so that we can test | |
484 // disowning prevents the file from being deleted. | |
485 bool take_ownership_of_file_; | |
486 | |
487 // Expected file error code for the test. OK when expecting success. | |
488 int expected_file_error_; | |
489 }; | |
490 | |
491 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { | 547 void URLFetcherDownloadProgressTest::CreateFetcher(const GURL& url) { |
492 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | 548 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); |
493 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 549 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
494 io_message_loop_proxy().get(), request_context())); | 550 io_message_loop_proxy().get(), request_context())); |
495 fetcher_->Start(); | 551 fetcher_->Start(); |
496 } | 552 } |
497 | 553 |
498 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( | 554 void URLFetcherDownloadProgressTest::OnURLFetchDownloadProgress( |
499 const URLFetcher* source, int64 progress, int64 total) { | 555 const URLFetcher* source, int64 progress, int64 total) { |
500 // Increasing between 0 and total. | 556 // Increasing between 0 and total. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 data_ = data; | 686 data_ = data; |
631 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | 687 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
632 io_message_loop_proxy().get(), request_context())); | 688 io_message_loop_proxy().get(), request_context())); |
633 fetcher_->Start(); | 689 fetcher_->Start(); |
634 } else { | 690 } else { |
635 EXPECT_EQ(data, data_); | 691 EXPECT_EQ(data, data_); |
636 CleanupAfterFetchComplete(); | 692 CleanupAfterFetchComplete(); |
637 } | 693 } |
638 } | 694 } |
639 | 695 |
640 void URLFetcherFileTest::CreateFetcherForFile(const GURL& url, | |
641 const base::FilePath& file_path) { | |
642 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | |
643 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
644 io_message_loop_proxy().get(), request_context())); | |
645 | |
646 // Use the IO message loop to do the file operations in this test. | |
647 fetcher_->SaveResponseToFileAtPath(file_path, io_message_loop_proxy()); | |
648 fetcher_->Start(); | |
649 } | |
650 | |
651 void URLFetcherFileTest::CreateFetcherForTempFile(const GURL& url) { | |
652 fetcher_ = new URLFetcherImpl(url, URLFetcher::GET, this); | |
653 fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( | |
654 io_message_loop_proxy().get(), request_context())); | |
655 | |
656 // Use the IO message loop to do the file operations in this test. | |
657 fetcher_->SaveResponseToTemporaryFile(io_message_loop_proxy()); | |
658 fetcher_->Start(); | |
659 } | |
660 | |
661 void URLFetcherFileTest::OnURLFetchComplete(const URLFetcher* source) { | |
662 if (expected_file_error_ == OK) { | |
663 EXPECT_TRUE(source->GetStatus().is_success()); | |
664 EXPECT_EQ(OK, source->GetStatus().error()); | |
665 EXPECT_EQ(200, source->GetResponseCode()); | |
666 | |
667 EXPECT_TRUE(source->GetResponseAsFilePath( | |
668 take_ownership_of_file_, &file_path_)); | |
669 | |
670 EXPECT_TRUE(base::ContentsEqual(expected_file_, file_path_)); | |
671 } else { | |
672 EXPECT_FALSE(source->GetStatus().is_success()); | |
673 EXPECT_EQ(expected_file_error_, source->GetStatus().error()); | |
674 } | |
675 CleanupAfterFetchComplete(); | |
676 } | |
677 | |
678 // Create the fetcher on the main thread. Since network IO will happen on the | 696 // Create the fetcher on the main thread. Since network IO will happen on the |
679 // main thread, this will test URLFetcher's ability to do everything on one | 697 // main thread, this will test URLFetcher's ability to do everything on one |
680 // thread. | 698 // thread. |
681 TEST_F(URLFetcherTest, SameThreadTest) { | 699 TEST_F(URLFetcherTest, SameThreadTest) { |
682 WaitingURLFetcherDelegate delegate; | 700 WaitingURLFetcherDelegate delegate; |
683 delegate.CreateFetcherWithContext(test_server_->GetURL(kDefaultResponsePath), | 701 delegate.CreateFetcherWithContext(test_server_->GetURL(kDefaultResponsePath), |
684 URLFetcher::GET, request_context()); | 702 URLFetcher::GET, request_context()); |
685 delegate.StartFetcherAndWait(); | 703 delegate.StartFetcherAndWait(); |
686 | 704 |
687 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); | 705 EXPECT_TRUE(delegate.fetcher()->GetStatus().is_success()); |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1195 | 1213 |
1196 TEST_F(URLFetcherMultipleAttemptTest, SameData) { | 1214 TEST_F(URLFetcherMultipleAttemptTest, SameData) { |
1197 // Create the fetcher on the main thread. Since IO will happen on the main | 1215 // Create the fetcher on the main thread. Since IO will happen on the main |
1198 // thread, this will test URLFetcher's ability to do everything on one | 1216 // thread, this will test URLFetcher's ability to do everything on one |
1199 // thread. | 1217 // thread. |
1200 CreateFetcher(test_server_->GetURL(kDefaultResponsePath)); | 1218 CreateFetcher(test_server_->GetURL(kDefaultResponsePath)); |
1201 | 1219 |
1202 base::MessageLoop::current()->Run(); | 1220 base::MessageLoop::current()->Run(); |
1203 } | 1221 } |
1204 | 1222 |
1205 TEST_F(URLFetcherFileTest, SmallGet) { | 1223 // Get a small file. |
1224 TEST_F(URLFetcherTest, FileTestSmallGet) { | |
1225 const char kFileToFetch[] = "simple.html"; | |
1226 | |
1206 base::ScopedTempDir temp_dir; | 1227 base::ScopedTempDir temp_dir; |
1207 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1228 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1208 | 1229 base::FilePath out_path = temp_dir.path().AppendASCII(kFileToFetch); |
1209 // Get a small file. | 1230 SaveFileTest(kFileToFetch, out_path, false); |
1210 static const char kFileToFetch[] = "simple.html"; | |
1211 expected_file_ = test_server_->GetDocumentRoot().AppendASCII(kFileToFetch); | |
1212 CreateFetcherForFile( | |
1213 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | |
1214 temp_dir.path().AppendASCII(kFileToFetch)); | |
1215 | |
1216 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | |
1217 | |
1218 ASSERT_FALSE(base::PathExists(file_path_)) | |
1219 << file_path_.value() << " not removed."; | |
1220 } | 1231 } |
1221 | 1232 |
1222 TEST_F(URLFetcherFileTest, LargeGet) { | 1233 // Get a file large enough to require more than one read into URLFetcher::Core's |
1234 // IOBuffer. | |
1235 TEST_F(URLFetcherTest, FileTestLargeGet) { | |
1236 const char kFileToFetch[] = "animate1.gif"; | |
1237 | |
1223 base::ScopedTempDir temp_dir; | 1238 base::ScopedTempDir temp_dir; |
1224 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1239 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1225 | 1240 base::FilePath out_path = temp_dir.path().AppendASCII(kFileToFetch); |
1226 // Get a file large enough to require more than one read into | 1241 SaveFileTest(kFileToFetch, out_path, false); |
1227 // URLFetcher::Core's IOBuffer. | |
1228 static const char kFileToFetch[] = "animate1.gif"; | |
1229 expected_file_ = test_server_->GetDocumentRoot().AppendASCII(kFileToFetch); | |
1230 CreateFetcherForFile( | |
1231 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | |
1232 temp_dir.path().AppendASCII(kFileToFetch)); | |
1233 | |
1234 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | |
1235 } | 1242 } |
1236 | 1243 |
1237 TEST_F(URLFetcherFileTest, SavedOutputFileOwnerhisp) { | 1244 // If the caller takes the ownership of the output file, the file should persist |
1238 // If the caller takes the ownership of the output file, the file should | 1245 // even after URLFetcher is gone. |
1239 // persist even after URLFetcher is gone. If not, the file must be deleted. | 1246 TEST_F(URLFetcherTest, FileTestTakeOwnership) { |
1240 const bool kTake[] = {false, true}; | 1247 const char kFileToFetch[] = "simple.html"; |
1241 for (size_t i = 0; i < arraysize(kTake); ++i) { | |
1242 take_ownership_of_file_ = kTake[i]; | |
1243 base::ScopedTempDir temp_dir; | |
1244 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
1245 | 1248 |
1246 // Get a small file. | 1249 base::ScopedTempDir temp_dir; |
1247 static const char kFileToFetch[] = "simple.html"; | 1250 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1248 expected_file_ = test_server_->GetDocumentRoot().AppendASCII(kFileToFetch); | 1251 base::FilePath out_path = temp_dir.path().AppendASCII(kFileToFetch); |
1249 CreateFetcherForFile( | 1252 SaveFileTest(kFileToFetch, out_path, true); |
1250 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | |
1251 temp_dir.path().AppendASCII(kFileToFetch)); | |
1252 | |
1253 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | |
1254 | |
1255 base::MessageLoop::current()->RunUntilIdle(); | |
1256 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << | |
1257 "FilePath: " << file_path_.value(); | |
1258 } | |
1259 } | 1253 } |
1260 | 1254 |
1261 TEST_F(URLFetcherFileTest, OverwriteExistingFile) { | 1255 // Test that an existing file can be overwritten be a fetcher. |
1256 TEST_F(URLFetcherTest, FileTestOverwriteExisting) { | |
1262 base::ScopedTempDir temp_dir; | 1257 base::ScopedTempDir temp_dir; |
1263 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1258 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1264 | 1259 |
1265 // Create a file before trying to fetch. | 1260 // Create a file before trying to fetch. |
1266 static const char kFileToFetch[] = "simple.html"; | 1261 const char kFileToFetch[] = "simple.html"; |
1267 std::string data(10000, '?'); // Meant to be larger than simple.html. | 1262 std::string data(10000, '?'); // Meant to be larger than simple.html. |
1268 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); | 1263 base::FilePath out_path = temp_dir.path().AppendASCII(kFileToFetch); |
1269 ASSERT_EQ(static_cast<int>(data.size()), | 1264 ASSERT_EQ(static_cast<int>(data.size()), |
1270 base::WriteFile(file_path_, data.data(), data.size())); | 1265 base::WriteFile(out_path, data.data(), data.size())); |
1271 ASSERT_TRUE(base::PathExists(file_path_)); | 1266 ASSERT_TRUE(base::PathExists(out_path)); |
1272 expected_file_ = test_server_->GetDocumentRoot().AppendASCII(kFileToFetch); | |
1273 ASSERT_FALSE(base::ContentsEqual(file_path_, expected_file_)); | |
1274 | 1267 |
1275 // Get a small file. | 1268 SaveFileTest(kFileToFetch, out_path, true); |
davidben
2015/04/15 18:21:10
Not from this CL, but take_ownership = false + exi
mmenke
2015/04/15 18:43:41
Yea, it does seem weird. Not sure it's worth fixi
davidben
2015/04/15 18:49:28
Yeah, certainly not in this CL.
| |
1276 CreateFetcherForFile( | |
1277 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | |
1278 file_path_); | |
1279 | |
1280 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | |
1281 } | 1269 } |
1282 | 1270 |
1283 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) { | 1271 // Test trying to overwrite a directory with a file when using a fetcher fails. |
1272 TEST_F(URLFetcherTest, FileTestTryToOverwriteDirectory) { | |
1284 base::ScopedTempDir temp_dir; | 1273 base::ScopedTempDir temp_dir; |
1285 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1274 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
1286 | 1275 |
1287 // Create a directory before trying to fetch. | 1276 // Create a directory before trying to fetch. |
1288 static const char kFileToFetch[] = "simple.html"; | 1277 static const char kFileToFetch[] = "simple.html"; |
1289 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); | 1278 base::FilePath out_path = temp_dir.path().AppendASCII(kFileToFetch); |
1290 ASSERT_TRUE(base::CreateDirectory(file_path_)); | 1279 ASSERT_TRUE(base::CreateDirectory(out_path)); |
1291 ASSERT_TRUE(base::PathExists(file_path_)); | 1280 ASSERT_TRUE(base::PathExists(out_path)); |
1292 | 1281 |
1293 // Get a small file. | 1282 WaitingURLFetcherDelegate delegate; |
1294 expected_file_error_ = ERR_ACCESS_DENIED; | 1283 delegate.CreateFetcherWithContext( |
1295 expected_file_ = test_server_->GetDocumentRoot().AppendASCII(kFileToFetch); | |
1296 CreateFetcherForFile( | |
1297 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), | 1284 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), |
1298 file_path_); | 1285 URLFetcher::GET, request_context()); |
1286 delegate.fetcher()->SaveResponseToFileAtPath( | |
1287 out_path, | |
1288 scoped_refptr<base::MessageLoopProxy>(base::MessageLoopProxy::current())); | |
1289 delegate.StartFetcherAndWait(); | |
1299 | 1290 |
1300 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | 1291 EXPECT_FALSE(delegate.fetcher()->GetStatus().is_success()); |
1301 | 1292 EXPECT_EQ(ERR_ACCESS_DENIED, delegate.fetcher()->GetStatus().error()); |
1302 base::MessageLoop::current()->RunUntilIdle(); | |
1303 } | 1293 } |
1304 | 1294 |
1305 TEST_F(URLFetcherFileTest, SmallGetToTempFile) { | 1295 // Get a small file and save it to a temp file. |
1306 // Get a small file. | 1296 TEST_F(URLFetcherTest, TempFileTestSmallGet) { |
1307 static const char kFileToFetch[] = "simple.html"; | 1297 SaveTempFileTest("simple.html", false); |
1308 expected_file_ = test_server_->GetDocumentRoot().AppendASCII(kFileToFetch); | |
1309 CreateFetcherForTempFile( | |
1310 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | |
1311 | |
1312 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | |
1313 | |
1314 ASSERT_FALSE(base::PathExists(file_path_)) | |
1315 << file_path_.value() << " not removed."; | |
1316 } | 1298 } |
1317 | 1299 |
1318 TEST_F(URLFetcherFileTest, LargeGetToTempFile) { | 1300 // Get a file large enough to require more than one read into URLFetcher::Core's |
1319 // Get a file large enough to require more than one read into | 1301 // IOBuffer and save it to a temp file. |
1320 // URLFetcher::Core's IOBuffer. | 1302 TEST_F(URLFetcherTest, TempFileTestLargeGet) { |
1321 static const char kFileToFetch[] = "animate1.gif"; | 1303 SaveTempFileTest("animate1.gif", false); |
1322 expected_file_ = test_server_->GetDocumentRoot().AppendASCII(kFileToFetch); | |
1323 CreateFetcherForTempFile( | |
1324 test_server_->GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); | |
1325 | |
1326 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | |
1327 } | 1304 } |
1328 | 1305 |
1329 TEST_F(URLFetcherFileTest, SavedOutputTempFileOwnerhisp) { | 1306 // If the caller takes the ownership of the temp file, check that the file |
1330 // If the caller takes the ownership of the temp file, the file should persist | 1307 // persists even after URLFetcher is gone. |
1331 // even after URLFetcher is gone. If not, the file must be deleted. | 1308 TEST_F(URLFetcherTest, TempFileTestTakeOwnership) { |
1332 const bool kTake[] = {false, true}; | 1309 SaveTempFileTest("simple.html", true); |
1333 for (size_t i = 0; i < arraysize(kTake); ++i) { | |
1334 take_ownership_of_file_ = kTake[i]; | |
1335 | |
1336 // Get a small file. | |
1337 static const char kFileToFetch[] = "simple.html"; | |
1338 expected_file_ = test_server_->GetDocumentRoot().AppendASCII(kFileToFetch); | |
1339 CreateFetcherForTempFile(test_server_->GetURL( | |
1340 std::string(kTestServerFilePrefix) + kFileToFetch)); | |
1341 | |
1342 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). | |
1343 | |
1344 base::MessageLoop::current()->RunUntilIdle(); | |
1345 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) << | |
1346 "FilePath: " << file_path_.value(); | |
1347 } | |
1348 } | 1310 } |
1349 | 1311 |
1350 } // namespace | 1312 } // namespace |
1351 | 1313 |
1352 } // namespace net | 1314 } // namespace net |
OLD | NEW |