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

Side by Side Diff: base/files/file_unittest.cc

Issue 2567383002: Add FLAG_CAN_DELETE_ON_CLOSE and DeleteOnClose for use on Windows. (Closed)
Patch Set: thakis comments Created 3 years, 11 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
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/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
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.
Nico 2017/01/11 15:47:18 The Windows API flag is called DELETE, but maybe a
grt (UTC plus 2) 2017/01/12 13:58:20 CAN sounds good to me. Done.
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, marking it for delete, then clearing delete on
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 }
564
565 TEST(FileTest, DeleteWithoutPermission) {
566 base::ScopedTempDir temp_dir;
567 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
568 FilePath file_path = temp_dir.GetPath().AppendASCII("file");
569
570 // It should not be possible to mark a file for deletion when it was not
571 // created/opened with DELETE.
572 File file(file_path, (base::File::FLAG_CREATE | base::File::FLAG_READ |
573 base::File::FLAG_WRITE));
574 ASSERT_TRUE(file.IsValid());
575 ASSERT_FALSE(file.DeleteOnClose(true));
576 file.Close();
577 ASSERT_TRUE(base::PathExists(file_path));
578 }
520 #endif // defined(OS_WIN) 579 #endif // defined(OS_WIN)
OLDNEW
« base/files/file.h ('K') | « base/files/file.h ('k') | base/files/file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698