| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/test/test_file_util.h" | 13 #include "base/test/test_file_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 16 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 17 #include "chrome/browser/download/download_crx_util.h" | 17 #include "chrome/browser/download/download_crx_util.h" |
| 18 #include "chrome/browser/download/download_history.h" | 18 #include "chrome/browser/download/download_history.h" |
| 19 #include "chrome/browser/download/download_prefs.h" | 19 #include "chrome/browser/download/download_prefs.h" |
| 20 #include "chrome/browser/download/download_service.h" |
| 21 #include "chrome/browser/download/download_service_factory.h" |
| 20 #include "chrome/browser/download/download_shelf.h" | 22 #include "chrome/browser/download/download_shelf.h" |
| 21 #include "chrome/browser/download/download_util.h" | 23 #include "chrome/browser/download/download_util.h" |
| 22 #include "chrome/browser/extensions/extension_install_ui.h" | 24 #include "chrome/browser/extensions/extension_install_ui.h" |
| 23 #include "chrome/browser/extensions/extension_service.h" | 25 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/history/history.h" | 26 #include "chrome/browser/history/history.h" |
| 25 #include "chrome/browser/net/url_request_mock_util.h" | 27 #include "chrome/browser/net/url_request_mock_util.h" |
| 26 #include "chrome/browser/prefs/pref_service.h" | 28 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_list.h" | 31 #include "chrome/browser/ui/browser_list.h" |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 int rdh_pending_requests_; | 493 int rdh_pending_requests_; |
| 492 int dfm_pending_downloads_; | 494 int dfm_pending_downloads_; |
| 493 | 495 |
| 494 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); | 496 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); |
| 495 }; | 497 }; |
| 496 | 498 |
| 497 class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate { | 499 class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate { |
| 498 public: | 500 public: |
| 499 explicit PickSuggestedFileDelegate(Profile* profile) | 501 explicit PickSuggestedFileDelegate(Profile* profile) |
| 500 : ChromeDownloadManagerDelegate(profile) { | 502 : ChromeDownloadManagerDelegate(profile) { |
| 501 SetDownloadManager(profile->GetDownloadManager()); | 503 SetDownloadManager( |
| 504 DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager()); |
| 502 } | 505 } |
| 503 | 506 |
| 504 virtual void ChooseDownloadPath(TabContents* tab_contents, | 507 virtual void ChooseDownloadPath(TabContents* tab_contents, |
| 505 const FilePath& suggested_path, | 508 const FilePath& suggested_path, |
| 506 void* data) OVERRIDE { | 509 void* data) OVERRIDE { |
| 507 if (download_manager_) | 510 if (download_manager_) |
| 508 download_manager_->FileSelected(suggested_path, data); | 511 download_manager_->FileSelected(suggested_path, data); |
| 509 } | 512 } |
| 510 }; | 513 }; |
| 511 | 514 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 590 |
| 588 // Proceed without confirmation prompt. | 591 // Proceed without confirmation prompt. |
| 589 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { | 592 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { |
| 590 delegate->InstallUIProceed(); | 593 delegate->InstallUIProceed(); |
| 591 } | 594 } |
| 592 | 595 |
| 593 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} | 596 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} |
| 594 virtual void OnInstallFailure(const std::string& error) {} | 597 virtual void OnInstallFailure(const std::string& error) {} |
| 595 }; | 598 }; |
| 596 | 599 |
| 600 static DownloadManager* DownloadManagerForBrowser(Browser* browser) { |
| 601 return DownloadServiceFactory::GetForProfile(browser->profile()) |
| 602 ->GetDownloadManager(); |
| 603 } |
| 604 |
| 597 } // namespace | 605 } // namespace |
| 598 | 606 |
| 599 // While an object of this class exists, it will mock out download | 607 // While an object of this class exists, it will mock out download |
| 600 // opening for all downloads created on the specified download manager. | 608 // opening for all downloads created on the specified download manager. |
| 601 class MockDownloadOpeningObserver : public DownloadManager::Observer { | 609 class MockDownloadOpeningObserver : public DownloadManager::Observer { |
| 602 public: | 610 public: |
| 603 explicit MockDownloadOpeningObserver(DownloadManager* manager) | 611 explicit MockDownloadOpeningObserver(DownloadManager* manager) |
| 604 : download_manager_(manager) { | 612 : download_manager_(manager) { |
| 605 download_manager_->AddObserver(this); | 613 download_manager_->AddObserver(this); |
| 606 } | 614 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 667 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 660 | 668 |
| 661 // Set up the temporary download folder. | 669 // Set up the temporary download folder. |
| 662 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser()); | 670 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser()); |
| 663 EXPECT_TRUE(created_downloads_dir); | 671 EXPECT_TRUE(created_downloads_dir); |
| 664 if (!created_downloads_dir) | 672 if (!created_downloads_dir) |
| 665 return false; | 673 return false; |
| 666 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 674 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 667 prompt_for_download); | 675 prompt_for_download); |
| 668 | 676 |
| 669 DownloadManager* manager = browser()->profile()->GetDownloadManager(); | 677 DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 670 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | 678 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); |
| 671 manager->RemoveAllDownloads(); | 679 manager->RemoveAllDownloads(); |
| 672 | 680 |
| 673 return true; | 681 return true; |
| 674 } | 682 } |
| 675 | 683 |
| 676 protected: | 684 protected: |
| 677 | 685 |
| 678 enum SizeTestType { | 686 enum SizeTestType { |
| 679 SIZE_TEST_TYPE_KNOWN, | 687 SIZE_TEST_TYPE_KNOWN, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 703 | 711 |
| 704 browser->profile()->GetPrefs()->SetFilePath( | 712 browser->profile()->GetPrefs()->SetFilePath( |
| 705 prefs::kDownloadDefaultDirectory, | 713 prefs::kDownloadDefaultDirectory, |
| 706 downloads_directory_.path()); | 714 downloads_directory_.path()); |
| 707 | 715 |
| 708 return true; | 716 return true; |
| 709 } | 717 } |
| 710 | 718 |
| 711 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 719 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
| 712 return DownloadPrefs::FromDownloadManager( | 720 return DownloadPrefs::FromDownloadManager( |
| 713 browser->profile()->GetDownloadManager()); | 721 DownloadManagerForBrowser(browser)); |
| 714 } | 722 } |
| 715 | 723 |
| 716 FilePath GetDownloadDirectory(Browser* browser) { | 724 FilePath GetDownloadDirectory(Browser* browser) { |
| 717 return GetDownloadPrefs(browser)->download_path(); | 725 return GetDownloadPrefs(browser)->download_path(); |
| 718 } | 726 } |
| 719 | 727 |
| 720 // Create a DownloadsObserver that will wait for the | 728 // Create a DownloadsObserver that will wait for the |
| 721 // specified number of downloads to finish. | 729 // specified number of downloads to finish. |
| 722 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { | 730 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { |
| 723 DownloadManager* download_manager = | 731 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 724 browser->profile()->GetDownloadManager(); | |
| 725 return new DownloadsObserver( | 732 return new DownloadsObserver( |
| 726 download_manager, num_downloads, | 733 download_manager, num_downloads, |
| 727 DownloadItem::COMPLETE, // Really done | 734 DownloadItem::COMPLETE, // Really done |
| 728 true, // Bail on select file | 735 true, // Bail on select file |
| 729 ON_DANGEROUS_DOWNLOAD_FAIL); | 736 ON_DANGEROUS_DOWNLOAD_FAIL); |
| 730 } | 737 } |
| 731 | 738 |
| 732 // Create a DownloadsObserver that will wait for the | 739 // Create a DownloadsObserver that will wait for the |
| 733 // specified number of downloads to start. | 740 // specified number of downloads to start. |
| 734 DownloadsObserver* CreateInProgressWaiter(Browser* browser, | 741 DownloadsObserver* CreateInProgressWaiter(Browser* browser, |
| 735 int num_downloads) { | 742 int num_downloads) { |
| 736 DownloadManager* download_manager = | 743 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 737 browser->profile()->GetDownloadManager(); | |
| 738 return new DownloadsObserver( | 744 return new DownloadsObserver( |
| 739 download_manager, num_downloads, | 745 download_manager, num_downloads, |
| 740 DownloadItem::IN_PROGRESS, // Has started | 746 DownloadItem::IN_PROGRESS, // Has started |
| 741 true, // Bail on select file | 747 true, // Bail on select file |
| 742 ON_DANGEROUS_DOWNLOAD_FAIL); | 748 ON_DANGEROUS_DOWNLOAD_FAIL); |
| 743 } | 749 } |
| 744 | 750 |
| 745 // Create a DownloadsObserver that will wait for the | 751 // Create a DownloadsObserver that will wait for the |
| 746 // specified number of downloads to finish, or for | 752 // specified number of downloads to finish, or for |
| 747 // a dangerous download warning to be shown. | 753 // a dangerous download warning to be shown. |
| 748 DownloadsObserver* DangerousInstallWaiter( | 754 DownloadsObserver* DangerousInstallWaiter( |
| 749 Browser* browser, | 755 Browser* browser, |
| 750 int num_downloads, | 756 int num_downloads, |
| 751 DownloadItem::DownloadState final_state, | 757 DownloadItem::DownloadState final_state, |
| 752 DangerousDownloadAction dangerous_download_action) { | 758 DangerousDownloadAction dangerous_download_action) { |
| 753 DownloadManager* download_manager = | 759 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 754 browser->profile()->GetDownloadManager(); | |
| 755 return new DownloadsObserver( | 760 return new DownloadsObserver( |
| 756 download_manager, num_downloads, | 761 download_manager, num_downloads, |
| 757 final_state, | 762 final_state, |
| 758 true, // Bail on select file | 763 true, // Bail on select file |
| 759 dangerous_download_action); | 764 dangerous_download_action); |
| 760 } | 765 } |
| 761 | 766 |
| 762 // Download |url|, then wait for the download to finish. | 767 // Download |url|, then wait for the download to finish. |
| 763 // |disposition| indicates where the navigation occurs (current tab, new | 768 // |disposition| indicates where the navigation occurs (current tab, new |
| 764 // foreground tab, etc). | 769 // foreground tab, etc). |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 | 909 |
| 905 // Delete the file we just downloaded. | 910 // Delete the file we just downloaded. |
| 906 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); | 911 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); |
| 907 EXPECT_FALSE(file_util::PathExists(download_path)); | 912 EXPECT_FALSE(file_util::PathExists(download_path)); |
| 908 | 913 |
| 909 return true; | 914 return true; |
| 910 } | 915 } |
| 911 | 916 |
| 912 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { | 917 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { |
| 913 DCHECK(downloads); | 918 DCHECK(downloads); |
| 914 DownloadManager* manager = browser->profile()->GetDownloadManager(); | 919 DownloadManager* manager = DownloadManagerForBrowser(browser); |
| 915 manager->SearchDownloads(string16(), downloads); | 920 manager->SearchDownloads(string16(), downloads); |
| 916 } | 921 } |
| 917 | 922 |
| 918 // Check that the download UI (shelf on non-chromeos or panel on chromeos) | 923 // Check that the download UI (shelf on non-chromeos or panel on chromeos) |
| 919 // is visible or not as expected. Additionally, check that the filename | 924 // is visible or not as expected. Additionally, check that the filename |
| 920 // is present in the UI (currently only on chromeos). | 925 // is present in the UI (currently only on chromeos). |
| 921 void CheckDownloadUI(Browser* browser, bool expected_non_cros, | 926 void CheckDownloadUI(Browser* browser, bool expected_non_cros, |
| 922 bool expected_cros, const FilePath& filename) { | 927 bool expected_cros, const FilePath& filename) { |
| 923 #if defined(OS_CHROMEOS) | 928 #if defined(OS_CHROMEOS) |
| 924 #if defined(TOUCH_UI) | 929 #if defined(TOUCH_UI) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 #endif | 971 #endif |
| 967 EXPECT_EQ(expected, BrowserList::size()); | 972 EXPECT_EQ(expected, BrowserList::size()); |
| 968 } | 973 } |
| 969 | 974 |
| 970 // Arrange for select file calls on the given browser from the | 975 // Arrange for select file calls on the given browser from the |
| 971 // download manager to always choose the suggested file. | 976 // download manager to always choose the suggested file. |
| 972 void NullSelectFile(Browser* browser) { | 977 void NullSelectFile(Browser* browser) { |
| 973 PickSuggestedFileDelegate* new_delegate = | 978 PickSuggestedFileDelegate* new_delegate = |
| 974 new PickSuggestedFileDelegate(browser->profile()); | 979 new PickSuggestedFileDelegate(browser->profile()); |
| 975 | 980 |
| 976 DownloadManager* manager = browser->profile()->GetDownloadManager(); | 981 // Gives ownership to DownloadService. |
| 977 | 982 DownloadServiceFactory::GetForProfile( |
| 978 new_delegate->SetDownloadManager(manager); | 983 browser->profile())->SetDownloadManagerDelegateForTesting(new_delegate); |
| 979 manager->set_delegate(new_delegate); | |
| 980 | |
| 981 // Gives ownership to Profile. | |
| 982 browser->profile()->SetDownloadManagerDelegate(new_delegate); | |
| 983 } | 984 } |
| 984 | 985 |
| 985 private: | 986 private: |
| 986 // Location of the test data. | 987 // Location of the test data. |
| 987 FilePath test_dir_; | 988 FilePath test_dir_; |
| 988 | 989 |
| 989 // Location of the downloads directory for these tests | 990 // Location of the downloads directory for these tests |
| 990 ScopedTempDir downloads_directory_; | 991 ScopedTempDir downloads_directory_; |
| 991 }; | 992 }; |
| 992 | 993 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 ASSERT_TRUE(InitialSetup(true)); | 1040 ASSERT_TRUE(InitialSetup(true)); |
| 1040 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1041 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1041 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1042 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1042 | 1043 |
| 1043 NullSelectFile(browser()); | 1044 NullSelectFile(browser()); |
| 1044 | 1045 |
| 1045 // Download the file and wait. We expect the Select File dialog to appear | 1046 // Download the file and wait. We expect the Select File dialog to appear |
| 1046 // due to the MIME type, but we still wait until the download completes. | 1047 // due to the MIME type, but we still wait until the download completes. |
| 1047 scoped_ptr<DownloadsObserver> observer( | 1048 scoped_ptr<DownloadsObserver> observer( |
| 1048 new DownloadsObserver( | 1049 new DownloadsObserver( |
| 1049 browser()->profile()->GetDownloadManager(), | 1050 DownloadManagerForBrowser(browser()), |
| 1050 1, | 1051 1, |
| 1051 DownloadItem::COMPLETE, // Really done | 1052 DownloadItem::COMPLETE, // Really done |
| 1052 false, // Continue on select file. | 1053 false, // Continue on select file. |
| 1053 ON_DANGEROUS_DOWNLOAD_FAIL)); | 1054 ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1054 ui_test_utils::NavigateToURLWithDisposition( | 1055 ui_test_utils::NavigateToURLWithDisposition( |
| 1055 browser(), url, CURRENT_TAB, | 1056 browser(), url, CURRENT_TAB, |
| 1056 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1057 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1057 observer->WaitForFinished(); | 1058 observer->WaitForFinished(); |
| 1058 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1059 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 1059 | 1060 |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 | 1485 |
| 1485 // Create a download, wait until it's started, and confirm | 1486 // Create a download, wait until it's started, and confirm |
| 1486 // we're in the expected state. | 1487 // we're in the expected state. |
| 1487 scoped_ptr<DownloadsObserver> observer( | 1488 scoped_ptr<DownloadsObserver> observer( |
| 1488 CreateInProgressWaiter(browser(), 1)); | 1489 CreateInProgressWaiter(browser(), 1)); |
| 1489 ui_test_utils::NavigateToURL( | 1490 ui_test_utils::NavigateToURL( |
| 1490 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1491 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 1491 observer->WaitForFinished(); | 1492 observer->WaitForFinished(); |
| 1492 | 1493 |
| 1493 std::vector<DownloadItem*> downloads; | 1494 std::vector<DownloadItem*> downloads; |
| 1494 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1495 DownloadManagerForBrowser(browser())->SearchDownloads( |
| 1495 string16(), &downloads); | 1496 string16(), &downloads); |
| 1496 ASSERT_EQ(1u, downloads.size()); | 1497 ASSERT_EQ(1u, downloads.size()); |
| 1497 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); | 1498 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); |
| 1498 CheckDownloadUI(browser(), true, true, FilePath()); | 1499 CheckDownloadUI(browser(), true, true, FilePath()); |
| 1499 | 1500 |
| 1500 // Cancel the download and wait for download system quiesce. | 1501 // Cancel the download and wait for download system quiesce. |
| 1501 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 1502 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 1502 scoped_refptr<DownloadsFlushObserver> flush_observer( | 1503 scoped_refptr<DownloadsFlushObserver> flush_observer( |
| 1503 new DownloadsFlushObserver(browser()->profile()->GetDownloadManager())); | 1504 new DownloadsFlushObserver(DownloadManagerForBrowser(browser()))); |
| 1504 flush_observer->WaitForFlush(); | 1505 flush_observer->WaitForFlush(); |
| 1505 | 1506 |
| 1506 // Get the important info from other threads and check it. | 1507 // Get the important info from other threads and check it. |
| 1507 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); | 1508 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); |
| 1508 info->WaitForDataCollected(); | 1509 info->WaitForDataCollected(); |
| 1509 EXPECT_EQ(0, info->rdh_pending_requests()); | 1510 EXPECT_EQ(0, info->rdh_pending_requests()); |
| 1510 EXPECT_EQ(0, info->dfm_pending_downloads()); | 1511 EXPECT_EQ(0, info->dfm_pending_downloads()); |
| 1511 | 1512 |
| 1512 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1513 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
| 1513 // which completely removes the browser from the shelf and closes the shelf | 1514 // which completely removes the browser from the shelf and closes the shelf |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1534 int64 db_handle = downloads[0]->db_handle(); | 1535 int64 db_handle = downloads[0]->db_handle(); |
| 1535 | 1536 |
| 1536 // Check state. | 1537 // Check state. |
| 1537 EXPECT_EQ(1, browser()->tab_count()); | 1538 EXPECT_EQ(1, browser()->tab_count()); |
| 1538 CheckDownload(browser(), file, file); | 1539 CheckDownload(browser(), file, file); |
| 1539 CheckDownloadUI(browser(), true, true, file); | 1540 CheckDownloadUI(browser(), true, true, file); |
| 1540 | 1541 |
| 1541 // Check history results. | 1542 // Check history results. |
| 1542 DownloadsHistoryDataCollector history_collector( | 1543 DownloadsHistoryDataCollector history_collector( |
| 1543 db_handle, | 1544 db_handle, |
| 1544 browser()->profile()->GetDownloadManager()); | 1545 DownloadManagerForBrowser(browser())); |
| 1545 DownloadPersistentStoreInfo info; | 1546 DownloadPersistentStoreInfo info; |
| 1546 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; | 1547 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; |
| 1547 EXPECT_EQ(file, info.path.BaseName()); | 1548 EXPECT_EQ(file, info.path.BaseName()); |
| 1548 EXPECT_EQ(url, info.url); | 1549 EXPECT_EQ(url, info.url); |
| 1549 // Ignore start_time. | 1550 // Ignore start_time. |
| 1550 EXPECT_EQ(origin_size, info.received_bytes); | 1551 EXPECT_EQ(origin_size, info.received_bytes); |
| 1551 EXPECT_EQ(origin_size, info.total_bytes); | 1552 EXPECT_EQ(origin_size, info.total_bytes); |
| 1552 EXPECT_EQ(DownloadItem::COMPLETE, info.state); | 1553 EXPECT_EQ(DownloadItem::COMPLETE, info.state); |
| 1553 } | 1554 } |
| 1554 | 1555 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1629 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
| 1629 ASSERT_TRUE(InitialSetup(false)); | 1630 ASSERT_TRUE(InitialSetup(false)); |
| 1630 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1631 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 1631 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1632 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1632 | 1633 |
| 1633 ASSERT_TRUE( | 1634 ASSERT_TRUE( |
| 1634 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1635 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 1635 | 1636 |
| 1636 // Mock out external opening on all downloads until end of test. | 1637 // Mock out external opening on all downloads until end of test. |
| 1637 MockDownloadOpeningObserver observer( | 1638 MockDownloadOpeningObserver observer( |
| 1638 browser()->profile()->GetDownloadManager()); | 1639 DownloadManagerForBrowser(browser())); |
| 1639 | 1640 |
| 1640 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1641 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 1641 | 1642 |
| 1642 // Find the download and confirm it was opened. | 1643 // Find the download and confirm it was opened. |
| 1643 std::vector<DownloadItem*> downloads; | 1644 std::vector<DownloadItem*> downloads; |
| 1644 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1645 DownloadManagerForBrowser(browser())->SearchDownloads( |
| 1645 string16(), &downloads); | 1646 string16(), &downloads); |
| 1646 ASSERT_EQ(1u, downloads.size()); | 1647 ASSERT_EQ(1u, downloads.size()); |
| 1647 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); | 1648 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); |
| 1648 EXPECT_TRUE(downloads[0]->opened()); | 1649 EXPECT_TRUE(downloads[0]->opened()); |
| 1649 | 1650 |
| 1650 // As long as we're here, confirmed everything else is good. | 1651 // As long as we're here, confirmed everything else is good. |
| 1651 EXPECT_EQ(1, browser()->tab_count()); | 1652 EXPECT_EQ(1, browser()->tab_count()); |
| 1652 CheckDownload(browser(), file, file); | 1653 CheckDownload(browser(), file, file); |
| 1653 // Download shelf should close. Download panel stays open on ChromeOS. | 1654 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1654 CheckDownloadUI(browser(), false, true, FilePath()); | 1655 CheckDownloadUI(browser(), false, true, FilePath()); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1787 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1788 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1788 | 1789 |
| 1789 // Download shelf should close. Download panel stays open on ChromeOS. | 1790 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1790 CheckDownloadUI(browser(), false, true, FilePath()); | 1791 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1791 | 1792 |
| 1792 // Check that the extension was installed. | 1793 // Check that the extension was installed. |
| 1793 ExtensionService* extension_service = | 1794 ExtensionService* extension_service = |
| 1794 browser()->profile()->GetExtensionService(); | 1795 browser()->profile()->GetExtensionService(); |
| 1795 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1796 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 1796 } | 1797 } |
| OLD | NEW |