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

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

Issue 2453633006: [downloads] Move platform specific code out of DownloadTargetDeterminer. (Closed)
Patch Set: . Created 4 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_browsertest.h" 5 #include "chrome/browser/download/download_browsertest.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <sstream> 8 #include <sstream>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 base::FilePath test_file_directory; 475 base::FilePath test_file_directory;
476 PathService::Get(chrome::DIR_TEST_DATA, &test_file_directory); 476 PathService::Get(chrome::DIR_TEST_DATA, &test_file_directory);
477 return test_file_directory; 477 return test_file_directory;
478 } 478 }
479 479
480 base::FilePath GetDownloadsDirectory() { 480 base::FilePath GetDownloadsDirectory() {
481 return downloads_directory_.GetPath(); 481 return downloads_directory_.GetPath();
482 } 482 }
483 483
484 // Location of the file source (the place from which it is downloaded). 484 // Location of the file source (the place from which it is downloaded).
485 base::FilePath OriginFile(base::FilePath file) { 485 base::FilePath OriginFile(const base::FilePath& file) {
486 return test_dir_.Append(file); 486 return test_dir_.Append(file);
487 } 487 }
488 488
489 // Location of the file destination (place to which it is downloaded). 489 // Location of the file destination (place to which it is downloaded).
490 base::FilePath DestinationFile(Browser* browser, base::FilePath file) { 490 base::FilePath DestinationFile(Browser* browser, const base::FilePath& file) {
491 return GetDownloadDirectory(browser).Append(file.BaseName()); 491 return GetDownloadDirectory(browser).Append(file.BaseName());
492 } 492 }
493 493
494 // Must be called after browser creation. Creates a temporary 494 // Must be called after browser creation. Creates a temporary
495 // directory for downloads that is auto-deleted on destruction. 495 // directory for downloads that is auto-deleted on destruction.
496 // Returning false indicates a failure of the function, and should be asserted 496 // Returning false indicates a failure of the function, and should be asserted
497 // in the caller. 497 // in the caller.
498 bool CreateAndSetDownloadsDirectory(Browser* browser) { 498 bool CreateAndSetDownloadsDirectory(Browser* browser) {
499 if (!browser) 499 if (!browser)
500 return false; 500 return false;
(...skipping 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2870 // korean 2870 // korean
2871 L"\u97d3-\u4e2d \uc815\uc0c1, \ucc9c\uc548\ud568 \uc758\uacac.zip", 2871 L"\u97d3-\u4e2d \uc815\uc0c1, \ucc9c\uc548\ud568 \uc758\uacac.zip",
2872 L"jiho....tiho...miho.zip", 2872 L"jiho....tiho...miho.zip",
2873 L"jiho!@#$tiho$%^&-()_+=miho copy.zip", // special chars 2873 L"jiho!@#$tiho$%^&-()_+=miho copy.zip", // special chars
2874 L"Wohoo-to hoo+I.zip", 2874 L"Wohoo-to hoo+I.zip",
2875 L"Picture 1.zip", 2875 L"Picture 1.zip",
2876 L"This is a very very long english sentence with spaces and , and +.zip", 2876 L"This is a very very long english sentence with spaces and , and +.zip",
2877 }; 2877 };
2878 2878
2879 std::vector<DownloadItem*> download_items; 2879 std::vector<DownloadItem*> download_items;
2880 base::FilePath origin(FILE_PATH_LITERAL("origin")); 2880 base::FilePath origin_directory =
2881 ASSERT_TRUE(base::CreateDirectory(DestinationFile(browser(), origin))); 2881 GetDownloadDirectory(browser()).Append(FILE_PATH_LITERAL("origin"));
2882 ASSERT_TRUE(base::CreateDirectory(origin_directory));
2882 2883
2883 for (size_t index = 0; index < arraysize(kCrazyFilenames); ++index) { 2884 for (size_t index = 0; index < arraysize(kCrazyFilenames); ++index) {
2885 SCOPED_TRACE(testing::Message() << "Index " << index);
2884 base::string16 crazy16; 2886 base::string16 crazy16;
2885 std::string crazy8; 2887 std::string crazy8;
2886 const wchar_t* crazy_w = kCrazyFilenames[index]; 2888 const wchar_t* crazy_w = kCrazyFilenames[index];
2887 ASSERT_TRUE(base::WideToUTF8(crazy_w, wcslen(crazy_w), &crazy8)); 2889 ASSERT_TRUE(base::WideToUTF8(crazy_w, wcslen(crazy_w), &crazy8));
2888 ASSERT_TRUE(base::WideToUTF16(crazy_w, wcslen(crazy_w), &crazy16)); 2890 ASSERT_TRUE(base::WideToUTF16(crazy_w, wcslen(crazy_w), &crazy16));
2889 base::FilePath file_path(DestinationFile(browser(), origin.Append( 2891 base::FilePath file_path(origin_directory.Append(
2890 #if defined(OS_WIN) 2892 #if defined(OS_WIN)
2891 crazy16 2893 crazy16
2892 #elif defined(OS_POSIX) 2894 #elif defined(OS_POSIX)
2893 crazy8 2895 crazy8
2894 #endif 2896 #endif
2895 ))); 2897 ));
2896 2898
2897 // Create the file. 2899 // Create the file.
2898 EXPECT_EQ(static_cast<int>(crazy8.size()), 2900 EXPECT_EQ(static_cast<int>(crazy8.size()),
2899 base::WriteFile(file_path, crazy8.c_str(), crazy8.size())); 2901 base::WriteFile(file_path, crazy8.c_str(), crazy8.size()));
2900 GURL file_url(net::FilePathToFileURL(file_path)); 2902 GURL file_url(net::FilePathToFileURL(file_path));
2901 2903
2902 // Download the file and check that the filename is correct. 2904 // Download the file and check that the filename is correct.
2903 DownloadAndWait(browser(), file_url); 2905 DownloadAndWait(browser(), file_url);
2904 GetDownloads(browser(), &download_items); 2906 GetDownloads(browser(), &download_items);
2905 ASSERT_EQ(1UL, download_items.size()); 2907 ASSERT_EQ(1UL, download_items.size());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2962 // Timing out on ARM linux: http://crbug.com/238459 2964 // Timing out on ARM linux: http://crbug.com/238459
2963 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete 2965 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete
2964 #elif defined(OS_MACOSX) 2966 #elif defined(OS_MACOSX)
2965 // Disable on mac: http://crbug.com/238831 2967 // Disable on mac: http://crbug.com/238831
2966 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete 2968 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete
2967 #else 2969 #else
2968 #define MAYBE_DownloadTest_PercentComplete DownloadTest_PercentComplete 2970 #define MAYBE_DownloadTest_PercentComplete DownloadTest_PercentComplete
2969 #endif 2971 #endif
2970 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) { 2972 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) {
2971 // Write a huge file. 2973 // Write a huge file.
2972 base::FilePath file_path(DestinationFile( 2974 base::FilePath file_path(
2973 browser(), base::FilePath(FILE_PATH_LITERAL("DownloadTest_BigZip.zip")))); 2975 GetDownloadDirectory(browser()).AppendASCII("source").AppendASCII(
2976 "DownloadTest_BigZip.zip"));
2977 ASSERT_TRUE(CreateDirectory(file_path.DirName()));
2974 base::File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE); 2978 base::File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE);
2975 ASSERT_TRUE(file.IsValid()); 2979 ASSERT_TRUE(file.IsValid());
2976 int64_t size = 1 << 25; 2980 int64_t size = 1 << 25;
2977 EXPECT_EQ(1, file.Write(size, "a", 1)); 2981 EXPECT_EQ(1, file.Write(size, "a", 1));
2978 file.Close(); 2982 file.Close();
2979 2983
2980 #if defined(OS_POSIX) 2984 #if defined(OS_POSIX)
2981 // Make it readable by chronos on chromeos 2985 // Make it readable by chronos on chromeos
2982 base::SetPosixFilePermissions(file_path, 0755); 2986 base::SetPosixFilePermissions(file_path, 0755);
2983 #endif 2987 #endif
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
3667 browser(), 1, 3671 browser(), 1,
3668 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3672 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3669 ui_test_utils::NavigateToURL(browser(), extension_url); 3673 ui_test_utils::NavigateToURL(browser(), extension_url);
3670 3674
3671 observer->WaitForFinished(); 3675 observer->WaitForFinished();
3672 3676
3673 // Download shelf should close. 3677 // Download shelf should close.
3674 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3678 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3675 } 3679 }
3676 #endif // defined(OS_CHROMEOS) 3680 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698