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

Unified Diff: chrome/browser/download/save_package_unittest.cc

Issue 155266: Ensure proper paths when saving pages with no title (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months 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 | « chrome/browser/download/save_package.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/save_package_unittest.cc
===================================================================
--- chrome/browser/download/save_package_unittest.cc (revision 20414)
+++ chrome/browser/download/save_package_unittest.cc (working copy)
@@ -92,6 +92,11 @@
return SavePackage::EnsureHtmlExtension(name);
}
+ FilePath GetSuggestedNameForSaveAs(const FilePath& title,
+ bool ensure_html_extension) {
+ return SavePackage::GetSuggestedNameForSaveAs(title, ensure_html_extension);
+ }
+
private:
// SavePackage for successfully generating file name.
scoped_refptr<SavePackage> save_package_success_;
@@ -213,3 +218,33 @@
kExtensionTestCases[i].page_title;
}
}
+
+// Test that the suggested names generated by SavePackage are reasonable:
+// If the name is a URL, retrieve only the path component since the path name
+// generation code will turn the entire URL into the file name leading to bad
+// extension names. For example, a page with no title and a URL:
+// http://www.foo.com/a/path/name.txt will turn into file:
+// "http www.foo.com a path name.txt", when we want to save it as "name.txt".
+
+static const struct {
+ const FilePath::CharType* page_title;
+ const FilePath::CharType* expected_name;
+ bool ensure_html_extension;
+} kSuggestedSaveNames[] = {
+ {FPL("A page title"), FPL("A page title") FPL_HTML_EXTENSION, true},
+ {FPL("A page title with.ext"), FPL("A page title with.ext"), false},
+ {FPL("http://www.foo.com/path/title.txt"), FPL("title.txt"), false},
+ {FPL("http://www.foo.com/path/"), FPL("path"), false},
+ {FPL("http://www.foo.com/"), FPL("www.foo.com"), false},
+};
+
+TEST_F(SavePackageTest, TestSuggestedSaveNames) {
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSuggestedSaveNames); ++i) {
+ FilePath title = FilePath(kSuggestedSaveNames[i].page_title);
+ FilePath save_name =
+ GetSuggestedNameForSaveAs(title,
+ kSuggestedSaveNames[i].ensure_html_extension);
+ EXPECT_EQ(save_name.value(), kSuggestedSaveNames[i].expected_name);
+ }
+}
+
« no previous file with comments | « chrome/browser/download/save_package.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698