| 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 #include <sstream> | 8 #include <sstream> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 SIZE_TEST_TYPE_UNKNOWN, | 471 SIZE_TEST_TYPE_UNKNOWN, |
| 472 }; | 472 }; |
| 473 | 473 |
| 474 base::FilePath GetTestDataDirectory() { | 474 base::FilePath GetTestDataDirectory() { |
| 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_.path(); | 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(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, 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; |
| 501 | 501 |
| 502 if (!downloads_directory_.CreateUniqueTempDir()) | 502 if (!downloads_directory_.CreateUniqueTempDir()) |
| 503 return false; | 503 return false; |
| 504 | 504 |
| 505 browser->profile()->GetPrefs()->SetFilePath( | 505 browser->profile()->GetPrefs()->SetFilePath( |
| 506 prefs::kDownloadDefaultDirectory, | 506 prefs::kDownloadDefaultDirectory, downloads_directory_.GetPath()); |
| 507 downloads_directory_.path()); | |
| 508 browser->profile()->GetPrefs()->SetFilePath( | 507 browser->profile()->GetPrefs()->SetFilePath( |
| 509 prefs::kSaveFileDefaultDirectory, | 508 prefs::kSaveFileDefaultDirectory, downloads_directory_.GetPath()); |
| 510 downloads_directory_.path()); | |
| 511 | 509 |
| 512 return true; | 510 return true; |
| 513 } | 511 } |
| 514 | 512 |
| 515 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 513 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
| 516 return DownloadPrefs::FromDownloadManager( | 514 return DownloadPrefs::FromDownloadManager( |
| 517 DownloadManagerForBrowser(browser)); | 515 DownloadManagerForBrowser(browser)); |
| 518 } | 516 } |
| 519 | 517 |
| 520 base::FilePath GetDownloadDirectory(Browser* browser) { | 518 base::FilePath GetDownloadDirectory(Browser* browser) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 735 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 738 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE); | 736 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE); |
| 739 | 737 |
| 740 EXPECT_EQ(2, browser->tab_strip_model()->count()); | 738 EXPECT_EQ(2, browser->tab_strip_model()->count()); |
| 741 | 739 |
| 742 // TODO(ahendrickson): check download status text after downloading. | 740 // TODO(ahendrickson): check download status text after downloading. |
| 743 | 741 |
| 744 base::FilePath basefilename(filename.BaseName()); | 742 base::FilePath basefilename(filename.BaseName()); |
| 745 net::FileURLToFilePath(url, &filename); | 743 net::FileURLToFilePath(url, &filename); |
| 746 base::FilePath download_path = | 744 base::FilePath download_path = |
| 747 downloads_directory_.path().Append(basefilename); | 745 downloads_directory_.GetPath().Append(basefilename); |
| 748 | 746 |
| 749 bool downloaded_path_exists = base::PathExists(download_path); | 747 bool downloaded_path_exists = base::PathExists(download_path); |
| 750 EXPECT_TRUE(downloaded_path_exists); | 748 EXPECT_TRUE(downloaded_path_exists); |
| 751 if (!downloaded_path_exists) | 749 if (!downloaded_path_exists) |
| 752 return false; | 750 return false; |
| 753 | 751 |
| 754 // Check the file contents. | 752 // Check the file contents. |
| 755 size_t file_size = net::URLRequestSlowDownloadJob::kFirstDownloadSize + | 753 size_t file_size = net::URLRequestSlowDownloadJob::kFirstDownloadSize + |
| 756 net::URLRequestSlowDownloadJob::kSecondDownloadSize; | 754 net::URLRequestSlowDownloadJob::kSecondDownloadSize; |
| 757 std::string expected_contents(file_size, '*'); | 755 std::string expected_contents(file_size, '*'); |
| (...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 2149 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 2152 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); | 2150 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 2153 | 2151 |
| 2154 WebContents* web_contents = | 2152 WebContents* web_contents = |
| 2155 browser()->tab_strip_model()->GetActiveWebContents(); | 2153 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2156 ASSERT_TRUE(web_contents); | 2154 ASSERT_TRUE(web_contents); |
| 2157 | 2155 |
| 2158 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 2156 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 2159 base::ScopedTempDir other_directory; | 2157 base::ScopedTempDir other_directory; |
| 2160 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 2158 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 2161 base::FilePath target_file_full_path | 2159 base::FilePath target_file_full_path = |
| 2162 = other_directory.path().Append(file.BaseName()); | 2160 other_directory.GetPath().Append(file.BaseName()); |
| 2163 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 2161 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
| 2164 std::unique_ptr<DownloadUrlParameters> params( | 2162 std::unique_ptr<DownloadUrlParameters> params( |
| 2165 DownloadUrlParameters::CreateForWebContentsMainFrame( | 2163 DownloadUrlParameters::CreateForWebContentsMainFrame( |
| 2166 web_contents, url)); | 2164 web_contents, url)); |
| 2167 params->set_file_path(target_file_full_path); | 2165 params->set_file_path(target_file_full_path); |
| 2168 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); | 2166 DownloadManagerForBrowser(browser())->DownloadUrl(std::move(params)); |
| 2169 observer->WaitForFinished(); | 2167 observer->WaitForFinished(); |
| 2170 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2168 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2171 | 2169 |
| 2172 // Check state. | 2170 // Check state. |
| (...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3640 browser(), 1, | 3638 browser(), 1, |
| 3641 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3639 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3642 ui_test_utils::NavigateToURL(browser(), extension_url); | 3640 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3643 | 3641 |
| 3644 observer->WaitForFinished(); | 3642 observer->WaitForFinished(); |
| 3645 | 3643 |
| 3646 // Download shelf should close. | 3644 // Download shelf should close. |
| 3647 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3645 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3648 } | 3646 } |
| 3649 #endif // defined(OS_CHROMEOS) | 3647 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |