| 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/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 base_file_->Finish(); | 457 base_file_->Finish(); |
| 458 } | 458 } |
| 459 | 459 |
| 460 // Test that a failed rename reports the correct error. | 460 // Test that a failed rename reports the correct error. |
| 461 TEST_F(BaseFileTest, RenameWithError) { | 461 TEST_F(BaseFileTest, RenameWithError) { |
| 462 ASSERT_TRUE(InitializeFile()); | 462 ASSERT_TRUE(InitializeFile()); |
| 463 | 463 |
| 464 // TestDir is a subdirectory in |temp_dir_| that we will make read-only so | 464 // TestDir is a subdirectory in |temp_dir_| that we will make read-only so |
| 465 // that the rename will fail. | 465 // that the rename will fail. |
| 466 base::FilePath test_dir(temp_dir_.path().AppendASCII("TestDir")); | 466 base::FilePath test_dir(temp_dir_.path().AppendASCII("TestDir")); |
| 467 ASSERT_TRUE(file_util::CreateDirectory(test_dir)); | 467 ASSERT_TRUE(base::CreateDirectory(test_dir)); |
| 468 | 468 |
| 469 base::FilePath new_path(test_dir.AppendASCII("TestFile")); | 469 base::FilePath new_path(test_dir.AppendASCII("TestFile")); |
| 470 EXPECT_FALSE(base::PathExists(new_path)); | 470 EXPECT_FALSE(base::PathExists(new_path)); |
| 471 | 471 |
| 472 { | 472 { |
| 473 file_util::PermissionRestorer restore_permissions_for(test_dir); | 473 file_util::PermissionRestorer restore_permissions_for(test_dir); |
| 474 ASSERT_TRUE(file_util::MakeFileUnwritable(test_dir)); | 474 ASSERT_TRUE(file_util::MakeFileUnwritable(test_dir)); |
| 475 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, | 475 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, |
| 476 base_file_->Rename(new_path)); | 476 base_file_->Rename(new_path)); |
| 477 } | 477 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 // they are in the same directory. | 624 // they are in the same directory. |
| 625 base::FilePath temp_file; | 625 base::FilePath temp_file; |
| 626 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); | 626 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); |
| 627 ASSERT_FALSE(temp_file.empty()); | 627 ASSERT_FALSE(temp_file.empty()); |
| 628 EXPECT_STREQ(temp_file.DirName().value().c_str(), | 628 EXPECT_STREQ(temp_file.DirName().value().c_str(), |
| 629 base_file_->full_path().DirName().value().c_str()); | 629 base_file_->full_path().DirName().value().c_str()); |
| 630 base_file_->Finish(); | 630 base_file_->Finish(); |
| 631 } | 631 } |
| 632 | 632 |
| 633 } // namespace content | 633 } // namespace content |
| OLD | NEW |