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

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

Issue 243102: Convert base dependencies to use sys_string_conversions instead of the ICU... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | « base/values.cc ('k') | no next file » | 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) 2009 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/string_util.h"
8 #include "build/build_config.h"
7 #include "chrome/browser/download/download_manager.h" 9 #include "chrome/browser/download/download_manager.h"
8 #include "chrome/browser/download/download_util.h" 10 #include "chrome/browser/download/download_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
13 #if defined(OS_LINUX)
14 #include <locale.h>
15 #endif
16
11 class DownloadManagerTest : public testing::Test { 17 class DownloadManagerTest : public testing::Test {
12 public: 18 public:
13 DownloadManagerTest() { 19 DownloadManagerTest() {
14 download_manager_ = new DownloadManager(); 20 download_manager_ = new DownloadManager();
15 download_util::InitializeExeTypes(&download_manager_->exe_types_); 21 download_util::InitializeExeTypes(&download_manager_->exe_types_);
16 } 22 }
17 23
18 void GetGeneratedFilename(const std::string& content_disposition, 24 void GetGeneratedFilename(const std::string& content_disposition,
19 const std::string& url, 25 const std::string& url,
20 const std::string& mime_type, 26 const std::string& mime_type,
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 "http://www.example.com/.download.txt", 454 "http://www.example.com/.download.txt",
449 "text/plain", 455 "text/plain",
450 L"download.txt"}, 456 L"download.txt"},
451 }; 457 };
452 458
453 } // namespace 459 } // namespace
454 460
455 // Tests to ensure that the file names we generate from hints from the server 461 // Tests to ensure that the file names we generate from hints from the server
456 // (content-disposition, URL name, etc) don't cause security holes. 462 // (content-disposition, URL name, etc) don't cause security holes.
457 TEST_F(DownloadManagerTest, TestDownloadFilename) { 463 TEST_F(DownloadManagerTest, TestDownloadFilename) {
464 #if defined(OS_LINUX)
465 // This test doesn't run when the locale is not UTF-8 becuase some of the
466 // string conversions fail. This is OK (we have the default value) but they
467 // don't match our expectations.
468 std::string locale = setlocale(LC_CTYPE, NULL);
469 StringToLowerASCII(&locale);
470 ASSERT_NE(std::string::npos, locale.find("utf-8"))
471 << "Your locale must be set to UTF-8 for this test to pass!";
472 #endif
473
458 std::wstring file_name; 474 std::wstring file_name;
459 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGeneratedFiles); ++i) { 475 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGeneratedFiles); ++i) {
460 GetGeneratedFilename(kGeneratedFiles[i].disposition, 476 GetGeneratedFilename(kGeneratedFiles[i].disposition,
461 kGeneratedFiles[i].url, 477 kGeneratedFiles[i].url,
462 kGeneratedFiles[i].mime_type, 478 kGeneratedFiles[i].mime_type,
463 "", 479 "",
464 &file_name); 480 &file_name);
465 EXPECT_EQ(kGeneratedFiles[i].expected_name, file_name); 481 EXPECT_EQ(kGeneratedFiles[i].expected_name, file_name);
466 GetGeneratedFilename(kGeneratedFiles[i].disposition, 482 GetGeneratedFilename(kGeneratedFiles[i].disposition,
467 kGeneratedFiles[i].url, 483 kGeneratedFiles[i].url,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // TODO(port): port to non-Windows. 551 // TODO(port): port to non-Windows.
536 TEST_F(DownloadManagerTest, GetSafeFilename) { 552 TEST_F(DownloadManagerTest, GetSafeFilename) {
537 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) { 553 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) {
538 FilePath path(kSafeFilenameCases[i].path); 554 FilePath path(kSafeFilenameCases[i].path);
539 download_manager_->GenerateSafeFilename(kSafeFilenameCases[i].mime_type, 555 download_manager_->GenerateSafeFilename(kSafeFilenameCases[i].mime_type,
540 &path); 556 &path);
541 EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value()); 557 EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value());
542 } 558 }
543 } 559 }
544 #endif // OS_WIN 560 #endif // OS_WIN
OLDNEW
« no previous file with comments | « base/values.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698