Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2886)

Unified Diff: base/files/file_util_unittest.cc

Issue 1917893004: Merge M51: Add base::IsOnNetworkDrive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/file_util.h ('k') | base/files/file_util_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_util_unittest.cc
diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc
index a0d0a28927f6eae9c672fa201f30291765300369..ac3a654fdd3d8b179ecc9710b8fd48a1b4ab7a36 100644
--- a/base/files/file_util_unittest.cc
+++ b/base/files/file_util_unittest.cc
@@ -33,6 +33,7 @@
#include <shlobj.h>
#include <tchar.h>
#include <winioctl.h>
+#include "base/environment.h"
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
#endif
@@ -1664,6 +1665,63 @@ TEST_F(FileUtilTest, GetTempDirTest) {
::_tputenv_s(kTmpKey, _T(""));
}
}
+
+TEST_F(FileUtilTest, IsOnNetworkDrive) {
+ struct LocalTestData {
+ const FilePath::CharType* input;
+ bool expected;
+ };
+
+ const LocalTestData local_cases[] = {
+ { FPL(""), false },
+ { FPL("c:\\"), false },
+ { FPL("c:"), false },
+ { FPL("c:\\windows\\notepad.exe"), false }
+ };
+
+ for (const auto& test_case : local_cases) {
+ FilePath input(test_case.input);
+ bool observed = IsOnNetworkDrive(input);
+ EXPECT_EQ(test_case.expected, observed) << " input: " << input.value();
+ }
+
+ Environment* env = Environment::Create();
+ ASSERT_TRUE(!!env);
+
+ // To test IsOnNetworkDrive() for remote cases, set up a file server
+ // and place a file called file.txt on the server e.g.
+ // \\DC01\TESTSHARE\file.txt
+ // then set the two environment variables:
+ // set BASE_TEST_FILE_SERVER=DC01
+ // set BASE_TEST_FILE_SHARE=TESTSHARE
+ if (!env->HasVar("BASE_TEST_FILE_SERVER") ||
+ !env->HasVar("BASE_TEST_FILE_SHARE")) {
+ return;
+ }
+
+ struct NetworkTestData {
+ const wchar_t* input;
+ bool expected;
+ };
+
+ const NetworkTestData network_cases[] = {
+ { L"\\\\%BASE_TEST_FILE_SERVER%", false },
+ { L"\\\\%BASE_TEST_FILE_SERVER%\\", false },
+ { L"\\\\%BASE_TEST_FILE_SERVER%\\file.txt", false },
+ { L"\\\\%BASE_TEST_FILE_SERVER%\\%BASE_TEST_FILE_SHARE%", true },
+ { L"\\\\%BASE_TEST_FILE_SERVER%\\%BASE_TEST_FILE_SHARE%\\", true },
+ { L"\\\\%BASE_TEST_FILE_SERVER%\\%BASE_TEST_FILE_SHARE%\\file.txt", true },
+ { L"\\\\%BASE_TEST_FILE_SERVER%\\%BASE_TEST_FILE_SHARE%\\no.txt", false }
+ };
+
+ for (const auto& test_case : network_cases) {
+ wchar_t path[MAX_PATH] = {0};
+ ::ExpandEnvironmentStringsW(test_case.input, path, arraysize(path));
+ FilePath input(path);
+ EXPECT_EQ(test_case.expected, IsOnNetworkDrive(input)) << " input : "
+ << input.value();
+ }
+}
#endif // OS_WIN
TEST_F(FileUtilTest, CreateTemporaryFileTest) {
« no previous file with comments | « base/files/file_util.h ('k') | base/files/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698