Chromium Code Reviews| 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 "base/files/file.h" | 5 #include "base/files/file.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 510 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
| 511 NULL)); | 511 NULL)); |
| 512 ASSERT_TRUE(dir.IsValid()); | 512 ASSERT_TRUE(dir.IsValid()); |
| 513 | 513 |
| 514 base::File::Info info; | 514 base::File::Info info; |
| 515 EXPECT_TRUE(dir.GetInfo(&info)); | 515 EXPECT_TRUE(dir.GetInfo(&info)); |
| 516 EXPECT_TRUE(info.is_directory); | 516 EXPECT_TRUE(info.is_directory); |
| 517 EXPECT_FALSE(info.is_symbolic_link); | 517 EXPECT_FALSE(info.is_symbolic_link); |
| 518 EXPECT_EQ(0, info.size); | 518 EXPECT_EQ(0, info.size); |
| 519 } | 519 } |
| 520 | |
| 521 TEST(FileTest, DeleteNoop) { | |
| 522 base::ScopedTempDir temp_dir; | |
| 523 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 524 FilePath file_path = temp_dir.GetPath().AppendASCII("file"); | |
| 525 | |
| 526 // Creating and closing a file with DELETE perms should do nothing special. | |
| 527 File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ | | |
| 528 base::File::FLAG_WRITE | base::File::FLAG_DELETE)); | |
| 529 ASSERT_TRUE(file.IsValid()); | |
| 530 file.Close(); | |
| 531 ASSERT_TRUE(base::PathExists(file_path)); | |
| 532 } | |
| 533 | |
| 534 TEST(FileTest, Delete) { | |
| 535 base::ScopedTempDir temp_dir; | |
| 536 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 537 FilePath file_path = temp_dir.GetPath().AppendASCII("file"); | |
| 538 | |
| 539 // Creating a file with DELETE and then marking for delete on close should | |
| 540 // delete it. | |
| 541 File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ | | |
| 542 base::File::FLAG_WRITE | base::File::FLAG_DELETE)); | |
| 543 ASSERT_TRUE(file.IsValid()); | |
| 544 ASSERT_TRUE(file.DeleteOnClose(true)); | |
| 545 file.Close(); | |
| 546 ASSERT_FALSE(base::PathExists(file_path)); | |
| 547 } | |
| 548 | |
| 549 TEST(FileTest, DeleteThenRevoke) { | |
| 550 base::ScopedTempDir temp_dir; | |
| 551 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 552 FilePath file_path = temp_dir.GetPath().AppendASCII("file"); | |
| 553 | |
| 554 // Creating a file with DELETE, mraking it for delete, then clearing delete on | |
|
Nico
2017/01/10 18:04:16
(typo mraking)
grt (UTC plus 2)
2017/01/11 13:52:17
Done.
| |
| 555 // close should not delete it. | |
| 556 File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ | | |
| 557 base::File::FLAG_WRITE | base::File::FLAG_DELETE)); | |
| 558 ASSERT_TRUE(file.IsValid()); | |
| 559 ASSERT_TRUE(file.DeleteOnClose(true)); | |
| 560 ASSERT_TRUE(file.DeleteOnClose(false)); | |
| 561 file.Close(); | |
| 562 ASSERT_TRUE(base::PathExists(file_path)); | |
| 563 } | |
|
Nico
2017/01/10 18:04:15
what happens if you file.DeleteOnClose(true) on a
grt (UTC plus 2)
2017/01/11 13:52:17
The call to set attributes fails and DOC returns f
| |
| 520 #endif // defined(OS_WIN) | 564 #endif // defined(OS_WIN) |
| OLD | NEW |