Commit b7a95ad6 authored by brettw@chromium.org's avatar brettw@chromium.org

Remove wstring file path helpers from test_file_util.

These were only used by one test file, so I moved the implementation there. I
considered updating the test, but the way the test uses wstrings seems
reasonable.

R=rvargas@chromium.org, rvargas

Review URL: https://codereview.chromium.org/448763003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288084 0039d316-1c4b-4281-b951-d872f2087c98
parent 9f2bf3ca
......@@ -52,12 +52,6 @@ bool HasInternetZoneIdentifier(const FilePath& full_path);
// TODO(brettw) move all of this to the base namespace.
namespace file_util {
// In general it's not reliable to convert a FilePath to a wstring and we use
// string16 elsewhere for Unicode strings, but in tests it is frequently
// convenient to be able to compare paths to literals like L"foobar".
std::wstring FilePathAsWString(const base::FilePath& path);
base::FilePath WStringAsFilePath(const std::wstring& path);
// For testing, make the file unreadable or unwritable.
// In POSIX, this does not apply to the root user.
bool MakeFileUnreadable(const base::FilePath& path) WARN_UNUSED_RESULT;
......
......@@ -17,8 +17,6 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
using base::MakeAbsoluteFilePath;
namespace base {
namespace {
......@@ -95,13 +93,6 @@ using base::DenyFilePermission;
using base::GetPermissionInfo;
using base::RestorePermissionInfo;
std::wstring FilePathAsWString(const base::FilePath& path) {
return base::UTF8ToWide(path.value());
}
base::FilePath WStringAsFilePath(const std::wstring& path) {
return base::FilePath(base::WideToUTF8(path));
}
bool MakeFileUnreadable(const base::FilePath& path) {
return DenyFilePermission(path, S_IRUSR | S_IRGRP | S_IROTH);
}
......
......@@ -267,13 +267,6 @@ using base::DenyFilePermission;
using base::GetPermissionInfo;
using base::RestorePermissionInfo;
std::wstring FilePathAsWString(const base::FilePath& path) {
return path.value();
}
base::FilePath WStringAsFilePath(const std::wstring& path) {
return base::FilePath(path);
}
bool MakeFileUnreadable(const base::FilePath& path) {
return DenyFilePermission(path, GENERIC_READ);
}
......
......@@ -32,14 +32,29 @@ struct GenerateFilenameCase {
const wchar_t* expected_filename;
};
// The expected filenames are coded as wchar_t for convenience.
std::wstring FilePathAsWString(const base::FilePath& path) {
#if defined(OS_WIN)
return path.value();
#else
return base::UTF8ToWide(path.value());
#endif
}
base::FilePath WStringAsFilePath(const std::wstring& str) {
#if defined(OS_WIN)
return base::FilePath(str);
#else
return base::FilePath(base::WideToUTF8(str));
#endif
}
void RunGenerateFileNameTestCase(const GenerateFilenameCase* test_case) {
std::string default_filename(base::WideToUTF8(test_case->default_filename));
base::FilePath file_path = GenerateFileName(
GURL(test_case->url), test_case->content_disp_header,
test_case->referrer_charset, test_case->suggested_filename,
test_case->mime_type, default_filename);
EXPECT_EQ(test_case->expected_filename,
file_util::FilePathAsWString(file_path))
EXPECT_EQ(test_case->expected_filename, FilePathAsWString(file_path))
<< "test case at line number: " << test_case->lineno;
}
......@@ -171,12 +186,12 @@ TEST(FilenameUtilTest, FileURLConversion) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(round_trip_cases); i++) {
// convert to the file URL
GURL file_url(FilePathToFileURL(
file_util::WStringAsFilePath(round_trip_cases[i].file)));
WStringAsFilePath(round_trip_cases[i].file)));
EXPECT_EQ(round_trip_cases[i].url, file_url.spec());
// Back to the filename.
EXPECT_TRUE(FileURLToFilePath(file_url, &output));
EXPECT_EQ(round_trip_cases[i].file, file_util::FilePathAsWString(output));
EXPECT_EQ(round_trip_cases[i].file, FilePathAsWString(output));
}
// Test that various file: URLs get decoded into the correct file type
......@@ -215,7 +230,7 @@ TEST(FilenameUtilTest, FileURLConversion) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_cases); i++) {
FileURLToFilePath(GURL(url_cases[i].url), &output);
EXPECT_EQ(url_cases[i].file, file_util::FilePathAsWString(output));
EXPECT_EQ(url_cases[i].file, FilePathAsWString(output));
}
// Unfortunately, UTF8ToWide discards invalid UTF8 input.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment