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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 2104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2115 | 2115 |
2116 ASSERT_TRUE(TouchFile(foobar, access_time, modification_time)); | 2116 ASSERT_TRUE(TouchFile(foobar, access_time, modification_time)); |
2117 File::Info file_info; | 2117 File::Info file_info; |
2118 ASSERT_TRUE(GetFileInfo(foobar, &file_info)); | 2118 ASSERT_TRUE(GetFileInfo(foobar, &file_info)); |
2119 EXPECT_EQ(access_time.ToInternalValue(), | 2119 EXPECT_EQ(access_time.ToInternalValue(), |
2120 file_info.last_accessed.ToInternalValue()); | 2120 file_info.last_accessed.ToInternalValue()); |
2121 EXPECT_EQ(modification_time.ToInternalValue(), | 2121 EXPECT_EQ(modification_time.ToInternalValue(), |
2122 file_info.last_modified.ToInternalValue()); | 2122 file_info.last_modified.ToInternalValue()); |
2123 } | 2123 } |
2124 | 2124 |
| 2125 #if defined(OS_POSIX) |
| 2126 TEST_F(FileUtilTest, WriteFileWithMode) { |
| 2127 FilePath data_dir = |
| 2128 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 2129 |
| 2130 // Create a fresh, empty copy of this directory. |
| 2131 if (PathExists(data_dir)) { |
| 2132 ASSERT_TRUE(DeleteFile(data_dir, true)); |
| 2133 } |
| 2134 ASSERT_TRUE(CreateDirectory(data_dir)); |
| 2135 |
| 2136 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
| 2137 std::string data("hello"); |
| 2138 mode_t mode = 0644; |
| 2139 ASSERT_TRUE(WriteFileWithMode(foobar, data.c_str(), data.length(), mode)); |
| 2140 |
| 2141 struct stat status; |
| 2142 ASSERT_EQ(0, stat(foobar.value().c_str(), &status)); |
| 2143 ASSERT_EQ(mode, status.st_mode & 0777); |
| 2144 } |
| 2145 #endif |
| 2146 |
2125 TEST_F(FileUtilTest, IsDirectoryEmpty) { | 2147 TEST_F(FileUtilTest, IsDirectoryEmpty) { |
2126 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); | 2148 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); |
2127 | 2149 |
2128 ASSERT_FALSE(PathExists(empty_dir)); | 2150 ASSERT_FALSE(PathExists(empty_dir)); |
2129 | 2151 |
2130 ASSERT_TRUE(CreateDirectory(empty_dir)); | 2152 ASSERT_TRUE(CreateDirectory(empty_dir)); |
2131 | 2153 |
2132 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); | 2154 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); |
2133 | 2155 |
2134 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 2156 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2586 // Trying to close it should crash. This is important for security. | 2608 // Trying to close it should crash. This is important for security. |
2587 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2609 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
2588 #endif | 2610 #endif |
2589 } | 2611 } |
2590 | 2612 |
2591 #endif // defined(OS_POSIX) | 2613 #endif // defined(OS_POSIX) |
2592 | 2614 |
2593 } // namespace | 2615 } // namespace |
2594 | 2616 |
2595 } // namespace base | 2617 } // namespace base |
OLD | NEW |