summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-25 21:58:22 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-25 21:58:22 +0000
commitd0437d9953d748fd01b3cc551fc363f793666838 (patch)
tree598ece71c65ce9141fafd7b2bddb738399c3c820
parentbbda5c2c105e02f91485b6d6a94a4897dbf63c3a (diff)
downloadchromium_src-d0437d9953d748fd01b3cc551fc363f793666838.zip
chromium_src-d0437d9953d748fd01b3cc551fc363f793666838.tar.gz
chromium_src-d0437d9953d748fd01b3cc551fc363f793666838.tar.bz2
linux: port some of the download manager unit test
Mostly lots of #ifdefs tracking platform behaviors. I tried to make the logic correct for Mac, too, but I didn't enable Mac here. BUG=21632 Review URL: http://codereview.chromium.org/220025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27260 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/download/download_manager_unittest.cc160
-rw-r--r--chrome/chrome.gyp5
2 files changed, 137 insertions, 28 deletions
diff --git a/chrome/browser/download/download_manager_unittest.cc b/chrome/browser/download/download_manager_unittest.cc
index 01f4839..164c92b 100644
--- a/chrome/browser/download/download_manager_unittest.cc
+++ b/chrome/browser/download/download_manager_unittest.cc
@@ -64,7 +64,13 @@ const struct {
L"a_file_name.txt"},
// No useful information in disposition or URL, use default
- {"", "http://www.truncated.com/path/", "text/plain", L"download.txt"},
+ {"", "http://www.truncated.com/path/", "text/plain",
+#if defined(OS_LINUX)
+ L"download"
+#else
+ L"download.txt"
+#endif
+ },
// A normal avi should get .avi and not .avi.avi
{"", "https://blah.google.com/misc/2.avi", "video/x-msvideo", L"2.avi"},
@@ -75,6 +81,10 @@ const struct {
"application/octet-stream",
L"My Downloaded File.exe"},
+ // This block tests whether we append extensions based on MIME types;
+ // we don't do this on Linux, so we skip the tests rather than #ifdef
+ // them up.
+#if !defined(OS_LINUX)
{"filename=my-cat",
"http://www.example.com/my-cat",
"image/jpeg",
@@ -94,12 +104,15 @@ const struct {
"http://www.example.com/my-cat",
"dance/party",
L"my-cat"},
+#endif // defined(OS_LINUX)
{"filename=my-cat.jpg",
"http://www.example.com/my-cat.jpg",
"text/plain",
L"my-cat.jpg"},
+ // .exe tests.
+#if defined(OS_WIN)
{"filename=evil.exe",
"http://www.goodguy.com/evil.exe",
"image/jpeg",
@@ -129,6 +142,7 @@ const struct {
"http://www.goodguy.com/evil.exe",
"application/rss+xml",
L"evil.download"},
+#endif // OS_WIN
{"filename=utils.js",
"http://www.goodguy.com/utils.js",
@@ -173,22 +187,38 @@ const struct {
{"filename=..\\foo.txt",
"http://www.evil.com/..\\foo.txt",
"text/plain",
- L"foo.txt"},
+#if defined(OS_WIN)
+ L"foo.txt"
+#else
+ L"\\foo.txt"
+#endif
+ },
{"filename=.hidden",
"http://www.evil.com/.hidden",
"text/plain",
- L"hidden.txt"},
+#if defined(OS_LINUX)
+ L"hidden"
+#else
+ L"hidden.txt"
+#endif
+ },
{"filename=trailing.",
"http://www.evil.com/trailing.",
"dance/party",
- L"trailing"},
+ L"trailing"
+ },
{"filename=trailing.",
"http://www.evil.com/trailing.",
"text/plain",
- L"trailing.txt"},
+#if defined(OS_LINUX)
+ L"trailing"
+#else
+ L"trailing.txt"
+#endif
+ },
{"filename=.",
"http://www.evil.com/.",
@@ -205,15 +235,26 @@ const struct {
"dance/party",
L"download"},
+ // Note that this one doesn't have "filename=" on it.
{"a_file_name.txt",
"http://www.evil.com/",
"image/jpeg",
- L"download.jpg"},
+#if defined(OS_LINUX)
+ L"download"
+#else
+ L"download.jpg"
+#endif
+ },
{"filename=",
"http://www.evil.com/",
"image/jpeg",
- L"download.jpg"},
+#if defined(OS_LINUX)
+ L"download"
+#else
+ L"download.jpg"
+#endif
+ },
{"filename=simple",
"http://www.example.com/simple",
@@ -223,22 +264,42 @@ const struct {
{"filename=COM1",
"http://www.goodguy.com/COM1",
"application/foo-bar",
- L"_COM1"},
+#if defined(OS_WIN)
+ L"_COM1"
+#else
+ L"COM1"
+#endif
+ },
{"filename=COM4.txt",
"http://www.goodguy.com/COM4.txt",
"text/plain",
- L"_COM4.txt"},
+#if defined(OS_WIN)
+ L"_COM4.txt"
+#else
+ L"COM4.txt"
+#endif
+ },
{"filename=lpt1.TXT",
"http://www.goodguy.com/lpt1.TXT",
"text/plain",
- L"_lpt1.TXT"},
+#if defined(OS_WIN)
+ L"_lpt1.TXT"
+#else
+ L"lpt1.TXT"
+#endif
+ },
{"filename=clock$.txt",
"http://www.goodguy.com/clock$.txt",
"text/plain",
- L"_clock$.txt"},
+#if defined(OS_WIN)
+ L"_clock$.txt"
+#else
+ L"clock$.txt"
+#endif
+ },
{"filename=mycom1.foo",
"http://www.goodguy.com/mycom1.foo",
@@ -248,32 +309,62 @@ const struct {
{"filename=Setup.exe.local",
"http://www.badguy.com/Setup.exe.local",
"application/foo-bar",
- L"Setup.exe.download"},
+#if defined(OS_WIN)
+ L"Setup.exe.download"
+#else
+ L"Setup.exe.local"
+#endif
+ },
{"filename=Setup.exe.local.local",
"http://www.badguy.com/Setup.exe.local",
"application/foo-bar",
- L"Setup.exe.local.download"},
+#if defined(OS_WIN)
+ L"Setup.exe.local.download"
+#else
+ L"Setup.exe.local.local"
+#endif
+ },
{"filename=Setup.exe.lnk",
"http://www.badguy.com/Setup.exe.lnk",
"application/foo-bar",
- L"Setup.exe.download"},
+#if defined(OS_WIN)
+ L"Setup.exe.download"
+#else
+ L"Setup.exe.lnk"
+#endif
+ },
{"filename=Desktop.ini",
"http://www.badguy.com/Desktop.ini",
"application/foo-bar",
- L"_Desktop.ini"},
+#if defined(OS_WIN)
+ L"_Desktop.ini"
+#else
+ L"Desktop.ini"
+#endif
+ },
{"filename=Thumbs.db",
"http://www.badguy.com/Thumbs.db",
"application/foo-bar",
- L"_Thumbs.db"},
+#if defined(OS_WIN)
+ L"_Thumbs.db"
+#else
+ L"Thumbs.db"
+#endif
+ },
{"filename=source.srf",
"http://www.hotmail.com",
"image/jpeg",
- L"source.srf.jpg"},
+#if defined(OS_WIN)
+ L"source.srf.jpg"
+#else
+ L"source.srf"
+#endif
+},
{"filename=source.jpg",
"http://www.hotmail.com",
@@ -302,7 +393,12 @@ const struct {
{"attachment; filename==?iiso88591?Q?caf=EG?=",
"http://www.example.com/test%20123",
"image/jpeg",
- L"test 123.jpg"},
+#if defined(OS_LINUX)
+ L"test 123"
+#else
+ L"test 123.jpg"
+#endif
+ },
{"malformed_disposition",
"http://www.google.com/%EC%98%88%EC%88%A0%20%EC%98%88%EC%88%A0.jpg",
@@ -313,7 +409,12 @@ const struct {
{"attachment; filename==?iso88591?Q?caf=E3?",
"http://www.google.com/path1/path2/",
"image/jpeg",
- L"download.jpg"},
+#if defined(OS_LINUX)
+ L"download"
+#else
+ L"download.jpg"
+#endif
+ },
// Issue=5772.
{"",
@@ -335,8 +436,18 @@ const struct {
{"",
"http://www.example.com/bar.bogus",
"application/x-tar",
- L"bar.bogus.tar"},
-
+#if defined(OS_LINUX)
+ L"bar.bogus"
+#else
+ L"bar.bogus.tar"
+#endif
+ },
+
+ // http://code.google.com/p/chromium/issues/detail?id=20337
+ {"filename=.download.txt",
+ "http://www.example.com/.download.txt",
+ "text/plain",
+ L"download.txt"},
};
} // namespace
@@ -345,7 +456,7 @@ const struct {
// (content-disposition, URL name, etc) don't cause security holes.
TEST_F(DownloadManagerTest, TestDownloadFilename) {
std::wstring file_name;
- for (int i = 0; i < arraysize(kGeneratedFiles); ++i) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGeneratedFiles); ++i) {
GetGeneratedFilename(kGeneratedFiles[i].disposition,
kGeneratedFiles[i].url,
kGeneratedFiles[i].mime_type,
@@ -420,11 +531,14 @@ const struct {
} // namespace
+#if defined(OS_WIN)
+// TODO(port): port to non-Windows.
TEST_F(DownloadManagerTest, GetSafeFilename) {
- for (int i = 0; i < arraysize(kSafeFilenameCases); ++i) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) {
FilePath path(kSafeFilenameCases[i].path);
download_manager_->GenerateSafeFilename(kSafeFilenameCases[i].mime_type,
&path);
EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value());
}
}
+#endif // OS_WIN
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index f4e2153..ed18daa 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -4355,11 +4355,6 @@
'browser/renderer_host/gtk_key_bindings_handler_unittest.cc',
],
'sources!': [
- # This test is mostly about renaming downloads to safe file
- # names. As such we don't need/want to port it to linux. We
- # might want to write our own tests for the download manager
- # on linux, though.
- 'browser/download/download_manager_unittest.cc',
'browser/views/bookmark_context_menu_test.cc',
'browser/gtk/options/cookies_view_unittest.cc',
# Compact Language Detection (cld) is not supported in linux yet.