| 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 <set> | 10 #include <set> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "testing/platform_test.h" | 29 #include "testing/platform_test.h" |
| 30 | 30 |
| 31 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 32 #include <windows.h> | 32 #include <windows.h> |
| 33 #include <shellapi.h> | 33 #include <shellapi.h> |
| 34 #include <shlobj.h> | 34 #include <shlobj.h> |
| 35 #include <tchar.h> | 35 #include <tchar.h> |
| 36 #include <winioctl.h> | 36 #include <winioctl.h> |
| 37 #include "base/environment.h" | |
| 38 #include "base/win/scoped_handle.h" | 37 #include "base/win/scoped_handle.h" |
| 39 #include "base/win/windows_version.h" | 38 #include "base/win/windows_version.h" |
| 40 #endif | 39 #endif |
| 41 | 40 |
| 42 #if defined(OS_POSIX) | 41 #if defined(OS_POSIX) |
| 43 #include <errno.h> | 42 #include <errno.h> |
| 44 #include <fcntl.h> | 43 #include <fcntl.h> |
| 45 #include <unistd.h> | 44 #include <unistd.h> |
| 46 #endif | 45 #endif |
| 47 | 46 |
| (...skipping 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 // Copy the directory recursively. | 1399 // Copy the directory recursively. |
| 1401 FilePath dir_name_to = | 1400 FilePath dir_name_to = |
| 1402 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1401 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1403 FilePath file_name_to = | 1402 FilePath file_name_to = |
| 1404 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1403 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1405 | 1404 |
| 1406 // Create from path with trailing separators. | 1405 // Create from path with trailing separators. |
| 1407 #if defined(OS_WIN) | 1406 #if defined(OS_WIN) |
| 1408 FilePath from_path = | 1407 FilePath from_path = |
| 1409 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); | 1408 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); |
| 1410 #elif defined (OS_POSIX) | 1409 #elif defined(OS_POSIX) |
| 1411 FilePath from_path = | 1410 FilePath from_path = |
| 1412 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); | 1411 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); |
| 1413 #endif | 1412 #endif |
| 1414 | 1413 |
| 1415 EXPECT_TRUE(CopyDirectory(from_path, dir_name_to, true)); | 1414 EXPECT_TRUE(CopyDirectory(from_path, dir_name_to, true)); |
| 1416 | 1415 |
| 1417 // Check everything has been copied. | 1416 // Check everything has been copied. |
| 1418 EXPECT_TRUE(PathExists(dir_name_from)); | 1417 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1419 EXPECT_TRUE(PathExists(file_name_from)); | 1418 EXPECT_TRUE(PathExists(file_name_from)); |
| 1420 EXPECT_TRUE(PathExists(dir_name_to)); | 1419 EXPECT_TRUE(PathExists(dir_name_to)); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 { FPL("c:"), false }, | 1717 { FPL("c:"), false }, |
| 1719 { FPL("c:\\windows\\notepad.exe"), false } | 1718 { FPL("c:\\windows\\notepad.exe"), false } |
| 1720 }; | 1719 }; |
| 1721 | 1720 |
| 1722 for (const auto& test_case : local_cases) { | 1721 for (const auto& test_case : local_cases) { |
| 1723 FilePath input(test_case.input); | 1722 FilePath input(test_case.input); |
| 1724 bool observed = IsOnNetworkDrive(input); | 1723 bool observed = IsOnNetworkDrive(input); |
| 1725 EXPECT_EQ(test_case.expected, observed) << " input: " << input.value(); | 1724 EXPECT_EQ(test_case.expected, observed) << " input: " << input.value(); |
| 1726 } | 1725 } |
| 1727 | 1726 |
| 1728 Environment* env = Environment::Create(); | 1727 std::unique_ptr<Environment> env(Environment::Create()); |
| 1729 ASSERT_TRUE(!!env); | |
| 1730 | |
| 1731 // To test IsOnNetworkDrive() for remote cases, set up a file server | 1728 // To test IsOnNetworkDrive() for remote cases, set up a file server |
| 1732 // and place a file called file.txt on the server e.g. | 1729 // and place a file called file.txt on the server e.g. |
| 1733 // \\DC01\TESTSHARE\file.txt | 1730 // \\DC01\TESTSHARE\file.txt |
| 1734 // then set the two environment variables: | 1731 // then set the two environment variables: |
| 1735 // set BASE_TEST_FILE_SERVER=DC01 | 1732 // set BASE_TEST_FILE_SERVER=DC01 |
| 1736 // set BASE_TEST_FILE_SHARE=TESTSHARE | 1733 // set BASE_TEST_FILE_SHARE=TESTSHARE |
| 1737 if (!env->HasVar("BASE_TEST_FILE_SERVER") || | 1734 if (!env->HasVar("BASE_TEST_FILE_SERVER") || |
| 1738 !env->HasVar("BASE_TEST_FILE_SHARE")) { | 1735 !env->HasVar("BASE_TEST_FILE_SHARE")) { |
| 1739 return; | 1736 return; |
| 1740 } | 1737 } |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 // Trying to close it should crash. This is important for security. | 2615 // Trying to close it should crash. This is important for security. |
| 2619 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2616 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
| 2620 #endif | 2617 #endif |
| 2621 } | 2618 } |
| 2622 | 2619 |
| 2623 #endif // defined(OS_POSIX) | 2620 #endif // defined(OS_POSIX) |
| 2624 | 2621 |
| 2625 } // namespace | 2622 } // namespace |
| 2626 | 2623 |
| 2627 } // namespace base | 2624 } // namespace base |
| OLD | NEW |