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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <fstream> | 9 #include <fstream> |
10 #include <initializer_list> | 10 #include <initializer_list> |
(...skipping 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2248 | 2248 |
2249 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 2249 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
2250 std::string bar("baz"); | 2250 std::string bar("baz"); |
2251 ASSERT_EQ(static_cast<int>(bar.length()), | 2251 ASSERT_EQ(static_cast<int>(bar.length()), |
2252 WriteFile(foo, bar.c_str(), bar.length())); | 2252 WriteFile(foo, bar.c_str(), bar.length())); |
2253 | 2253 |
2254 EXPECT_FALSE(IsDirectoryEmpty(empty_dir)); | 2254 EXPECT_FALSE(IsDirectoryEmpty(empty_dir)); |
2255 } | 2255 } |
2256 | 2256 |
2257 #if defined(OS_POSIX) | 2257 #if defined(OS_POSIX) |
2258 TEST_F(FileUtilTest, SetNonBlocking) { | |
2259 const int kInvalidFd = 99999; | |
2260 EXPECT_FALSE(SetNonBlocking(kInvalidFd)); | |
2261 | |
2262 base::FilePath path; | |
2263 ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &path)); | |
2264 path = path.Append(FPL("file_util")).Append(FPL("original.txt")); | |
2265 ScopedFD fd(open(path.value().c_str(), O_RDONLY)); | |
tfarina
2017/04/18 22:14:42
Could we also test with socket() or for our test i
Lei Zhang
2017/04/18 22:19:11
I wasn't really aiming for this to be a comprehens
| |
2266 ASSERT_GE(fd.get(), 0); | |
2267 EXPECT_TRUE(SetNonBlocking(fd.get())); | |
2268 } | |
2258 | 2269 |
2259 // Testing VerifyPathControlledByAdmin() is hard, because there is no | 2270 // Testing VerifyPathControlledByAdmin() is hard, because there is no |
2260 // way a test can make a file owned by root, or change file paths | 2271 // way a test can make a file owned by root, or change file paths |
2261 // at the root of the file system. VerifyPathControlledByAdmin() | 2272 // at the root of the file system. VerifyPathControlledByAdmin() |
2262 // is implemented as a call to VerifyPathControlledByUser, which gives | 2273 // is implemented as a call to VerifyPathControlledByUser, which gives |
2263 // us the ability to test with paths under the test's temp directory, | 2274 // us the ability to test with paths under the test's temp directory, |
2264 // using a user id we control. | 2275 // using a user id we control. |
2265 // Pull tests of VerifyPathControlledByUserTest() into a separate test class | 2276 // Pull tests of VerifyPathControlledByUserTest() into a separate test class |
2266 // with a common SetUp() method. | 2277 // with a common SetUp() method. |
2267 class VerifyPathControlledByUserTest : public FileUtilTest { | 2278 class VerifyPathControlledByUserTest : public FileUtilTest { |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2618 // Trying to close it should crash. This is important for security. | 2629 // Trying to close it should crash. This is important for security. |
2619 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2630 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
2620 #endif | 2631 #endif |
2621 } | 2632 } |
2622 | 2633 |
2623 #endif // defined(OS_POSIX) | 2634 #endif // defined(OS_POSIX) |
2624 | 2635 |
2625 } // namespace | 2636 } // namespace |
2626 | 2637 |
2627 } // namespace base | 2638 } // namespace base |
OLD | NEW |