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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 | 429 |
430 // Tests to ensure that the file names we generate from hints from the server | 430 // 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. | 431 // (content-disposition, URL name, etc) don't cause security holes. |
432 TEST(DownloadUtilTest, GenerateFileName) { | 432 TEST(DownloadUtilTest, GenerateFileName) { |
433 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 433 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
434 // This test doesn't run when the locale is not UTF-8 because some of the | 434 // 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 | 435 // string conversions fail. This is OK (we have the default value) but they |
436 // don't match our expectations. | 436 // don't match our expectations. |
437 std::string locale = setlocale(LC_CTYPE, NULL); | 437 std::string locale = setlocale(LC_CTYPE, NULL); |
438 StringToLowerASCII(&locale); | 438 StringToLowerASCII(&locale); |
439 EXPECT_NE(std::string::npos, locale.find("utf-8")) | 439 bool found = (locale.find("utf-8") != std::string::npos) || |
440 (locale.find("utf8") != std::string::npos); | |
441 EXPECT_TRUE(found) | |
Scott Hess - ex-Googler
2010/12/03 23:21:44
Don't include this change with the overall change.
| |
440 << "Your locale must be set to UTF-8 for this test to pass!"; | 442 << "Your locale must be set to UTF-8 for this test to pass!"; |
441 #endif | 443 #endif |
442 | 444 |
443 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGenerateFileNameTestCases); ++i) { | 445 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGenerateFileNameTestCases); ++i) { |
444 FilePath generated_name; | 446 FilePath generated_name; |
445 download_util::GenerateFileName(GURL(kGenerateFileNameTestCases[i].url), | 447 download_util::GenerateFileName(GURL(kGenerateFileNameTestCases[i].url), |
446 kGenerateFileNameTestCases[i].disposition, | 448 kGenerateFileNameTestCases[i].disposition, |
447 "", | 449 "", |
448 kGenerateFileNameTestCases[i].mime_type, | 450 kGenerateFileNameTestCases[i].mime_type, |
449 &generated_name); | 451 &generated_name); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 TEST(DownloadUtilTest, GenerateSafeFileName) { | 564 TEST(DownloadUtilTest, GenerateSafeFileName) { |
563 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) { | 565 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) { |
564 FilePath path(kSafeFilenameCases[i].path); | 566 FilePath path(kSafeFilenameCases[i].path); |
565 download_util::GenerateSafeFileName(kSafeFilenameCases[i].mime_type, &path); | 567 download_util::GenerateSafeFileName(kSafeFilenameCases[i].mime_type, &path); |
566 EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value()) << i; | 568 EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value()) << i; |
567 } | 569 } |
568 } | 570 } |
569 | 571 |
570 } // namespace | 572 } // namespace |
571 | 573 |
OLD | NEW |