diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-02 22:56:40 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-02 22:56:40 +0000 |
commit | 0ee9da3a1737d047dfbbd33d5d1b1f7ef5d4097d (patch) | |
tree | c59a6bf02fdd145c403e1e4f43e18f5a3c744633 | |
parent | 385e5b56919c8e55dffb814c19edd33839dd7b50 (diff) | |
download | chromium_src-0ee9da3a1737d047dfbbd33d5d1b1f7ef5d4097d.zip chromium_src-0ee9da3a1737d047dfbbd33d5d1b1f7ef5d4097d.tar.gz chromium_src-0ee9da3a1737d047dfbbd33d5d1b1f7ef5d4097d.tar.bz2 |
Win: Don't give some downloads duplicate extensions like .arj.arj
BUG=49621
TEST=See bug. Also unittests.
Review URL: http://codereview.chromium.org/3069018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54625 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/shell_dialogs_win.cc | 7 | ||||
-rw-r--r-- | chrome/browser/views/shell_dialogs_win_unittest.cc | 24 |
2 files changed, 29 insertions, 2 deletions
diff --git a/chrome/browser/views/shell_dialogs_win.cc b/chrome/browser/views/shell_dialogs_win.cc index 7d74595..c1b6f5c 100644 --- a/chrome/browser/views/shell_dialogs_win.cc +++ b/chrome/browser/views/shell_dialogs_win.cc @@ -41,11 +41,14 @@ std::wstring AppendExtensionIfNeeded(const std::wstring& filename, DCHECK(!filename.empty()); std::wstring return_value = filename; - // If the user didn't give us a known extension, and we wanted one, add it. + // If we wanted a specific extension, but the user's filename deleted it or + // changed it to something that the system doesn't understand, re-append. std::string selected_mime_type; + std::wstring file_extension = file_util::GetFileExtensionFromPath(filename); if (!(filter_selected.empty() || filter_selected == L"*.*") && !net::GetMimeTypeFromExtension( - file_util::GetFileExtensionFromPath(filename), &selected_mime_type)) { + file_extension, &selected_mime_type) && + file_extension != suggested_ext) { if (return_value[return_value.length() - 1] != L'.') return_value.append(L"."); return_value.append(suggested_ext); diff --git a/chrome/browser/views/shell_dialogs_win_unittest.cc b/chrome/browser/views/shell_dialogs_win_unittest.cc index b267e16..bbe2525 100644 --- a/chrome/browser/views/shell_dialogs_win_unittest.cc +++ b/chrome/browser/views/shell_dialogs_win_unittest.cc @@ -70,3 +70,27 @@ TEST(AppendExtensionIfNeeded, AllFilesFilter_NoExtensionAppended) { ASSERT_EQ(L"sample.unknown-mime-type", actual_filename); } + +TEST(AppendExtensionIfNeeded, StripsDotsForUnknownSelectedMimeType) { + const std::wstring filename = L"product"; + const std::wstring filter_selected = L"*.unknown-extension."; + const std::wstring suggested_ext = L"html"; + + const std::wstring actual_filename = AppendExtensionIfNeeded(filename, + filter_selected, suggested_ext); + + ASSERT_EQ(L"product.html", actual_filename); +} + +TEST(AppendExtensionIfNeeded, EqualToExtension_NoDoubleExtension) { + // Make sure we don't add a duplicate extension like .tbl.tbl for + // files that the system doesn't have a mime type for. + const std::wstring filename = L"product.tbl"; + const std::wstring filter_selected = L"*.tbl"; + const std::wstring suggested_ext = L"tbl"; + + const std::wstring actual_filename = AppendExtensionIfNeeded(filename, + filter_selected, suggested_ext); + + ASSERT_EQ(L"product.tbl", actual_filename); +} |