Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 9568003: Fixed issue with DownloadTestObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split DownloadTestObserver in two Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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"
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 FilePath GetDownloadDirectory(Browser* browser) { 388 FilePath GetDownloadDirectory(Browser* browser) {
389 return GetDownloadPrefs(browser)->download_path(); 389 return GetDownloadPrefs(browser)->download_path();
390 } 390 }
391 391
392 // Create a DownloadTestObserver that will wait for the 392 // Create a DownloadTestObserver that will wait for the
393 // specified number of downloads to finish. 393 // specified number of downloads to finish.
394 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { 394 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) {
395 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 395 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
396 return new DownloadTestObserver( 396 return new DownloadTestObserver(
397 download_manager, num_downloads, 397 download_manager, num_downloads,
398 DownloadItem::COMPLETE, // Really done
399 true, // Bail on select file 398 true, // Bail on select file
400 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 399 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
401 } 400 }
402 401
403 // Create a DownloadTestObserver that will wait for the 402 // Create a DownloadTestObserver that will wait for the
404 // specified number of downloads to start. 403 // specified number of downloads to start.
405 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, 404 DownloadTestObserver* CreateInProgressWaiter(Browser* browser,
406 int num_downloads) { 405 int num_downloads) {
407 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 406 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
408 return new DownloadTestObserver( 407 return new DownloadTestObserverInProgress(
409 download_manager, num_downloads, 408 download_manager, num_downloads);
410 DownloadItem::IN_PROGRESS, // Has started
411 true, // Bail on select file
412 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
413 } 409 }
414 410
415 // Create a DownloadTestObserver that will wait for the 411 // Create a DownloadTestObserver that will wait for the
416 // specified number of downloads to finish, or for 412 // specified number of downloads to finish, or for
417 // a dangerous download warning to be shown. 413 // a dangerous download warning to be shown.
418 DownloadTestObserver* DangerousInstallWaiter( 414 DownloadTestObserver* DangerousInstallWaiter(
419 Browser* browser, 415 Browser* browser,
420 int num_downloads, 416 int num_downloads,
421 DownloadItem::DownloadState final_state,
422 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { 417 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) {
423 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 418 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
424 return new DownloadTestObserver( 419 return new DownloadTestObserver(
425 download_manager, num_downloads, 420 download_manager, num_downloads,
426 final_state,
427 true, // Bail on select file 421 true, // Bail on select file
428 dangerous_download_action); 422 dangerous_download_action);
429 } 423 }
430 424
431 // Download |url|, then wait for the download to finish. 425 // Download |url|, then wait for the download to finish.
432 // |disposition| indicates where the navigation occurs (current tab, new 426 // |disposition| indicates where the navigation occurs (current tab, new
433 // foreground tab, etc). 427 // foreground tab, etc).
434 // |expectation| indicates whether or not a Select File dialog should be 428 // |expectation| indicates whether or not a Select File dialog should be
435 // open when the download is finished, or if we don't care. 429 // open when the download is finished, or if we don't care.
436 // If the dialog appears, the routine exits. The only effect |expectation| 430 // If the dialog appears, the routine exits. The only effect |expectation|
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 std::string server_path = "files/downloads/"; 684 std::string server_path = "files/downloads/";
691 server_path += download_info.url_name; 685 server_path += download_info.url_name;
692 GURL url = test_server()->GetURL(server_path); 686 GURL url = test_server()->GetURL(server_path);
693 ASSERT_TRUE(url.is_valid()); 687 ASSERT_TRUE(url.is_valid());
694 688
695 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 689 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
696 scoped_ptr<DownloadTestObserver> observer( 690 scoped_ptr<DownloadTestObserver> observer(
697 new DownloadTestObserver( 691 new DownloadTestObserver(
698 download_manager, 692 download_manager,
699 1, 693 1,
700 download_info.reason == DOWNLOAD_INTERRUPT_REASON_NONE ?
701 DownloadItem::COMPLETE : // Really done
702 DownloadItem::INTERRUPTED,
703 true, // Bail on select file 694 true, // Bail on select file
704 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 695 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
705 696
706 if (download_info.download_method == DOWNLOAD_DIRECT) { 697 if (download_info.download_method == DOWNLOAD_DIRECT) {
707 // Go directly to download. 698 // Go directly to download.
708 WebContents* web_contents = browser()->GetSelectedWebContents(); 699 WebContents* web_contents = browser()->GetSelectedWebContents();
709 ASSERT_TRUE(web_contents); 700 ASSERT_TRUE(web_contents);
710 DownloadSaveInfo save_info; 701 DownloadSaveInfo save_info;
711 save_info.prompt_for_save_location = false; 702 save_info.prompt_for_save_location = false;
712 703
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 786 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
796 787
797 NullSelectFile(browser()); 788 NullSelectFile(browser());
798 789
799 // Download the file and wait. We expect the Select File dialog to appear 790 // Download the file and wait. We expect the Select File dialog to appear
800 // due to the MIME type, but we still wait until the download completes. 791 // due to the MIME type, but we still wait until the download completes.
801 scoped_ptr<DownloadTestObserver> observer( 792 scoped_ptr<DownloadTestObserver> observer(
802 new DownloadTestObserver( 793 new DownloadTestObserver(
803 DownloadManagerForBrowser(browser()), 794 DownloadManagerForBrowser(browser()),
804 1, 795 1,
805 DownloadItem::COMPLETE, // Really done
806 false, // Continue on select file. 796 false, // Continue on select file.
807 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 797 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
808 ui_test_utils::NavigateToURLWithDisposition( 798 ui_test_utils::NavigateToURLWithDisposition(
809 browser(), url, CURRENT_TAB, 799 browser(), url, CURRENT_TAB,
810 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 800 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
811 observer->WaitForFinished(); 801 observer->WaitForFinished();
812 EXPECT_TRUE(observer->select_file_dialog_seen()); 802 EXPECT_TRUE(observer->select_file_dialog_seen());
813 803
814 // Check state. 804 // Check state.
815 EXPECT_EQ(1, browser()->tab_count()); 805 EXPECT_EQ(1, browser()->tab_count());
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 } 1535 }
1546 1536
1547 // Download an extension. Expect a dangerous download warning. 1537 // Download an extension. Expect a dangerous download warning.
1548 // Deny the download. 1538 // Deny the download.
1549 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { 1539 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) {
1550 ASSERT_TRUE(InitialSetup(false)); 1540 ASSERT_TRUE(InitialSetup(false));
1551 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1541 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1552 1542
1553 scoped_ptr<DownloadTestObserver> observer( 1543 scoped_ptr<DownloadTestObserver> observer(
1554 DangerousInstallWaiter( 1544 DangerousInstallWaiter(
1555 browser(), 1, DownloadItem::CANCELLED, 1545 browser(), 1,
1556 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 1546 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
1557 ui_test_utils::NavigateToURL(browser(), extension_url); 1547 ui_test_utils::NavigateToURL(browser(), extension_url);
1558 1548
1559 observer->WaitForFinished(); 1549 observer->WaitForFinished();
1560 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1550 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1561 1551
1562 // Download shelf should close. Download panel stays open on ChromeOS. 1552 // Download shelf should close. Download panel stays open on ChromeOS.
1563 CheckDownloadUI(browser(), false, true, FilePath()); 1553 CheckDownloadUI(browser(), false, true, FilePath());
1564 1554
1565 // Check that the CRX is not installed. 1555 // Check that the CRX is not installed.
1566 ExtensionService* extension_service = 1556 ExtensionService* extension_service =
1567 browser()->profile()->GetExtensionService(); 1557 browser()->profile()->GetExtensionService();
1568 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1558 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1569 } 1559 }
1570 1560
1571 // Download an extension. Expect a dangerous download warning. 1561 // Download an extension. Expect a dangerous download warning.
1572 // Allow the download, deny the install. 1562 // Allow the download, deny the install.
1573 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { 1563 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) {
1574 ASSERT_TRUE(InitialSetup(false)); 1564 ASSERT_TRUE(InitialSetup(false));
1575 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1565 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1576 1566
1577 // Install a mock install UI that simulates a user denying permission to 1567 // Install a mock install UI that simulates a user denying permission to
1578 // finish the install. 1568 // finish the install.
1579 download_crx_util::SetMockInstallUIForTesting( 1569 download_crx_util::SetMockInstallUIForTesting(
1580 new MockAbortExtensionInstallUI()); 1570 new MockAbortExtensionInstallUI());
1581 1571
1582 scoped_ptr<DownloadTestObserver> observer( 1572 scoped_ptr<DownloadTestObserver> observer(
1583 DangerousInstallWaiter( 1573 DangerousInstallWaiter(
1584 browser(), 1, DownloadItem::COMPLETE, 1574 browser(), 1,
1585 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1575 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1586 ui_test_utils::NavigateToURL(browser(), extension_url); 1576 ui_test_utils::NavigateToURL(browser(), extension_url);
1587 1577
1588 observer->WaitForFinished(); 1578 observer->WaitForFinished();
1589 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1579 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1590 1580
1591 // Download shelf should close. Download panel stays open on ChromeOS. 1581 // Download shelf should close. Download panel stays open on ChromeOS.
1592 CheckDownloadUI(browser(), false, true, FilePath()); 1582 CheckDownloadUI(browser(), false, true, FilePath());
1593 1583
1594 // Check that the extension was not installed. 1584 // Check that the extension was not installed.
1595 ExtensionService* extension_service = 1585 ExtensionService* extension_service =
1596 browser()->profile()->GetExtensionService(); 1586 browser()->profile()->GetExtensionService();
1597 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1587 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1598 } 1588 }
1599 1589
1600 // Download an extension. Expect a dangerous download warning. 1590 // Download an extension. Expect a dangerous download warning.
1601 // Allow the download, and the install. 1591 // Allow the download, and the install.
1602 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { 1592 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) {
1603 ASSERT_TRUE(InitialSetup(false)); 1593 ASSERT_TRUE(InitialSetup(false));
1604 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1594 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1605 1595
1606 // Install a mock install UI that simulates a user allowing permission to 1596 // Install a mock install UI that simulates a user allowing permission to
1607 // finish the install. 1597 // finish the install.
1608 download_crx_util::SetMockInstallUIForTesting( 1598 download_crx_util::SetMockInstallUIForTesting(
1609 new MockAutoConfirmExtensionInstallUI(browser()->profile())); 1599 new MockAutoConfirmExtensionInstallUI(browser()->profile()));
1610 1600
1611 scoped_ptr<DownloadTestObserver> observer( 1601 scoped_ptr<DownloadTestObserver> observer(
1612 DangerousInstallWaiter( 1602 DangerousInstallWaiter(
1613 browser(), 1, DownloadItem::COMPLETE, 1603 browser(), 1,
1614 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1604 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1615 ui_test_utils::NavigateToURL(browser(), extension_url); 1605 ui_test_utils::NavigateToURL(browser(), extension_url);
1616 1606
1617 observer->WaitForFinished(); 1607 observer->WaitForFinished();
1618 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1608 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1619 1609
1620 // Download shelf should close. Download panel stays open on ChromeOS. 1610 // Download shelf should close. Download panel stays open on ChromeOS.
1621 CheckDownloadUI(browser(), false, true, FilePath()); 1611 CheckDownloadUI(browser(), false, true, FilePath());
1622 1612
1623 // Check that the extension was installed. 1613 // Check that the extension was installed.
1624 ExtensionService* extension_service = 1614 ExtensionService* extension_service =
1625 browser()->profile()->GetExtensionService(); 1615 browser()->profile()->GetExtensionService();
1626 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1616 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
1627 } 1617 }
1628 1618
1629 // Test installing a CRX that fails integrity checks. 1619 // Test installing a CRX that fails integrity checks.
1630 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1620 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
1631 ASSERT_TRUE(InitialSetup(false)); 1621 ASSERT_TRUE(InitialSetup(false));
1632 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); 1622 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx"));
1633 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1623 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file));
1634 1624
1635 // Install a mock install UI that simulates a user allowing permission to 1625 // Install a mock install UI that simulates a user allowing permission to
1636 // finish the install, and dismisses any error message. We check that the 1626 // finish the install, and dismisses any error message. We check that the
1637 // install failed below. 1627 // install failed below.
1638 download_crx_util::SetMockInstallUIForTesting( 1628 download_crx_util::SetMockInstallUIForTesting(
1639 new MockAutoConfirmExtensionInstallUI(browser()->profile())); 1629 new MockAutoConfirmExtensionInstallUI(browser()->profile()));
1640 1630
1641 scoped_ptr<DownloadTestObserver> observer( 1631 scoped_ptr<DownloadTestObserver> observer(
1642 DangerousInstallWaiter( 1632 DangerousInstallWaiter(
1643 browser(), 1, DownloadItem::COMPLETE, 1633 browser(), 1,
1644 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1634 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1645 ui_test_utils::NavigateToURL(browser(), extension_url); 1635 ui_test_utils::NavigateToURL(browser(), extension_url);
1646 1636
1647 observer->WaitForFinished(); 1637 observer->WaitForFinished();
1648 1638
1649 // Check that the extension was not installed. 1639 // Check that the extension was not installed.
1650 ExtensionService* extension_service = 1640 ExtensionService* extension_service =
1651 browser()->profile()->GetExtensionService(); 1641 browser()->profile()->GetExtensionService();
1652 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1642 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1653 } 1643 }
1654 1644
1655 // Install a large (100kb) theme. 1645 // Install a large (100kb) theme.
1656 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { 1646 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) {
1657 ASSERT_TRUE(InitialSetup(false)); 1647 ASSERT_TRUE(InitialSetup(false));
1658 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); 1648 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath));
1659 1649
1660 // Install a mock install UI that simulates a user allowing permission to 1650 // Install a mock install UI that simulates a user allowing permission to
1661 // finish the install. 1651 // finish the install.
1662 download_crx_util::SetMockInstallUIForTesting( 1652 download_crx_util::SetMockInstallUIForTesting(
1663 new MockAutoConfirmExtensionInstallUI(browser()->profile())); 1653 new MockAutoConfirmExtensionInstallUI(browser()->profile()));
1664 1654
1665 scoped_ptr<DownloadTestObserver> observer( 1655 scoped_ptr<DownloadTestObserver> observer(
1666 DangerousInstallWaiter( 1656 DangerousInstallWaiter(
1667 browser(), 1, DownloadItem::COMPLETE, 1657 browser(), 1,
1668 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 1658 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1669 ui_test_utils::NavigateToURL(browser(), extension_url); 1659 ui_test_utils::NavigateToURL(browser(), extension_url);
1670 1660
1671 observer->WaitForFinished(); 1661 observer->WaitForFinished();
1672 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1662 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1673 1663
1674 // Download shelf should close. Download panel stays open on ChromeOS. 1664 // Download shelf should close. Download panel stays open on ChromeOS.
1675 CheckDownloadUI(browser(), false, true, FilePath()); 1665 CheckDownloadUI(browser(), false, true, FilePath());
1676 1666
1677 // Check that the extension was installed. 1667 // Check that the extension was installed.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 1810
1821 // DownloadUrl always prompts; return acceptance of whatever it prompts. 1811 // DownloadUrl always prompts; return acceptance of whatever it prompts.
1822 NullSelectFile(browser()); 1812 NullSelectFile(browser());
1823 1813
1824 WebContents* web_contents = browser()->GetSelectedWebContents(); 1814 WebContents* web_contents = browser()->GetSelectedWebContents();
1825 ASSERT_TRUE(web_contents); 1815 ASSERT_TRUE(web_contents);
1826 1816
1827 DownloadTestObserver* observer( 1817 DownloadTestObserver* observer(
1828 new DownloadTestObserver( 1818 new DownloadTestObserver(
1829 DownloadManagerForBrowser(browser()), 1, 1819 DownloadManagerForBrowser(browser()), 1,
1830 DownloadItem::COMPLETE, // Really done
1831 false, // Ignore select file. 1820 false, // Ignore select file.
1832 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1821 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1833 DownloadSaveInfo save_info; 1822 DownloadSaveInfo save_info;
1834 save_info.prompt_for_save_location = true; 1823 save_info.prompt_for_save_location = true;
1835 DownloadManagerForBrowser(browser())->DownloadUrl( 1824 DownloadManagerForBrowser(browser())->DownloadUrl(
1836 url, GURL(""), "", false, -1, save_info, web_contents); 1825 url, GURL(""), "", false, -1, save_info, web_contents);
1837 observer->WaitForFinished(); 1826 observer->WaitForFinished();
1838 EXPECT_TRUE(observer->select_file_dialog_seen()); 1827 EXPECT_TRUE(observer->select_file_dialog_seen());
1839 1828
1840 // Check state. 1829 // Check state.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 GURL url = test_server()->GetURL("files/downloads/image.jpg"); 1877 GURL url = test_server()->GetURL("files/downloads/image.jpg");
1889 ASSERT_TRUE(url.is_valid()); 1878 ASSERT_TRUE(url.is_valid());
1890 ui_test_utils::NavigateToURL(browser(), url); 1879 ui_test_utils::NavigateToURL(browser(), url);
1891 1880
1892 // Stop the test server, and then try to save the page. If cache validation 1881 // Stop the test server, and then try to save the page. If cache validation
1893 // is not bypassed then this will fail since the server is no longer 1882 // is not bypassed then this will fail since the server is no longer
1894 // reachable. 1883 // reachable.
1895 ASSERT_TRUE(test_server()->Stop()); 1884 ASSERT_TRUE(test_server()->Stop());
1896 scoped_ptr<DownloadTestObserver> waiter( 1885 scoped_ptr<DownloadTestObserver> waiter(
1897 new DownloadTestObserver( 1886 new DownloadTestObserver(
1898 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, 1887 DownloadManagerForBrowser(browser()), 1,
1899 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1888 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1900 browser()->SavePage(); 1889 browser()->SavePage();
1901 waiter->WaitForFinished(); 1890 waiter->WaitForFinished();
1902 1891
1903 // Validate that the correct file was downloaded. 1892 // Validate that the correct file was downloaded.
1904 GetDownloads(browser(), &download_items); 1893 GetDownloads(browser(), &download_items);
1905 EXPECT_TRUE(waiter->select_file_dialog_seen()); 1894 EXPECT_TRUE(waiter->select_file_dialog_seen());
1906 ASSERT_EQ(1u, download_items.size()); 1895 ASSERT_EQ(1u, download_items.size());
1907 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); 1896 ASSERT_EQ(url, download_items[0]->GetOriginalUrl());
1897 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState());
1908 1898
1909 // Try to download it via a context menu. 1899 // Try to download it via a context menu.
1910 scoped_ptr<DownloadTestObserver> waiter_context_menu( 1900 scoped_ptr<DownloadTestObserver> waiter_context_menu(
1911 new DownloadTestObserver( 1901 new DownloadTestObserver(
1912 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, 1902 DownloadManagerForBrowser(browser()), 1,
1913 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1903 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1914 content::ContextMenuParams context_menu_params; 1904 content::ContextMenuParams context_menu_params;
1915 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; 1905 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
1916 context_menu_params.src_url = url; 1906 context_menu_params.src_url = url;
1917 context_menu_params.page_url = url; 1907 context_menu_params.page_url = url;
1918 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(), 1908 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(),
1919 context_menu_params); 1909 context_menu_params);
1920 menu.Init(); 1910 menu.Init();
1921 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); 1911 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS);
1922 waiter_context_menu->WaitForFinished(); 1912 waiter_context_menu->WaitForFinished();
1923 1913
1924 // Validate that the correct file was downloaded via the context menu. 1914 // Validate that the correct file was downloaded via the context menu.
1925 download_items.clear(); 1915 download_items.clear();
1926 GetDownloads(browser(), &download_items); 1916 GetDownloads(browser(), &download_items);
1927 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); 1917 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen());
1918 EXPECT_EQ(DownloadItem::COMPLETE, download_items[0]->GetState());
1928 ASSERT_EQ(2u, download_items.size()); 1919 ASSERT_EQ(2u, download_items.size());
1929 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); 1920 ASSERT_EQ(url, download_items[0]->GetOriginalUrl());
1930 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); 1921 ASSERT_EQ(url, download_items[1]->GetOriginalUrl());
1922 EXPECT_EQ(DownloadItem::COMPLETE, download_items[1]->GetState());
1931 } 1923 }
1932 1924
1933 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { 1925 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) {
1934 // Do initial setup. 1926 // Do initial setup.
1935 ASSERT_TRUE(InitialSetup(false)); 1927 ASSERT_TRUE(InitialSetup(false));
1936 ASSERT_TRUE(test_server()->Start()); 1928 ASSERT_TRUE(test_server()->Start());
1937 NullSelectFile(browser()); 1929 NullSelectFile(browser());
1938 std::vector<DownloadItem*> download_items; 1930 std::vector<DownloadItem*> download_items;
1939 GetDownloads(browser(), &download_items); 1931 GetDownloads(browser(), &download_items);
1940 ASSERT_TRUE(download_items.empty()); 1932 ASSERT_TRUE(download_items.empty());
(...skipping 22 matching lines...) Expand all
1963 observer.Wait(); 1955 observer.Wait();
1964 EXPECT_EQ(jpeg_url, web_contents->GetURL()); 1956 EXPECT_EQ(jpeg_url, web_contents->GetURL());
1965 1957
1966 // Stop the test server, and then try to save the page. If cache validation 1958 // Stop the test server, and then try to save the page. If cache validation
1967 // is not bypassed then this will fail since the server is no longer 1959 // is not bypassed then this will fail since the server is no longer
1968 // reachable. This will also fail if it tries to be retrieved via "GET" 1960 // reachable. This will also fail if it tries to be retrieved via "GET"
1969 // rather than "POST". 1961 // rather than "POST".
1970 ASSERT_TRUE(test_server()->Stop()); 1962 ASSERT_TRUE(test_server()->Stop());
1971 scoped_ptr<DownloadTestObserver> waiter( 1963 scoped_ptr<DownloadTestObserver> waiter(
1972 new DownloadTestObserver( 1964 new DownloadTestObserver(
1973 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, 1965 DownloadManagerForBrowser(browser()), 1,
1974 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1966 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1975 browser()->SavePage(); 1967 browser()->SavePage();
1976 waiter->WaitForFinished(); 1968 waiter->WaitForFinished();
1977 1969
1978 // Validate that the correct file was downloaded. 1970 // Validate that the correct file was downloaded.
1979 GetDownloads(browser(), &download_items); 1971 GetDownloads(browser(), &download_items);
1980 EXPECT_TRUE(waiter->select_file_dialog_seen()); 1972 EXPECT_TRUE(waiter->select_file_dialog_seen());
1981 ASSERT_EQ(1u, download_items.size()); 1973 ASSERT_EQ(1u, download_items.size());
1982 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 1974 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
1983 1975
1984 // Try to download it via a context menu. 1976 // Try to download it via a context menu.
1985 scoped_ptr<DownloadTestObserver> waiter_context_menu( 1977 scoped_ptr<DownloadTestObserver> waiter_context_menu(
1986 new DownloadTestObserver( 1978 new DownloadTestObserver(
1987 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, 1979 DownloadManagerForBrowser(browser()), 1,
1988 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1980 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1989 content::ContextMenuParams context_menu_params; 1981 content::ContextMenuParams context_menu_params;
1990 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; 1982 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
1991 context_menu_params.src_url = jpeg_url; 1983 context_menu_params.src_url = jpeg_url;
1992 context_menu_params.page_url = jpeg_url; 1984 context_menu_params.page_url = jpeg_url;
1993 TestRenderViewContextMenu menu(web_contents, context_menu_params); 1985 TestRenderViewContextMenu menu(web_contents, context_menu_params);
1994 menu.Init(); 1986 menu.Init();
1995 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); 1987 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS);
1996 waiter_context_menu->WaitForFinished(); 1988 waiter_context_menu->WaitForFinished();
1997 1989
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 "zip_file_not_found.zip", 2066 "zip_file_not_found.zip",
2075 DOWNLOAD_NAVIGATE, 2067 DOWNLOAD_NAVIGATE,
2076 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, 2068 DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
2077 false 2069 false
2078 }; 2070 };
2079 2071
2080 // Do initial setup. 2072 // Do initial setup.
2081 ASSERT_TRUE(InitialSetup(false)); 2073 ASSERT_TRUE(InitialSetup(false));
2082 DownloadFileCheckErrors(download_info); 2074 DownloadFileCheckErrors(download_info);
2083 } 2075 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_extension_test.cc » ('j') | chrome/browser/download/download_test_observer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698