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

Unified Diff: base/files/file_util_unittest.cc

Issue 1892153003: Add base::IsOnNetworkDrive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code review comments 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
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..c620c9d6b774f27be8126d13e75af65312f97a29 100644
--- a/base/files/file_util_unittest.cc
+++ b/base/files/file_util_unittest.cc
@@ -20,6 +20,7 @@
#include "base/macros.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_file_util.h"
#include "base/threading/platform_thread.h"
@@ -33,6 +34,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 +1666,71 @@ 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);
+
+ std::string network_server;
+ std::string network_share;
+
+ // To test IsOnNetworkDrive() for remote cases, set up a file server
Will Harris 2016/04/15 23:42:19 added environment variables for testing network sh
+ // 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->GetVar("BASE_TEST_FILE_SERVER", &network_server) ||
+ !env->GetVar("BASE_TEST_FILE_SHARE", &network_share)) {
+ return;
+ }
+
+ struct NetworkTestData {
+ const char* input;
+ bool format_string_both;
+ bool expected;
+ };
+
+ const NetworkTestData network_cases[] = {
+ { "\\\\%hs", false, false },
+ { "\\\\%hs\\", false, false },
+ { "\\\\%hs\\file.txt", false, false },
+ { "\\\\%hs\\%hs", true, true },
+ { "\\\\%hs\\%hs\\", true, true },
+ { "\\\\%hs\\%hs\\file.txt", true, true }
+ };
+
+ for (const auto& test_case : network_cases) {
+ std::string full_path;
+ if (test_case.format_string_both) {
+ full_path = base::StringPrintf(test_case.input, network_server.c_str(),
Will Harris 2016/04/15 23:51:08 in retrospect I should probably just use ExpandEnv
+ network_share.c_str());
+ } else {
+ full_path = base::StringPrintf(test_case.input, network_server.c_str());
+ }
+ FilePath input(base::UTF8ToUTF16(full_path));
+ EXPECT_EQ(test_case.expected, IsOnNetworkDrive(input)) << " input : "
+ << input.value();
+ }
+}
#endif // OS_WIN
TEST_F(FileUtilTest, CreateTemporaryFileTest) {

Powered by Google App Engine
This is Rietveld 408576698