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

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

Issue 6973052: When the download folder does not exist, change the download folder to a user's "Downloads" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add ChooseSavableDirectory() and ScopedDefaultDownloadDirectory Created 9 years, 6 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
OLDNEW
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 #include "chrome/browser/download/download_util.h" 5 #include "chrome/browser/download/download_util.h"
6 6
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) 7 #if defined(OS_POSIX) && !defined(OS_MACOSX)
8 #include <locale.h> 8 #include <locale.h>
9 #endif 9 #endif
10 10
11 #include "base/path_service.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/test/test_file_util.h" 13 #include "base/test/test_file_util.h"
14 #include "chrome/common/chrome_paths.h"
13 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 #if defined(OS_WIN) 18 #if defined(OS_WIN)
17 #define JPEG_EXT L".jpg" 19 #define JPEG_EXT L".jpg"
18 #define HTML_EXT L".htm" 20 #define HTML_EXT L".htm"
19 #define TXT_EXT L".txt" 21 #define TXT_EXT L".txt"
20 #define TAR_EXT L".tar" 22 #define TAR_EXT L".tar"
21 #elif defined(OS_MACOSX) 23 #elif defined(OS_MACOSX)
22 #define JPEG_EXT L".jpeg" 24 #define JPEG_EXT L".jpeg"
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 }; 573 };
572 574
573 TEST(DownloadUtilTest, GenerateSafeFileName) { 575 TEST(DownloadUtilTest, GenerateSafeFileName) {
574 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) { 576 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kSafeFilenameCases); ++i) {
575 FilePath path(kSafeFilenameCases[i].path); 577 FilePath path(kSafeFilenameCases[i].path);
576 download_util::GenerateSafeFileName(kSafeFilenameCases[i].mime_type, &path); 578 download_util::GenerateSafeFileName(kSafeFilenameCases[i].mime_type, &path);
577 EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value()) << i; 579 EXPECT_EQ(kSafeFilenameCases[i].expected_path, path.value()) << i;
578 } 580 }
579 } 581 }
580 582
583 TEST(DownloadUtilTest, OverrideDefaultDownloadFolder) {
584 FilePath override_path(FILE_PATH_LITERAL("/koakuma/mikity/moemoe/nyannyan"));
585 FilePath original_path;
586 ASSERT_TRUE(PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &original_path));
587 download_util::ScopedDefaultDownloadDirectory override_default_downloads;
588
589 FilePath current_path = download_util::DefaultDownloadDirectory::Get();
590 EXPECT_EQ(current_path, original_path);
591
592 override_default_downloads.Override(override_path);
593 current_path = download_util::DefaultDownloadDirectory::Get();
594 EXPECT_EQ(current_path, override_path);
595
596 override_default_downloads.UnOverride();
597 current_path = download_util::DefaultDownloadDirectory::Get();
598 EXPECT_EQ(current_path, original_path);
599 }
600
581 } // namespace 601 } // namespace
582
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698