OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/download/download_browsertest.h" | 5 #include "chrome/browser/download/download_browsertest.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 observer->WaitForFinished(); | 598 observer->WaitForFinished(); |
599 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 599 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
600 // We don't expect a file chooser to be shown. | 600 // We don't expect a file chooser to be shown. |
601 EXPECT_FALSE(DidShowFileChooser()); | 601 EXPECT_FALSE(DidShowFileChooser()); |
602 } | 602 } |
603 | 603 |
604 // Download a file in the current tab, then wait for the download to finish. | 604 // Download a file in the current tab, then wait for the download to finish. |
605 void DownloadAndWait(Browser* browser, | 605 void DownloadAndWait(Browser* browser, |
606 const GURL& url) { | 606 const GURL& url) { |
607 DownloadAndWaitWithDisposition( | 607 DownloadAndWaitWithDisposition( |
608 browser, | 608 browser, url, WindowOpenDisposition::CURRENT_TAB, |
609 url, | |
610 CURRENT_TAB, | |
611 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 609 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
612 } | 610 } |
613 | 611 |
614 // Should only be called when the download is known to have finished | 612 // Should only be called when the download is known to have finished |
615 // (in error or not). | 613 // (in error or not). |
616 // Returning false indicates a failure of the function, and should be asserted | 614 // Returning false indicates a failure of the function, and should be asserted |
617 // in the caller. | 615 // in the caller. |
618 bool CheckDownload(Browser* browser, | 616 bool CheckDownload(Browser* browser, |
619 const base::FilePath& downloaded_filename, | 617 const base::FilePath& downloaded_filename, |
620 const base::FilePath& origin_filename) { | 618 const base::FilePath& origin_filename) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 // - Add a member function to |DownloadShelf| to get the status text | 724 // - Add a member function to |DownloadShelf| to get the status text |
727 // of a given member (for example, via the name in |DownloadItemView|'s | 725 // of a given member (for example, via the name in |DownloadItemView|'s |
728 // GetAccessibleState() member function), by index. | 726 // GetAccessibleState() member function), by index. |
729 // - Iterate over browser->window()->GetDownloadShelf()'s members | 727 // - Iterate over browser->window()->GetDownloadShelf()'s members |
730 // to see if any match the status text we want. Start with the last one. | 728 // to see if any match the status text we want. Start with the last one. |
731 | 729 |
732 // Allow the request to finish. We do this by loading a second URL in a | 730 // Allow the request to finish. We do this by loading a second URL in a |
733 // separate tab. | 731 // separate tab. |
734 GURL finish_url(net::URLRequestSlowDownloadJob::kFinishDownloadUrl); | 732 GURL finish_url(net::URLRequestSlowDownloadJob::kFinishDownloadUrl); |
735 ui_test_utils::NavigateToURLWithDisposition( | 733 ui_test_utils::NavigateToURLWithDisposition( |
736 browser, | 734 browser, finish_url, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
737 finish_url, | |
738 NEW_FOREGROUND_TAB, | |
739 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 735 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
740 observer->WaitForFinished(); | 736 observer->WaitForFinished(); |
741 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 737 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
742 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE); | 738 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE); |
743 | 739 |
744 EXPECT_EQ(2, browser->tab_strip_model()->count()); | 740 EXPECT_EQ(2, browser->tab_strip_model()->count()); |
745 | 741 |
746 // TODO(ahendrickson): check download status text after downloading. | 742 // TODO(ahendrickson): check download status text after downloading. |
747 | 743 |
748 base::FilePath basefilename(filename.BaseName()); | 744 base::FilePath basefilename(filename.BaseName()); |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 EXPECT_TRUE(base::GetFileSize(origin, &origin_file_size)); | 1439 EXPECT_TRUE(base::GetFileSize(origin, &origin_file_size)); |
1444 std::string original_contents; | 1440 std::string original_contents; |
1445 EXPECT_TRUE(base::ReadFileToString(origin, &original_contents)); | 1441 EXPECT_TRUE(base::ReadFileToString(origin, &original_contents)); |
1446 | 1442 |
1447 std::vector<DownloadItem*> download_items; | 1443 std::vector<DownloadItem*> download_items; |
1448 GetDownloads(browser(), &download_items); | 1444 GetDownloads(browser(), &download_items); |
1449 ASSERT_TRUE(download_items.empty()); | 1445 ASSERT_TRUE(download_items.empty()); |
1450 | 1446 |
1451 // Download a file in the on-record browser and check that it was downloaded | 1447 // Download a file in the on-record browser and check that it was downloaded |
1452 // correctly. | 1448 // correctly. |
1453 DownloadAndWaitWithDisposition(browser(), | 1449 DownloadAndWaitWithDisposition(browser(), url, |
1454 url, | 1450 WindowOpenDisposition::CURRENT_TAB, |
1455 CURRENT_TAB, | |
1456 ui_test_utils::BROWSER_TEST_NONE); | 1451 ui_test_utils::BROWSER_TEST_NONE); |
1457 GetDownloads(browser(), &download_items); | 1452 GetDownloads(browser(), &download_items); |
1458 ASSERT_EQ(1UL, download_items.size()); | 1453 ASSERT_EQ(1UL, download_items.size()); |
1459 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file.zip")), | 1454 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file.zip")), |
1460 download_items[0]->GetTargetFilePath().BaseName()); | 1455 download_items[0]->GetTargetFilePath().BaseName()); |
1461 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); | 1456 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); |
1462 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), | 1457 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), |
1463 original_contents, origin_file_size)); | 1458 original_contents, origin_file_size)); |
1464 | 1459 |
1465 // Setup an incognito window. | 1460 // Setup an incognito window. |
1466 Browser* incognito = CreateIncognitoBrowser(); | 1461 Browser* incognito = CreateIncognitoBrowser(); |
1467 ASSERT_TRUE(incognito); | 1462 ASSERT_TRUE(incognito); |
1468 int window_count = BrowserList::GetInstance()->size(); | 1463 int window_count = BrowserList::GetInstance()->size(); |
1469 EXPECT_EQ(2, window_count); | 1464 EXPECT_EQ(2, window_count); |
1470 incognito->profile()->GetPrefs()->SetFilePath( | 1465 incognito->profile()->GetPrefs()->SetFilePath( |
1471 prefs::kDownloadDefaultDirectory, | 1466 prefs::kDownloadDefaultDirectory, |
1472 GetDownloadsDirectory()); | 1467 GetDownloadsDirectory()); |
1473 incognito->profile()->GetPrefs()->SetFilePath( | 1468 incognito->profile()->GetPrefs()->SetFilePath( |
1474 prefs::kSaveFileDefaultDirectory, | 1469 prefs::kSaveFileDefaultDirectory, |
1475 GetDownloadsDirectory()); | 1470 GetDownloadsDirectory()); |
1476 | 1471 |
1477 download_items.clear(); | 1472 download_items.clear(); |
1478 GetDownloads(incognito, &download_items); | 1473 GetDownloads(incognito, &download_items); |
1479 ASSERT_TRUE(download_items.empty()); | 1474 ASSERT_TRUE(download_items.empty()); |
1480 | 1475 |
1481 // Download a file in the incognito browser and check that it was downloaded | 1476 // Download a file in the incognito browser and check that it was downloaded |
1482 // correctly. | 1477 // correctly. |
1483 DownloadAndWaitWithDisposition(incognito, | 1478 DownloadAndWaitWithDisposition(incognito, url, |
1484 url, | 1479 WindowOpenDisposition::CURRENT_TAB, |
1485 CURRENT_TAB, | |
1486 ui_test_utils::BROWSER_TEST_NONE); | 1480 ui_test_utils::BROWSER_TEST_NONE); |
1487 GetDownloads(incognito, &download_items); | 1481 GetDownloads(incognito, &download_items); |
1488 ASSERT_EQ(1UL, download_items.size()); | 1482 ASSERT_EQ(1UL, download_items.size()); |
1489 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file (1).zip")), | 1483 ASSERT_EQ(base::FilePath(FILE_PATH_LITERAL("a_zip_file (1).zip")), |
1490 download_items[0]->GetTargetFilePath().BaseName()); | 1484 download_items[0]->GetTargetFilePath().BaseName()); |
1491 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); | 1485 ASSERT_TRUE(base::PathExists(download_items[0]->GetTargetFilePath())); |
1492 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), | 1486 EXPECT_TRUE(VerifyFile(download_items[0]->GetTargetFilePath(), |
1493 original_contents, origin_file_size)); | 1487 original_contents, origin_file_size)); |
1494 } | 1488 } |
1495 | 1489 |
1496 // Navigate to a new background page, but don't download. | 1490 // Navigate to a new background page, but don't download. |
1497 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { | 1491 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { |
1498 // Because it's an HTML link, it should open a web page rather than | 1492 // Because it's an HTML link, it should open a web page rather than |
1499 // downloading. | 1493 // downloading. |
1500 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test2.html")); | 1494 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test2.html")); |
1501 | 1495 |
1502 // Open a web page and wait. | 1496 // Open a web page and wait. |
1503 ui_test_utils::NavigateToURLWithDisposition( | 1497 ui_test_utils::NavigateToURLWithDisposition( |
1504 browser(), | 1498 browser(), url, WindowOpenDisposition::NEW_BACKGROUND_TAB, |
1505 url, | |
1506 NEW_BACKGROUND_TAB, | |
1507 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1499 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1508 | 1500 |
1509 // We should have two tabs now. | 1501 // We should have two tabs now. |
1510 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1502 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
1511 EXPECT_TRUE(VerifyNoDownloads()); | 1503 EXPECT_TRUE(VerifyNoDownloads()); |
1512 } | 1504 } |
1513 | 1505 |
1514 // Download a file in a background tab. Verify that the tab is closed | 1506 // Download a file in a background tab. Verify that the tab is closed |
1515 // automatically. | 1507 // automatically. |
1516 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { | 1508 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { |
1517 // Download a file in a new background tab and wait. The tab is automatically | 1509 // Download a file in a new background tab and wait. The tab is automatically |
1518 // closed when the download begins. | 1510 // closed when the download begins. |
1519 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); | 1511 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
1520 DownloadAndWaitWithDisposition( | 1512 DownloadAndWaitWithDisposition(browser(), url, |
1521 browser(), | 1513 WindowOpenDisposition::NEW_BACKGROUND_TAB, 0); |
1522 url, | |
1523 NEW_BACKGROUND_TAB, | |
1524 0); | |
1525 | 1514 |
1526 // When the download finishes, we should still have one tab. | 1515 // When the download finishes, we should still have one tab. |
1527 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1516 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
1528 | 1517 |
1529 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1518 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1530 CheckDownload(browser(), file, file); | 1519 CheckDownload(browser(), file, file); |
1531 } | 1520 } |
1532 | 1521 |
1533 // Open a web page in the current tab, then download a file in another tab via | 1522 // Open a web page in the current tab, then download a file in another tab via |
1534 // a Javascript call. | 1523 // a Javascript call. |
1535 // Verify that we have 2 tabs. | 1524 // Verify that we have 2 tabs. |
1536 // | 1525 // |
1537 // The download_page1.html page contains an openNew() function that opens a | 1526 // The download_page1.html page contains an openNew() function that opens a |
1538 // tab and then downloads download-test1.lib. | 1527 // tab and then downloads download-test1.lib. |
1539 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) { | 1528 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab2) { |
1540 // Because it's an HTML link, it should open a web page rather than | 1529 // Because it's an HTML link, it should open a web page rather than |
1541 // downloading. | 1530 // downloading. |
1542 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page1.html")); | 1531 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page1.html")); |
1543 | 1532 |
1544 // Open a web page and wait. | 1533 // Open a web page and wait. |
1545 ui_test_utils::NavigateToURL(browser(), url); | 1534 ui_test_utils::NavigateToURL(browser(), url); |
1546 | 1535 |
1547 // Download a file in a new tab and wait (via Javascript). | 1536 // Download a file in a new tab and wait (via Javascript). |
1548 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1537 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1549 DownloadAndWaitWithDisposition(browser(), | 1538 DownloadAndWaitWithDisposition(browser(), GURL("javascript:openNew()"), |
1550 GURL("javascript:openNew()"), | 1539 WindowOpenDisposition::CURRENT_TAB, |
1551 CURRENT_TAB, | |
1552 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1540 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1553 | 1541 |
1554 // When the download finishes, we should have two tabs. | 1542 // When the download finishes, we should have two tabs. |
1555 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1543 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
1556 | 1544 |
1557 CheckDownload(browser(), file, file); | 1545 CheckDownload(browser(), file, file); |
1558 } | 1546 } |
1559 | 1547 |
1560 // Open a web page in the current tab, open another tab via a Javascript call, | 1548 // Open a web page in the current tab, open another tab via a Javascript call, |
1561 // then download a file in the new tab. | 1549 // then download a file in the new tab. |
1562 // Verify that we have 2 tabs. | 1550 // Verify that we have 2 tabs. |
1563 // | 1551 // |
1564 // The download_page2.html page contains an openNew() function that opens a | 1552 // The download_page2.html page contains an openNew() function that opens a |
1565 // tab. | 1553 // tab. |
1566 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) { | 1554 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab3) { |
1567 // Because it's an HTML link, it should open a web page rather than | 1555 // Because it's an HTML link, it should open a web page rather than |
1568 // downloading. | 1556 // downloading. |
1569 GURL url1(URLRequestMockHTTPJob::GetMockUrl("download_page2.html")); | 1557 GURL url1(URLRequestMockHTTPJob::GetMockUrl("download_page2.html")); |
1570 | 1558 |
1571 // Open a web page and wait. | 1559 // Open a web page and wait. |
1572 ui_test_utils::NavigateToURL(browser(), url1); | 1560 ui_test_utils::NavigateToURL(browser(), url1); |
1573 | 1561 |
1574 // Open a new tab and wait. | 1562 // Open a new tab and wait. |
1575 ui_test_utils::NavigateToURLWithDisposition( | 1563 ui_test_utils::NavigateToURLWithDisposition( |
1576 browser(), | 1564 browser(), GURL("javascript:openNew()"), |
1577 GURL("javascript:openNew()"), | 1565 WindowOpenDisposition::CURRENT_TAB, |
1578 CURRENT_TAB, | |
1579 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1566 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1580 | 1567 |
1581 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1568 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
1582 | 1569 |
1583 // Download a file and wait. | 1570 // Download a file and wait. |
1584 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); | 1571 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
1585 DownloadAndWaitWithDisposition(browser(), | 1572 DownloadAndWaitWithDisposition(browser(), url, |
1586 url, | 1573 WindowOpenDisposition::CURRENT_TAB, |
1587 CURRENT_TAB, | |
1588 ui_test_utils::BROWSER_TEST_NONE); | 1574 ui_test_utils::BROWSER_TEST_NONE); |
1589 | 1575 |
1590 // When the download finishes, we should have two tabs. | 1576 // When the download finishes, we should have two tabs. |
1591 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 1577 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
1592 | 1578 |
1593 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1579 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1594 CheckDownload(browser(), file, file); | 1580 CheckDownload(browser(), file, file); |
1595 } | 1581 } |
1596 | 1582 |
1597 // Open a web page in the current tab, then download a file via Javascript, | 1583 // Open a web page in the current tab, then download a file via Javascript, |
1598 // which will do so in a temporary tab. Verify that we have 1 tab. | 1584 // which will do so in a temporary tab. Verify that we have 1 tab. |
1599 // | 1585 // |
1600 // The download_page3.html page contains an openNew() function that opens a | 1586 // The download_page3.html page contains an openNew() function that opens a |
1601 // tab with download-test1.lib in the URL. When the URL is determined to be | 1587 // tab with download-test1.lib in the URL. When the URL is determined to be |
1602 // a download, the tab is closed automatically. | 1588 // a download, the tab is closed automatically. |
1603 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) { | 1589 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab2) { |
1604 // Because it's an HTML link, it should open a web page rather than | 1590 // Because it's an HTML link, it should open a web page rather than |
1605 // downloading. | 1591 // downloading. |
1606 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page3.html")); | 1592 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page3.html")); |
1607 | 1593 |
1608 // Open a web page and wait. | 1594 // Open a web page and wait. |
1609 ui_test_utils::NavigateToURL(browser(), url); | 1595 ui_test_utils::NavigateToURL(browser(), url); |
1610 | 1596 |
1611 // Download a file and wait. | 1597 // Download a file and wait. |
1612 // The file to download is "download-test1.lib". | 1598 // The file to download is "download-test1.lib". |
1613 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1599 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1614 DownloadAndWaitWithDisposition(browser(), | 1600 DownloadAndWaitWithDisposition(browser(), GURL("javascript:openNew()"), |
1615 GURL("javascript:openNew()"), | 1601 WindowOpenDisposition::CURRENT_TAB, |
1616 CURRENT_TAB, | |
1617 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1602 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1618 | 1603 |
1619 // When the download finishes, we should still have one tab. | 1604 // When the download finishes, we should still have one tab. |
1620 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1605 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
1621 | 1606 |
1622 CheckDownload(browser(), file, file); | 1607 CheckDownload(browser(), file, file); |
1623 } | 1608 } |
1624 | 1609 |
1625 // Open a web page in the current tab, then call Javascript via a button to | 1610 // Open a web page in the current tab, then call Javascript via a button to |
1626 // download a file in a new tab, which is closed automatically when the | 1611 // download a file in a new tab, which is closed automatically when the |
1627 // download begins. | 1612 // download begins. |
1628 // Verify that we have 1 tab. | 1613 // Verify that we have 1 tab. |
1629 // | 1614 // |
1630 // The download_page4.html page contains a form with download-test1.lib as the | 1615 // The download_page4.html page contains a form with download-test1.lib as the |
1631 // action. | 1616 // action. |
1632 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) { | 1617 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab3) { |
1633 // Because it's an HTML link, it should open a web page rather than | 1618 // Because it's an HTML link, it should open a web page rather than |
1634 // downloading. | 1619 // downloading. |
1635 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page4.html")); | 1620 GURL url(URLRequestMockHTTPJob::GetMockUrl("download_page4.html")); |
1636 | 1621 |
1637 // Open a web page and wait. | 1622 // Open a web page and wait. |
1638 ui_test_utils::NavigateToURL(browser(), url); | 1623 ui_test_utils::NavigateToURL(browser(), url); |
1639 | 1624 |
1640 // Download a file in a new tab and wait. The tab will automatically close | 1625 // Download a file in a new tab and wait. The tab will automatically close |
1641 // when the download begins. | 1626 // when the download begins. |
1642 // The file to download is "download-test1.lib". | 1627 // The file to download is "download-test1.lib". |
1643 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1628 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1644 DownloadAndWaitWithDisposition( | 1629 DownloadAndWaitWithDisposition( |
1645 browser(), | 1630 browser(), GURL("javascript:document.getElementById('form').submit()"), |
1646 GURL("javascript:document.getElementById('form').submit()"), | 1631 WindowOpenDisposition::CURRENT_TAB, |
1647 CURRENT_TAB, | |
1648 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1632 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1649 | 1633 |
1650 // When the download finishes, we should still have one tab. | 1634 // When the download finishes, we should still have one tab. |
1651 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1635 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
1652 | 1636 |
1653 CheckDownload(browser(), file, file); | 1637 CheckDownload(browser(), file, file); |
1654 } | 1638 } |
1655 | 1639 |
1656 // Open a second tab, then download a file in that tab. However, have the | 1640 // Open a second tab, then download a file in that tab. However, have the |
1657 // download be canceled by having the file picker act like the user canceled | 1641 // download be canceled by having the file picker act like the user canceled |
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2902 } | 2886 } |
2903 } | 2887 } |
2904 | 2888 |
2905 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Remove) { | 2889 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Remove) { |
2906 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); | 2890 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("downloads/a_zip_file.zip"); |
2907 std::vector<DownloadItem*> download_items; | 2891 std::vector<DownloadItem*> download_items; |
2908 GetDownloads(browser(), &download_items); | 2892 GetDownloads(browser(), &download_items); |
2909 ASSERT_TRUE(download_items.empty()); | 2893 ASSERT_TRUE(download_items.empty()); |
2910 | 2894 |
2911 // Download a file. | 2895 // Download a file. |
2912 DownloadAndWaitWithDisposition(browser(), | 2896 DownloadAndWaitWithDisposition(browser(), url, |
2913 url, | 2897 WindowOpenDisposition::CURRENT_TAB, |
2914 CURRENT_TAB, | |
2915 ui_test_utils::BROWSER_TEST_NONE); | 2898 ui_test_utils::BROWSER_TEST_NONE); |
2916 GetDownloads(browser(), &download_items); | 2899 GetDownloads(browser(), &download_items); |
2917 ASSERT_EQ(1UL, download_items.size()); | 2900 ASSERT_EQ(1UL, download_items.size()); |
2918 base::FilePath downloaded(download_items[0]->GetTargetFilePath()); | 2901 base::FilePath downloaded(download_items[0]->GetTargetFilePath()); |
2919 | 2902 |
2920 // Remove the DownloadItem but not the file, then check that the file still | 2903 // Remove the DownloadItem but not the file, then check that the file still |
2921 // exists. | 2904 // exists. |
2922 download_items[0]->Remove(); | 2905 download_items[0]->Remove(); |
2923 download_items.clear(); | 2906 download_items.clear(); |
2924 GetDownloads(browser(), &download_items); | 2907 GetDownloads(browser(), &download_items); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2976 int64_t free_space = | 2959 int64_t free_space = |
2977 base::SysInfo::AmountOfFreeDiskSpace(GetDownloadDirectory(browser())); | 2960 base::SysInfo::AmountOfFreeDiskSpace(GetDownloadDirectory(browser())); |
2978 ASSERT_LE(size, free_space) << "Not enough disk space to download. Got " | 2961 ASSERT_LE(size, free_space) << "Not enough disk space to download. Got " |
2979 << free_space; | 2962 << free_space; |
2980 GURL file_url(net::FilePathToFileURL(file_path)); | 2963 GURL file_url(net::FilePathToFileURL(file_path)); |
2981 std::unique_ptr<content::DownloadTestObserver> progress_waiter( | 2964 std::unique_ptr<content::DownloadTestObserver> progress_waiter( |
2982 CreateInProgressWaiter(browser(), 1)); | 2965 CreateInProgressWaiter(browser(), 1)); |
2983 | 2966 |
2984 // Start downloading a file, wait for it to be created. | 2967 // Start downloading a file, wait for it to be created. |
2985 ui_test_utils::NavigateToURLWithDisposition( | 2968 ui_test_utils::NavigateToURLWithDisposition( |
2986 browser(), file_url, CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE); | 2969 browser(), file_url, WindowOpenDisposition::CURRENT_TAB, |
| 2970 ui_test_utils::BROWSER_TEST_NONE); |
2987 progress_waiter->WaitForFinished(); | 2971 progress_waiter->WaitForFinished(); |
2988 EXPECT_EQ(1u, progress_waiter->NumDownloadsSeenInState( | 2972 EXPECT_EQ(1u, progress_waiter->NumDownloadsSeenInState( |
2989 DownloadItem::IN_PROGRESS)); | 2973 DownloadItem::IN_PROGRESS)); |
2990 std::vector<DownloadItem*> download_items; | 2974 std::vector<DownloadItem*> download_items; |
2991 GetDownloads(browser(), &download_items); | 2975 GetDownloads(browser(), &download_items); |
2992 ASSERT_EQ(1UL, download_items.size()); | 2976 ASSERT_EQ(1UL, download_items.size()); |
2993 | 2977 |
2994 // Wait for the download to complete, checking along the way that the | 2978 // Wait for the download to complete, checking along the way that the |
2995 // PercentComplete() never regresses. | 2979 // PercentComplete() never regresses. |
2996 PercentWaiter waiter(download_items[0]); | 2980 PercentWaiter waiter(download_items[0]); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3226 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 3210 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
3227 true); | 3211 true); |
3228 GURL download_url = | 3212 GURL download_url = |
3229 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath); | 3213 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath); |
3230 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( | 3214 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( |
3231 DangerousDownloadWaiter( | 3215 DangerousDownloadWaiter( |
3232 browser(), 1, | 3216 browser(), 1, |
3233 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3217 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
3234 std::unique_ptr<content::DownloadTestObserver> in_progress_observer( | 3218 std::unique_ptr<content::DownloadTestObserver> in_progress_observer( |
3235 new DisableSafeBrowsingOnInProgressDownload(browser())); | 3219 new DisableSafeBrowsingOnInProgressDownload(browser())); |
3236 ui_test_utils::NavigateToURLWithDisposition(browser(), | 3220 ui_test_utils::NavigateToURLWithDisposition( |
3237 download_url, | 3221 browser(), download_url, WindowOpenDisposition::NEW_BACKGROUND_TAB, |
3238 NEW_BACKGROUND_TAB, | 3222 ui_test_utils::BROWSER_TEST_NONE); |
3239 ui_test_utils::BROWSER_TEST_NONE); | |
3240 in_progress_observer->WaitForFinished(); | 3223 in_progress_observer->WaitForFinished(); |
3241 | 3224 |
3242 // SafeBrowsing should have been disabled by our observer. | 3225 // SafeBrowsing should have been disabled by our observer. |
3243 ASSERT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( | 3226 ASSERT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( |
3244 prefs::kSafeBrowsingEnabled)); | 3227 prefs::kSafeBrowsingEnabled)); |
3245 | 3228 |
3246 std::vector<DownloadItem*> downloads; | 3229 std::vector<DownloadItem*> downloads; |
3247 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 3230 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
3248 ASSERT_EQ(1u, downloads.size()); | 3231 ASSERT_EQ(1u, downloads.size()); |
3249 DownloadItem* download = downloads[0]; | 3232 DownloadItem* download = downloads[0]; |
(...skipping 10 matching lines...) Expand all Loading... |
3260 // Disable SafeBrowsing | 3243 // Disable SafeBrowsing |
3261 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 3244 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
3262 false); | 3245 false); |
3263 | 3246 |
3264 GURL download_url = | 3247 GURL download_url = |
3265 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath); | 3248 net::URLRequestMockHTTPJob::GetMockUrl(kDangerousMockFilePath); |
3266 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( | 3249 std::unique_ptr<content::DownloadTestObserver> dangerous_observer( |
3267 DangerousDownloadWaiter( | 3250 DangerousDownloadWaiter( |
3268 browser(), 1, | 3251 browser(), 1, |
3269 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3252 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
3270 ui_test_utils::NavigateToURLWithDisposition(browser(), | 3253 ui_test_utils::NavigateToURLWithDisposition( |
3271 download_url, | 3254 browser(), download_url, WindowOpenDisposition::NEW_BACKGROUND_TAB, |
3272 NEW_BACKGROUND_TAB, | 3255 ui_test_utils::BROWSER_TEST_NONE); |
3273 ui_test_utils::BROWSER_TEST_NONE); | |
3274 dangerous_observer->WaitForFinished(); | 3256 dangerous_observer->WaitForFinished(); |
3275 | 3257 |
3276 std::vector<DownloadItem*> downloads; | 3258 std::vector<DownloadItem*> downloads; |
3277 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 3259 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
3278 ASSERT_EQ(1u, downloads.size()); | 3260 ASSERT_EQ(1u, downloads.size()); |
3279 | 3261 |
3280 DownloadItem* download = downloads[0]; | 3262 DownloadItem* download = downloads[0]; |
3281 EXPECT_TRUE(download->IsDangerous()); | 3263 EXPECT_TRUE(download->IsDangerous()); |
3282 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 3264 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
3283 download->GetDangerType()); | 3265 download->GetDangerType()); |
(...skipping 20 matching lines...) Expand all Loading... |
3304 | 3286 |
3305 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { | 3287 IN_PROC_BROWSER_TEST_F(DownloadTest, FeedbackService) { |
3306 // Make a dangerous file. | 3288 // Make a dangerous file. |
3307 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( | 3289 GURL download_url(net::URLRequestMockHTTPJob::GetMockUrl( |
3308 "downloads/dangerous/dangerous.swf")); | 3290 "downloads/dangerous/dangerous.swf")); |
3309 std::unique_ptr<content::DownloadTestObserverInterrupted> observer( | 3291 std::unique_ptr<content::DownloadTestObserverInterrupted> observer( |
3310 new content::DownloadTestObserverInterrupted( | 3292 new content::DownloadTestObserverInterrupted( |
3311 DownloadManagerForBrowser(browser()), 1, | 3293 DownloadManagerForBrowser(browser()), 1, |
3312 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); | 3294 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_QUIT)); |
3313 ui_test_utils::NavigateToURLWithDisposition( | 3295 ui_test_utils::NavigateToURLWithDisposition( |
3314 browser(), | 3296 browser(), GURL(download_url), WindowOpenDisposition::NEW_BACKGROUND_TAB, |
3315 GURL(download_url), | |
3316 NEW_BACKGROUND_TAB, | |
3317 ui_test_utils::BROWSER_TEST_NONE); | 3297 ui_test_utils::BROWSER_TEST_NONE); |
3318 observer->WaitForFinished(); | 3298 observer->WaitForFinished(); |
3319 | 3299 |
3320 // Get the download from the DownloadManager. | 3300 // Get the download from the DownloadManager. |
3321 std::vector<DownloadItem*> downloads; | 3301 std::vector<DownloadItem*> downloads; |
3322 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 3302 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
3323 ASSERT_EQ(1u, downloads.size()); | 3303 ASSERT_EQ(1u, downloads.size()); |
3324 EXPECT_TRUE(downloads[0]->IsDangerous()); | 3304 EXPECT_TRUE(downloads[0]->IsDangerous()); |
3325 | 3305 |
3326 // Save fake pings for the download. | 3306 // Save fake pings for the download. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3513 // | 3493 // |
3514 // Regression test for http://crbug.com/44454 | 3494 // Regression test for http://crbug.com/44454 |
3515 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { | 3495 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { |
3516 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); | 3496 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
3517 #if !defined(OS_MACOSX) | 3497 #if !defined(OS_MACOSX) |
3518 // See below. | 3498 // See below. |
3519 Browser* first_browser = browser(); | 3499 Browser* first_browser = browser(); |
3520 #endif | 3500 #endif |
3521 | 3501 |
3522 // Download a file in a new window and wait. | 3502 // Download a file in a new window and wait. |
3523 DownloadAndWaitWithDisposition(browser(), url, NEW_WINDOW, | 3503 DownloadAndWaitWithDisposition(browser(), url, |
| 3504 WindowOpenDisposition::NEW_WINDOW, |
3524 ui_test_utils::BROWSER_TEST_NONE); | 3505 ui_test_utils::BROWSER_TEST_NONE); |
3525 | 3506 |
3526 // When the download finishes, the download shelf SHOULD NOT be visible in | 3507 // When the download finishes, the download shelf SHOULD NOT be visible in |
3527 // the first window. | 3508 // the first window. |
3528 ExpectWindowCountAfterDownload(2); | 3509 ExpectWindowCountAfterDownload(2); |
3529 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 3510 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
3530 // Download shelf should close. | 3511 // Download shelf should close. |
3531 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3512 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
3532 | 3513 |
3533 // The download shelf SHOULD be visible in the second window. | 3514 // The download shelf SHOULD be visible in the second window. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3659 browser(), 1, | 3640 browser(), 1, |
3660 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3641 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
3661 ui_test_utils::NavigateToURL(browser(), extension_url); | 3642 ui_test_utils::NavigateToURL(browser(), extension_url); |
3662 | 3643 |
3663 observer->WaitForFinished(); | 3644 observer->WaitForFinished(); |
3664 | 3645 |
3665 // Download shelf should close. | 3646 // Download shelf should close. |
3666 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3647 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
3667 } | 3648 } |
3668 #endif // defined(OS_CHROMEOS) | 3649 #endif // defined(OS_CHROMEOS) |
OLD | NEW |