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 "content/browser/download/base_file.h" | 5 #include "content/browser/download/base_file.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 460 |
461 // TestDir is a subdirectory in |temp_dir_| that we will make read-only so | 461 // TestDir is a subdirectory in |temp_dir_| that we will make read-only so |
462 // that the rename will fail. | 462 // that the rename will fail. |
463 base::FilePath test_dir(temp_dir_.path().AppendASCII("TestDir")); | 463 base::FilePath test_dir(temp_dir_.path().AppendASCII("TestDir")); |
464 ASSERT_TRUE(base::CreateDirectory(test_dir)); | 464 ASSERT_TRUE(base::CreateDirectory(test_dir)); |
465 | 465 |
466 base::FilePath new_path(test_dir.AppendASCII("TestFile")); | 466 base::FilePath new_path(test_dir.AppendASCII("TestFile")); |
467 EXPECT_FALSE(base::PathExists(new_path)); | 467 EXPECT_FALSE(base::PathExists(new_path)); |
468 | 468 |
469 { | 469 { |
470 file_util::PermissionRestorer restore_permissions_for(test_dir); | 470 base::FilePermissionRestorer restore_permissions_for(test_dir); |
471 ASSERT_TRUE(file_util::MakeFileUnwritable(test_dir)); | 471 ASSERT_TRUE(base::MakeFileUnwritable(test_dir)); |
472 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, | 472 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, |
473 base_file_->Rename(new_path)); | 473 base_file_->Rename(new_path)); |
474 } | 474 } |
475 | 475 |
476 base_file_->Finish(); | 476 base_file_->Finish(); |
477 } | 477 } |
478 | 478 |
479 // Test that a failed write reports an error. | 479 // Test that a failed write reports an error. |
480 TEST_F(BaseFileTest, WriteWithError) { | 480 TEST_F(BaseFileTest, WriteWithError) { |
481 base::FilePath path; | 481 base::FilePath path; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 base_file_->Detach(); | 551 base_file_->Detach(); |
552 expect_file_survives_ = true; | 552 expect_file_survives_ = true; |
553 } | 553 } |
554 | 554 |
555 // Create a read-only file and attempt to write to it. | 555 // Create a read-only file and attempt to write to it. |
556 TEST_F(BaseFileTest, ReadonlyBaseFile) { | 556 TEST_F(BaseFileTest, ReadonlyBaseFile) { |
557 // Create a new file. | 557 // Create a new file. |
558 base::FilePath readonly_file_name = CreateTestFile(); | 558 base::FilePath readonly_file_name = CreateTestFile(); |
559 | 559 |
560 // Restore permissions to the file when we are done with this test. | 560 // Restore permissions to the file when we are done with this test. |
561 file_util::PermissionRestorer restore_permissions(readonly_file_name); | 561 base::FilePermissionRestorer restore_permissions(readonly_file_name); |
562 | 562 |
563 // Make it read-only. | 563 // Make it read-only. |
564 EXPECT_TRUE(file_util::MakeFileUnwritable(readonly_file_name)); | 564 EXPECT_TRUE(base::MakeFileUnwritable(readonly_file_name)); |
565 | 565 |
566 // Try to overwrite it. | 566 // Try to overwrite it. |
567 base_file_.reset(new BaseFile(readonly_file_name, | 567 base_file_.reset(new BaseFile(readonly_file_name, |
568 GURL(), | 568 GURL(), |
569 GURL(), | 569 GURL(), |
570 0, | 570 0, |
571 false, | 571 false, |
572 std::string(), | 572 std::string(), |
573 base::File(), | 573 base::File(), |
574 net::BoundNetLog())); | 574 net::BoundNetLog())); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 630 |
631 const char kData[] = "hello"; | 631 const char kData[] = "hello"; |
632 const int kDataLength = static_cast<int>(arraysize(kData) - 1); | 632 const int kDataLength = static_cast<int>(arraysize(kData) - 1); |
633 ASSERT_EQ(kDataLength, base::WriteFile(full_path, kData, kDataLength)); | 633 ASSERT_EQ(kDataLength, base::WriteFile(full_path, kData, kDataLength)); |
634 // The file that we created here should stick around when the BaseFile is | 634 // The file that we created here should stick around when the BaseFile is |
635 // destroyed during TearDown. | 635 // destroyed during TearDown. |
636 expect_file_survives_ = true; | 636 expect_file_survives_ = true; |
637 } | 637 } |
638 | 638 |
639 } // namespace content | 639 } // namespace content |
OLD | NEW |