summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/download/save_package.cc22
-rw-r--r--chrome/browser/download/save_package_unittest.cc25
-rw-r--r--chrome/browser/download/save_page_uitest.cc7
3 files changed, 39 insertions, 15 deletions
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index beca753..8d8873b 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -63,6 +63,13 @@ namespace {
// resource URL.
const wchar_t kDefaultSaveName[] = L"saved_resource";
+const FilePath::CharType kDefaultHtmlExtension[] =
+#if defined(OS_WIN)
+ FILE_PATH_LITERAL("htm");
+#else
+ FILE_PATH_LITERAL("html");
+#endif
+
// Maximum number of file ordinal number. I think it's big enough for resolving
// name-conflict files which has same base file name.
const int32 kMaxFileOrdinalNumber = 9999;
@@ -295,9 +302,11 @@ bool SavePackage::GenerateFilename(const std::string& disposition,
file_path.RemoveExtension().BaseName().value();
FilePath::StringType file_name_ext = file_path.Extension();
- // If it is HTML resource, use ".htm" as its extension name.
- if (need_html_ext)
- file_name_ext = FILE_PATH_LITERAL(".htm");
+ // If it is HTML resource, use ".htm{l,}" as its extension.
+ if (need_html_ext) {
+ file_name_ext = FILE_PATH_LITERAL(".");
+ file_name_ext.append(kDefaultHtmlExtension);
+ }
// Get safe pure file name.
if (!GetSafePureFileName(saved_main_directory_path_, file_name_ext,
@@ -988,12 +997,13 @@ FilePath SavePackage::GetSuggestNameForSaveAs(
FilePath SavePackage::EnsureHtmlExtension(const FilePath& name) {
// If the file name doesn't have an extension suitable for HTML files,
- // append ".htm".
+ // append one.
FilePath::StringType ext = file_util::GetFileExtensionFromPath(name);
std::string mime_type;
if (!net::GetMimeTypeFromExtension(ext, &mime_type) ||
!CanSaveAsComplete(mime_type)) {
- return FilePath(name.value() + FILE_PATH_LITERAL(".htm"));
+ return FilePath(name.value() + FILE_PATH_LITERAL(".") +
+ kDefaultHtmlExtension);
}
return name;
}
@@ -1029,7 +1039,7 @@ void SavePackage::GetSaveInfo() {
file_type_info.extension_description_overrides.push_back(
WideToUTF16(l10n_util::GetString(IDS_SAVE_PAGE_DESC_COMPLETE)));
file_type_info.include_all_files = false;
- default_extension = FILE_PATH_LITERAL("htm");
+ default_extension = kDefaultHtmlExtension;
} else {
file_type_info.extensions.resize(1);
file_type_info.extensions[0].push_back(suggested_path.Extension());
diff --git a/chrome/browser/download/save_package_unittest.cc b/chrome/browser/download/save_package_unittest.cc
index d828dcb..6522a80 100644
--- a/chrome/browser/download/save_package_unittest.cc
+++ b/chrome/browser/download/save_package_unittest.cc
@@ -11,6 +11,14 @@
#include "testing/gtest/include/gtest/gtest.h"
#define FPL FILE_PATH_LITERAL
+#if defined(OS_WIN)
+#define HTML_EXTENSION ".htm"
+// This second define is needed because MSVC is broken.
+#define FPL_HTML_EXTENSION L".htm"
+#else
+#define HTML_EXTENSION ".html"
+#define FPL_HTML_EXTENSION ".html"
+#endif
namespace {
@@ -52,7 +60,7 @@ class SavePackageTest : public testing::Test {
PathService::Get(base::DIR_TEMP, &test_dir);
save_package_success_ = new SavePackage(
- test_dir.AppendASCII("testfile.htm"),
+ test_dir.AppendASCII("testfile" HTML_EXTENSION),
test_dir.AppendASCII("testfile_files"));
// We need to construct a path that is *almost* kMaxFilePathLength long
@@ -62,7 +70,7 @@ class SavePackageTest : public testing::Test {
long_file_name.resize(kMaxFilePathLength - 9 - test_dir.value().length());
save_package_fail_ = new SavePackage(
- test_dir.AppendASCII(long_file_name + ".htm"),
+ test_dir.AppendASCII(long_file_name + HTML_EXTENSION),
test_dir.AppendASCII(long_file_name + "_files"));
}
@@ -103,7 +111,8 @@ static const struct {
// name from disposition and url has been tested in DownloadManagerTest.
// No useful information in disposition or URL, use default.
- {"1.html", "http://www.savepage.com/", FPL("saved_resource.htm"), true},
+ {"1.html", "http://www.savepage.com/",
+ FPL("saved_resource") FPL_HTML_EXTENSION, true},
// No duplicate occurs.
{"filename=1.css", "http://www.savepage.com", FPL("1.css"), false},
@@ -187,12 +196,12 @@ static const struct {
{FPL("filename.HTML"), FPL("filename.HTML")},
{FPL("filename.htm"), FPL("filename.htm")},
// ".htm" is added if the extension is improper for HTML.
- {FPL("hello.world"), FPL("hello.world.htm")},
- {FPL("hello.txt"), FPL("hello.txt.htm")},
- {FPL("is.html.good"), FPL("is.html.good.htm")},
+ {FPL("hello.world"), FPL("hello.world") FPL_HTML_EXTENSION},
+ {FPL("hello.txt"), FPL("hello.txt") FPL_HTML_EXTENSION},
+ {FPL("is.html.good"), FPL("is.html.good") FPL_HTML_EXTENSION},
// ".htm" is added if the name doesn't have an extension.
- {FPL("helloworld"), FPL("helloworld.htm")},
- {FPL("helloworld."), FPL("helloworld..htm")},
+ {FPL("helloworld"), FPL("helloworld") FPL_HTML_EXTENSION},
+ {FPL("helloworld."), FPL("helloworld.") FPL_HTML_EXTENSION},
};
TEST_F(SavePackageTest, TestEnsureHtmlExtension) {
diff --git a/chrome/browser/download/save_page_uitest.cc b/chrome/browser/download/save_page_uitest.cc
index 7acec74..cbd10c1 100644
--- a/chrome/browser/download/save_page_uitest.cc
+++ b/chrome/browser/download/save_page_uitest.cc
@@ -28,7 +28,12 @@
const char* const kTestDir = "save_page";
-const char* const kAppendedExtension = ".htm";
+const char* const kAppendedExtension =
+#if defined(OS_WIN)
+ ".htm";
+#else
+ ".html";
+#endif
class SavePageTest : public UITest {
protected: