summaryrefslogtreecommitdiffstats
path: root/base/i18n/file_util_icu_unittest.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 23:06:12 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-22 23:06:12 +0000
commitde29433580baeecc204edc9ca0c2aa47c51aa93a (patch)
treeec55f655f63f7e09fb373c1e7d784c2e721c6119 /base/i18n/file_util_icu_unittest.cc
parent2c1639589b5932b565c9d420cb79b56a4212a706 (diff)
downloadchromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.zip
chromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.tar.gz
chromium_src-de29433580baeecc204edc9ca0c2aa47c51aa93a.tar.bz2
Do some cleanup of file path name handling.
This started trying to cleanup DownloadManager::GenerateFilename which asserts if your system locale isn't UTF-8 (I ran into this when mine got messed up). The solution is to have GetSuggestedFilename return a FilePath rather than calling FromWStringHack. The rest of the patch is a result of trying to write GetSuggestedFilename in a reasonable way. I changed ReplaceIllegalCharacters to work on a FilePath::StringType. Some places in the code calling these functions got cleaner, some got messier. I think overall the ones that got messier are the ones doing sketchy things with paths and the ones that got cleaner are the ones doing things more properly. The only code here that gets called a nontrivial number of times is the weburlloader, and I think the new code does about the same number of string conversions overall (though on certain platforms the number will be higher or lower). BUG=none TEST=none Review URL: http://codereview.chromium.org/271056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29832 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/i18n/file_util_icu_unittest.cc')
-rw-r--r--base/i18n/file_util_icu_unittest.cc46
1 files changed, 40 insertions, 6 deletions
diff --git a/base/i18n/file_util_icu_unittest.cc b/base/i18n/file_util_icu_unittest.cc
index aebcd0df..b46fe55 100644
--- a/base/i18n/file_util_icu_unittest.cc
+++ b/base/i18n/file_util_icu_unittest.cc
@@ -6,6 +6,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -34,9 +35,34 @@ class FileUtilICUTest : public PlatformTest {
FilePath test_dir_;
};
+#if defined(OS_LINUX)
+
+// Linux disallows some evil ASCII characters, but passes all non-ASCII.
+static const struct goodbad_pair {
+ const char* bad_name;
+ const char* good_name;
+} kIllegalCharacterCases[] = {
+ {"bad*file:name?.jpg", "bad-file-name-.jpg"},
+ {"**********::::.txt", "--------------.txt"},
+ {"\xe9\xf0zzzz.\xff", "\xe9\xf0zzzz.\xff"},
+};
+
+TEST_F(FileUtilICUTest, ReplaceIllegalCharacersInPathLinuxTest) {
+ for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) {
+ std::string bad_name(kIllegalCharacterCases[i].bad_name);
+ file_util::ReplaceIllegalCharactersInPath(&bad_name, '-');
+ EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name);
+ }
+}
+
+#else
+
+// For Mac & Windows, which both do Unicode validation on filenames. These
+// characters are given as wide strings since its more convenient to specify
+// unicode characters. For Mac they should be converted to UTF-8.
static const struct goodbad_pair {
- std::wstring bad_name;
- std::wstring good_name;
+ const wchar_t* bad_name;
+ const wchar_t* good_name;
} kIllegalCharacterCases[] = {
{L"bad*file:name?.jpg", L"bad-file-name-.jpg"},
{L"**********::::.txt", L"--------------.txt"},
@@ -46,7 +72,7 @@ static const struct goodbad_pair {
#if defined(OS_WIN)
{L"bad*file\\name.jpg", L"bad-file-name.jpg"},
{L"\t bad*file\\name/.jpg ", L"bad-file-name-.jpg"},
-#elif defined(OS_POSIX)
+#elif defined(OS_MACOSX)
{L"bad*file?name.jpg", L"bad-file-name.jpg"},
{L"\t bad*file?name/.jpg ", L"bad-file-name-.jpg"},
#endif
@@ -61,11 +87,19 @@ static const struct goodbad_pair {
{L"bad\uFDD0file\uFDEFname.jpg ", L"bad-file-name.jpg"},
};
-TEST_F(FileUtilICUTest, ReplaceIllegalCharactersTest) {
- for (unsigned int i = 0; i < arraysize(kIllegalCharacterCases); ++i) {
+TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathTest) {
+ for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) {
+#if defined(OS_WIN)
std::wstring bad_name(kIllegalCharacterCases[i].bad_name);
- file_util::ReplaceIllegalCharacters(&bad_name, L'-');
+ file_util::ReplaceIllegalCharactersInPath(&bad_name, '-');
EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name);
+#elif defined(OS_MACOSX)
+ std::string bad_name(WideToUTF8(kIllegalCharacterCases[i].bad_name));
+ file_util::ReplaceIllegalCharactersInPath(&bad_name, '-');
+ EXPECT_EQ(WideToUTF8(kIllegalCharacterCases[i].good_name), bad_name);
+#endif
}
}
+#endif
+