OLD | NEW |
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 |
| 9 #include <memory> |
| 10 #include <set> |
8 #include <sstream> | 11 #include <sstream> |
| 12 #include <string> |
9 #include <utility> | 13 #include <utility> |
| 14 #include <vector> |
10 | 15 |
11 #include "base/bind.h" | 16 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 18 #include "base/command_line.h" |
14 #include "base/feature_list.h" | 19 #include "base/feature_list.h" |
15 #include "base/files/file.h" | 20 #include "base/files/file.h" |
16 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
17 #include "base/files/file_util.h" | 22 #include "base/files/file_util.h" |
18 #include "base/files/scoped_temp_dir.h" | 23 #include "base/files/scoped_temp_dir.h" |
19 #include "base/macros.h" | 24 #include "base/macros.h" |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 base::FilePath test_file_directory; | 479 base::FilePath test_file_directory; |
475 PathService::Get(chrome::DIR_TEST_DATA, &test_file_directory); | 480 PathService::Get(chrome::DIR_TEST_DATA, &test_file_directory); |
476 return test_file_directory; | 481 return test_file_directory; |
477 } | 482 } |
478 | 483 |
479 base::FilePath GetDownloadsDirectory() { | 484 base::FilePath GetDownloadsDirectory() { |
480 return downloads_directory_.GetPath(); | 485 return downloads_directory_.GetPath(); |
481 } | 486 } |
482 | 487 |
483 // Location of the file source (the place from which it is downloaded). | 488 // Location of the file source (the place from which it is downloaded). |
484 base::FilePath OriginFile(base::FilePath file) { | 489 base::FilePath OriginFile(const base::FilePath& file) { |
485 return test_dir_.Append(file); | 490 return test_dir_.Append(file); |
486 } | 491 } |
487 | 492 |
488 // Location of the file destination (place to which it is downloaded). | 493 // Location of the file destination (place to which it is downloaded). |
489 base::FilePath DestinationFile(Browser* browser, base::FilePath file) { | 494 base::FilePath DestinationFile(Browser* browser, const base::FilePath& file) { |
490 return GetDownloadDirectory(browser).Append(file.BaseName()); | 495 return GetDownloadDirectory(browser).Append(file.BaseName()); |
491 } | 496 } |
492 | 497 |
493 // Must be called after browser creation. Creates a temporary | 498 // Must be called after browser creation. Creates a temporary |
494 // directory for downloads that is auto-deleted on destruction. | 499 // directory for downloads that is auto-deleted on destruction. |
495 // Returning false indicates a failure of the function, and should be asserted | 500 // Returning false indicates a failure of the function, and should be asserted |
496 // in the caller. | 501 // in the caller. |
497 bool CreateAndSetDownloadsDirectory(Browser* browser) { | 502 bool CreateAndSetDownloadsDirectory(Browser* browser) { |
498 if (!browser) | 503 if (!browser) |
499 return false; | 504 return false; |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 override { | 1110 override { |
1106 NOTREACHED(); | 1111 NOTREACHED(); |
1107 return nullptr; | 1112 return nullptr; |
1108 } | 1113 } |
1109 safe_browsing::ResourceRequestDetector* CreateResourceRequestDetector() | 1114 safe_browsing::ResourceRequestDetector* CreateResourceRequestDetector() |
1110 override { | 1115 override { |
1111 NOTREACHED(); | 1116 NOTREACHED(); |
1112 return nullptr; | 1117 return nullptr; |
1113 } | 1118 } |
1114 | 1119 |
| 1120 private: |
1115 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService); | 1121 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingService); |
1116 }; | 1122 }; |
1117 | 1123 |
1118 // Factory that creates FakeSafeBrowsingService instances. | 1124 // Factory that creates FakeSafeBrowsingService instances. |
1119 class TestSafeBrowsingServiceFactory | 1125 class TestSafeBrowsingServiceFactory |
1120 : public safe_browsing::SafeBrowsingServiceFactory { | 1126 : public safe_browsing::SafeBrowsingServiceFactory { |
1121 public: | 1127 public: |
1122 TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {} | 1128 TestSafeBrowsingServiceFactory() : fake_safe_browsing_service_(nullptr) {} |
1123 ~TestSafeBrowsingServiceFactory() override {} | 1129 ~TestSafeBrowsingServiceFactory() override {} |
1124 | 1130 |
(...skipping 1819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2944 // korean | 2950 // korean |
2945 L"\u97d3-\u4e2d \uc815\uc0c1, \ucc9c\uc548\ud568 \uc758\uacac.zip", | 2951 L"\u97d3-\u4e2d \uc815\uc0c1, \ucc9c\uc548\ud568 \uc758\uacac.zip", |
2946 L"jiho....tiho...miho.zip", | 2952 L"jiho....tiho...miho.zip", |
2947 L"jiho!@#$tiho$%^&-()_+=miho copy.zip", // special chars | 2953 L"jiho!@#$tiho$%^&-()_+=miho copy.zip", // special chars |
2948 L"Wohoo-to hoo+I.zip", | 2954 L"Wohoo-to hoo+I.zip", |
2949 L"Picture 1.zip", | 2955 L"Picture 1.zip", |
2950 L"This is a very very long english sentence with spaces and , and +.zip", | 2956 L"This is a very very long english sentence with spaces and , and +.zip", |
2951 }; | 2957 }; |
2952 | 2958 |
2953 std::vector<DownloadItem*> download_items; | 2959 std::vector<DownloadItem*> download_items; |
2954 base::FilePath origin(FILE_PATH_LITERAL("origin")); | 2960 base::FilePath origin_directory = |
2955 ASSERT_TRUE(base::CreateDirectory(DestinationFile(browser(), origin))); | 2961 GetDownloadDirectory(browser()).Append(FILE_PATH_LITERAL("origin")); |
| 2962 ASSERT_TRUE(base::CreateDirectory(origin_directory)); |
2956 | 2963 |
2957 for (size_t index = 0; index < arraysize(kCrazyFilenames); ++index) { | 2964 for (size_t index = 0; index < arraysize(kCrazyFilenames); ++index) { |
| 2965 SCOPED_TRACE(testing::Message() << "Index " << index); |
2958 base::string16 crazy16; | 2966 base::string16 crazy16; |
2959 std::string crazy8; | 2967 std::string crazy8; |
2960 const wchar_t* crazy_w = kCrazyFilenames[index]; | 2968 const wchar_t* crazy_w = kCrazyFilenames[index]; |
2961 ASSERT_TRUE(base::WideToUTF8(crazy_w, wcslen(crazy_w), &crazy8)); | 2969 ASSERT_TRUE(base::WideToUTF8(crazy_w, wcslen(crazy_w), &crazy8)); |
2962 ASSERT_TRUE(base::WideToUTF16(crazy_w, wcslen(crazy_w), &crazy16)); | 2970 ASSERT_TRUE(base::WideToUTF16(crazy_w, wcslen(crazy_w), &crazy16)); |
2963 base::FilePath file_path(DestinationFile(browser(), origin.Append( | 2971 base::FilePath file_path(origin_directory.Append( |
2964 #if defined(OS_WIN) | 2972 #if defined(OS_WIN) |
2965 crazy16 | 2973 crazy16 |
2966 #elif defined(OS_POSIX) | 2974 #elif defined(OS_POSIX) |
2967 crazy8 | 2975 crazy8 |
2968 #endif | 2976 #endif |
2969 ))); | 2977 )); |
2970 | 2978 |
2971 // Create the file. | 2979 // Create the file. |
2972 EXPECT_EQ(static_cast<int>(crazy8.size()), | 2980 EXPECT_EQ(static_cast<int>(crazy8.size()), |
2973 base::WriteFile(file_path, crazy8.c_str(), crazy8.size())); | 2981 base::WriteFile(file_path, crazy8.c_str(), crazy8.size())); |
2974 GURL file_url(net::FilePathToFileURL(file_path)); | 2982 GURL file_url(net::FilePathToFileURL(file_path)); |
2975 | 2983 |
2976 // Download the file and check that the filename is correct. | 2984 // Download the file and check that the filename is correct. |
2977 DownloadAndWait(browser(), file_url); | 2985 DownloadAndWait(browser(), file_url); |
2978 GetDownloads(browser(), &download_items); | 2986 GetDownloads(browser(), &download_items); |
2979 ASSERT_EQ(1UL, download_items.size()); | 2987 ASSERT_EQ(1UL, download_items.size()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3036 // Timing out on ARM linux: http://crbug.com/238459 | 3044 // Timing out on ARM linux: http://crbug.com/238459 |
3037 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete | 3045 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete |
3038 #elif defined(OS_MACOSX) | 3046 #elif defined(OS_MACOSX) |
3039 // Disable on mac: http://crbug.com/238831 | 3047 // Disable on mac: http://crbug.com/238831 |
3040 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete | 3048 #define MAYBE_DownloadTest_PercentComplete DISABLED_DownloadTest_PercentComplete |
3041 #else | 3049 #else |
3042 #define MAYBE_DownloadTest_PercentComplete DownloadTest_PercentComplete | 3050 #define MAYBE_DownloadTest_PercentComplete DownloadTest_PercentComplete |
3043 #endif | 3051 #endif |
3044 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) { | 3052 IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadTest_PercentComplete) { |
3045 // Write a huge file. | 3053 // Write a huge file. |
3046 base::FilePath file_path(DestinationFile( | 3054 base::FilePath file_path( |
3047 browser(), base::FilePath(FILE_PATH_LITERAL("DownloadTest_BigZip.zip")))); | 3055 GetDownloadDirectory(browser()).AppendASCII("source").AppendASCII( |
| 3056 "DownloadTest_BigZip.zip")); |
| 3057 ASSERT_TRUE(CreateDirectory(file_path.DirName())); |
3048 base::File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE); | 3058 base::File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
3049 ASSERT_TRUE(file.IsValid()); | 3059 ASSERT_TRUE(file.IsValid()); |
3050 int64_t size = 1 << 25; | 3060 int64_t size = 1 << 25; |
3051 EXPECT_EQ(1, file.Write(size, "a", 1)); | 3061 EXPECT_EQ(1, file.Write(size, "a", 1)); |
3052 file.Close(); | 3062 file.Close(); |
3053 | 3063 |
3054 #if defined(OS_POSIX) | 3064 #if defined(OS_POSIX) |
3055 // Make it readable by chronos on chromeos | 3065 // Make it readable by chronos on chromeos |
3056 base::SetPosixFilePermissions(file_path, 0755); | 3066 base::SetPosixFilePermissions(file_path, 0755); |
3057 #endif | 3067 #endif |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3804 browser(), 1, | 3814 browser(), 1, |
3805 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3815 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
3806 ui_test_utils::NavigateToURL(browser(), extension_url); | 3816 ui_test_utils::NavigateToURL(browser(), extension_url); |
3807 | 3817 |
3808 observer->WaitForFinished(); | 3818 observer->WaitForFinished(); |
3809 | 3819 |
3810 // Download shelf should close. | 3820 // Download shelf should close. |
3811 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3821 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
3812 } | 3822 } |
3813 #endif // defined(OS_CHROMEOS) | 3823 #endif // defined(OS_CHROMEOS) |
OLD | NEW |