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 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 }; | 1557 }; |
1558 // Save the original $TMP. | 1558 // Save the original $TMP. |
1559 size_t original_tmp_size; | 1559 size_t original_tmp_size; |
1560 TCHAR* original_tmp; | 1560 TCHAR* original_tmp; |
1561 ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey)); | 1561 ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey)); |
1562 // original_tmp may be NULL. | 1562 // original_tmp may be NULL. |
1563 | 1563 |
1564 for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) { | 1564 for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) { |
1565 FilePath path; | 1565 FilePath path; |
1566 ::_tputenv_s(kTmpKey, kTmpValues[i]); | 1566 ::_tputenv_s(kTmpKey, kTmpValues[i]); |
1567 file_util::GetTempDir(&path); | 1567 base::GetTempDir(&path); |
1568 EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] << | 1568 EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] << |
1569 " result=" << path.value(); | 1569 " result=" << path.value(); |
1570 } | 1570 } |
1571 | 1571 |
1572 // Restore the original $TMP. | 1572 // Restore the original $TMP. |
1573 if (original_tmp) { | 1573 if (original_tmp) { |
1574 ::_tputenv_s(kTmpKey, original_tmp); | 1574 ::_tputenv_s(kTmpKey, original_tmp); |
1575 free(original_tmp); | 1575 free(original_tmp); |
1576 } else { | 1576 } else { |
1577 ::_tputenv_s(kTmpKey, _T("")); | 1577 ::_tputenv_s(kTmpKey, _T("")); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1630 temp_dir_.path(), | 1630 temp_dir_.path(), |
1631 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), | 1631 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), |
1632 &new_dir)); | 1632 &new_dir)); |
1633 EXPECT_TRUE(PathExists(new_dir)); | 1633 EXPECT_TRUE(PathExists(new_dir)); |
1634 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); | 1634 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); |
1635 EXPECT_TRUE(DeleteFile(new_dir, false)); | 1635 EXPECT_TRUE(DeleteFile(new_dir, false)); |
1636 } | 1636 } |
1637 | 1637 |
1638 TEST_F(FileUtilTest, GetShmemTempDirTest) { | 1638 TEST_F(FileUtilTest, GetShmemTempDirTest) { |
1639 FilePath dir; | 1639 FilePath dir; |
1640 EXPECT_TRUE(file_util::GetShmemTempDir(&dir, false)); | 1640 EXPECT_TRUE(GetShmemTempDir(false, &dir)); |
1641 EXPECT_TRUE(DirectoryExists(dir)); | 1641 EXPECT_TRUE(DirectoryExists(dir)); |
1642 } | 1642 } |
1643 | 1643 |
1644 TEST_F(FileUtilTest, CreateDirectoryTest) { | 1644 TEST_F(FileUtilTest, CreateDirectoryTest) { |
1645 FilePath test_root = | 1645 FilePath test_root = |
1646 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); | 1646 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); |
1647 #if defined(OS_WIN) | 1647 #if defined(OS_WIN) |
1648 FilePath test_path = | 1648 FilePath test_path = |
1649 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); | 1649 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); |
1650 #elif defined(OS_POSIX) | 1650 #elif defined(OS_POSIX) |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 modification_time.ToInternalValue()); | 1926 modification_time.ToInternalValue()); |
1927 } | 1927 } |
1928 | 1928 |
1929 TEST_F(FileUtilTest, IsDirectoryEmpty) { | 1929 TEST_F(FileUtilTest, IsDirectoryEmpty) { |
1930 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); | 1930 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); |
1931 | 1931 |
1932 ASSERT_FALSE(PathExists(empty_dir)); | 1932 ASSERT_FALSE(PathExists(empty_dir)); |
1933 | 1933 |
1934 ASSERT_TRUE(file_util::CreateDirectory(empty_dir)); | 1934 ASSERT_TRUE(file_util::CreateDirectory(empty_dir)); |
1935 | 1935 |
1936 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); | 1936 EXPECT_TRUE(base::IsDirectoryEmpty(empty_dir)); |
1937 | 1937 |
1938 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 1938 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
1939 std::string bar("baz"); | 1939 std::string bar("baz"); |
1940 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); | 1940 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); |
1941 | 1941 |
1942 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); | 1942 EXPECT_FALSE(base::IsDirectoryEmpty(empty_dir)); |
1943 } | 1943 } |
1944 | 1944 |
1945 #if defined(OS_POSIX) | 1945 #if defined(OS_POSIX) |
1946 | 1946 |
1947 // Testing VerifyPathControlledByAdmin() is hard, because there is no | 1947 // Testing VerifyPathControlledByAdmin() is hard, because there is no |
1948 // way a test can make a file owned by root, or change file paths | 1948 // way a test can make a file owned by root, or change file paths |
1949 // at the root of the file system. VerifyPathControlledByAdmin() | 1949 // at the root of the file system. VerifyPathControlledByAdmin() |
1950 // is implemented as a call to VerifyPathControlledByUser, which gives | 1950 // is implemented as a call to VerifyPathControlledByUser, which gives |
1951 // us the ability to test with paths under the test's temp directory, | 1951 // us the ability to test with paths under the test's temp directory, |
1952 // using a user id we control. | 1952 // using a user id we control. |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2354 int fd = OpenContentUriForRead(path); | 2354 int fd = OpenContentUriForRead(path); |
2355 EXPECT_EQ(-1, fd); | 2355 EXPECT_EQ(-1, fd); |
2356 } | 2356 } |
2357 #endif | 2357 #endif |
2358 | 2358 |
2359 #endif // defined(OS_POSIX) | 2359 #endif // defined(OS_POSIX) |
2360 | 2360 |
2361 } // namespace | 2361 } // namespace |
2362 | 2362 |
2363 } // namespace base | 2363 } // namespace base |
OLD | NEW |