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 2125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 | 2136 |
2137 ASSERT_TRUE(TouchFile(foobar, access_time, modification_time)); | 2137 ASSERT_TRUE(TouchFile(foobar, access_time, modification_time)); |
2138 File::Info file_info; | 2138 File::Info file_info; |
2139 ASSERT_TRUE(GetFileInfo(foobar, &file_info)); | 2139 ASSERT_TRUE(GetFileInfo(foobar, &file_info)); |
2140 EXPECT_EQ(access_time.ToInternalValue(), | 2140 EXPECT_EQ(access_time.ToInternalValue(), |
2141 file_info.last_accessed.ToInternalValue()); | 2141 file_info.last_accessed.ToInternalValue()); |
2142 EXPECT_EQ(modification_time.ToInternalValue(), | 2142 EXPECT_EQ(modification_time.ToInternalValue(), |
2143 file_info.last_modified.ToInternalValue()); | 2143 file_info.last_modified.ToInternalValue()); |
2144 } | 2144 } |
2145 | 2145 |
| 2146 #if defined(OS_POSIX) |
| 2147 TEST_F(FileUtilTest, WriteFileWithMode) { |
| 2148 FilePath data_dir = |
| 2149 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 2150 |
| 2151 // Create a fresh, empty copy of this directory. |
| 2152 if (PathExists(data_dir)) { |
| 2153 ASSERT_TRUE(DeleteFile(data_dir, true)); |
| 2154 } |
| 2155 ASSERT_TRUE(CreateDirectory(data_dir)); |
| 2156 |
| 2157 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
| 2158 std::string data("hello"); |
| 2159 mode_t mode = 0644; |
| 2160 ASSERT_TRUE(WriteFileWithMode(foobar, data.c_str(), data.length(), mode)); |
| 2161 |
| 2162 struct stat status; |
| 2163 ASSERT_EQ(0, stat(foobar.value().c_str(), &status)); |
| 2164 ASSERT_EQ(mode, status.st_mode & 0777); |
| 2165 } |
| 2166 #endif |
| 2167 |
2146 TEST_F(FileUtilTest, IsDirectoryEmpty) { | 2168 TEST_F(FileUtilTest, IsDirectoryEmpty) { |
2147 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); | 2169 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); |
2148 | 2170 |
2149 ASSERT_FALSE(PathExists(empty_dir)); | 2171 ASSERT_FALSE(PathExists(empty_dir)); |
2150 | 2172 |
2151 ASSERT_TRUE(CreateDirectory(empty_dir)); | 2173 ASSERT_TRUE(CreateDirectory(empty_dir)); |
2152 | 2174 |
2153 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); | 2175 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); |
2154 | 2176 |
2155 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 2177 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2607 // Trying to close it should crash. This is important for security. | 2629 // Trying to close it should crash. This is important for security. |
2608 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2630 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
2609 #endif | 2631 #endif |
2610 } | 2632 } |
2611 | 2633 |
2612 #endif // defined(OS_POSIX) | 2634 #endif // defined(OS_POSIX) |
2613 | 2635 |
2614 } // namespace | 2636 } // namespace |
2615 | 2637 |
2616 } // namespace base | 2638 } // namespace base |
OLD | NEW |