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

Unified Diff: net/base/filename_util_unittest.cc

Issue 790903003: Generalizing conditional compilation logic for systems with native utf8 locale. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated BUILD.gn based on rvargas comments. Created 6 years 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/strings/sys_string_conversions_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/filename_util_unittest.cc
diff --git a/net/base/filename_util_unittest.cc b/net/base/filename_util_unittest.cc
index 391baeb331247204d6ff74653dbdbf372fdf02ee..0e7d5046ddf16910c0efcee7e7aa7cd002e01318 100644
--- a/net/base/filename_util_unittest.cc
+++ b/net/base/filename_util_unittest.cc
@@ -48,6 +48,25 @@ base::FilePath WStringAsFilePath(const std::wstring& str) {
#endif
}
+std::string GetLocaleWarningString() {
+#if defined(OS_POSIX) && !defined(OS_ANDROID)
+ // The generate filename tests can fail on certain OS_POSIX platforms when
+ // LC_CTYPE is not "utf8" or "utf-8" because some of the string conversions
+ // fail.
+ // This warning text is appended to any test failures to save people time if
+ // this happens to be the cause of failure :)
+ // Note: some platforms (MACOSX, Chromecast) don't have this problem:
+ // setlocale returns "c" but it functions as utf8. And Android doesn't
+ // have setlocale at all.
+ std::string locale = setlocale(LC_CTYPE, NULL);
+ return " this test may have failed because the current LC_CTYPE locale is "
+ "not utf8 (currently set to " +
+ locale + ")";
+#else
+ return "";
+#endif
+}
+
void RunGenerateFileNameTestCase(const GenerateFilenameCase* test_case) {
std::string default_filename(base::WideToUTF8(test_case->default_filename));
base::FilePath file_path = GenerateFileName(
@@ -55,7 +74,8 @@ void RunGenerateFileNameTestCase(const GenerateFilenameCase* test_case) {
test_case->referrer_charset, test_case->suggested_filename,
test_case->mime_type, default_filename);
EXPECT_EQ(test_case->expected_filename, FilePathAsWString(file_path))
- << "test case at line number: " << test_case->lineno;
+ << "test case at line number: " << test_case->lineno << "; "
+ << GetLocaleWarningString();
}
} // namespace
@@ -418,18 +438,6 @@ TEST(FilenameUtilTest, GenerateSafeFileName) {
}
TEST(FilenameUtilTest, GenerateFileName) {
-#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
- // This test doesn't run when the locale is not UTF-8 because some of the
- // string conversions fail. This is OK (we have the default value) but they
- // don't match our expectations.
- std::string locale = setlocale(LC_CTYPE, NULL);
- base::StringToLowerASCII(&locale);
- EXPECT_TRUE(locale.find("utf-8") != std::string::npos ||
- locale.find("utf8") != std::string::npos)
- << "Your locale (" << locale << ") must be set to UTF-8 "
- << "for this test to pass!";
-#endif
-
// Tests whether the correct filename is selected from the the given
// parameters and that Content-Disposition headers are properly
// handled including failovers when the header is malformed.
« no previous file with comments | « base/strings/sys_string_conversions_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698