Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: content/browser/download/download_file_unittest.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/test/test_file_util.h" 8 #include "base/test/test_file_util.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/byte_stream.h" 10 #include "content/browser/byte_stream.h"
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 407
408 // Check the hash. 408 // Check the hash.
409 EXPECT_TRUE(download_file_->GetHash(&hash)); 409 EXPECT_TRUE(download_file_->GetHash(&hash));
410 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); 410 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size()));
411 411
412 // Check that a rename with overwrite to an existing file succeeds. 412 // Check that a rename with overwrite to an existing file succeeds.
413 std::string file_contents; 413 std::string file_contents;
414 ASSERT_FALSE(base::PathExists(path_5)); 414 ASSERT_FALSE(base::PathExists(path_5));
415 static const char file_data[] = "xyzzy"; 415 static const char file_data[] = "xyzzy";
416 ASSERT_EQ(static_cast<int>(sizeof(file_data) - 1), 416 ASSERT_EQ(static_cast<int>(sizeof(file_data) - 1),
417 file_util::WriteFile(path_5, file_data, sizeof(file_data) - 1)); 417 base::WriteFile(path_5, file_data, sizeof(file_data) - 1));
418 ASSERT_TRUE(base::PathExists(path_5)); 418 ASSERT_TRUE(base::PathExists(path_5));
419 EXPECT_TRUE(base::ReadFileToString(path_5, &file_contents)); 419 EXPECT_TRUE(base::ReadFileToString(path_5, &file_contents));
420 EXPECT_EQ(std::string(file_data), file_contents); 420 EXPECT_EQ(std::string(file_data), file_contents);
421 421
422 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, 422 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE,
423 RenameAndAnnotate(path_5, &output_path)); 423 RenameAndAnnotate(path_5, &output_path));
424 EXPECT_EQ(path_5, output_path); 424 EXPECT_EQ(path_5, output_path);
425 425
426 file_contents = ""; 426 file_contents = "";
427 EXPECT_TRUE(base::ReadFileToString(path_5, &file_contents)); 427 EXPECT_TRUE(base::ReadFileToString(path_5, &file_contents));
428 EXPECT_NE(std::string(file_data), file_contents); 428 EXPECT_NE(std::string(file_data), file_contents);
429 429
430 DestroyDownloadFile(0); 430 DestroyDownloadFile(0);
431 } 431 }
432 432
433 // Test to make sure the rename uniquifies if we aren't overwriting 433 // Test to make sure the rename uniquifies if we aren't overwriting
434 // and there's a file where we're aiming. 434 // and there's a file where we're aiming.
435 TEST_F(DownloadFileTest, RenameUniquifies) { 435 TEST_F(DownloadFileTest, RenameUniquifies) {
436 ASSERT_TRUE(CreateDownloadFile(0, true)); 436 ASSERT_TRUE(CreateDownloadFile(0, true));
437 base::FilePath initial_path(download_file_->FullPath()); 437 base::FilePath initial_path(download_file_->FullPath());
438 EXPECT_TRUE(base::PathExists(initial_path)); 438 EXPECT_TRUE(base::PathExists(initial_path));
439 base::FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1")); 439 base::FilePath path_1(initial_path.InsertBeforeExtensionASCII("_1"));
440 base::FilePath path_1_suffixed(path_1.InsertBeforeExtensionASCII(" (1)")); 440 base::FilePath path_1_suffixed(path_1.InsertBeforeExtensionASCII(" (1)"));
441 441
442 ASSERT_FALSE(base::PathExists(path_1)); 442 ASSERT_FALSE(base::PathExists(path_1));
443 static const char file_data[] = "xyzzy"; 443 static const char file_data[] = "xyzzy";
444 ASSERT_EQ(static_cast<int>(sizeof(file_data)), 444 ASSERT_EQ(static_cast<int>(sizeof(file_data)),
445 file_util::WriteFile(path_1, file_data, sizeof(file_data))); 445 base::WriteFile(path_1, file_data, sizeof(file_data)));
446 ASSERT_TRUE(base::PathExists(path_1)); 446 ASSERT_TRUE(base::PathExists(path_1));
447 447
448 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, RenameAndUniquify(path_1, NULL)); 448 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, RenameAndUniquify(path_1, NULL));
449 EXPECT_TRUE(base::PathExists(path_1_suffixed)); 449 EXPECT_TRUE(base::PathExists(path_1_suffixed));
450 450
451 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); 451 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true);
452 loop_.RunUntilIdle(); 452 loop_.RunUntilIdle();
453 DestroyDownloadFile(0); 453 DestroyDownloadFile(0);
454 } 454 }
455 455
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 596
597 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), 597 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)),
598 bytes_); 598 bytes_);
599 EXPECT_EQ(download_file_->GetHashState(), hash_state_); 599 EXPECT_EQ(download_file_->GetHashState(), hash_state_);
600 600
601 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); 601 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true);
602 DestroyDownloadFile(0); 602 DestroyDownloadFile(0);
603 } 603 }
604 604
605 } // namespace content 605 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/base_file_posix.cc ('k') | content/browser/fileapi/blob_url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698