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/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 209 } |
210 | 210 |
211 ~MockDownloadOpeningObserver() { | 211 ~MockDownloadOpeningObserver() { |
212 download_manager_->RemoveObserver(this); | 212 download_manager_->RemoveObserver(this); |
213 } | 213 } |
214 | 214 |
215 // DownloadManager::Observer | 215 // DownloadManager::Observer |
216 virtual void ModelChanged(DownloadManager* manager) OVERRIDE { | 216 virtual void ModelChanged(DownloadManager* manager) OVERRIDE { |
217 DCHECK_EQ(manager, download_manager_); | 217 DCHECK_EQ(manager, download_manager_); |
218 std::vector<DownloadItem*> downloads; | 218 std::vector<DownloadItem*> downloads; |
219 download_manager_->SearchDownloads(string16(), &downloads); | 219 download_manager_->GetAllDownloads(&downloads); |
220 | 220 |
221 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 221 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
222 it != downloads.end(); ++it) { | 222 it != downloads.end(); ++it) { |
223 (*it)->MockDownloadOpenForTesting(); | 223 (*it)->MockDownloadOpenForTesting(); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 private: | 227 private: |
228 DownloadManager* download_manager_; | 228 DownloadManager* download_manager_; |
229 | 229 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 // Delete the file we just downloaded. | 546 // Delete the file we just downloaded. |
547 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); | 547 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); |
548 EXPECT_FALSE(file_util::PathExists(download_path)); | 548 EXPECT_FALSE(file_util::PathExists(download_path)); |
549 | 549 |
550 return true; | 550 return true; |
551 } | 551 } |
552 | 552 |
553 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { | 553 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { |
554 DCHECK(downloads); | 554 DCHECK(downloads); |
555 DownloadManager* manager = DownloadManagerForBrowser(browser); | 555 DownloadManager* manager = DownloadManagerForBrowser(browser); |
556 manager->SearchDownloads(string16(), downloads); | 556 manager->GetAllDownloads(downloads); |
557 } | 557 } |
558 | 558 |
559 static void ExpectWindowCountAfterDownload(size_t expected) { | 559 static void ExpectWindowCountAfterDownload(size_t expected) { |
560 EXPECT_EQ(expected, BrowserList::size()); | 560 EXPECT_EQ(expected, BrowserList::size()); |
561 } | 561 } |
562 | 562 |
563 void EnableFileChooser(bool enable) { | 563 void EnableFileChooser(bool enable) { |
564 file_chooser_observer_->EnableFileChooser(enable); | 564 file_chooser_observer_->EnableFileChooser(enable); |
565 } | 565 } |
566 | 566 |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1525 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
1526 | 1526 |
1527 // Mock out external opening on all downloads until end of test. | 1527 // Mock out external opening on all downloads until end of test. |
1528 MockDownloadOpeningObserver observer( | 1528 MockDownloadOpeningObserver observer( |
1529 DownloadManagerForBrowser(browser())); | 1529 DownloadManagerForBrowser(browser())); |
1530 | 1530 |
1531 DownloadAndWait(browser(), url); | 1531 DownloadAndWait(browser(), url); |
1532 | 1532 |
1533 // Find the download and confirm it was opened. | 1533 // Find the download and confirm it was opened. |
1534 std::vector<DownloadItem*> downloads; | 1534 std::vector<DownloadItem*> downloads; |
1535 DownloadManagerForBrowser(browser())->SearchDownloads( | 1535 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
1536 string16(), &downloads); | |
1537 ASSERT_EQ(1u, downloads.size()); | 1536 ASSERT_EQ(1u, downloads.size()); |
1538 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); | 1537 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); |
1539 EXPECT_TRUE(downloads[0]->GetOpened()); | 1538 EXPECT_TRUE(downloads[0]->GetOpened()); |
1540 | 1539 |
1541 // As long as we're here, confirmed everything else is good. | 1540 // As long as we're here, confirmed everything else is good. |
1542 EXPECT_EQ(1, browser()->tab_count()); | 1541 EXPECT_EQ(1, browser()->tab_count()); |
1543 CheckDownload(browser(), file, file); | 1542 CheckDownload(browser(), file, file); |
1544 // Download shelf should close. Download panel stays open on ChromeOS. | 1543 // Download shelf should close. Download panel stays open on ChromeOS. |
1545 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1544 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1546 } | 1545 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 std::vector<DownloadPersistentStoreInfo> entries( | 1740 std::vector<DownloadPersistentStoreInfo> entries( |
1742 population_entries, population_entries + arraysize(population_entries)); | 1741 population_entries, population_entries + arraysize(population_entries)); |
1743 | 1742 |
1744 // Populate the manager. | 1743 // Populate the manager. |
1745 DownloadManager* manager = DownloadManagerForBrowser(browser()); | 1744 DownloadManager* manager = DownloadManagerForBrowser(browser()); |
1746 manager->OnPersistentStoreQueryComplete(&entries); | 1745 manager->OnPersistentStoreQueryComplete(&entries); |
1747 | 1746 |
1748 // Do some searches and check the results. | 1747 // Do some searches and check the results. |
1749 std::vector<DownloadItem*> search_results; | 1748 std::vector<DownloadItem*> search_results; |
1750 | 1749 |
1751 manager->SearchDownloads(string16(), &search_results); | 1750 manager->GetAllDownloads(&search_results); |
1752 ASSERT_EQ(3u, search_results.size()); | 1751 ASSERT_EQ(3u, search_results.size()); |
1753 std::sort(search_results.begin(), search_results.end(), | 1752 std::sort(search_results.begin(), search_results.end(), |
1754 DownloadItemSorter); | 1753 DownloadItemSorter); |
1755 // We do a full check only once to protect against the data | 1754 // We do a full check only once to protect against the data |
1756 // somehow getting scrambled on its way into the DownloadItems. | 1755 // somehow getting scrambled on its way into the DownloadItems. |
1757 { | 1756 { |
1758 DownloadItem* d1 = search_results[0]; | 1757 DownloadItem* d1 = search_results[0]; |
1759 DownloadItem* d2 = search_results[1]; | 1758 DownloadItem* d2 = search_results[1]; |
1760 DownloadItem* d3 = search_results[2]; | 1759 DownloadItem* d3 = search_results[2]; |
1761 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); | 1760 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2347 GetDownloads(browser(), &download_items); | 2346 GetDownloads(browser(), &download_items); |
2348 ASSERT_EQ(1u, download_items.size()); | 2347 ASSERT_EQ(1u, download_items.size()); |
2349 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2348 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2350 download_items[0]->GetOriginalUrl()); | 2349 download_items[0]->GetOriginalUrl()); |
2351 | 2350 |
2352 // Check that the file contains the expected referrer. | 2351 // Check that the file contains the expected referrer. |
2353 FilePath file(download_items[0]->GetFullPath()); | 2352 FilePath file(download_items[0]->GetFullPath()); |
2354 std::string expected_contents = test_server()->GetURL("").spec(); | 2353 std::string expected_contents = test_server()->GetURL("").spec(); |
2355 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2354 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2356 } | 2355 } |
OLD | NEW |