| 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);
|
| + }
|
| +}
|
| +
|
|
|