| 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" | 20 #include "chrome/browser/download/download_service.h" |
| 21 #include "chrome/browser/download/download_service_factory.h" | 21 #include "chrome/browser/download/download_service_factory.h" |
| 22 #include "chrome/browser/download/download_shelf.h" | 22 #include "chrome/browser/download/download_shelf.h" |
| 23 #include "chrome/browser/download/download_test_observer.h" |
| 23 #include "chrome/browser/download/download_util.h" | 24 #include "chrome/browser/download/download_util.h" |
| 24 #include "chrome/browser/extensions/extension_install_ui.h" | 25 #include "chrome/browser/extensions/extension_install_ui.h" |
| 25 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" |
| 26 #include "chrome/browser/history/history.h" | 27 #include "chrome/browser/history/history.h" |
| 27 #include "chrome/browser/net/url_request_mock_util.h" | 28 #include "chrome/browser/net/url_request_mock_util.h" |
| 28 #include "chrome/browser/prefs/pref_service.h" | 29 #include "chrome/browser/prefs/pref_service.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_list.h" |
| 32 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 | 711 |
| 711 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 712 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
| 712 return DownloadPrefs::FromDownloadManager( | 713 return DownloadPrefs::FromDownloadManager( |
| 713 DownloadManagerForBrowser(browser)); | 714 DownloadManagerForBrowser(browser)); |
| 714 } | 715 } |
| 715 | 716 |
| 716 FilePath GetDownloadDirectory(Browser* browser) { | 717 FilePath GetDownloadDirectory(Browser* browser) { |
| 717 return GetDownloadPrefs(browser)->download_path(); | 718 return GetDownloadPrefs(browser)->download_path(); |
| 718 } | 719 } |
| 719 | 720 |
| 720 // Create a DownloadsObserver that will wait for the | 721 // Create a DownloadTestObserver that will wait for the |
| 721 // specified number of downloads to finish. | 722 // specified number of downloads to finish. |
| 722 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { | 723 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { |
| 723 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 724 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 724 return new DownloadsObserver( | 725 return new DownloadTestObserver( |
| 725 download_manager, num_downloads, | 726 download_manager, num_downloads, |
| 726 DownloadItem::COMPLETE, // Really done | 727 DownloadItem::COMPLETE, // Really done |
| 727 true, // Bail on select file | 728 true, // Bail on select file |
| 728 ON_DANGEROUS_DOWNLOAD_FAIL); | 729 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 729 } | 730 } |
| 730 | 731 |
| 731 // Create a DownloadsObserver that will wait for the | 732 // Create a DownloadTestObserver that will wait for the |
| 732 // specified number of downloads to start. | 733 // specified number of downloads to start. |
| 733 DownloadsObserver* CreateInProgressWaiter(Browser* browser, | 734 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, |
| 734 int num_downloads) { | 735 int num_downloads) { |
| 735 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 736 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 736 return new DownloadsObserver( | 737 return new DownloadTestObserver( |
| 737 download_manager, num_downloads, | 738 download_manager, num_downloads, |
| 738 DownloadItem::IN_PROGRESS, // Has started | 739 DownloadItem::IN_PROGRESS, // Has started |
| 739 true, // Bail on select file | 740 true, // Bail on select file |
| 740 ON_DANGEROUS_DOWNLOAD_FAIL); | 741 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 741 } | 742 } |
| 742 | 743 |
| 743 // Create a DownloadsObserver that will wait for the | 744 // Create a DownloadTestObserver that will wait for the |
| 744 // specified number of downloads to finish, or for | 745 // specified number of downloads to finish, or for |
| 745 // a dangerous download warning to be shown. | 746 // a dangerous download warning to be shown. |
| 746 DownloadsObserver* DangerousInstallWaiter( | 747 DownloadTestObserver* DangerousInstallWaiter( |
| 747 Browser* browser, | 748 Browser* browser, |
| 748 int num_downloads, | 749 int num_downloads, |
| 749 DownloadItem::DownloadState final_state, | 750 DownloadItem::DownloadState final_state, |
| 750 DangerousDownloadAction dangerous_download_action) { | 751 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { |
| 751 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 752 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 752 return new DownloadsObserver( | 753 return new DownloadTestObserver( |
| 753 download_manager, num_downloads, | 754 download_manager, num_downloads, |
| 754 final_state, | 755 final_state, |
| 755 true, // Bail on select file | 756 true, // Bail on select file |
| 756 dangerous_download_action); | 757 dangerous_download_action); |
| 757 } | 758 } |
| 758 | 759 |
| 759 // Download |url|, then wait for the download to finish. | 760 // Download |url|, then wait for the download to finish. |
| 760 // |disposition| indicates where the navigation occurs (current tab, new | 761 // |disposition| indicates where the navigation occurs (current tab, new |
| 761 // foreground tab, etc). | 762 // foreground tab, etc). |
| 762 // |expectation| indicates whether or not a Select File dialog should be | 763 // |expectation| indicates whether or not a Select File dialog should be |
| 763 // open when the download is finished, or if we don't care. | 764 // open when the download is finished, or if we don't care. |
| 764 // If the dialog appears, the routine exits. The only effect |expectation| | 765 // If the dialog appears, the routine exits. The only effect |expectation| |
| 765 // has is whether or not the test succeeds. | 766 // has is whether or not the test succeeds. |
| 766 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 767 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
| 767 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 768 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
| 768 void DownloadAndWaitWithDisposition(Browser* browser, | 769 void DownloadAndWaitWithDisposition(Browser* browser, |
| 769 const GURL& url, | 770 const GURL& url, |
| 770 WindowOpenDisposition disposition, | 771 WindowOpenDisposition disposition, |
| 771 SelectExpectation expectation, | 772 SelectExpectation expectation, |
| 772 int browser_test_flags) { | 773 int browser_test_flags) { |
| 773 // Setup notification, navigate, and block. | 774 // Setup notification, navigate, and block. |
| 774 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 775 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
| 775 // This call will block until the condition specified by | 776 // This call will block until the condition specified by |
| 776 // |browser_test_flags|, but will not wait for the download to finish. | 777 // |browser_test_flags|, but will not wait for the download to finish. |
| 777 ui_test_utils::NavigateToURLWithDisposition(browser, | 778 ui_test_utils::NavigateToURLWithDisposition(browser, |
| 778 url, | 779 url, |
| 779 disposition, | 780 disposition, |
| 780 browser_test_flags); | 781 browser_test_flags); |
| 781 // Waits for the download to complete. | 782 // Waits for the download to complete. |
| 782 observer->WaitForFinished(); | 783 observer->WaitForFinished(); |
| 783 | 784 |
| 784 // If specified, check the state of the select file dialog. | 785 // If specified, check the state of the select file dialog. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 // |expected_title_finished| need to be checked. | 856 // |expected_title_finished| need to be checked. |
| 856 FilePath filename; | 857 FilePath filename; |
| 857 net::FileURLToFilePath(url, &filename); | 858 net::FileURLToFilePath(url, &filename); |
| 858 string16 expected_title_in_progress( | 859 string16 expected_title_in_progress( |
| 859 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); | 860 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); |
| 860 string16 expected_title_finished( | 861 string16 expected_title_finished( |
| 861 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); | 862 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); |
| 862 | 863 |
| 863 // Download a partial web page in a background tab and wait. | 864 // Download a partial web page in a background tab and wait. |
| 864 // The mock system will not complete until it gets a special URL. | 865 // The mock system will not complete until it gets a special URL. |
| 865 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 866 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
| 866 ui_test_utils::NavigateToURL(browser, url); | 867 ui_test_utils::NavigateToURL(browser, url); |
| 867 | 868 |
| 868 // TODO(ahendrickson): check download status text before downloading. | 869 // TODO(ahendrickson): check download status text before downloading. |
| 869 // Need to: | 870 // Need to: |
| 870 // - Add a member function to the |DownloadShelf| interface class, that | 871 // - Add a member function to the |DownloadShelf| interface class, that |
| 871 // indicates how many members it has. | 872 // indicates how many members it has. |
| 872 // - Add a member function to |DownloadShelf| to get the status text | 873 // - Add a member function to |DownloadShelf| to get the status text |
| 873 // of a given member (for example, via the name in |DownloadItemView|'s | 874 // of a given member (for example, via the name in |DownloadItemView|'s |
| 874 // GetAccessibleState() member function), by index. | 875 // GetAccessibleState() member function), by index. |
| 875 // - Iterate over browser->window()->GetDownloadShelf()'s members | 876 // - Iterate over browser->window()->GetDownloadShelf()'s members |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 // downloads preferences settings. | 1031 // downloads preferences settings. |
| 1031 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 1032 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 1032 ASSERT_TRUE(InitialSetup(true)); | 1033 ASSERT_TRUE(InitialSetup(true)); |
| 1033 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1034 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1034 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1035 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1035 | 1036 |
| 1036 NullSelectFile(browser()); | 1037 NullSelectFile(browser()); |
| 1037 | 1038 |
| 1038 // Download the file and wait. We expect the Select File dialog to appear | 1039 // Download the file and wait. We expect the Select File dialog to appear |
| 1039 // due to the MIME type, but we still wait until the download completes. | 1040 // due to the MIME type, but we still wait until the download completes. |
| 1040 scoped_ptr<DownloadsObserver> observer( | 1041 scoped_ptr<DownloadTestObserver> observer( |
| 1041 new DownloadsObserver( | 1042 new DownloadTestObserver( |
| 1042 DownloadManagerForBrowser(browser()), | 1043 DownloadManagerForBrowser(browser()), |
| 1043 1, | 1044 1, |
| 1044 DownloadItem::COMPLETE, // Really done | 1045 DownloadItem::COMPLETE, // Really done |
| 1045 false, // Continue on select file. | 1046 false, // Continue on select file. |
| 1046 ON_DANGEROUS_DOWNLOAD_FAIL)); | 1047 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1047 ui_test_utils::NavigateToURLWithDisposition( | 1048 ui_test_utils::NavigateToURLWithDisposition( |
| 1048 browser(), url, CURRENT_TAB, | 1049 browser(), url, CURRENT_TAB, |
| 1049 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1050 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1050 observer->WaitForFinished(); | 1051 observer->WaitForFinished(); |
| 1051 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1052 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 1052 | 1053 |
| 1053 // Check state. | 1054 // Check state. |
| 1054 EXPECT_EQ(1, browser()->tab_count()); | 1055 EXPECT_EQ(1, browser()->tab_count()); |
| 1055 CheckDownload(browser(), file, file); | 1056 CheckDownload(browser(), file, file); |
| 1056 CheckDownloadUI(browser(), true, true, file); | 1057 CheckDownloadUI(browser(), true, true, file); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 CheckDownloadUI(browser(), false, true, file); | 1455 CheckDownloadUI(browser(), false, true, file); |
| 1455 | 1456 |
| 1456 CheckDownload(browser(), file, file); | 1457 CheckDownload(browser(), file, file); |
| 1457 } | 1458 } |
| 1458 | 1459 |
| 1459 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | 1460 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { |
| 1460 ASSERT_TRUE(InitialSetup(false)); | 1461 ASSERT_TRUE(InitialSetup(false)); |
| 1461 EXPECT_EQ(1, browser()->tab_count()); | 1462 EXPECT_EQ(1, browser()->tab_count()); |
| 1462 | 1463 |
| 1463 // TODO(rdsmith): Fragile code warning! The code below relies on the | 1464 // TODO(rdsmith): Fragile code warning! The code below relies on the |
| 1464 // DownloadsObserver only finishing when the new download has reached | 1465 // DownloadTestObserver only finishing when the new download has reached |
| 1465 // the state of being entered into the history and being user-visible | 1466 // the state of being entered into the history and being user-visible |
| 1466 // (that's what's required for the Remove to be valid and for the | 1467 // (that's what's required for the Remove to be valid and for the |
| 1467 // download shelf to be visible). By the pure semantics of | 1468 // download shelf to be visible). By the pure semantics of |
| 1468 // DownloadsObserver, that's not guaranteed; DownloadItems are created | 1469 // DownloadTestObserver, that's not guaranteed; DownloadItems are created |
| 1469 // in the IN_PROGRESS state and made known to the DownloadManager | 1470 // in the IN_PROGRESS state and made known to the DownloadManager |
| 1470 // immediately, so any ModelChanged event on the DownloadManager after | 1471 // immediately, so any ModelChanged event on the DownloadManager after |
| 1471 // navigation would allow the observer to return. However, the only | 1472 // navigation would allow the observer to return. However, the only |
| 1472 // ModelChanged() event the code will currently fire is in | 1473 // ModelChanged() event the code will currently fire is in |
| 1473 // OnCreateDownloadEntryComplete, at which point the download item will | 1474 // OnCreateDownloadEntryComplete, at which point the download item will |
| 1474 // be in the state we need. | 1475 // be in the state we need. |
| 1475 // The right way to fix this is to create finer grained states on the | 1476 // The right way to fix this is to create finer grained states on the |
| 1476 // DownloadItem, and wait for the state that indicates the item has been | 1477 // DownloadItem, and wait for the state that indicates the item has been |
| 1477 // entered in the history and made visible in the UI. | 1478 // entered in the history and made visible in the UI. |
| 1478 | 1479 |
| 1479 // Create a download, wait until it's started, and confirm | 1480 // Create a download, wait until it's started, and confirm |
| 1480 // we're in the expected state. | 1481 // we're in the expected state. |
| 1481 scoped_ptr<DownloadsObserver> observer( | 1482 scoped_ptr<DownloadTestObserver> observer( |
| 1482 CreateInProgressWaiter(browser(), 1)); | 1483 CreateInProgressWaiter(browser(), 1)); |
| 1483 ui_test_utils::NavigateToURL( | 1484 ui_test_utils::NavigateToURL( |
| 1484 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1485 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 1485 observer->WaitForFinished(); | 1486 observer->WaitForFinished(); |
| 1486 | 1487 |
| 1487 std::vector<DownloadItem*> downloads; | 1488 std::vector<DownloadItem*> downloads; |
| 1488 DownloadManagerForBrowser(browser())->SearchDownloads( | 1489 DownloadManagerForBrowser(browser())->SearchDownloads( |
| 1489 string16(), &downloads); | 1490 string16(), &downloads); |
| 1490 ASSERT_EQ(1u, downloads.size()); | 1491 ASSERT_EQ(1u, downloads.size()); |
| 1491 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); | 1492 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); |
| 1492 CheckDownloadUI(browser(), true, true, FilePath()); | 1493 CheckDownloadUI(browser(), true, true, FilePath()); |
| 1493 | 1494 |
| 1494 // Cancel the download and wait for download system quiesce. | 1495 // Cancel the download and wait for download system quiesce. |
| 1495 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 1496 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 1496 scoped_refptr<DownloadsFlushObserver> flush_observer( | 1497 scoped_refptr<DownloadTestFlushObserver> flush_observer( |
| 1497 new DownloadsFlushObserver(DownloadManagerForBrowser(browser()))); | 1498 new DownloadTestFlushObserver( |
| 1499 DownloadManagerForBrowser(browser()))); |
| 1498 flush_observer->WaitForFlush(); | 1500 flush_observer->WaitForFlush(); |
| 1499 | 1501 |
| 1500 // Get the important info from other threads and check it. | 1502 // Get the important info from other threads and check it. |
| 1501 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); | 1503 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); |
| 1502 info->WaitForDataCollected(); | 1504 info->WaitForDataCollected(); |
| 1503 EXPECT_EQ(0, info->rdh_pending_requests()); | 1505 EXPECT_EQ(0, info->rdh_pending_requests()); |
| 1504 EXPECT_EQ(0, info->dfm_pending_downloads()); | 1506 EXPECT_EQ(0, info->dfm_pending_downloads()); |
| 1505 | 1507 |
| 1506 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1508 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
| 1507 // which completely removes the browser from the shelf and closes the shelf | 1509 // which completely removes the browser from the shelf and closes the shelf |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 } | 1603 } |
| 1602 | 1604 |
| 1603 // Test to make sure the 'download' attribute in anchor tag is respected. | 1605 // Test to make sure the 'download' attribute in anchor tag is respected. |
| 1604 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1606 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| 1605 ASSERT_TRUE(InitialSetup(false)); | 1607 ASSERT_TRUE(InitialSetup(false)); |
| 1606 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1608 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
| 1607 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1609 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1608 | 1610 |
| 1609 // Create a download, wait until it's complete, and confirm | 1611 // Create a download, wait until it's complete, and confirm |
| 1610 // we're in the expected state. | 1612 // we're in the expected state. |
| 1611 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1)); | 1613 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); |
| 1612 ui_test_utils::NavigateToURL(browser(), url); | 1614 ui_test_utils::NavigateToURL(browser(), url); |
| 1613 observer->WaitForFinished(); | 1615 observer->WaitForFinished(); |
| 1614 | 1616 |
| 1615 // Confirm the downloaded data exists. | 1617 // Confirm the downloaded data exists. |
| 1616 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1618 FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 1617 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1619 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 1618 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1620 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
| 1619 } | 1621 } |
| 1620 | 1622 |
| 1621 // Test to make sure auto-open works. | 1623 // Test to make sure auto-open works. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1647 // Download shelf should close. Download panel stays open on ChromeOS. | 1649 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1648 CheckDownloadUI(browser(), false, true, FilePath()); | 1650 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1649 } | 1651 } |
| 1650 | 1652 |
| 1651 // Download an extension. Expect a dangerous download warning. | 1653 // Download an extension. Expect a dangerous download warning. |
| 1652 // Deny the download. | 1654 // Deny the download. |
| 1653 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1655 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
| 1654 ASSERT_TRUE(InitialSetup(false)); | 1656 ASSERT_TRUE(InitialSetup(false)); |
| 1655 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1657 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1656 | 1658 |
| 1657 scoped_ptr<DownloadsObserver> observer( | 1659 scoped_ptr<DownloadTestObserver> observer( |
| 1658 DangerousInstallWaiter(browser(), | 1660 DangerousInstallWaiter( |
| 1659 1, | 1661 browser(), 1, DownloadItem::CANCELLED, |
| 1660 DownloadItem::CANCELLED, | 1662 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 1661 ON_DANGEROUS_DOWNLOAD_DENY)); | |
| 1662 ui_test_utils::NavigateToURL(browser(), extension_url); | 1663 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1663 | 1664 |
| 1664 observer->WaitForFinished(); | 1665 observer->WaitForFinished(); |
| 1665 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1666 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1666 | 1667 |
| 1667 // Download shelf should close. Download panel stays open on ChromeOS. | 1668 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1668 CheckDownloadUI(browser(), false, true, FilePath()); | 1669 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1669 | 1670 |
| 1670 // Check that the CRX is not installed. | 1671 // Check that the CRX is not installed. |
| 1671 ExtensionService* extension_service = | 1672 ExtensionService* extension_service = |
| 1672 browser()->profile()->GetExtensionService(); | 1673 browser()->profile()->GetExtensionService(); |
| 1673 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1674 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1674 } | 1675 } |
| 1675 | 1676 |
| 1676 // Download an extension. Expect a dangerous download warning. | 1677 // Download an extension. Expect a dangerous download warning. |
| 1677 // Allow the download, deny the install. | 1678 // Allow the download, deny the install. |
| 1678 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1679 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
| 1679 ASSERT_TRUE(InitialSetup(false)); | 1680 ASSERT_TRUE(InitialSetup(false)); |
| 1680 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1681 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1681 | 1682 |
| 1682 // Install a mock install UI that simulates a user denying permission to | 1683 // Install a mock install UI that simulates a user denying permission to |
| 1683 // finish the install. | 1684 // finish the install. |
| 1684 download_crx_util::SetMockInstallUIForTesting( | 1685 download_crx_util::SetMockInstallUIForTesting( |
| 1685 new MockAbortExtensionInstallUI()); | 1686 new MockAbortExtensionInstallUI()); |
| 1686 | 1687 |
| 1687 scoped_ptr<DownloadsObserver> observer( | 1688 scoped_ptr<DownloadTestObserver> observer( |
| 1688 DangerousInstallWaiter(browser(), | 1689 DangerousInstallWaiter( |
| 1689 1, | 1690 browser(), 1, DownloadItem::COMPLETE, |
| 1690 DownloadItem::COMPLETE, | 1691 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1691 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 1692 ui_test_utils::NavigateToURL(browser(), extension_url); | 1692 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1693 | 1693 |
| 1694 observer->WaitForFinished(); | 1694 observer->WaitForFinished(); |
| 1695 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1695 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1696 | 1696 |
| 1697 // Download shelf should close. Download panel stays open on ChromeOS. | 1697 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1698 CheckDownloadUI(browser(), false, true, FilePath()); | 1698 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1699 | 1699 |
| 1700 // Check that the extension was not installed. | 1700 // Check that the extension was not installed. |
| 1701 ExtensionService* extension_service = | 1701 ExtensionService* extension_service = |
| 1702 browser()->profile()->GetExtensionService(); | 1702 browser()->profile()->GetExtensionService(); |
| 1703 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1703 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1704 } | 1704 } |
| 1705 | 1705 |
| 1706 // Download an extension. Expect a dangerous download warning. | 1706 // Download an extension. Expect a dangerous download warning. |
| 1707 // Allow the download, and the install. | 1707 // Allow the download, and the install. |
| 1708 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1708 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
| 1709 ASSERT_TRUE(InitialSetup(false)); | 1709 ASSERT_TRUE(InitialSetup(false)); |
| 1710 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1710 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1711 | 1711 |
| 1712 // Install a mock install UI that simulates a user allowing permission to | 1712 // Install a mock install UI that simulates a user allowing permission to |
| 1713 // finish the install. | 1713 // finish the install. |
| 1714 download_crx_util::SetMockInstallUIForTesting( | 1714 download_crx_util::SetMockInstallUIForTesting( |
| 1715 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1715 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1716 | 1716 |
| 1717 scoped_ptr<DownloadsObserver> observer( | 1717 scoped_ptr<DownloadTestObserver> observer( |
| 1718 DangerousInstallWaiter(browser(), | 1718 DangerousInstallWaiter( |
| 1719 1, | 1719 browser(), 1, DownloadItem::COMPLETE, |
| 1720 DownloadItem::COMPLETE, | 1720 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1721 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 1722 ui_test_utils::NavigateToURL(browser(), extension_url); | 1721 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1723 | 1722 |
| 1724 observer->WaitForFinished(); | 1723 observer->WaitForFinished(); |
| 1725 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1724 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1726 | 1725 |
| 1727 // Download shelf should close. Download panel stays open on ChromeOS. | 1726 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1728 CheckDownloadUI(browser(), false, true, FilePath()); | 1727 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1729 | 1728 |
| 1730 // Check that the extension was installed. | 1729 // Check that the extension was installed. |
| 1731 ExtensionService* extension_service = | 1730 ExtensionService* extension_service = |
| 1732 browser()->profile()->GetExtensionService(); | 1731 browser()->profile()->GetExtensionService(); |
| 1733 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1732 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1734 } | 1733 } |
| 1735 | 1734 |
| 1736 // Test installing a CRX that fails integrity checks. | 1735 // Test installing a CRX that fails integrity checks. |
| 1737 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1736 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
| 1738 ASSERT_TRUE(InitialSetup(false)); | 1737 ASSERT_TRUE(InitialSetup(false)); |
| 1739 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1738 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
| 1740 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1739 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1741 | 1740 |
| 1742 // Install a mock install UI that simulates a user allowing permission to | 1741 // Install a mock install UI that simulates a user allowing permission to |
| 1743 // finish the install, and dismisses any error message. We check that the | 1742 // finish the install, and dismisses any error message. We check that the |
| 1744 // install failed below. | 1743 // install failed below. |
| 1745 download_crx_util::SetMockInstallUIForTesting( | 1744 download_crx_util::SetMockInstallUIForTesting( |
| 1746 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1745 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1747 | 1746 |
| 1748 scoped_ptr<DownloadsObserver> observer( | 1747 scoped_ptr<DownloadTestObserver> observer( |
| 1749 DangerousInstallWaiter(browser(), | 1748 DangerousInstallWaiter( |
| 1750 1, | 1749 browser(), 1, DownloadItem::COMPLETE, |
| 1751 DownloadItem::COMPLETE, | 1750 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1752 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 1753 ui_test_utils::NavigateToURL(browser(), extension_url); | 1751 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1754 | 1752 |
| 1755 observer->WaitForFinished(); | 1753 observer->WaitForFinished(); |
| 1756 | 1754 |
| 1757 // Check that the extension was not installed. | 1755 // Check that the extension was not installed. |
| 1758 ExtensionService* extension_service = | 1756 ExtensionService* extension_service = |
| 1759 browser()->profile()->GetExtensionService(); | 1757 browser()->profile()->GetExtensionService(); |
| 1760 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1758 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1761 } | 1759 } |
| 1762 | 1760 |
| 1763 // Install a large (100kb) theme. | 1761 // Install a large (100kb) theme. |
| 1764 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1762 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
| 1765 ASSERT_TRUE(InitialSetup(false)); | 1763 ASSERT_TRUE(InitialSetup(false)); |
| 1766 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1764 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
| 1767 | 1765 |
| 1768 // Install a mock install UI that simulates a user allowing permission to | 1766 // Install a mock install UI that simulates a user allowing permission to |
| 1769 // finish the install. | 1767 // finish the install. |
| 1770 download_crx_util::SetMockInstallUIForTesting( | 1768 download_crx_util::SetMockInstallUIForTesting( |
| 1771 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1769 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1772 | 1770 |
| 1773 scoped_ptr<DownloadsObserver> observer( | 1771 scoped_ptr<DownloadTestObserver> observer( |
| 1774 DangerousInstallWaiter(browser(), | 1772 DangerousInstallWaiter( |
| 1775 1, | 1773 browser(), 1, DownloadItem::COMPLETE, |
| 1776 DownloadItem::COMPLETE, | 1774 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1777 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 1778 ui_test_utils::NavigateToURL(browser(), extension_url); | 1775 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1779 | 1776 |
| 1780 observer->WaitForFinished(); | 1777 observer->WaitForFinished(); |
| 1781 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1778 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1782 | 1779 |
| 1783 // Download shelf should close. Download panel stays open on ChromeOS. | 1780 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1784 CheckDownloadUI(browser(), false, true, FilePath()); | 1781 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1785 | 1782 |
| 1786 // Check that the extension was installed. | 1783 // Check that the extension was installed. |
| 1787 ExtensionService* extension_service = | 1784 ExtensionService* extension_service = |
| 1788 browser()->profile()->GetExtensionService(); | 1785 browser()->profile()->GetExtensionService(); |
| 1789 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1786 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 1790 } | 1787 } |
| OLD | NEW |