| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 | 653 |
| 654 // Find the origin path (from which the data comes). | 654 // Find the origin path (from which the data comes). |
| 655 base::FilePath origin_file(OriginFile(origin_filename)); | 655 base::FilePath origin_file(OriginFile(origin_filename)); |
| 656 return CheckDownloadFullPaths(browser, downloaded_file, origin_file); | 656 return CheckDownloadFullPaths(browser, downloaded_file, origin_file); |
| 657 } | 657 } |
| 658 | 658 |
| 659 // A version of CheckDownload that allows complete path specification. | 659 // A version of CheckDownload that allows complete path specification. |
| 660 bool CheckDownloadFullPaths(Browser* browser, | 660 bool CheckDownloadFullPaths(Browser* browser, |
| 661 const base::FilePath& downloaded_file, | 661 const base::FilePath& downloaded_file, |
| 662 const base::FilePath& origin_file) { | 662 const base::FilePath& origin_file) { |
| 663 bool origin_file_exists = file_util::PathExists(origin_file); | 663 bool origin_file_exists = base::PathExists(origin_file); |
| 664 EXPECT_TRUE(origin_file_exists) << origin_file.value(); | 664 EXPECT_TRUE(origin_file_exists) << origin_file.value(); |
| 665 if (!origin_file_exists) | 665 if (!origin_file_exists) |
| 666 return false; | 666 return false; |
| 667 | 667 |
| 668 // Confirm the downloaded data file exists. | 668 // Confirm the downloaded data file exists. |
| 669 bool downloaded_file_exists = file_util::PathExists(downloaded_file); | 669 bool downloaded_file_exists = base::PathExists(downloaded_file); |
| 670 EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value(); | 670 EXPECT_TRUE(downloaded_file_exists) << downloaded_file.value(); |
| 671 if (!downloaded_file_exists) | 671 if (!downloaded_file_exists) |
| 672 return false; | 672 return false; |
| 673 | 673 |
| 674 int64 origin_file_size = 0; | 674 int64 origin_file_size = 0; |
| 675 EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size)); | 675 EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size)); |
| 676 std::string original_file_contents; | 676 std::string original_file_contents; |
| 677 EXPECT_TRUE( | 677 EXPECT_TRUE( |
| 678 file_util::ReadFileToString(origin_file, &original_file_contents)); | 678 file_util::ReadFileToString(origin_file, &original_file_contents)); |
| 679 EXPECT_TRUE( | 679 EXPECT_TRUE( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 EXPECT_EQ(2, browser->tab_strip_model()->count()); | 776 EXPECT_EQ(2, browser->tab_strip_model()->count()); |
| 777 | 777 |
| 778 // TODO(ahendrickson): check download status text after downloading. | 778 // TODO(ahendrickson): check download status text after downloading. |
| 779 | 779 |
| 780 base::FilePath basefilename(filename.BaseName()); | 780 base::FilePath basefilename(filename.BaseName()); |
| 781 net::FileURLToFilePath(url, &filename); | 781 net::FileURLToFilePath(url, &filename); |
| 782 base::FilePath download_path = | 782 base::FilePath download_path = |
| 783 downloads_directory_.path().Append(basefilename); | 783 downloads_directory_.path().Append(basefilename); |
| 784 EXPECT_TRUE(browser->window()->IsDownloadShelfVisible()); | 784 EXPECT_TRUE(browser->window()->IsDownloadShelfVisible()); |
| 785 | 785 |
| 786 bool downloaded_path_exists = file_util::PathExists(download_path); | 786 bool downloaded_path_exists = base::PathExists(download_path); |
| 787 EXPECT_TRUE(downloaded_path_exists); | 787 EXPECT_TRUE(downloaded_path_exists); |
| 788 if (!downloaded_path_exists) | 788 if (!downloaded_path_exists) |
| 789 return false; | 789 return false; |
| 790 | 790 |
| 791 // Check the file contents. | 791 // Check the file contents. |
| 792 size_t file_size = URLRequestSlowDownloadJob::kFirstDownloadSize + | 792 size_t file_size = URLRequestSlowDownloadJob::kFirstDownloadSize + |
| 793 URLRequestSlowDownloadJob::kSecondDownloadSize; | 793 URLRequestSlowDownloadJob::kSecondDownloadSize; |
| 794 std::string expected_contents(file_size, '*'); | 794 std::string expected_contents(file_size, '*'); |
| 795 EXPECT_TRUE(VerifyFile(download_path, expected_contents, file_size)); | 795 EXPECT_TRUE(VerifyFile(download_path, expected_contents, file_size)); |
| 796 | 796 |
| 797 // Delete the file we just downloaded. | 797 // Delete the file we just downloaded. |
| 798 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); | 798 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); |
| 799 EXPECT_FALSE(file_util::PathExists(download_path)); | 799 EXPECT_FALSE(base::PathExists(download_path)); |
| 800 | 800 |
| 801 return true; | 801 return true; |
| 802 } | 802 } |
| 803 | 803 |
| 804 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { | 804 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { |
| 805 DCHECK(downloads); | 805 DCHECK(downloads); |
| 806 DownloadManager* manager = DownloadManagerForBrowser(browser); | 806 DownloadManager* manager = DownloadManagerForBrowser(browser); |
| 807 manager->GetAllDownloads(downloads); | 807 manager->GetAllDownloads(downloads); |
| 808 } | 808 } |
| 809 | 809 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 } | 951 } |
| 952 | 952 |
| 953 ASSERT_EQ(url, item->GetOriginalUrl()) << s.str(); | 953 ASSERT_EQ(url, item->GetOriginalUrl()) << s.str(); |
| 954 | 954 |
| 955 ASSERT_EQ(download_info.reason, item->GetLastReason()) << s.str(); | 955 ASSERT_EQ(download_info.reason, item->GetLastReason()) << s.str(); |
| 956 | 956 |
| 957 if (item->GetState() == content::DownloadItem::COMPLETE) { | 957 if (item->GetState() == content::DownloadItem::COMPLETE) { |
| 958 // Clean up the file, in case it ended up in the My Documents folder. | 958 // Clean up the file, in case it ended up in the My Documents folder. |
| 959 base::FilePath destination_folder = GetDownloadDirectory(browser()); | 959 base::FilePath destination_folder = GetDownloadDirectory(browser()); |
| 960 base::FilePath my_downloaded_file = item->GetTargetFilePath(); | 960 base::FilePath my_downloaded_file = item->GetTargetFilePath(); |
| 961 EXPECT_TRUE(file_util::PathExists(my_downloaded_file)); | 961 EXPECT_TRUE(base::PathExists(my_downloaded_file)); |
| 962 EXPECT_TRUE(base::Delete(my_downloaded_file, false)); | 962 EXPECT_TRUE(base::Delete(my_downloaded_file, false)); |
| 963 | 963 |
| 964 EXPECT_EQ(download_info.should_redirect_to_documents ? | 964 EXPECT_EQ(download_info.should_redirect_to_documents ? |
| 965 std::string::npos : | 965 std::string::npos : |
| 966 0u, | 966 0u, |
| 967 my_downloaded_file.value().find(destination_folder.value())); | 967 my_downloaded_file.value().find(destination_folder.value())); |
| 968 if (download_info.should_redirect_to_documents) { | 968 if (download_info.should_redirect_to_documents) { |
| 969 // If it's not where we asked it to be, it should be in the | 969 // If it's not where we asked it to be, it should be in the |
| 970 // My Documents folder. | 970 // My Documents folder. |
| 971 base::FilePath my_docs_folder; | 971 base::FilePath my_docs_folder; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 // did not initiate. | 1202 // did not initiate. |
| 1203 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 1203 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
| 1204 base::FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 1204 base::FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
| 1205 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1205 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1206 base::FilePath file_path(DestinationFile(browser(), file)); | 1206 base::FilePath file_path(DestinationFile(browser(), file)); |
| 1207 | 1207 |
| 1208 // Open a web page and wait. | 1208 // Open a web page and wait. |
| 1209 ui_test_utils::NavigateToURL(browser(), url); | 1209 ui_test_utils::NavigateToURL(browser(), url); |
| 1210 | 1210 |
| 1211 // Check that we did not download the web page. | 1211 // Check that we did not download the web page. |
| 1212 EXPECT_FALSE(file_util::PathExists(file_path)); | 1212 EXPECT_FALSE(base::PathExists(file_path)); |
| 1213 | 1213 |
| 1214 // Check state. | 1214 // Check state. |
| 1215 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1215 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1216 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1216 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1217 } | 1217 } |
| 1218 | 1218 |
| 1219 IN_PROC_BROWSER_TEST_F(DownloadTest, MimeTypesToShowNotDownload) { | 1219 IN_PROC_BROWSER_TEST_F(DownloadTest, MimeTypesToShowNotDownload) { |
| 1220 ASSERT_TRUE(test_server()->Start()); | 1220 ASSERT_TRUE(test_server()->Start()); |
| 1221 | 1221 |
| 1222 // These files should all be displayed in the browser. | 1222 // These files should all be displayed in the browser. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 &download_assempted)); | 1288 &download_assempted)); |
| 1289 ASSERT_TRUE(download_assempted); | 1289 ASSERT_TRUE(download_assempted); |
| 1290 observer.WaitForObservation( | 1290 observer.WaitForObservation( |
| 1291 base::Bind(&content::RunMessageLoop), | 1291 base::Bind(&content::RunMessageLoop), |
| 1292 base::Bind(&base::MessageLoop::Quit, | 1292 base::Bind(&base::MessageLoop::Quit, |
| 1293 base::Unretained(base::MessageLoopForUI::current()))); | 1293 base::Unretained(base::MessageLoopForUI::current()))); |
| 1294 | 1294 |
| 1295 // Check that we did not download the file. | 1295 // Check that we did not download the file. |
| 1296 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1296 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1297 base::FilePath file_path(DestinationFile(browser(), file)); | 1297 base::FilePath file_path(DestinationFile(browser(), file)); |
| 1298 EXPECT_FALSE(file_util::PathExists(file_path)); | 1298 EXPECT_FALSE(base::PathExists(file_path)); |
| 1299 | 1299 |
| 1300 // Check state. | 1300 // Check state. |
| 1301 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1301 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1302 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1302 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1303 | 1303 |
| 1304 // Verify that there's no pending download. The resource throttle | 1304 // Verify that there's no pending download. The resource throttle |
| 1305 // should have deleted it before it created a download item, so it | 1305 // should have deleted it before it created a download item, so it |
| 1306 // shouldn't be available as a cancelled download either. | 1306 // shouldn't be available as a cancelled download either. |
| 1307 DownloadManagerForBrowser(browser())->GetAllDownloads(&items); | 1307 DownloadManagerForBrowser(browser())->GetAllDownloads(&items); |
| 1308 EXPECT_EQ(0u, items.size()); | 1308 EXPECT_EQ(0u, items.size()); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 // bug; this next test tests that filename deduplication happens independently | 1457 // bug; this next test tests that filename deduplication happens independently |
| 1458 // of DownloadManager/CDMD. | 1458 // of DownloadManager/CDMD. |
| 1459 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { | 1459 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_IncognitoRegular) { |
| 1460 ASSERT_TRUE(test_server()->Start()); | 1460 ASSERT_TRUE(test_server()->Start()); |
| 1461 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); | 1461 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); |
| 1462 | 1462 |
| 1463 // Read the origin file now so that we can compare the downloaded files to it | 1463 // Read the origin file now so that we can compare the downloaded files to it |
| 1464 // later. | 1464 // later. |
| 1465 base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL( | 1465 base::FilePath origin(OriginFile(base::FilePath(FILE_PATH_LITERAL( |
| 1466 "downloads/a_zip_file.zip")))); | 1466 "downloads/a_zip_file.zip")))); |
| 1467 ASSERT_TRUE(file_util::PathExists(origin)); | 1467 ASSERT_TRUE(base::PathExists(origin)); |
| 1468 int64 origin_file_size = 0; | 1468 int64 origin_file_size = 0; |
| 1469 EXPECT_TRUE(file_util::GetFileSize(origin, &origin_file_size)); | 1469 EXPECT_TRUE(file_util::GetFileSize(origin, &origin_file_size)); |
| 1470 std::string original_contents; | 1470 std::string original_contents; |
| 1471 EXPECT_TRUE(file_util::ReadFileToString(origin, &original_contents)); | 1471 EXPECT_TRUE(file_util::ReadFileToString(origin, &original_contents)); |
| 1472 | 1472 |
| 1473 std::vector<DownloadItem*> download_items; | 1473 std::vector<DownloadItem*> download_items; |
| 1474 GetDownloads(browser(), &download_items); | 1474 GetDownloads(browser(), &download_items); |
| 1475 ASSERT_TRUE(download_items.empty()); | 1475 ASSERT_TRUE(download_items.empty()); |
| 1476 | 1476 |
| 1477 // Download a file in the on-record browser and check that it was downloaded | 1477 // Download a file in the on-record browser and check that it was downloaded |
| 1478 // correctly. | 1478 // correctly. |
| 1479 DownloadAndWaitWithDisposition(browser(), | 1479 DownloadAndWaitWithDisposition(browser(), |
| 1480 url, | 1480 url, |
| 1481 CURRENT_TAB, | 1481 CURRENT_TAB, |
| 1482 ui_test_utils::BROWSER_TEST_NONE); | 1482 ui_test_utils::BROWSER_TEST_NONE); |
| 1483 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1483 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1484 GetDownloads(browser(), &download_items); | 1484 GetDownloads(browser(), &download_items); |
| 1485 ASSERT_EQ(1UL, download_items.size()); | 1485 ASSERT_EQ(1UL, download_items.size()); |
| 1486 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file.zip")), | 1486 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file.zip")), |
| 1487 download_items[0]->GetTargetFilePath().BaseName()); | 1487 download_items[0]->GetTargetFilePath().BaseName()); |
| 1488 ASSERT_TRUE(file_util::PathExists(download_items[0]->GetTargetFilePath())); | 1488 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); |
| 1489 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), | 1489 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), |
| 1490 original_contents, origin_file_size)); | 1490 original_contents, origin_file_size)); |
| 1491 | 1491 |
| 1492 // Setup an incognito window. | 1492 // Setup an incognito window. |
| 1493 Browser* incognito = CreateIncognitoBrowser(); | 1493 Browser* incognito = CreateIncognitoBrowser(); |
| 1494 ASSERT_TRUE(incognito); | 1494 ASSERT_TRUE(incognito); |
| 1495 int window_count = BrowserList::GetInstance( | 1495 int window_count = BrowserList::GetInstance( |
| 1496 browser()->host_desktop_type())->size(); | 1496 browser()->host_desktop_type())->size(); |
| 1497 EXPECT_EQ(2, window_count); | 1497 EXPECT_EQ(2, window_count); |
| 1498 incognito->profile()->GetPrefs()->SetFilePath( | 1498 incognito->profile()->GetPrefs()->SetFilePath( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1510 // correctly. | 1510 // correctly. |
| 1511 DownloadAndWaitWithDisposition(incognito, | 1511 DownloadAndWaitWithDisposition(incognito, |
| 1512 url, | 1512 url, |
| 1513 CURRENT_TAB, | 1513 CURRENT_TAB, |
| 1514 ui_test_utils::BROWSER_TEST_NONE); | 1514 ui_test_utils::BROWSER_TEST_NONE); |
| 1515 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); | 1515 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); |
| 1516 GetDownloads(incognito, &download_items); | 1516 GetDownloads(incognito, &download_items); |
| 1517 ASSERT_EQ(1UL, download_items.size()); | 1517 ASSERT_EQ(1UL, download_items.size()); |
| 1518 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file (1).zip")), | 1518 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file (1).zip")), |
| 1519 download_items[0]->GetTargetFilePath().BaseName()); | 1519 download_items[0]->GetTargetFilePath().BaseName()); |
| 1520 ASSERT_TRUE(file_util::PathExists(download_items[0]->GetTargetFilePath())); | 1520 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); |
| 1521 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), | 1521 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), |
| 1522 original_contents, origin_file_size)); | 1522 original_contents, origin_file_size)); |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 // Navigate to a new background page, but don't download. Confirm that the | 1525 // Navigate to a new background page, but don't download. Confirm that the |
| 1526 // download shelf is not visible and that we have two tabs. | 1526 // download shelf is not visible and that we have two tabs. |
| 1527 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { | 1527 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { |
| 1528 // Because it's an HTML link, it should open a web page rather than | 1528 // Because it's an HTML link, it should open a web page rather than |
| 1529 // downloading. | 1529 // downloading. |
| 1530 base::FilePath file1(FILE_PATH_LITERAL("download-test2.html")); | 1530 base::FilePath file1(FILE_PATH_LITERAL("download-test2.html")); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2003 scoped_ptr<content::DownloadTestObserver> observer( | 2003 scoped_ptr<content::DownloadTestObserver> observer( |
| 2004 CreateWaiter(browser(), 1)); | 2004 CreateWaiter(browser(), 1)); |
| 2005 ui_test_utils::NavigateToURL(browser(), url); | 2005 ui_test_utils::NavigateToURL(browser(), url); |
| 2006 observer->WaitForFinished(); | 2006 observer->WaitForFinished(); |
| 2007 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2007 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2008 CheckDownloadStates(1, DownloadItem::COMPLETE); | 2008 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 2009 | 2009 |
| 2010 // Confirm the downloaded data exists. | 2010 // Confirm the downloaded data exists. |
| 2011 base::FilePath downloaded_file = GetDownloadDirectory(browser()); | 2011 base::FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 2012 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 2012 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 2013 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 2013 EXPECT_TRUE(base::PathExists(downloaded_file)); |
| 2014 } | 2014 } |
| 2015 | 2015 |
| 2016 // Test to make sure auto-open works. | 2016 // Test to make sure auto-open works. |
| 2017 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 2017 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
| 2018 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 2018 base::FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 2019 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 2019 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 2020 | 2020 |
| 2021 ASSERT_TRUE( | 2021 ASSERT_TRUE( |
| 2022 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 2022 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 2023 | 2023 |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2812 EXPECT_EQ(2u, downloads_observer->NumDownloadsSeenInState( | 2812 EXPECT_EQ(2u, downloads_observer->NumDownloadsSeenInState( |
| 2813 DownloadItem::COMPLETE)); | 2813 DownloadItem::COMPLETE)); |
| 2814 } | 2814 } |
| 2815 | 2815 |
| 2816 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) { | 2816 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) { |
| 2817 ASSERT_TRUE(test_server()->Start()); | 2817 ASSERT_TRUE(test_server()->Start()); |
| 2818 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); | 2818 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); |
| 2819 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); | 2819 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 2820 base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL( | 2820 base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL( |
| 2821 "downloads/a_zip_file.zip")))); | 2821 "downloads/a_zip_file.zip")))); |
| 2822 ASSERT_TRUE(file_util::PathExists(origin_file)); | 2822 ASSERT_TRUE(base::PathExists(origin_file)); |
| 2823 std::string origin_contents; | 2823 std::string origin_contents; |
| 2824 ASSERT_TRUE(file_util::ReadFileToString(origin_file, &origin_contents)); | 2824 ASSERT_TRUE(file_util::ReadFileToString(origin_file, &origin_contents)); |
| 2825 | 2825 |
| 2826 // Download the same url several times and expect that all downloaded files | 2826 // Download the same url several times and expect that all downloaded files |
| 2827 // after the zero-th contain a deduplication counter. | 2827 // after the zero-th contain a deduplication counter. |
| 2828 for (int index = 0; index < 5; ++index) { | 2828 for (int index = 0; index < 5; ++index) { |
| 2829 DownloadAndWait(browser(), url); | 2829 DownloadAndWait(browser(), url); |
| 2830 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 2830 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 2831 content::DownloadItem* item = manager->GetDownload(index); | 2831 content::DownloadItem* item = manager->GetDownload(index); |
| 2832 ASSERT_TRUE(item); | 2832 ASSERT_TRUE(item); |
| 2833 ASSERT_EQ(DownloadItem::COMPLETE, item->GetState()); | 2833 ASSERT_EQ(DownloadItem::COMPLETE, item->GetState()); |
| 2834 base::FilePath target_path(item->GetTargetFilePath()); | 2834 base::FilePath target_path(item->GetTargetFilePath()); |
| 2835 EXPECT_EQ(std::string("a_zip_file") + | 2835 EXPECT_EQ(std::string("a_zip_file") + |
| 2836 (index == 0 ? std::string(".zip") : | 2836 (index == 0 ? std::string(".zip") : |
| 2837 base::StringPrintf(" (%d).zip", index)), | 2837 base::StringPrintf(" (%d).zip", index)), |
| 2838 target_path.BaseName().AsUTF8Unsafe()); | 2838 target_path.BaseName().AsUTF8Unsafe()); |
| 2839 ASSERT_TRUE(file_util::PathExists(target_path)); | 2839 ASSERT_TRUE(base::PathExists(target_path)); |
| 2840 ASSERT_TRUE(VerifyFile(target_path, origin_contents, | 2840 ASSERT_TRUE(VerifyFile(target_path, origin_contents, |
| 2841 origin_contents.size())); | 2841 origin_contents.size())); |
| 2842 } | 2842 } |
| 2843 } | 2843 } |
| 2844 | 2844 |
| 2845 // Test that the entire download pipeline handles unicode correctly. | 2845 // Test that the entire download pipeline handles unicode correctly. |
| 2846 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_CrazyFilenames) { | 2846 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_CrazyFilenames) { |
| 2847 const wchar_t* kCrazyFilenames[] = { | 2847 const wchar_t* kCrazyFilenames[] = { |
| 2848 L"a_file_name.zip", | 2848 L"a_file_name.zip", |
| 2849 L"\u89c6\u9891\u76f4\u64ad\u56fe\u7247.zip", // chinese chars | 2849 L"\u89c6\u9891\u76f4\u64ad\u56fe\u7247.zip", // chinese chars |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3014 | 3014 |
| 3015 // Wait for the download to complete, checking along the way that the | 3015 // Wait for the download to complete, checking along the way that the |
| 3016 // PercentComplete() never regresses. | 3016 // PercentComplete() never regresses. |
| 3017 PercentWaiter waiter(download_items[0]); | 3017 PercentWaiter waiter(download_items[0]); |
| 3018 EXPECT_TRUE(waiter.WaitForFinished()); | 3018 EXPECT_TRUE(waiter.WaitForFinished()); |
| 3019 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState()); | 3019 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState()); |
| 3020 ASSERT_EQ(100, download_items[0]->PercentComplete()); | 3020 ASSERT_EQ(100, download_items[0]->PercentComplete()); |
| 3021 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 3021 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 3022 | 3022 |
| 3023 // Check that the file downloaded correctly. | 3023 // Check that the file downloaded correctly. |
| 3024 ASSERT_TRUE(file_util::PathExists(download_items[0]->GetTargetFilePath())); | 3024 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); |
| 3025 int64 downloaded_size = 0; | 3025 int64 downloaded_size = 0; |
| 3026 ASSERT_TRUE(file_util::GetFileSize( | 3026 ASSERT_TRUE(file_util::GetFileSize( |
| 3027 download_items[0]->GetTargetFilePath(), &downloaded_size)); | 3027 download_items[0]->GetTargetFilePath(), &downloaded_size)); |
| 3028 #if defined(OS_WIN) | 3028 #if defined(OS_WIN) |
| 3029 ASSERT_EQ(1, downloaded_size); | 3029 ASSERT_EQ(1, downloaded_size); |
| 3030 #else | 3030 #else |
| 3031 ASSERT_EQ(size + 1, downloaded_size); | 3031 ASSERT_EQ(size + 1, downloaded_size); |
| 3032 #endif | 3032 #endif |
| 3033 ASSERT_TRUE(file_util::DieFileDie(file_path, false)); | 3033 ASSERT_TRUE(file_util::DieFileDie(file_path, false)); |
| 3034 ASSERT_TRUE(file_util::DieFileDie(download_items[0]->GetTargetFilePath(), | 3034 ASSERT_TRUE(file_util::DieFileDie(download_items[0]->GetTargetFilePath(), |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3220 | 3220 |
| 3221 // No errors this time. The download should complete successfully. | 3221 // No errors this time. The download should complete successfully. |
| 3222 EXPECT_FALSE(completion_observer->IsFinished()); | 3222 EXPECT_FALSE(completion_observer->IsFinished()); |
| 3223 completion_observer->StartObserving(); | 3223 completion_observer->StartObserving(); |
| 3224 download->Resume(); | 3224 download->Resume(); |
| 3225 completion_observer->WaitForFinished(); | 3225 completion_observer->WaitForFinished(); |
| 3226 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); | 3226 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 3227 | 3227 |
| 3228 EXPECT_FALSE(DidShowFileChooser()); | 3228 EXPECT_FALSE(DidShowFileChooser()); |
| 3229 } | 3229 } |
| OLD | NEW |