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

Side by Side Diff: chrome/browser/download/save_package_unittest.cc

Issue 155095: Make default extension for downloading html "html" rather than "htm" on non-w... (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/save_package.cc ('k') | chrome/browser/download/save_page_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/browser/download/save_package.h" 10 #include "chrome/browser/download/save_package.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 #define FPL FILE_PATH_LITERAL 13 #define FPL FILE_PATH_LITERAL
14 #if defined(OS_WIN)
15 #define HTML_EXTENSION ".htm"
16 #else
17 #define HTML_EXTENSION ".html"
18 #endif
14 19
15 namespace { 20 namespace {
16 21
17 // This constant copied from save_package.cc. 22 // This constant copied from save_package.cc.
18 #if defined(OS_WIN) 23 #if defined(OS_WIN)
19 const uint32 kMaxFilePathLength = MAX_PATH - 1; 24 const uint32 kMaxFilePathLength = MAX_PATH - 1;
20 #elif defined(OS_POSIX) 25 #elif defined(OS_POSIX)
21 const uint32 kMaxFilePathLength = PATH_MAX - 1; 26 const uint32 kMaxFilePathLength = PATH_MAX - 1;
22 #endif 27 #endif
23 28
(...skipping 21 matching lines...) Expand all
45 50
46 } // namespace 51 } // namespace
47 52
48 class SavePackageTest : public testing::Test { 53 class SavePackageTest : public testing::Test {
49 public: 54 public:
50 SavePackageTest() { 55 SavePackageTest() {
51 FilePath test_dir; 56 FilePath test_dir;
52 PathService::Get(base::DIR_TEMP, &test_dir); 57 PathService::Get(base::DIR_TEMP, &test_dir);
53 58
54 save_package_success_ = new SavePackage( 59 save_package_success_ = new SavePackage(
55 test_dir.AppendASCII("testfile.htm"), 60 test_dir.AppendASCII("testfile" HTML_EXTENSION),
56 test_dir.AppendASCII("testfile_files")); 61 test_dir.AppendASCII("testfile_files"));
57 62
58 // We need to construct a path that is *almost* kMaxFilePathLength long 63 // We need to construct a path that is *almost* kMaxFilePathLength long
59 long_file_name.resize(kMaxFilePathLength + long_file_name.length()); 64 long_file_name.resize(kMaxFilePathLength + long_file_name.length());
60 while (long_file_name.length() < kMaxFilePathLength) 65 while (long_file_name.length() < kMaxFilePathLength)
61 long_file_name += long_file_name; 66 long_file_name += long_file_name;
62 long_file_name.resize(kMaxFilePathLength - 9 - test_dir.value().length()); 67 long_file_name.resize(kMaxFilePathLength - 9 - test_dir.value().length());
63 68
64 save_package_fail_ = new SavePackage( 69 save_package_fail_ = new SavePackage(
65 test_dir.AppendASCII(long_file_name + ".htm"), 70 test_dir.AppendASCII(long_file_name + HTML_EXTENSION),
66 test_dir.AppendASCII(long_file_name + "_files")); 71 test_dir.AppendASCII(long_file_name + "_files"));
67 } 72 }
68 73
69 bool GetGeneratedFilename(bool need_success_generate_filename, 74 bool GetGeneratedFilename(bool need_success_generate_filename,
70 const std::string& disposition, 75 const std::string& disposition,
71 const std::string& url, 76 const std::string& url,
72 bool need_htm_ext, 77 bool need_htm_ext,
73 FilePath::StringType* generated_name) { 78 FilePath::StringType* generated_name) {
74 SavePackage* save_package; 79 SavePackage* save_package;
75 if (need_success_generate_filename) 80 if (need_success_generate_filename)
(...skipping 20 matching lines...) Expand all
96 static const struct { 101 static const struct {
97 const char* disposition; 102 const char* disposition;
98 const char* url; 103 const char* url;
99 const FilePath::CharType* expected_name; 104 const FilePath::CharType* expected_name;
100 bool need_htm_ext; 105 bool need_htm_ext;
101 } kGeneratedFiles[] = { 106 } kGeneratedFiles[] = {
102 // We mainly focus on testing duplicated names here, since retrieving file 107 // We mainly focus on testing duplicated names here, since retrieving file
103 // name from disposition and url has been tested in DownloadManagerTest. 108 // name from disposition and url has been tested in DownloadManagerTest.
104 109
105 // No useful information in disposition or URL, use default. 110 // No useful information in disposition or URL, use default.
106 {"1.html", "http://www.savepage.com/", FPL("saved_resource.htm"), true}, 111 {"1.html", "http://www.savepage.com/", FPL("saved_resource") HTML_EXTENSION,
112 true},
107 113
108 // No duplicate occurs. 114 // No duplicate occurs.
109 {"filename=1.css", "http://www.savepage.com", FPL("1.css"), false}, 115 {"filename=1.css", "http://www.savepage.com", FPL("1.css"), false},
110 116
111 // No duplicate occurs. 117 // No duplicate occurs.
112 {"filename=1.js", "http://www.savepage.com", FPL("1.js"), false}, 118 {"filename=1.js", "http://www.savepage.com", FPL("1.js"), false},
113 119
114 // Append numbers for duplicated names. 120 // Append numbers for duplicated names.
115 {"filename=1.css", "http://www.savepage.com", FPL("1(1).css"), false}, 121 {"filename=1.css", "http://www.savepage.com", FPL("1(1).css"), false},
116 122
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 186
181 static const struct { 187 static const struct {
182 const FilePath::CharType* page_title; 188 const FilePath::CharType* page_title;
183 const FilePath::CharType* expected_name; 189 const FilePath::CharType* expected_name;
184 } kExtensionTestCases[] = { 190 } kExtensionTestCases[] = {
185 // Extension is preserved if it is already proper for HTML. 191 // Extension is preserved if it is already proper for HTML.
186 {FPL("filename.html"), FPL("filename.html")}, 192 {FPL("filename.html"), FPL("filename.html")},
187 {FPL("filename.HTML"), FPL("filename.HTML")}, 193 {FPL("filename.HTML"), FPL("filename.HTML")},
188 {FPL("filename.htm"), FPL("filename.htm")}, 194 {FPL("filename.htm"), FPL("filename.htm")},
189 // ".htm" is added if the extension is improper for HTML. 195 // ".htm" is added if the extension is improper for HTML.
190 {FPL("hello.world"), FPL("hello.world.htm")}, 196 {FPL("hello.world"), FPL("hello.world") FPL(HTML_EXTENSION)},
191 {FPL("hello.txt"), FPL("hello.txt.htm")}, 197 {FPL("hello.txt"), FPL("hello.txt") FPL(HTML_EXTENSION)},
192 {FPL("is.html.good"), FPL("is.html.good.htm")}, 198 {FPL("is.html.good"), FPL("is.html.good") FPL(HTML_EXTENSION)},
193 // ".htm" is added if the name doesn't have an extension. 199 // ".htm" is added if the name doesn't have an extension.
194 {FPL("helloworld"), FPL("helloworld.htm")}, 200 {FPL("helloworld"), FPL("helloworld") FPL(HTML_EXTENSION)},
195 {FPL("helloworld."), FPL("helloworld..htm")}, 201 {FPL("helloworld."), FPL("helloworld.") FPL(HTML_EXTENSION)},
196 }; 202 };
197 203
198 TEST_F(SavePackageTest, TestEnsureHtmlExtension) { 204 TEST_F(SavePackageTest, TestEnsureHtmlExtension) {
199 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExtensionTestCases); ++i) { 205 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExtensionTestCases); ++i) {
200 FilePath original = FilePath(kExtensionTestCases[i].page_title); 206 FilePath original = FilePath(kExtensionTestCases[i].page_title);
201 FilePath expected = FilePath(kExtensionTestCases[i].expected_name); 207 FilePath expected = FilePath(kExtensionTestCases[i].expected_name);
202 FilePath actual = EnsureHtmlExtension(original); 208 FilePath actual = EnsureHtmlExtension(original);
203 EXPECT_EQ(expected.value(), actual.value()) << "Failed for page title: " << 209 EXPECT_EQ(expected.value(), actual.value()) << "Failed for page title: " <<
204 kExtensionTestCases[i].page_title; 210 kExtensionTestCases[i].page_title;
205 } 211 }
206 } 212 }
OLDNEW
« no previous file with comments | « chrome/browser/download/save_package.cc ('k') | chrome/browser/download/save_page_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698