OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 5 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
6 #include <locale.h> | 6 #include <locale.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/browser/download/download_util.h" | 10 #include "chrome/browser/download/download_util.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 L"program.exe"}, | 181 L"program.exe"}, |
182 | 182 |
183 {"filename=../foo.txt", | 183 {"filename=../foo.txt", |
184 "http://www.evil.com/../foo.txt", | 184 "http://www.evil.com/../foo.txt", |
185 "text/plain", | 185 "text/plain", |
186 L"foo.txt"}, | 186 L"foo.txt"}, |
187 | 187 |
188 {"filename=..\\foo.txt", | 188 {"filename=..\\foo.txt", |
189 "http://www.evil.com/..\\foo.txt", | 189 "http://www.evil.com/..\\foo.txt", |
190 "text/plain", | 190 "text/plain", |
191 #if defined(OS_WIN) | |
192 L"foo.txt" | 191 L"foo.txt" |
193 #else | |
194 L"\\foo.txt" | |
195 #endif | |
196 }, | 192 }, |
197 | 193 |
198 {"filename=.hidden", | 194 {"filename=.hidden", |
199 "http://www.evil.com/.hidden", | 195 "http://www.evil.com/.hidden", |
200 "text/plain", | 196 "text/plain", |
201 L"hidden" TXT_EXT | 197 L"hidden" TXT_EXT |
202 }, | 198 }, |
203 | 199 |
204 {"filename=trailing.", | 200 {"filename=trailing.", |
205 "http://www.evil.com/trailing.", | 201 "http://www.evil.com/trailing.", |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // Tests to ensure that the file names we generate from hints from the server | 426 // Tests to ensure that the file names we generate from hints from the server |
431 // (content-disposition, URL name, etc) don't cause security holes. | 427 // (content-disposition, URL name, etc) don't cause security holes. |
432 TEST(DownloadUtilTest, GenerateFileName) { | 428 TEST(DownloadUtilTest, GenerateFileName) { |
433 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 429 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
434 // This test doesn't run when the locale is not UTF-8 because some of the | 430 // This test doesn't run when the locale is not UTF-8 because some of the |
435 // string conversions fail. This is OK (we have the default value) but they | 431 // string conversions fail. This is OK (we have the default value) but they |
436 // don't match our expectations. | 432 // don't match our expectations. |
437 std::string locale = setlocale(LC_CTYPE, NULL); | 433 std::string locale = setlocale(LC_CTYPE, NULL); |
438 StringToLowerASCII(&locale); | 434 StringToLowerASCII(&locale); |
439 EXPECT_NE(std::string::npos, locale.find("utf-8")) | 435 EXPECT_NE(std::string::npos, locale.find("utf-8")) |
440 << "Your locale must be set to UTF-8 for this test to pass!"; | 436 << "Your locale (" << locale << ") must be set to UTF-8 " |
| 437 << "for this test to pass!"; |
441 #endif | 438 #endif |
442 | 439 |
443 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGenerateFileNameTestCases); ++i) { | 440 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGenerateFileNameTestCases); ++i) { |
444 FilePath generated_name; | 441 FilePath generated_name; |
445 download_util::GenerateFileName(GURL(kGenerateFileNameTestCases[i].url), | 442 download_util::GenerateFileName(GURL(kGenerateFileNameTestCases[i].url), |
446 kGenerateFileNameTestCases[i].disposition, | 443 kGenerateFileNameTestCases[i].disposition, |
447 "", | 444 "", |
448 kGenerateFileNameTestCases[i].mime_type, | 445 kGenerateFileNameTestCases[i].mime_type, |
449 &generated_name); | 446 &generated_name); |
450 EXPECT_EQ(kGenerateFileNameTestCases[i].expected_name, | 447 EXPECT_EQ(kGenerateFileNameTestCases[i].expected_name, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 TEST(DownloadUtilTest, GenerateSafeFileName) { | 559 TEST(DownloadUtilTest, GenerateSafeFileName) { |
563 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) { | 560 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) { |
564 FilePath path(kSafeFilenameCases[i].path); | 561 FilePath path(kSafeFilenameCases[i].path); |
565 download_util::GenerateSafeFileName(kSafeFilenameCases[i].mime_type, &path); | 562 download_util::GenerateSafeFileName(kSafeFilenameCases[i].mime_type, &path); |
566 EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value()) << i; | 563 EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value()) << i; |
567 } | 564 } |
568 } | 565 } |
569 | 566 |
570 } // namespace | 567 } // namespace |
571 | 568 |
OLD | NEW |