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