Index: base/files/file_util_unittest.cc |
diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc |
index 7ef60a4b29881d0016adf5564956f5d1c749bd0a..30d77f8419c39b18eb0ed469a0beb90b9b352306 100644 |
--- a/base/files/file_util_unittest.cc |
+++ b/base/files/file_util_unittest.cc |
@@ -192,6 +192,46 @@ class FileUtilTest : public PlatformTest { |
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
} |
+ // Sets the file to read-only. |
+ static void SetReadOnly(const FilePath& path, bool read_only) { |
+#if defined(OS_WIN) |
+ // On Windows, it involves setting/removing the 'readonly' bit. |
+ DWORD attrs = GetFileAttributes(path.value().c_str()); |
+ ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs); |
+ ASSERT_TRUE(SetFileAttributes( |
+ path.value().c_str(), read_only ? (attrs | FILE_ATTRIBUTE_READONLY) |
+ : (attrs & ~FILE_ATTRIBUTE_READONLY))); |
+ |
+ DWORD expected = |
+ read_only |
+ ? ((attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)) | |
+ FILE_ATTRIBUTE_READONLY) |
+ : (attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)); |
+ |
+ // Ignore FILE_ATTRIBUTE_NOT_CONTENT_INDEXED if present. |
+ attrs = GetFileAttributes(path.value().c_str()) & |
+ ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; |
+ ASSERT_EQ(expected, attrs); |
+#else |
+ // On all other platforms, it involves removing/setting the write bit. |
+ mode_t mode = read_only ? S_IRUSR : (S_IRUSR | S_IWUSR); |
+ EXPECT_TRUE(SetPosixFilePermissions( |
+ path, DirectoryExists(path) ? (mode | S_IXUSR) : mode)); |
+#endif |
+ } |
+ |
+ static bool IsReadOnly(const FilePath& path) { |
+#if defined(OS_WIN) |
+ DWORD attrs = GetFileAttributes(path.value().c_str()); |
+ EXPECT_NE(INVALID_FILE_ATTRIBUTES, attrs); |
+ return attrs & FILE_ATTRIBUTE_READONLY; |
+#else |
+ int mode = 0; |
+ EXPECT_TRUE(GetPosixFilePermissions(path, &mode)); |
+ return !(mode & S_IWUSR); |
+#endif |
+ } |
+ |
ScopedTempDir temp_dir_; |
}; |
@@ -250,7 +290,7 @@ TEST_F(FileUtilTest, FileAndDirectorySize) { |
// Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize |
// should return 53 bytes. |
FilePath file_01 = temp_dir_.GetPath().Append(FPL("The file 01.txt")); |
- CreateTextFile(file_01, L"12345678901234567890"); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_01, L"12345678901234567890")); |
int64_t size_f1 = 0; |
ASSERT_TRUE(GetFileSize(file_01, &size_f1)); |
EXPECT_EQ(20ll, size_f1); |
@@ -259,7 +299,8 @@ TEST_F(FileUtilTest, FileAndDirectorySize) { |
CreateDirectory(subdir_path); |
FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); |
- CreateTextFile(file_02, L"123456789012345678901234567890"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_02, L"123456789012345678901234567890")); |
int64_t size_f2 = 0; |
ASSERT_TRUE(GetFileSize(file_02, &size_f2)); |
EXPECT_EQ(30ll, size_f2); |
@@ -268,7 +309,7 @@ TEST_F(FileUtilTest, FileAndDirectorySize) { |
CreateDirectory(subsubdir_path); |
FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); |
- CreateTextFile(file_03, L"123"); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_03, L"123")); |
int64_t computed_size = ComputeDirectorySize(temp_dir_.GetPath()); |
EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); |
@@ -287,11 +328,11 @@ TEST_F(FileUtilTest, NormalizeFilePathBasic) { |
ASSERT_FALSE(NormalizeFilePath(file_a_path, &normalized_file_a_path)) |
<< "NormalizeFilePath() should fail on nonexistent paths."; |
- CreateTextFile(file_a_path, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_a_path, bogus_content)); |
ASSERT_TRUE(PathExists(file_a_path)); |
ASSERT_TRUE(NormalizeFilePath(file_a_path, &normalized_file_a_path)); |
- CreateTextFile(file_b_path, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_b_path, bogus_content)); |
ASSERT_TRUE(PathExists(file_b_path)); |
ASSERT_TRUE(NormalizeFilePath(file_b_path, &normalized_file_b_path)); |
@@ -333,7 +374,7 @@ TEST_F(FileUtilTest, NormalizeFilePathReparsePoints) { |
ASSERT_TRUE(CreateDirectory(sub_a)); |
FilePath file_txt = sub_a.Append(FPL("file.txt")); |
- CreateTextFile(file_txt, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_txt, bogus_content)); |
// Want a directory whose name is long enough to make the path to the file |
// inside just under MAX_PATH chars. This will be used to test that when |
@@ -360,7 +401,7 @@ TEST_F(FileUtilTest, NormalizeFilePathReparsePoints) { |
FilePath sub_long = deep_file.DirName(); |
ASSERT_TRUE(CreateDirectory(sub_long)); |
- CreateTextFile(deep_file, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(deep_file, bogus_content)); |
FilePath base_b = temp_dir_.GetPath().Append(FPL("base_b")); |
ASSERT_TRUE(CreateDirectory(base_b)); |
@@ -553,7 +594,7 @@ TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { |
TEST_F(FileUtilTest, CreateAndReadSymlinks) { |
FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file")); |
FilePath link_to = temp_dir_.GetPath().Append(FPL("to_file")); |
- CreateTextFile(link_to, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(link_to, bogus_content)); |
ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
<< "Failed to create file symlink."; |
@@ -590,7 +631,7 @@ TEST_F(FileUtilTest, NormalizeFilePathSymlinks) { |
// Link one file to another. |
FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file")); |
FilePath link_to = temp_dir_.GetPath().Append(FPL("to_file")); |
- CreateTextFile(link_to, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(link_to, bogus_content)); |
ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
<< "Failed to create file symlink."; |
@@ -650,7 +691,7 @@ TEST_F(FileUtilTest, DeleteNonExistentWithNonExistentParent) { |
TEST_F(FileUtilTest, DeleteFile) { |
// Create a file |
FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 1.txt")); |
- CreateTextFile(file_name, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
ASSERT_TRUE(PathExists(file_name)); |
// Make sure it's deleted |
@@ -659,7 +700,7 @@ TEST_F(FileUtilTest, DeleteFile) { |
// Test recursive case, create a new file |
file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); |
- CreateTextFile(file_name, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
ASSERT_TRUE(PathExists(file_name)); |
// Make sure it's deleted |
@@ -667,11 +708,35 @@ TEST_F(FileUtilTest, DeleteFile) { |
EXPECT_FALSE(PathExists(file_name)); |
} |
+TEST_F(FileUtilTest, DeleteReadOnlyFile) { |
+ // Create a read-only file. |
+ FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 1.txt")); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
+ ASSERT_TRUE(PathExists(file_name)); |
+ ASSERT_NO_FATAL_FAILURE(SetReadOnly(file_name, true)); |
+ ASSERT_TRUE(IsReadOnly(file_name)); |
+ |
+ // Make sure it's deleted. |
+ EXPECT_TRUE(DeleteFile(file_name, false)); |
+ EXPECT_FALSE(PathExists(file_name)); |
+ |
+ // Test recursive case: create a new file. |
+ file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
+ ASSERT_TRUE(PathExists(file_name)); |
+ ASSERT_NO_FATAL_FAILURE(SetReadOnly(file_name, true)); |
+ ASSERT_TRUE(IsReadOnly(file_name)); |
+ |
+ // Make sure it's deleted. |
+ EXPECT_TRUE(DeleteFile(file_name, true)); |
+ EXPECT_FALSE(PathExists(file_name)); |
+} |
+ |
#if defined(OS_POSIX) |
TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { |
// Create a file. |
FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); |
- CreateTextFile(file_name, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
ASSERT_TRUE(PathExists(file_name)); |
// Create a symlink to the file. |
@@ -882,58 +947,6 @@ TEST_F(FileUtilTest, ExecutableExistsInPath) { |
#endif // defined(OS_POSIX) |
-#if defined(OS_WIN) |
-// Tests that the Delete function works for wild cards, especially |
-// with the recursion flag. Also coincidentally tests PathExists. |
-// TODO(erikkay): see if anyone's actually using this feature of the API |
-TEST_F(FileUtilTest, DeleteWildCard) { |
- // Create a file and a directory |
- FilePath file_name = |
- temp_dir_.GetPath().Append(FPL("Test DeleteWildCard.txt")); |
- CreateTextFile(file_name, bogus_content); |
- ASSERT_TRUE(PathExists(file_name)); |
- |
- FilePath subdir_path = temp_dir_.GetPath().Append(FPL("DeleteWildCardDir")); |
- CreateDirectory(subdir_path); |
- ASSERT_TRUE(PathExists(subdir_path)); |
- |
- // Create the wildcard path |
- FilePath directory_contents = temp_dir_.GetPath(); |
- directory_contents = directory_contents.Append(FPL("*")); |
- |
- // Delete non-recursively and check that only the file is deleted |
- EXPECT_TRUE(DeleteFile(directory_contents, false)); |
- EXPECT_FALSE(PathExists(file_name)); |
- EXPECT_TRUE(PathExists(subdir_path)); |
- |
- // Delete recursively and make sure all contents are deleted |
- EXPECT_TRUE(DeleteFile(directory_contents, true)); |
- EXPECT_FALSE(PathExists(file_name)); |
- EXPECT_FALSE(PathExists(subdir_path)); |
-} |
- |
-// TODO(erikkay): see if anyone's actually using this feature of the API |
-TEST_F(FileUtilTest, DeleteNonExistantWildCard) { |
- // Create a file and a directory |
- FilePath subdir_path = |
- temp_dir_.GetPath().Append(FPL("DeleteNonExistantWildCard")); |
- CreateDirectory(subdir_path); |
- ASSERT_TRUE(PathExists(subdir_path)); |
- |
- // Create the wildcard path |
- FilePath directory_contents = subdir_path; |
- directory_contents = directory_contents.Append(FPL("*")); |
- |
- // Delete non-recursively and check nothing got deleted |
- EXPECT_TRUE(DeleteFile(directory_contents, false)); |
- EXPECT_TRUE(PathExists(subdir_path)); |
- |
- // Delete recursively and check nothing got deleted |
- EXPECT_TRUE(DeleteFile(directory_contents, true)); |
- EXPECT_TRUE(PathExists(subdir_path)); |
-} |
-#endif |
- |
// Tests non-recursive Delete() for a directory. |
TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
// Create a subdirectory and put a file and two directories inside. |
@@ -943,7 +956,7 @@ TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
ASSERT_TRUE(PathExists(test_subdir)); |
FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); |
- CreateTextFile(file_name, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
ASSERT_TRUE(PathExists(file_name)); |
FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
@@ -973,7 +986,7 @@ TEST_F(FileUtilTest, DeleteDirRecursive) { |
ASSERT_TRUE(PathExists(test_subdir)); |
FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); |
- CreateTextFile(file_name, bogus_content); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
ASSERT_TRUE(PathExists(file_name)); |
FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
@@ -999,7 +1012,8 @@ TEST_F(FileUtilTest, MoveFileNew) { |
// Create a file |
FilePath file_name_from = |
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// The destination. |
@@ -1018,13 +1032,14 @@ TEST_F(FileUtilTest, MoveFileExists) { |
// Create a file |
FilePath file_name_from = |
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// The destination name. |
FilePath file_name_to = temp_dir_.GetPath().Append( |
FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
- CreateTextFile(file_name_to, L"Old file content"); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name_to, L"Old file content")); |
ASSERT_TRUE(PathExists(file_name_to)); |
EXPECT_TRUE(Move(file_name_from, file_name_to)); |
@@ -1039,7 +1054,8 @@ TEST_F(FileUtilTest, MoveFileDirExists) { |
// Create a file |
FilePath file_name_from = |
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// The destination directory |
@@ -1062,7 +1078,8 @@ TEST_F(FileUtilTest, MoveNew) { |
// Create a file under the directory |
FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); |
FilePath file_name_from = dir_name_from.Append(txt_file_name); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Move the directory. |
@@ -1103,7 +1120,8 @@ TEST_F(FileUtilTest, MoveExist) { |
// Create a file under the directory |
FilePath file_name_from = |
dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Move the directory |
@@ -1138,7 +1156,8 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
// Create a file under the directory. |
FilePath file_name_from = |
dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Create a subdirectory. |
@@ -1150,7 +1169,8 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
// Create a file under the subdirectory. |
FilePath file_name2_from = |
subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name2_from)); |
// Copy the directory recursively. |
@@ -1188,7 +1208,8 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
// Create a file under the directory. |
FilePath file_name_from = |
dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Create a subdirectory. |
@@ -1200,7 +1221,8 @@ TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
// Create a file under the subdirectory. |
FilePath file_name2_from = |
subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name2_from)); |
// Copy the directory recursively. |
@@ -1243,7 +1265,8 @@ TEST_F(FileUtilTest, CopyDirectoryNew) { |
// Create a file under the directory. |
FilePath file_name_from = |
dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Create a subdirectory. |
@@ -1255,7 +1278,8 @@ TEST_F(FileUtilTest, CopyDirectoryNew) { |
// Create a file under the subdirectory. |
FilePath file_name2_from = |
subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name2_from)); |
// Copy the directory not recursively. |
@@ -1290,7 +1314,8 @@ TEST_F(FileUtilTest, CopyDirectoryExists) { |
// Create a file under the directory. |
FilePath file_name_from = |
dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Create a subdirectory. |
@@ -1302,7 +1327,8 @@ TEST_F(FileUtilTest, CopyDirectoryExists) { |
// Create a file under the subdirectory. |
FilePath file_name2_from = |
subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name2_from)); |
// Copy the directory not recursively. |
@@ -1333,7 +1359,8 @@ TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { |
// Create a file |
FilePath file_name_from = |
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// The destination name |
@@ -1351,13 +1378,14 @@ TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { |
// Create a file |
FilePath file_name_from = |
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// The destination name |
FilePath file_name_to = temp_dir_.GetPath().Append( |
FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
- CreateTextFile(file_name_to, L"Old file content"); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name_to, L"Old file content")); |
ASSERT_TRUE(PathExists(file_name_to)); |
EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); |
@@ -1371,7 +1399,8 @@ TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { |
// Create a file |
FilePath file_name_from = |
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// The destination |
@@ -1398,7 +1427,8 @@ TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { |
// Create a file under the directory. |
FilePath file_name_from = |
dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Copy the directory recursively. |
@@ -1425,46 +1455,6 @@ TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { |
EXPECT_TRUE(PathExists(file_name_to)); |
} |
-// Sets the source file to read-only. |
-void SetReadOnly(const FilePath& path, bool read_only) { |
-#if defined(OS_WIN) |
- // On Windows, it involves setting/removing the 'readonly' bit. |
- DWORD attrs = GetFileAttributes(path.value().c_str()); |
- ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs); |
- ASSERT_TRUE(SetFileAttributes( |
- path.value().c_str(), |
- read_only ? (attrs | FILE_ATTRIBUTE_READONLY) : |
- (attrs & ~FILE_ATTRIBUTE_READONLY))); |
- |
- DWORD expected = read_only ? |
- ((attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)) | |
- FILE_ATTRIBUTE_READONLY) : |
- (attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)); |
- |
- // Ignore FILE_ATTRIBUTE_NOT_CONTENT_INDEXED if present. |
- attrs = GetFileAttributes(path.value().c_str()) & |
- ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; |
- ASSERT_EQ(expected, attrs); |
-#else |
- // On all other platforms, it involves removing/setting the write bit. |
- mode_t mode = read_only ? S_IRUSR : (S_IRUSR | S_IWUSR); |
- EXPECT_TRUE(SetPosixFilePermissions( |
- path, DirectoryExists(path) ? (mode | S_IXUSR) : mode)); |
-#endif |
-} |
- |
-bool IsReadOnly(const FilePath& path) { |
-#if defined(OS_WIN) |
- DWORD attrs = GetFileAttributes(path.value().c_str()); |
- EXPECT_NE(INVALID_FILE_ATTRIBUTES, attrs); |
- return attrs & FILE_ATTRIBUTE_READONLY; |
-#else |
- int mode = 0; |
- EXPECT_TRUE(GetPosixFilePermissions(path, &mode)); |
- return !(mode & S_IWUSR); |
-#endif |
-} |
- |
TEST_F(FileUtilTest, CopyDirectoryACL) { |
// Create source directories. |
FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src")); |
@@ -1474,12 +1464,13 @@ TEST_F(FileUtilTest, CopyDirectoryACL) { |
// Create a file under the directory. |
FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt")); |
- CreateTextFile(src_file, L"Gooooooooooooooooooooogle"); |
- SetReadOnly(src_file, true); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(src_file, L"Gooooooooooooooooooooogle")); |
+ ASSERT_NO_FATAL_FAILURE(SetReadOnly(src_file, true)); |
ASSERT_TRUE(IsReadOnly(src_file)); |
// Make directory read-only. |
- SetReadOnly(src_subdir, true); |
+ ASSERT_NO_FATAL_FAILURE(SetReadOnly(src_subdir, true)); |
ASSERT_TRUE(IsReadOnly(src_subdir)); |
// Copy the directory recursively. |
@@ -1492,7 +1483,7 @@ TEST_F(FileUtilTest, CopyDirectoryACL) { |
ASSERT_FALSE(IsReadOnly(dst_file)); |
// Give write permissions to allow deletion. |
- SetReadOnly(src_subdir, false); |
+ ASSERT_NO_FATAL_FAILURE(SetReadOnly(src_subdir, false)); |
ASSERT_FALSE(IsReadOnly(src_subdir)); |
} |
@@ -1507,7 +1498,7 @@ TEST_F(FileUtilTest, CopyFile) { |
FilePath file_name_from = |
dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
- CreateTextFile(file_name_from, file_contents); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name_from, file_contents)); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Copy the file. |
@@ -1539,11 +1530,11 @@ TEST_F(FileUtilTest, CopyFileACL) { |
// CopyFile(). |
FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src.txt")); |
const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
- CreateTextFile(src, file_contents); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(src, file_contents)); |
// Set the source file to read-only. |
ASSERT_FALSE(IsReadOnly(src)); |
- SetReadOnly(src, true); |
+ ASSERT_NO_FATAL_FAILURE(SetReadOnly(src, true)); |
ASSERT_TRUE(IsReadOnly(src)); |
// Copy the file. |
@@ -1661,7 +1652,8 @@ TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { |
// Create a file under the directory |
FilePath file_name_from = |
dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
- CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
ASSERT_TRUE(PathExists(file_name_from)); |
// Move the directory by using CopyAndDeleteDirectory |
@@ -1819,7 +1811,7 @@ TEST_F(FileUtilTest, CreateDirectoryTest) { |
// Doesn't work to create it on top of a non-dir |
test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); |
EXPECT_FALSE(PathExists(test_path)); |
- CreateTextFile(test_path, L"test file"); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(test_path, L"test file")); |
EXPECT_TRUE(PathExists(test_path)); |
EXPECT_FALSE(CreateDirectory(test_path)); |
@@ -1865,7 +1857,7 @@ TEST_F(FileUtilTest, DetectDirectoryTest) { |
FilePath test_path = |
test_root.Append(FILE_PATH_LITERAL("foobar.txt")); |
EXPECT_FALSE(PathExists(test_path)); |
- CreateTextFile(test_path, L"test file"); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(test_path, L"test file")); |
EXPECT_TRUE(PathExists(test_path)); |
EXPECT_FALSE(DirectoryExists(test_path)); |
EXPECT_TRUE(DeleteFile(test_path, false)); |
@@ -1897,14 +1889,14 @@ TEST_F(FileUtilTest, FileEnumeratorTest) { |
// create the files |
FilePath dir2file = dir2.Append(FPL("dir2file.txt")); |
- CreateTextFile(dir2file, std::wstring()); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(dir2file, std::wstring())); |
FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); |
- CreateTextFile(dir2innerfile, std::wstring()); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(dir2innerfile, std::wstring())); |
FilePath file1 = temp_dir_.GetPath().Append(FPL("file1.txt")); |
- CreateTextFile(file1, std::wstring()); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file1, std::wstring())); |
FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) |
.Append(FPL("file2.txt")); |
- CreateTextFile(file2_rel, std::wstring()); |
+ ASSERT_NO_FATAL_FAILURE(CreateTextFile(file2_rel, std::wstring())); |
FilePath file2_abs = temp_dir_.GetPath().Append(FPL("file2.txt")); |
// Only enumerate files. |
@@ -2231,7 +2223,8 @@ class VerifyPathControlledByUserTest : public FileUtilTest { |
ASSERT_TRUE(CreateDirectory(sub_dir_)); |
text_file_ = sub_dir_.AppendASCII("file.txt"); |
- CreateTextFile(text_file_, L"This text file has some text in it."); |
+ ASSERT_NO_FATAL_FAILURE( |
+ CreateTextFile(text_file_, L"This text file has some text in it.")); |
// Get the user and group files are created with from |base_dir_|. |
struct stat stat_buf; |