| 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 // Disable everything on windows only. http://crbug.com/306144 | 5 // Disable everything on windows only. http://crbug.com/306144 |
| 6 #ifndef OS_WIN | 6 #ifndef OS_WIN |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 off_item_arg); | 1483 off_item_arg); |
| 1484 EXPECT_STREQ(errors::kNotResumable, error.c_str()); | 1484 EXPECT_STREQ(errors::kNotResumable, error.c_str()); |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 // Test that we can start a download and that the correct sequence of events is | 1487 // Test that we can start a download and that the correct sequence of events is |
| 1488 // fired for it. | 1488 // fired for it. |
| 1489 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1489 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1490 DownloadExtensionTest_Download_Basic) { | 1490 DownloadExtensionTest_Download_Basic) { |
| 1491 LoadExtension("downloads_split"); | 1491 LoadExtension("downloads_split"); |
| 1492 ASSERT_TRUE(StartEmbeddedTestServer()); | 1492 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1493 ASSERT_TRUE(test_server()->Start()); | 1493 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 1494 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 1495 GoOnTheRecord(); | 1494 GoOnTheRecord(); |
| 1496 | 1495 |
| 1497 // Start downloading a file. | 1496 // Start downloading a file. |
| 1498 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1497 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1499 new DownloadsDownloadFunction(), base::StringPrintf( | 1498 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1500 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1499 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 1501 ASSERT_TRUE(result.get()); | 1500 ASSERT_TRUE(result.get()); |
| 1502 int result_id = -1; | 1501 int result_id = -1; |
| 1503 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1502 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1504 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1503 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1505 ASSERT_TRUE(item); | 1504 ASSERT_TRUE(item); |
| 1506 ScopedCancellingItem canceller(item); | 1505 ScopedCancellingItem canceller(item); |
| 1507 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1506 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1508 | 1507 |
| 1509 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1508 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
| 1510 base::StringPrintf( | 1509 base::StringPrintf( |
| 1511 "[{\"danger\": \"safe\"," | 1510 "[{\"danger\": \"safe\"," |
| 1512 " \"incognito\": false," | 1511 " \"incognito\": false," |
| 1513 " \"mime\": \"text/plain\"," | 1512 " \"mime\": \"text/plain\"," |
| 1514 " \"paused\": false," | 1513 " \"paused\": false," |
| 1515 " \"url\": \"%s\"}]", | 1514 " \"url\": \"%s\"}]", |
| 1516 download_url.c_str()))); | 1515 download_url.c_str()))); |
| 1516 ASSERT_TRUE( |
| 1517 WaitFor(downloads::OnChanged::kEventName, |
| 1518 base::StringPrintf("[{\"id\": %d," |
| 1519 " \"filename\": {" |
| 1520 " \"previous\": \"\"," |
| 1521 " \"current\": \"%s\"}}]", |
| 1522 result_id, GetFilename("slow.txt").c_str()))); |
| 1517 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 1523 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 1518 base::StringPrintf( | 1524 base::StringPrintf( |
| 1519 "[{\"id\": %d," | 1525 "[{\"id\": %d," |
| 1520 " \"filename\": {" | |
| 1521 " \"previous\": \"\"," | |
| 1522 " \"current\": \"%s\"}}]", | |
| 1523 result_id, | |
| 1524 GetFilename("slow.txt").c_str()))); | |
| 1525 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 1526 base::StringPrintf( | |
| 1527 "[{\"id\": %d," | |
| 1528 " \"state\": {" | 1526 " \"state\": {" |
| 1529 " \"previous\": \"in_progress\"," | 1527 " \"previous\": \"in_progress\"," |
| 1530 " \"current\": \"complete\"}}]", | 1528 " \"current\": \"complete\"}}]", |
| 1531 result_id))); | 1529 result_id))); |
| 1532 } | 1530 } |
| 1533 | 1531 |
| 1534 // Test that we can start a download from an incognito context, and that the | 1532 // Test that we can start a download from an incognito context, and that the |
| 1535 // download knows that it's incognito. | 1533 // download knows that it's incognito. |
| 1536 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1534 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1537 DownloadExtensionTest_Download_Incognito) { | 1535 DownloadExtensionTest_Download_Incognito) { |
| 1538 LoadExtension("downloads_split"); | 1536 LoadExtension("downloads_split"); |
| 1539 ASSERT_TRUE(StartEmbeddedTestServer()); | 1537 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1540 ASSERT_TRUE(test_server()->Start()); | |
| 1541 GoOffTheRecord(); | 1538 GoOffTheRecord(); |
| 1542 std::string download_url = test_server()->GetURL("slow?0").spec(); | 1539 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 1543 | 1540 |
| 1544 // Start downloading a file. | 1541 // Start downloading a file. |
| 1545 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1542 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1546 new DownloadsDownloadFunction(), base::StringPrintf( | 1543 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1547 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1544 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 1548 ASSERT_TRUE(result.get()); | 1545 ASSERT_TRUE(result.get()); |
| 1549 int result_id = -1; | 1546 int result_id = -1; |
| 1550 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1547 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1551 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1548 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1552 ASSERT_TRUE(item); | 1549 ASSERT_TRUE(item); |
| 1553 ScopedCancellingItem canceller(item); | 1550 ScopedCancellingItem canceller(item); |
| 1554 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1551 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1555 | 1552 |
| 1556 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1553 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
| 1557 base::StringPrintf( | 1554 base::StringPrintf( |
| 1558 "[{\"danger\": \"safe\"," | 1555 "[{\"danger\": \"safe\"," |
| 1559 " \"incognito\": true," | 1556 " \"incognito\": true," |
| 1560 " \"mime\": \"text/plain\"," | 1557 " \"mime\": \"text/plain\"," |
| 1561 " \"paused\": false," | 1558 " \"paused\": false," |
| 1562 " \"url\": \"%s\"}]", | 1559 " \"url\": \"%s\"}]", |
| 1563 download_url.c_str()))); | 1560 download_url.c_str()))); |
| 1561 ASSERT_TRUE( |
| 1562 WaitFor(downloads::OnChanged::kEventName, |
| 1563 base::StringPrintf("[{\"id\":%d," |
| 1564 " \"filename\": {" |
| 1565 " \"previous\": \"\"," |
| 1566 " \"current\": \"%s\"}}]", |
| 1567 result_id, GetFilename("slow.txt").c_str()))); |
| 1564 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 1568 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 1565 base::StringPrintf( | 1569 base::StringPrintf( |
| 1566 "[{\"id\":%d," | 1570 "[{\"id\":%d," |
| 1567 " \"filename\": {" | |
| 1568 " \"previous\": \"\"," | |
| 1569 " \"current\": \"%s\"}}]", | |
| 1570 result_id, | |
| 1571 GetFilename("slow.txt").c_str()))); | |
| 1572 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 1573 base::StringPrintf( | |
| 1574 "[{\"id\":%d," | |
| 1575 " \"state\": {" | 1571 " \"state\": {" |
| 1576 " \"current\": \"complete\"," | 1572 " \"current\": \"complete\"," |
| 1577 " \"previous\": \"in_progress\"}}]", | 1573 " \"previous\": \"in_progress\"}}]", |
| 1578 result_id))); | 1574 result_id))); |
| 1579 } | 1575 } |
| 1580 | 1576 |
| 1581 #if defined(OS_WIN) | 1577 #if defined(OS_WIN) |
| 1582 // This test is very flaky on Win. http://crbug.com/248438 | 1578 // This test is very flaky on Win. http://crbug.com/248438 |
| 1583 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ | 1579 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ |
| 1584 DISABLED_DownloadExtensionTest_Download_UnsafeHeaders | 1580 DISABLED_DownloadExtensionTest_Download_UnsafeHeaders |
| 1585 #else | 1581 #else |
| 1586 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ | 1582 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ |
| 1587 DownloadExtensionTest_Download_UnsafeHeaders | 1583 DownloadExtensionTest_Download_UnsafeHeaders |
| 1588 #endif | 1584 #endif |
| 1589 | 1585 |
| 1590 // Test that we disallow certain headers case-insensitively. | 1586 // Test that we disallow certain headers case-insensitively. |
| 1591 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1587 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1592 MAYBE_DownloadExtensionTest_Download_UnsafeHeaders) { | 1588 MAYBE_DownloadExtensionTest_Download_UnsafeHeaders) { |
| 1593 LoadExtension("downloads_split"); | 1589 LoadExtension("downloads_split"); |
| 1594 ASSERT_TRUE(StartEmbeddedTestServer()); | 1590 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1595 ASSERT_TRUE(test_server()->Start()); | |
| 1596 GoOnTheRecord(); | 1591 GoOnTheRecord(); |
| 1597 | 1592 |
| 1598 static const char* const kUnsafeHeaders[] = { | 1593 static const char* const kUnsafeHeaders[] = { |
| 1599 "Accept-chArsEt", | 1594 "Accept-chArsEt", |
| 1600 "accept-eNcoding", | 1595 "accept-eNcoding", |
| 1601 "coNNection", | 1596 "coNNection", |
| 1602 "coNteNt-leNgth", | 1597 "coNteNt-leNgth", |
| 1603 "cooKIE", | 1598 "cooKIE", |
| 1604 "cOOkie2", | 1599 "cOOkie2", |
| 1605 "coNteNt-traNsfer-eNcodiNg", | 1600 "coNteNt-traNsfer-eNcodiNg", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1617 "pRoxY-", | 1612 "pRoxY-", |
| 1618 "sEc-", | 1613 "sEc-", |
| 1619 "pRoxY-probably-not-evil", | 1614 "pRoxY-probably-not-evil", |
| 1620 "sEc-probably-not-evil", | 1615 "sEc-probably-not-evil", |
| 1621 "oRiGiN", | 1616 "oRiGiN", |
| 1622 "Access-Control-Request-Headers", | 1617 "Access-Control-Request-Headers", |
| 1623 "Access-Control-Request-Method", | 1618 "Access-Control-Request-Method", |
| 1624 }; | 1619 }; |
| 1625 | 1620 |
| 1626 for (size_t index = 0; index < arraysize(kUnsafeHeaders); ++index) { | 1621 for (size_t index = 0; index < arraysize(kUnsafeHeaders); ++index) { |
| 1627 std::string download_url = test_server()->GetURL("slow?0").spec(); | 1622 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 1628 EXPECT_STREQ(errors::kInvalidHeaderUnsafe, | 1623 EXPECT_STREQ(errors::kInvalidHeaderUnsafe, |
| 1629 RunFunctionAndReturnError(new DownloadsDownloadFunction(), | 1624 RunFunctionAndReturnError(new DownloadsDownloadFunction(), |
| 1630 base::StringPrintf( | 1625 base::StringPrintf( |
| 1631 "[{\"url\": \"%s\"," | 1626 "[{\"url\": \"%s\"," |
| 1632 " \"filename\": \"unsafe-header-%d.txt\"," | 1627 " \"filename\": \"unsafe-header-%d.txt\"," |
| 1633 " \"headers\": [{" | 1628 " \"headers\": [{" |
| 1634 " \"name\": \"%s\"," | 1629 " \"name\": \"%s\"," |
| 1635 " \"value\": \"unsafe\"}]}]", | 1630 " \"value\": \"unsafe\"}]}]", |
| 1636 download_url.c_str(), | 1631 download_url.c_str(), |
| 1637 static_cast<int>(index), | 1632 static_cast<int>(index), |
| 1638 kUnsafeHeaders[index])).c_str()); | 1633 kUnsafeHeaders[index])).c_str()); |
| 1639 } | 1634 } |
| 1640 } | 1635 } |
| 1641 | 1636 |
| 1642 // Tests that invalid header names and values are rejected. | 1637 // Tests that invalid header names and values are rejected. |
| 1643 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1638 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1644 DownloadExtensionTest_Download_InvalidHeaders) { | 1639 DownloadExtensionTest_Download_InvalidHeaders) { |
| 1645 LoadExtension("downloads_split"); | 1640 LoadExtension("downloads_split"); |
| 1646 ASSERT_TRUE(StartEmbeddedTestServer()); | 1641 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1647 ASSERT_TRUE(test_server()->Start()); | |
| 1648 GoOnTheRecord(); | 1642 GoOnTheRecord(); |
| 1649 std::string download_url = test_server()->GetURL("slow?0").spec(); | 1643 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 1650 EXPECT_STREQ(errors::kInvalidHeaderName, | 1644 EXPECT_STREQ(errors::kInvalidHeaderName, |
| 1651 RunFunctionAndReturnError(new DownloadsDownloadFunction(), | 1645 RunFunctionAndReturnError(new DownloadsDownloadFunction(), |
| 1652 base::StringPrintf( | 1646 base::StringPrintf( |
| 1653 "[{\"url\": \"%s\"," | 1647 "[{\"url\": \"%s\"," |
| 1654 " \"filename\": \"unsafe-header-crlf.txt\"," | 1648 " \"filename\": \"unsafe-header-crlf.txt\"," |
| 1655 " \"headers\": [{" | 1649 " \"headers\": [{" |
| 1656 " \"name\": \"Header\\r\\nSec-Spoof: Hey\\r\\nX-Split:X\"," | 1650 " \"name\": \"Header\\r\\nSec-Spoof: Hey\\r\\nX-Split:X\"," |
| 1657 " \"value\": \"unsafe\"}]}]", | 1651 " \"value\": \"unsafe\"}]}]", |
| 1658 download_url.c_str())).c_str()); | 1652 download_url.c_str())).c_str()); |
| 1659 | 1653 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1672 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\ | 1666 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\ |
| 1673 DISABLED_DownloadExtensionTest_Download_Subdirectory | 1667 DISABLED_DownloadExtensionTest_Download_Subdirectory |
| 1674 #else | 1668 #else |
| 1675 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\ | 1669 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\ |
| 1676 DownloadExtensionTest_Download_Subdirectory | 1670 DownloadExtensionTest_Download_Subdirectory |
| 1677 #endif | 1671 #endif |
| 1678 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1672 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1679 MAYBE_DownloadExtensionTest_Download_Subdirectory) { | 1673 MAYBE_DownloadExtensionTest_Download_Subdirectory) { |
| 1680 LoadExtension("downloads_split"); | 1674 LoadExtension("downloads_split"); |
| 1681 ASSERT_TRUE(StartEmbeddedTestServer()); | 1675 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1682 ASSERT_TRUE(test_server()->Start()); | 1676 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 1683 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 1684 GoOnTheRecord(); | 1677 GoOnTheRecord(); |
| 1685 | 1678 |
| 1686 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1679 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1687 new DownloadsDownloadFunction(), base::StringPrintf( | 1680 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1688 "[{\"url\": \"%s\"," | 1681 "[{\"url\": \"%s\"," |
| 1689 " \"filename\": \"sub/dir/ect/ory.txt\"}]", | 1682 " \"filename\": \"sub/dir/ect/ory.txt\"}]", |
| 1690 download_url.c_str()))); | 1683 download_url.c_str()))); |
| 1691 ASSERT_TRUE(result.get()); | 1684 ASSERT_TRUE(result.get()); |
| 1692 int result_id = -1; | 1685 int result_id = -1; |
| 1693 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1686 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1719 " \"previous\": \"in_progress\"," | 1712 " \"previous\": \"in_progress\"," |
| 1720 " \"current\": \"complete\"}}]", | 1713 " \"current\": \"complete\"}}]", |
| 1721 result_id))); | 1714 result_id))); |
| 1722 } | 1715 } |
| 1723 | 1716 |
| 1724 // Test that invalid filenames are disallowed. | 1717 // Test that invalid filenames are disallowed. |
| 1725 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1718 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1726 DownloadExtensionTest_Download_InvalidFilename) { | 1719 DownloadExtensionTest_Download_InvalidFilename) { |
| 1727 LoadExtension("downloads_split"); | 1720 LoadExtension("downloads_split"); |
| 1728 ASSERT_TRUE(StartEmbeddedTestServer()); | 1721 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1729 ASSERT_TRUE(test_server()->Start()); | 1722 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 1730 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 1731 GoOnTheRecord(); | 1723 GoOnTheRecord(); |
| 1732 | 1724 |
| 1733 EXPECT_STREQ(errors::kInvalidFilename, | 1725 EXPECT_STREQ(errors::kInvalidFilename, |
| 1734 RunFunctionAndReturnError(new DownloadsDownloadFunction(), | 1726 RunFunctionAndReturnError(new DownloadsDownloadFunction(), |
| 1735 base::StringPrintf( | 1727 base::StringPrintf( |
| 1736 "[{\"url\": \"%s\"," | 1728 "[{\"url\": \"%s\"," |
| 1737 " \"filename\": \"../../../../../etc/passwd\"}]", | 1729 " \"filename\": \"../../../../../etc/passwd\"}]", |
| 1738 download_url.c_str())).c_str()); | 1730 download_url.c_str())).c_str()); |
| 1739 } | 1731 } |
| 1740 | 1732 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 } | 1775 } |
| 1784 | 1776 |
| 1785 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to | 1777 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to |
| 1786 // permissions, test downloading from ftp. | 1778 // permissions, test downloading from ftp. |
| 1787 | 1779 |
| 1788 // Valid URLs plus fragments are still valid URLs. | 1780 // Valid URLs plus fragments are still valid URLs. |
| 1789 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1781 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1790 DownloadExtensionTest_Download_URLFragment) { | 1782 DownloadExtensionTest_Download_URLFragment) { |
| 1791 LoadExtension("downloads_split"); | 1783 LoadExtension("downloads_split"); |
| 1792 ASSERT_TRUE(StartEmbeddedTestServer()); | 1784 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1793 ASSERT_TRUE(test_server()->Start()); | 1785 std::string download_url = |
| 1794 std::string download_url = test_server()->GetURL("slow?0#fragment").spec(); | 1786 embedded_test_server()->GetURL("/slow?0#fragment").spec(); |
| 1795 GoOnTheRecord(); | 1787 GoOnTheRecord(); |
| 1796 | 1788 |
| 1797 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1789 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1798 new DownloadsDownloadFunction(), base::StringPrintf( | 1790 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1799 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1791 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 1800 ASSERT_TRUE(result.get()); | 1792 ASSERT_TRUE(result.get()); |
| 1801 int result_id = -1; | 1793 int result_id = -1; |
| 1802 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1794 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1803 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1795 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1804 ASSERT_TRUE(item); | 1796 ASSERT_TRUE(item); |
| 1805 ScopedCancellingItem canceller(item); | 1797 ScopedCancellingItem canceller(item); |
| 1806 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1798 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1807 | 1799 |
| 1808 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1800 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
| 1809 base::StringPrintf( | 1801 base::StringPrintf( |
| 1810 "[{\"danger\": \"safe\"," | 1802 "[{\"danger\": \"safe\"," |
| 1811 " \"incognito\": false," | 1803 " \"incognito\": false," |
| 1812 " \"mime\": \"text/plain\"," | 1804 " \"mime\": \"text/plain\"," |
| 1813 " \"paused\": false," | 1805 " \"paused\": false," |
| 1814 " \"url\": \"%s\"}]", | 1806 " \"url\": \"%s\"}]", |
| 1815 download_url.c_str()))); | 1807 download_url.c_str()))); |
| 1808 ASSERT_TRUE( |
| 1809 WaitFor(downloads::OnChanged::kEventName, |
| 1810 base::StringPrintf("[{\"id\": %d," |
| 1811 " \"filename\": {" |
| 1812 " \"previous\": \"\"," |
| 1813 " \"current\": \"%s\"}}]", |
| 1814 result_id, GetFilename("slow.txt").c_str()))); |
| 1816 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 1815 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 1817 base::StringPrintf( | 1816 base::StringPrintf( |
| 1818 "[{\"id\": %d," | 1817 "[{\"id\": %d," |
| 1819 " \"filename\": {" | |
| 1820 " \"previous\": \"\"," | |
| 1821 " \"current\": \"%s\"}}]", | |
| 1822 result_id, | |
| 1823 GetFilename("slow.txt").c_str()))); | |
| 1824 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 1825 base::StringPrintf( | |
| 1826 "[{\"id\": %d," | |
| 1827 " \"state\": {" | 1818 " \"state\": {" |
| 1828 " \"previous\": \"in_progress\"," | 1819 " \"previous\": \"in_progress\"," |
| 1829 " \"current\": \"complete\"}}]", | 1820 " \"current\": \"complete\"}}]", |
| 1830 result_id))); | 1821 result_id))); |
| 1831 } | 1822 } |
| 1832 | 1823 |
| 1833 // conflictAction may be specified without filename. | 1824 // conflictAction may be specified without filename. |
| 1834 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1825 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1835 DownloadExtensionTest_Download_ConflictAction) { | 1826 DownloadExtensionTest_Download_ConflictAction) { |
| 1836 static char kFilename[] = "download.txt"; | 1827 static char kFilename[] = "download.txt"; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2010 } | 2001 } |
| 2011 | 2002 |
| 2012 // Test that auth-basic-succeed would fail if the resource requires the | 2003 // Test that auth-basic-succeed would fail if the resource requires the |
| 2013 // Authorization header and chrome fails to propagate it back to the server. | 2004 // Authorization header and chrome fails to propagate it back to the server. |
| 2014 // This tests both that testserver.py does not succeed when it should fail as | 2005 // This tests both that testserver.py does not succeed when it should fail as |
| 2015 // well as how the downloads extension API exposes the failure to extensions. | 2006 // well as how the downloads extension API exposes the failure to extensions. |
| 2016 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2007 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2017 DownloadExtensionTest_Download_AuthBasic_Fail) { | 2008 DownloadExtensionTest_Download_AuthBasic_Fail) { |
| 2018 LoadExtension("downloads_split"); | 2009 LoadExtension("downloads_split"); |
| 2019 ASSERT_TRUE(StartEmbeddedTestServer()); | 2010 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2020 ASSERT_TRUE(test_server()->Start()); | 2011 std::string download_url = |
| 2021 std::string download_url = test_server()->GetURL("auth-basic").spec(); | 2012 embedded_test_server()->GetURL("/auth-basic").spec(); |
| 2022 GoOnTheRecord(); | 2013 GoOnTheRecord(); |
| 2023 | 2014 |
| 2024 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2015 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2025 new DownloadsDownloadFunction(), base::StringPrintf( | 2016 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2026 "[{\"url\": \"%s\"," | 2017 "[{\"url\": \"%s\"," |
| 2027 " \"filename\": \"auth-basic-fail.txt\"}]", | 2018 " \"filename\": \"auth-basic-fail.txt\"}]", |
| 2028 download_url.c_str()))); | 2019 download_url.c_str()))); |
| 2029 ASSERT_TRUE(result.get()); | 2020 ASSERT_TRUE(result.get()); |
| 2030 int result_id = -1; | 2021 int result_id = -1; |
| 2031 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2022 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2043 " \"paused\": false," | 2034 " \"paused\": false," |
| 2044 " \"url\": \"%s\"}]", | 2035 " \"url\": \"%s\"}]", |
| 2045 download_url.c_str()))); | 2036 download_url.c_str()))); |
| 2046 } | 2037 } |
| 2047 | 2038 |
| 2048 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. | 2039 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. |
| 2049 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2040 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2050 DownloadExtensionTest_Download_Headers) { | 2041 DownloadExtensionTest_Download_Headers) { |
| 2051 LoadExtension("downloads_split"); | 2042 LoadExtension("downloads_split"); |
| 2052 ASSERT_TRUE(StartEmbeddedTestServer()); | 2043 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2053 ASSERT_TRUE(test_server()->Start()); | 2044 std::string download_url = |
| 2054 std::string download_url = test_server()->GetURL("files/downloads/" | 2045 embedded_test_server() |
| 2055 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec(); | 2046 ->GetURL( |
| 2047 "/downloads/" |
| 2048 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo") |
| 2049 .spec(); |
| 2056 GoOnTheRecord(); | 2050 GoOnTheRecord(); |
| 2057 | 2051 |
| 2058 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2052 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2059 new DownloadsDownloadFunction(), base::StringPrintf( | 2053 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2060 "[{\"url\": \"%s\"," | 2054 "[{\"url\": \"%s\"," |
| 2061 " \"filename\": \"headers-succeed.txt\"," | 2055 " \"filename\": \"headers-succeed.txt\"," |
| 2062 " \"headers\": [" | 2056 " \"headers\": [" |
| 2063 " {\"name\": \"Foo\", \"value\": \"bar\"}," | 2057 " {\"name\": \"Foo\", \"value\": \"bar\"}," |
| 2064 " {\"name\": \"Qx\", \"value\":\"yo\"}]}]", | 2058 " {\"name\": \"Qx\", \"value\":\"yo\"}]}]", |
| 2065 download_url.c_str()))); | 2059 download_url.c_str()))); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2097 } | 2091 } |
| 2098 | 2092 |
| 2099 // Test that headers-succeed would fail if the resource requires the headers and | 2093 // Test that headers-succeed would fail if the resource requires the headers and |
| 2100 // chrome fails to propagate them back to the server. This tests both that | 2094 // chrome fails to propagate them back to the server. This tests both that |
| 2101 // testserver.py does not succeed when it should fail as well as how the | 2095 // testserver.py does not succeed when it should fail as well as how the |
| 2102 // downloads extension api exposes the failure to extensions. | 2096 // downloads extension api exposes the failure to extensions. |
| 2103 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2097 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2104 DownloadExtensionTest_Download_Headers_Fail) { | 2098 DownloadExtensionTest_Download_Headers_Fail) { |
| 2105 LoadExtension("downloads_split"); | 2099 LoadExtension("downloads_split"); |
| 2106 ASSERT_TRUE(StartEmbeddedTestServer()); | 2100 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2107 ASSERT_TRUE(test_server()->Start()); | 2101 std::string download_url = |
| 2108 std::string download_url = test_server()->GetURL("files/downloads/" | 2102 embedded_test_server() |
| 2109 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec(); | 2103 ->GetURL( |
| 2104 "/downloads/" |
| 2105 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo") |
| 2106 .spec(); |
| 2110 GoOnTheRecord(); | 2107 GoOnTheRecord(); |
| 2111 | 2108 |
| 2112 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2109 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2113 new DownloadsDownloadFunction(), base::StringPrintf( | 2110 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2114 "[{\"url\": \"%s\"," | 2111 "[{\"url\": \"%s\"," |
| 2115 " \"filename\": \"headers-fail.txt\"}]", | 2112 " \"filename\": \"headers-fail.txt\"}]", |
| 2116 download_url.c_str()))); | 2113 download_url.c_str()))); |
| 2117 ASSERT_TRUE(result.get()); | 2114 ASSERT_TRUE(result.get()); |
| 2118 int result_id = -1; | 2115 int result_id = -1; |
| 2119 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2116 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2134 " \"url\": \"%s\"}]", | 2131 " \"url\": \"%s\"}]", |
| 2135 download_url.c_str()))); | 2132 download_url.c_str()))); |
| 2136 } | 2133 } |
| 2137 | 2134 |
| 2138 // Test that DownloadsDownloadFunction propagates the Authorization header | 2135 // Test that DownloadsDownloadFunction propagates the Authorization header |
| 2139 // correctly. | 2136 // correctly. |
| 2140 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2137 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2141 DownloadExtensionTest_Download_AuthBasic) { | 2138 DownloadExtensionTest_Download_AuthBasic) { |
| 2142 LoadExtension("downloads_split"); | 2139 LoadExtension("downloads_split"); |
| 2143 ASSERT_TRUE(StartEmbeddedTestServer()); | 2140 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2144 ASSERT_TRUE(test_server()->Start()); | 2141 std::string download_url = |
| 2145 std::string download_url = test_server()->GetURL("auth-basic").spec(); | 2142 embedded_test_server()->GetURL("/auth-basic").spec(); |
| 2146 // This is just base64 of 'username:secret'. | 2143 // This is just base64 of 'username:secret'. |
| 2147 static const char kAuthorization[] = "dXNlcm5hbWU6c2VjcmV0"; | 2144 static const char kAuthorization[] = "dXNlcm5hbWU6c2VjcmV0"; |
| 2148 GoOnTheRecord(); | 2145 GoOnTheRecord(); |
| 2149 | 2146 |
| 2150 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2147 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2151 new DownloadsDownloadFunction(), base::StringPrintf( | 2148 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2152 "[{\"url\": \"%s\"," | 2149 "[{\"url\": \"%s\"," |
| 2153 " \"filename\": \"auth-basic-succeed.txt\"," | 2150 " \"filename\": \"auth-basic-succeed.txt\"," |
| 2154 " \"headers\": [{" | 2151 " \"headers\": [{" |
| 2155 " \"name\": \"Authorization\"," | 2152 " \"name\": \"Authorization\"," |
| 2156 " \"value\": \"Basic %s\"}]}]", | 2153 " \"value\": \"Basic %s\"}]}]", |
| 2157 download_url.c_str(), kAuthorization))); | 2154 download_url.c_str(), kAuthorization))); |
| 2158 ASSERT_TRUE(result.get()); | 2155 ASSERT_TRUE(result.get()); |
| 2159 int result_id = -1; | 2156 int result_id = -1; |
| 2160 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2157 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2161 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2158 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2162 ASSERT_TRUE(item); | 2159 ASSERT_TRUE(item); |
| 2163 ScopedCancellingItem canceller(item); | 2160 ScopedCancellingItem canceller(item); |
| 2164 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2161 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 2165 | 2162 |
| 2166 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2163 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
| 2167 base::StringPrintf( | 2164 base::StringPrintf( |
| 2168 "[{\"danger\": \"safe\"," | 2165 "[{\"danger\": \"safe\"," |
| 2169 " \"incognito\": false," | 2166 " \"incognito\": false," |
| 2170 " \"bytesReceived\": 0.0," | 2167 " \"bytesReceived\": 0.0," |
| 2171 " \"fileSize\": 0.0," | |
| 2172 " \"mime\": \"text/html\"," | 2168 " \"mime\": \"text/html\"," |
| 2173 " \"paused\": false," | 2169 " \"paused\": false," |
| 2174 " \"url\": \"%s\"}]", | 2170 " \"url\": \"%s\"}]", |
| 2175 download_url.c_str()))); | 2171 download_url.c_str()))); |
| 2176 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2172 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 2177 base::StringPrintf( | 2173 base::StringPrintf( |
| 2178 "[{\"id\": %d," | 2174 "[{\"id\": %d," |
| 2179 " \"state\": {" | 2175 " \"state\": {" |
| 2180 " \"previous\": \"in_progress\"," | 2176 " \"previous\": \"in_progress\"," |
| 2181 " \"current\": \"complete\"}}]", | 2177 " \"current\": \"complete\"}}]", |
| 2182 result_id))); | 2178 result_id))); |
| 2183 } | 2179 } |
| 2184 | 2180 |
| 2185 // Test that DownloadsDownloadFunction propagates the |method| and |body| | 2181 // Test that DownloadsDownloadFunction propagates the |method| and |body| |
| 2186 // parameters to the URLRequest. | 2182 // parameters to the URLRequest. |
| 2187 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2183 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2188 DownloadExtensionTest_Download_Post) { | 2184 DownloadExtensionTest_Download_Post) { |
| 2189 LoadExtension("downloads_split"); | 2185 LoadExtension("downloads_split"); |
| 2190 ASSERT_TRUE(StartEmbeddedTestServer()); | 2186 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2191 ASSERT_TRUE(test_server()->Start()); | 2187 std::string download_url = embedded_test_server() |
| 2192 std::string download_url = test_server()->GetURL("files/post/downloads/" | 2188 ->GetURL( |
| 2193 "a_zip_file.zip?expected_body=BODY").spec(); | 2189 "/post/downloads/" |
| 2190 "a_zip_file.zip?expected_body=BODY") |
| 2191 .spec(); |
| 2194 GoOnTheRecord(); | 2192 GoOnTheRecord(); |
| 2195 | 2193 |
| 2196 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2194 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2197 new DownloadsDownloadFunction(), base::StringPrintf( | 2195 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2198 "[{\"url\": \"%s\"," | 2196 "[{\"url\": \"%s\"," |
| 2199 " \"filename\": \"post-succeed.txt\"," | 2197 " \"filename\": \"post-succeed.txt\"," |
| 2200 " \"method\": \"POST\"," | 2198 " \"method\": \"POST\"," |
| 2201 " \"body\": \"BODY\"}]", | 2199 " \"body\": \"BODY\"}]", |
| 2202 download_url.c_str()))); | 2200 download_url.c_str()))); |
| 2203 ASSERT_TRUE(result.get()); | 2201 ASSERT_TRUE(result.get()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 | 2233 |
| 2236 // Test that downloadPostSuccess would fail if the resource requires the POST | 2234 // Test that downloadPostSuccess would fail if the resource requires the POST |
| 2237 // method, and chrome fails to propagate the |method| parameter back to the | 2235 // method, and chrome fails to propagate the |method| parameter back to the |
| 2238 // server. This tests both that testserver.py does not succeed when it should | 2236 // server. This tests both that testserver.py does not succeed when it should |
| 2239 // fail, and this tests how the downloads extension api exposes the failure to | 2237 // fail, and this tests how the downloads extension api exposes the failure to |
| 2240 // extensions. | 2238 // extensions. |
| 2241 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2239 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2242 DownloadExtensionTest_Download_Post_Get) { | 2240 DownloadExtensionTest_Download_Post_Get) { |
| 2243 LoadExtension("downloads_split"); | 2241 LoadExtension("downloads_split"); |
| 2244 ASSERT_TRUE(StartEmbeddedTestServer()); | 2242 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2245 ASSERT_TRUE(test_server()->Start()); | 2243 std::string download_url = embedded_test_server() |
| 2246 std::string download_url = test_server()->GetURL("files/post/downloads/" | 2244 ->GetURL( |
| 2247 "a_zip_file.zip?expected_body=BODY").spec(); | 2245 "/post/downloads/" |
| 2246 "a_zip_file.zip?expected_body=BODY") |
| 2247 .spec(); |
| 2248 GoOnTheRecord(); | 2248 GoOnTheRecord(); |
| 2249 | 2249 |
| 2250 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2250 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2251 new DownloadsDownloadFunction(), base::StringPrintf( | 2251 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2252 "[{\"url\": \"%s\"," | 2252 "[{\"url\": \"%s\"," |
| 2253 " \"body\": \"BODY\"," | 2253 " \"body\": \"BODY\"," |
| 2254 " \"filename\": \"post-get.txt\"}]", | 2254 " \"filename\": \"post-get.txt\"}]", |
| 2255 download_url.c_str()))); | 2255 download_url.c_str()))); |
| 2256 ASSERT_TRUE(result.get()); | 2256 ASSERT_TRUE(result.get()); |
| 2257 int result_id = -1; | 2257 int result_id = -1; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2276 | 2276 |
| 2277 // Test that downloadPostSuccess would fail if the resource requires the POST | 2277 // Test that downloadPostSuccess would fail if the resource requires the POST |
| 2278 // method, and chrome fails to propagate the |body| parameter back to the | 2278 // method, and chrome fails to propagate the |body| parameter back to the |
| 2279 // server. This tests both that testserver.py does not succeed when it should | 2279 // server. This tests both that testserver.py does not succeed when it should |
| 2280 // fail, and this tests how the downloads extension api exposes the failure to | 2280 // fail, and this tests how the downloads extension api exposes the failure to |
| 2281 // extensions. | 2281 // extensions. |
| 2282 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2282 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2283 DownloadExtensionTest_Download_Post_NoBody) { | 2283 DownloadExtensionTest_Download_Post_NoBody) { |
| 2284 LoadExtension("downloads_split"); | 2284 LoadExtension("downloads_split"); |
| 2285 ASSERT_TRUE(StartEmbeddedTestServer()); | 2285 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2286 ASSERT_TRUE(test_server()->Start()); | 2286 std::string download_url = embedded_test_server() |
| 2287 std::string download_url = test_server()->GetURL("files/post/downloads/" | 2287 ->GetURL( |
| 2288 "a_zip_file.zip?expected_body=BODY").spec(); | 2288 "/post/downloads/" |
| 2289 "a_zip_file.zip?expected_body=BODY") |
| 2290 .spec(); |
| 2289 GoOnTheRecord(); | 2291 GoOnTheRecord(); |
| 2290 | 2292 |
| 2291 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2293 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2292 new DownloadsDownloadFunction(), base::StringPrintf( | 2294 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2293 "[{\"url\": \"%s\"," | 2295 "[{\"url\": \"%s\"," |
| 2294 " \"method\": \"POST\"," | 2296 " \"method\": \"POST\"," |
| 2295 " \"filename\": \"post-nobody.txt\"}]", | 2297 " \"filename\": \"post-nobody.txt\"}]", |
| 2296 download_url.c_str()))); | 2298 download_url.c_str()))); |
| 2297 ASSERT_TRUE(result.get()); | 2299 ASSERT_TRUE(result.get()); |
| 2298 int result_id = -1; | 2300 int result_id = -1; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2316 } | 2318 } |
| 2317 | 2319 |
| 2318 // Test that cancel()ing an in-progress download causes its state to transition | 2320 // Test that cancel()ing an in-progress download causes its state to transition |
| 2319 // to interrupted, and test that that state transition is detectable by an | 2321 // to interrupted, and test that that state transition is detectable by an |
| 2320 // onChanged event listener. TODO(benjhayden): Test other sources of | 2322 // onChanged event listener. TODO(benjhayden): Test other sources of |
| 2321 // interruptions such as server death. | 2323 // interruptions such as server death. |
| 2322 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2324 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2323 DownloadExtensionTest_Download_Cancel) { | 2325 DownloadExtensionTest_Download_Cancel) { |
| 2324 LoadExtension("downloads_split"); | 2326 LoadExtension("downloads_split"); |
| 2325 ASSERT_TRUE(StartEmbeddedTestServer()); | 2327 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2326 ASSERT_TRUE(test_server()->Start()); | 2328 ASSERT_TRUE(spawned_test_server()->Start()); |
| 2327 std::string download_url = test_server()->GetURL( | 2329 std::string download_url = |
| 2328 "download-known-size").spec(); | 2330 spawned_test_server()->GetURL("download-known-size").spec(); |
| 2329 GoOnTheRecord(); | 2331 GoOnTheRecord(); |
| 2330 | 2332 |
| 2331 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2333 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2332 new DownloadsDownloadFunction(), base::StringPrintf( | 2334 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2333 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2335 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2334 ASSERT_TRUE(result.get()); | 2336 ASSERT_TRUE(result.get()); |
| 2335 int result_id = -1; | 2337 int result_id = -1; |
| 2336 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2338 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2337 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2339 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2338 ASSERT_TRUE(item); | 2340 ASSERT_TRUE(item); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2428 EXPECT_TRUE(base::ReadFileToString(item->GetTargetFilePath(), &disk_data)); | 2430 EXPECT_TRUE(base::ReadFileToString(item->GetTargetFilePath(), &disk_data)); |
| 2429 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2431 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
| 2430 } | 2432 } |
| 2431 | 2433 |
| 2432 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2434 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2433 DownloadExtensionTest_OnDeterminingFilename_NoChange) { | 2435 DownloadExtensionTest_OnDeterminingFilename_NoChange) { |
| 2434 GoOnTheRecord(); | 2436 GoOnTheRecord(); |
| 2435 LoadExtension("downloads_split"); | 2437 LoadExtension("downloads_split"); |
| 2436 AddFilenameDeterminer(); | 2438 AddFilenameDeterminer(); |
| 2437 ASSERT_TRUE(StartEmbeddedTestServer()); | 2439 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2438 ASSERT_TRUE(test_server()->Start()); | 2440 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 2439 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 2440 | 2441 |
| 2441 // Start downloading a file. | 2442 // Start downloading a file. |
| 2442 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2443 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2443 new DownloadsDownloadFunction(), base::StringPrintf( | 2444 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2444 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2445 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2445 ASSERT_TRUE(result.get()); | 2446 ASSERT_TRUE(result.get()); |
| 2446 int result_id = -1; | 2447 int result_id = -1; |
| 2447 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2448 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2448 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2449 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2449 ASSERT_TRUE(item); | 2450 ASSERT_TRUE(item); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2475 browser()->profile(), | 2476 browser()->profile(), |
| 2476 false, | 2477 false, |
| 2477 GetExtensionId(), | 2478 GetExtensionId(), |
| 2478 result_id, | 2479 result_id, |
| 2479 base::FilePath(), | 2480 base::FilePath(), |
| 2480 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 2481 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 2481 &error)); | 2482 &error)); |
| 2482 EXPECT_EQ("", error); | 2483 EXPECT_EQ("", error); |
| 2483 | 2484 |
| 2484 // The download should complete successfully. | 2485 // The download should complete successfully. |
| 2486 ASSERT_TRUE( |
| 2487 WaitFor(downloads::OnChanged::kEventName, |
| 2488 base::StringPrintf("[{\"id\": %d," |
| 2489 " \"filename\": {" |
| 2490 " \"previous\": \"\"," |
| 2491 " \"current\": \"%s\"}}]", |
| 2492 result_id, GetFilename("slow.txt").c_str()))); |
| 2485 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2493 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 2486 base::StringPrintf( | 2494 base::StringPrintf( |
| 2487 "[{\"id\": %d," | 2495 "[{\"id\": %d," |
| 2488 " \"filename\": {" | |
| 2489 " \"previous\": \"\"," | |
| 2490 " \"current\": \"%s\"}}]", | |
| 2491 result_id, | |
| 2492 GetFilename("slow.txt").c_str()))); | |
| 2493 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 2494 base::StringPrintf( | |
| 2495 "[{\"id\": %d," | |
| 2496 " \"state\": {" | 2496 " \"state\": {" |
| 2497 " \"previous\": \"in_progress\"," | 2497 " \"previous\": \"in_progress\"," |
| 2498 " \"current\": \"complete\"}}]", | 2498 " \"current\": \"complete\"}}]", |
| 2499 result_id))); | 2499 result_id))); |
| 2500 } | 2500 } |
| 2501 | 2501 |
| 2502 // Disabled due to cross-platform flakes; http://crbug.com/370531. | 2502 // Disabled due to cross-platform flakes; http://crbug.com/370531. |
| 2503 IN_PROC_BROWSER_TEST_F( | 2503 IN_PROC_BROWSER_TEST_F( |
| 2504 DownloadExtensionTest, | 2504 DownloadExtensionTest, |
| 2505 DISABLED_DownloadExtensionTest_OnDeterminingFilename_Timeout) { | 2505 DISABLED_DownloadExtensionTest_OnDeterminingFilename_Timeout) { |
| 2506 GoOnTheRecord(); | 2506 GoOnTheRecord(); |
| 2507 LoadExtension("downloads_split"); | 2507 LoadExtension("downloads_split"); |
| 2508 AddFilenameDeterminer(); | 2508 AddFilenameDeterminer(); |
| 2509 ASSERT_TRUE(StartEmbeddedTestServer()); | 2509 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2510 ASSERT_TRUE(test_server()->Start()); | 2510 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 2511 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 2512 | 2511 |
| 2513 ExtensionDownloadsEventRouter::SetDetermineFilenameTimeoutSecondsForTesting( | 2512 ExtensionDownloadsEventRouter::SetDetermineFilenameTimeoutSecondsForTesting( |
| 2514 0); | 2513 0); |
| 2515 | 2514 |
| 2516 // Start downloading a file. | 2515 // Start downloading a file. |
| 2517 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2516 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2518 new DownloadsDownloadFunction(), base::StringPrintf( | 2517 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2519 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2518 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2520 ASSERT_TRUE(result.get()); | 2519 ASSERT_TRUE(result.get()); |
| 2521 int result_id = -1; | 2520 int result_id = -1; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2539 downloads::OnDeterminingFilename::kEventName, | 2538 downloads::OnDeterminingFilename::kEventName, |
| 2540 base::StringPrintf("[{\"id\": %d," | 2539 base::StringPrintf("[{\"id\": %d," |
| 2541 " \"filename\":\"slow.txt\"}]", | 2540 " \"filename\":\"slow.txt\"}]", |
| 2542 result_id))); | 2541 result_id))); |
| 2543 ASSERT_TRUE(item->GetTargetFilePath().empty()); | 2542 ASSERT_TRUE(item->GetTargetFilePath().empty()); |
| 2544 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 2543 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 2545 | 2544 |
| 2546 // Do not respond to the onDeterminingFilename. | 2545 // Do not respond to the onDeterminingFilename. |
| 2547 | 2546 |
| 2548 // The download should complete successfully. | 2547 // The download should complete successfully. |
| 2549 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2548 ASSERT_TRUE( |
| 2550 base::StringPrintf("[{\"id\": %d," | 2549 WaitFor(downloads::OnChanged::kEventName, |
| 2551 " \"filename\": {" | 2550 base::StringPrintf("[{\"id\": %d," |
| 2552 " \"previous\": \"\"," | 2551 " \"filename\": {" |
| 2553 " \"current\": \"%s\"}}]", | 2552 " \"previous\": \"\"," |
| 2554 result_id, | 2553 " \"current\": \"%s\"}}]", |
| 2555 GetFilename("slow.txt").c_str()))); | 2554 result_id, GetFilename("slow.txt").c_str()))); |
| 2556 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2555 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 2557 base::StringPrintf("[{\"id\": %d," | 2556 base::StringPrintf("[{\"id\": %d," |
| 2558 " \"state\": {" | 2557 " \"state\": {" |
| 2559 " \"previous\": \"in_progress\"," | 2558 " \"previous\": \"in_progress\"," |
| 2560 " \"current\": \"complete\"}}]", | 2559 " \"current\": \"complete\"}}]", |
| 2561 result_id))); | 2560 result_id))); |
| 2562 } | 2561 } |
| 2563 | 2562 |
| 2564 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2563 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 2565 DownloadExtensionTest_OnDeterminingFilename_Twice) { | 2564 DownloadExtensionTest_OnDeterminingFilename_Twice) { |
| 2566 GoOnTheRecord(); | 2565 GoOnTheRecord(); |
| 2567 LoadExtension("downloads_split"); | 2566 LoadExtension("downloads_split"); |
| 2568 AddFilenameDeterminer(); | 2567 AddFilenameDeterminer(); |
| 2569 ASSERT_TRUE(StartEmbeddedTestServer()); | 2568 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2570 ASSERT_TRUE(test_server()->Start()); | 2569 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 2571 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 2572 | 2570 |
| 2573 // Start downloading a file. | 2571 // Start downloading a file. |
| 2574 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2572 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2575 new DownloadsDownloadFunction(), base::StringPrintf( | 2573 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2576 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2574 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2577 ASSERT_TRUE(result.get()); | 2575 ASSERT_TRUE(result.get()); |
| 2578 int result_id = -1; | 2576 int result_id = -1; |
| 2579 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2577 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2580 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2578 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2581 ASSERT_TRUE(item); | 2579 ASSERT_TRUE(item); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 browser()->profile(), | 2616 browser()->profile(), |
| 2619 false, | 2617 false, |
| 2620 GetExtensionId(), | 2618 GetExtensionId(), |
| 2621 result_id, | 2619 result_id, |
| 2622 base::FilePath(FILE_PATH_LITERAL("different")), | 2620 base::FilePath(FILE_PATH_LITERAL("different")), |
| 2623 downloads::FILENAME_CONFLICT_ACTION_OVERWRITE, | 2621 downloads::FILENAME_CONFLICT_ACTION_OVERWRITE, |
| 2624 &error)); | 2622 &error)); |
| 2625 EXPECT_EQ(errors::kTooManyListeners, error); | 2623 EXPECT_EQ(errors::kTooManyListeners, error); |
| 2626 | 2624 |
| 2627 // The download should complete successfully. | 2625 // The download should complete successfully. |
| 2628 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2626 ASSERT_TRUE( |
| 2629 base::StringPrintf("[{\"id\": %d," | 2627 WaitFor(downloads::OnChanged::kEventName, |
| 2630 " \"filename\": {" | 2628 base::StringPrintf("[{\"id\": %d," |
| 2631 " \"previous\": \"\"," | 2629 " \"filename\": {" |
| 2632 " \"current\": \"%s\"}}]", | 2630 " \"previous\": \"\"," |
| 2633 result_id, | 2631 " \"current\": \"%s\"}}]", |
| 2634 GetFilename("slow.txt").c_str()))); | 2632 result_id, GetFilename("slow.txt").c_str()))); |
| 2635 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2633 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 2636 base::StringPrintf("[{\"id\": %d," | 2634 base::StringPrintf("[{\"id\": %d," |
| 2637 " \"state\": {" | 2635 " \"state\": {" |
| 2638 " \"previous\": \"in_progress\"," | 2636 " \"previous\": \"in_progress\"," |
| 2639 " \"current\": \"complete\"}}]", | 2637 " \"current\": \"complete\"}}]", |
| 2640 result_id))); | 2638 result_id))); |
| 2641 } | 2639 } |
| 2642 | 2640 |
| 2643 IN_PROC_BROWSER_TEST_F( | 2641 IN_PROC_BROWSER_TEST_F( |
| 2644 DownloadExtensionTest, | 2642 DownloadExtensionTest, |
| 2645 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) { | 2643 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) { |
| 2646 GoOnTheRecord(); | 2644 GoOnTheRecord(); |
| 2647 LoadExtension("downloads_split"); | 2645 LoadExtension("downloads_split"); |
| 2648 AddFilenameDeterminer(); | 2646 AddFilenameDeterminer(); |
| 2649 ASSERT_TRUE(StartEmbeddedTestServer()); | 2647 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2650 ASSERT_TRUE(test_server()->Start()); | 2648 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 2651 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 2652 | 2649 |
| 2653 // Start downloading a file. | 2650 // Start downloading a file. |
| 2654 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2651 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2655 new DownloadsDownloadFunction(), base::StringPrintf( | 2652 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2656 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2653 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2657 ASSERT_TRUE(result.get()); | 2654 ASSERT_TRUE(result.get()); |
| 2658 int result_id = -1; | 2655 int result_id = -1; |
| 2659 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2656 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2660 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2657 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2661 ASSERT_TRUE(item); | 2658 ASSERT_TRUE(item); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2719 item->GetTargetFilePath()); | 2716 item->GetTargetFilePath()); |
| 2720 } | 2717 } |
| 2721 | 2718 |
| 2722 IN_PROC_BROWSER_TEST_F( | 2719 IN_PROC_BROWSER_TEST_F( |
| 2723 DownloadExtensionTest, | 2720 DownloadExtensionTest, |
| 2724 DownloadExtensionTest_OnDeterminingFilename_ReferencesParentInvalid) { | 2721 DownloadExtensionTest_OnDeterminingFilename_ReferencesParentInvalid) { |
| 2725 GoOnTheRecord(); | 2722 GoOnTheRecord(); |
| 2726 LoadExtension("downloads_split"); | 2723 LoadExtension("downloads_split"); |
| 2727 AddFilenameDeterminer(); | 2724 AddFilenameDeterminer(); |
| 2728 ASSERT_TRUE(StartEmbeddedTestServer()); | 2725 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2729 ASSERT_TRUE(test_server()->Start()); | 2726 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 2730 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 2731 | 2727 |
| 2732 // Start downloading a file. | 2728 // Start downloading a file. |
| 2733 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2729 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2734 new DownloadsDownloadFunction(), base::StringPrintf( | 2730 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2735 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2731 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2736 ASSERT_TRUE(result.get()); | 2732 ASSERT_TRUE(result.get()); |
| 2737 int result_id = -1; | 2733 int result_id = -1; |
| 2738 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2734 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2739 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2735 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2740 ASSERT_TRUE(item); | 2736 ASSERT_TRUE(item); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2763 std::string error; | 2759 std::string error; |
| 2764 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | 2760 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 2765 browser()->profile(), | 2761 browser()->profile(), |
| 2766 false, | 2762 false, |
| 2767 GetExtensionId(), | 2763 GetExtensionId(), |
| 2768 result_id, | 2764 result_id, |
| 2769 base::FilePath(FILE_PATH_LITERAL("sneaky/../../sneaky.txt")), | 2765 base::FilePath(FILE_PATH_LITERAL("sneaky/../../sneaky.txt")), |
| 2770 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 2766 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 2771 &error)); | 2767 &error)); |
| 2772 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); | 2768 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); |
| 2769 ASSERT_TRUE( |
| 2770 WaitFor(downloads::OnChanged::kEventName, |
| 2771 base::StringPrintf("[{\"id\": %d," |
| 2772 " \"filename\": {" |
| 2773 " \"previous\": \"\"," |
| 2774 " \"current\": \"%s\"}}]", |
| 2775 result_id, GetFilename("slow.txt").c_str()))); |
| 2773 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2776 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 2774 base::StringPrintf( | 2777 base::StringPrintf( |
| 2775 "[{\"id\": %d," | 2778 "[{\"id\": %d," |
| 2776 " \"filename\": {" | |
| 2777 " \"previous\": \"\"," | |
| 2778 " \"current\": \"%s\"}}]", | |
| 2779 result_id, | |
| 2780 GetFilename("slow.txt").c_str()))); | |
| 2781 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 2782 base::StringPrintf( | |
| 2783 "[{\"id\": %d," | |
| 2784 " \"state\": {" | 2779 " \"state\": {" |
| 2785 " \"previous\": \"in_progress\"," | 2780 " \"previous\": \"in_progress\"," |
| 2786 " \"current\": \"complete\"}}]", | 2781 " \"current\": \"complete\"}}]", |
| 2787 result_id))); | 2782 result_id))); |
| 2788 } | 2783 } |
| 2789 | 2784 |
| 2790 IN_PROC_BROWSER_TEST_F( | 2785 IN_PROC_BROWSER_TEST_F( |
| 2791 DownloadExtensionTest, | 2786 DownloadExtensionTest, |
| 2792 DownloadExtensionTest_OnDeterminingFilename_IllegalFilename) { | 2787 DownloadExtensionTest_OnDeterminingFilename_IllegalFilename) { |
| 2793 GoOnTheRecord(); | 2788 GoOnTheRecord(); |
| 2794 LoadExtension("downloads_split"); | 2789 LoadExtension("downloads_split"); |
| 2795 AddFilenameDeterminer(); | 2790 AddFilenameDeterminer(); |
| 2796 ASSERT_TRUE(StartEmbeddedTestServer()); | 2791 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2797 ASSERT_TRUE(test_server()->Start()); | 2792 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 2798 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 2799 | 2793 |
| 2800 // Start downloading a file. | 2794 // Start downloading a file. |
| 2801 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2795 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2802 new DownloadsDownloadFunction(), base::StringPrintf( | 2796 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2803 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2797 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2804 ASSERT_TRUE(result.get()); | 2798 ASSERT_TRUE(result.get()); |
| 2805 int result_id = -1; | 2799 int result_id = -1; |
| 2806 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2800 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2807 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2801 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2808 ASSERT_TRUE(item); | 2802 ASSERT_TRUE(item); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2831 std::string error; | 2825 std::string error; |
| 2832 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | 2826 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 2833 browser()->profile(), | 2827 browser()->profile(), |
| 2834 false, | 2828 false, |
| 2835 GetExtensionId(), | 2829 GetExtensionId(), |
| 2836 result_id, | 2830 result_id, |
| 2837 base::FilePath(FILE_PATH_LITERAL("<")), | 2831 base::FilePath(FILE_PATH_LITERAL("<")), |
| 2838 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 2832 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 2839 &error)); | 2833 &error)); |
| 2840 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); | 2834 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); |
| 2835 ASSERT_TRUE( |
| 2836 WaitFor(downloads::OnChanged::kEventName, |
| 2837 base::StringPrintf("[{\"id\": %d," |
| 2838 " \"filename\": {" |
| 2839 " \"previous\": \"\"," |
| 2840 " \"current\": \"%s\"}}]", |
| 2841 result_id, GetFilename("slow.txt").c_str()))); |
| 2841 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2842 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 2842 base::StringPrintf( | 2843 base::StringPrintf( |
| 2843 "[{\"id\": %d," | 2844 "[{\"id\": %d," |
| 2844 " \"filename\": {" | |
| 2845 " \"previous\": \"\"," | |
| 2846 " \"current\": \"%s\"}}]", | |
| 2847 result_id, | |
| 2848 GetFilename("slow.txt").c_str()))); | |
| 2849 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 2850 base::StringPrintf( | |
| 2851 "[{\"id\": %d," | |
| 2852 " \"state\": {" | 2845 " \"state\": {" |
| 2853 " \"previous\": \"in_progress\"," | 2846 " \"previous\": \"in_progress\"," |
| 2854 " \"current\": \"complete\"}}]", | 2847 " \"current\": \"complete\"}}]", |
| 2855 result_id))); | 2848 result_id))); |
| 2856 } | 2849 } |
| 2857 | 2850 |
| 2858 IN_PROC_BROWSER_TEST_F( | 2851 IN_PROC_BROWSER_TEST_F( |
| 2859 DownloadExtensionTest, | 2852 DownloadExtensionTest, |
| 2860 DownloadExtensionTest_OnDeterminingFilename_IllegalFilenameExtension) { | 2853 DownloadExtensionTest_OnDeterminingFilename_IllegalFilenameExtension) { |
| 2861 GoOnTheRecord(); | 2854 GoOnTheRecord(); |
| 2862 LoadExtension("downloads_split"); | 2855 LoadExtension("downloads_split"); |
| 2863 AddFilenameDeterminer(); | 2856 AddFilenameDeterminer(); |
| 2864 ASSERT_TRUE(StartEmbeddedTestServer()); | 2857 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2865 ASSERT_TRUE(test_server()->Start()); | 2858 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 2866 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 2867 | 2859 |
| 2868 // Start downloading a file. | 2860 // Start downloading a file. |
| 2869 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2861 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2870 new DownloadsDownloadFunction(), base::StringPrintf( | 2862 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2871 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2863 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2872 ASSERT_TRUE(result.get()); | 2864 ASSERT_TRUE(result.get()); |
| 2873 int result_id = -1; | 2865 int result_id = -1; |
| 2874 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2866 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2875 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2867 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2876 ASSERT_TRUE(item); | 2868 ASSERT_TRUE(item); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2900 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | 2892 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 2901 browser()->profile(), | 2893 browser()->profile(), |
| 2902 false, | 2894 false, |
| 2903 GetExtensionId(), | 2895 GetExtensionId(), |
| 2904 result_id, | 2896 result_id, |
| 2905 base::FilePath(FILE_PATH_LITERAL( | 2897 base::FilePath(FILE_PATH_LITERAL( |
| 2906 "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}/foo")), | 2898 "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}/foo")), |
| 2907 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 2899 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 2908 &error)); | 2900 &error)); |
| 2909 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); | 2901 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); |
| 2902 ASSERT_TRUE( |
| 2903 WaitFor(downloads::OnChanged::kEventName, |
| 2904 base::StringPrintf("[{\"id\": %d," |
| 2905 " \"filename\": {" |
| 2906 " \"previous\": \"\"," |
| 2907 " \"current\": \"%s\"}}]", |
| 2908 result_id, GetFilename("slow.txt").c_str()))); |
| 2910 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2909 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 2911 base::StringPrintf( | 2910 base::StringPrintf( |
| 2912 "[{\"id\": %d," | 2911 "[{\"id\": %d," |
| 2913 " \"filename\": {" | |
| 2914 " \"previous\": \"\"," | |
| 2915 " \"current\": \"%s\"}}]", | |
| 2916 result_id, | |
| 2917 GetFilename("slow.txt").c_str()))); | |
| 2918 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 2919 base::StringPrintf( | |
| 2920 "[{\"id\": %d," | |
| 2921 " \"state\": {" | 2912 " \"state\": {" |
| 2922 " \"previous\": \"in_progress\"," | 2913 " \"previous\": \"in_progress\"," |
| 2923 " \"current\": \"complete\"}}]", | 2914 " \"current\": \"complete\"}}]", |
| 2924 result_id))); | 2915 result_id))); |
| 2925 } | 2916 } |
| 2926 #if defined(OS_WIN) | 2917 #if defined(OS_WIN) |
| 2927 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename\ | 2918 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename\ |
| 2928 DISABLED_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename | 2919 DISABLED_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename |
| 2929 #else | 2920 #else |
| 2930 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename\ | 2921 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename\ |
| 2931 DownloadExtensionTest_OnDeterminingFilename_ReservedFilename | 2922 DownloadExtensionTest_OnDeterminingFilename_ReservedFilename |
| 2932 #endif | 2923 #endif |
| 2933 IN_PROC_BROWSER_TEST_F( | 2924 IN_PROC_BROWSER_TEST_F( |
| 2934 DownloadExtensionTest, | 2925 DownloadExtensionTest, |
| 2935 MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename) { | 2926 MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename) { |
| 2936 GoOnTheRecord(); | 2927 GoOnTheRecord(); |
| 2937 LoadExtension("downloads_split"); | 2928 LoadExtension("downloads_split"); |
| 2938 AddFilenameDeterminer(); | 2929 AddFilenameDeterminer(); |
| 2939 ASSERT_TRUE(StartEmbeddedTestServer()); | 2930 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 2940 ASSERT_TRUE(test_server()->Start()); | 2931 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 2941 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 2942 | 2932 |
| 2943 // Start downloading a file. | 2933 // Start downloading a file. |
| 2944 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2934 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2945 new DownloadsDownloadFunction(), base::StringPrintf( | 2935 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2946 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2936 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2947 ASSERT_TRUE(result.get()); | 2937 ASSERT_TRUE(result.get()); |
| 2948 int result_id = -1; | 2938 int result_id = -1; |
| 2949 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2939 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2950 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2940 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2951 ASSERT_TRUE(item); | 2941 ASSERT_TRUE(item); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2974 std::string error; | 2964 std::string error; |
| 2975 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | 2965 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 2976 browser()->profile(), | 2966 browser()->profile(), |
| 2977 false, | 2967 false, |
| 2978 GetExtensionId(), | 2968 GetExtensionId(), |
| 2979 result_id, | 2969 result_id, |
| 2980 base::FilePath(FILE_PATH_LITERAL("con.foo")), | 2970 base::FilePath(FILE_PATH_LITERAL("con.foo")), |
| 2981 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 2971 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 2982 &error)); | 2972 &error)); |
| 2983 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); | 2973 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); |
| 2974 ASSERT_TRUE( |
| 2975 WaitFor(downloads::OnChanged::kEventName, |
| 2976 base::StringPrintf("[{\"id\": %d," |
| 2977 " \"filename\": {" |
| 2978 " \"previous\": \"\"," |
| 2979 " \"current\": \"%s\"}}]", |
| 2980 result_id, GetFilename("slow.txt").c_str()))); |
| 2984 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 2981 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 2985 base::StringPrintf( | 2982 base::StringPrintf( |
| 2986 "[{\"id\": %d," | 2983 "[{\"id\": %d," |
| 2987 " \"filename\": {" | |
| 2988 " \"previous\": \"\"," | |
| 2989 " \"current\": \"%s\"}}]", | |
| 2990 result_id, | |
| 2991 GetFilename("slow.txt").c_str()))); | |
| 2992 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 2993 base::StringPrintf( | |
| 2994 "[{\"id\": %d," | |
| 2995 " \"state\": {" | 2984 " \"state\": {" |
| 2996 " \"previous\": \"in_progress\"," | 2985 " \"previous\": \"in_progress\"," |
| 2997 " \"current\": \"complete\"}}]", | 2986 " \"current\": \"complete\"}}]", |
| 2998 result_id))); | 2987 result_id))); |
| 2999 } | 2988 } |
| 3000 | 2989 |
| 3001 IN_PROC_BROWSER_TEST_F( | 2990 IN_PROC_BROWSER_TEST_F( |
| 3002 DownloadExtensionTest, | 2991 DownloadExtensionTest, |
| 3003 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) { | 2992 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) { |
| 3004 GoOnTheRecord(); | 2993 GoOnTheRecord(); |
| 3005 LoadExtension("downloads_split"); | 2994 LoadExtension("downloads_split"); |
| 3006 AddFilenameDeterminer(); | 2995 AddFilenameDeterminer(); |
| 3007 ASSERT_TRUE(StartEmbeddedTestServer()); | 2996 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3008 ASSERT_TRUE(test_server()->Start()); | 2997 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3009 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 3010 | 2998 |
| 3011 // Start downloading a file. | 2999 // Start downloading a file. |
| 3012 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3000 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 3013 new DownloadsDownloadFunction(), base::StringPrintf( | 3001 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3014 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3002 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3015 ASSERT_TRUE(result.get()); | 3003 ASSERT_TRUE(result.get()); |
| 3016 int result_id = -1; | 3004 int result_id = -1; |
| 3017 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3005 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 3018 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3006 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 3019 ASSERT_TRUE(item); | 3007 ASSERT_TRUE(item); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3042 std::string error; | 3030 std::string error; |
| 3043 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | 3031 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 3044 browser()->profile(), | 3032 browser()->profile(), |
| 3045 false, | 3033 false, |
| 3046 GetExtensionId(), | 3034 GetExtensionId(), |
| 3047 result_id, | 3035 result_id, |
| 3048 base::FilePath(FILE_PATH_LITERAL(".")), | 3036 base::FilePath(FILE_PATH_LITERAL(".")), |
| 3049 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 3037 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 3050 &error)); | 3038 &error)); |
| 3051 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); | 3039 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); |
| 3040 ASSERT_TRUE( |
| 3041 WaitFor(downloads::OnChanged::kEventName, |
| 3042 base::StringPrintf("[{\"id\": %d," |
| 3043 " \"filename\": {" |
| 3044 " \"previous\": \"\"," |
| 3045 " \"current\": \"%s\"}}]", |
| 3046 result_id, GetFilename("slow.txt").c_str()))); |
| 3052 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 3047 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 3053 base::StringPrintf( | 3048 base::StringPrintf( |
| 3054 "[{\"id\": %d," | 3049 "[{\"id\": %d," |
| 3055 " \"filename\": {" | |
| 3056 " \"previous\": \"\"," | |
| 3057 " \"current\": \"%s\"}}]", | |
| 3058 result_id, | |
| 3059 GetFilename("slow.txt").c_str()))); | |
| 3060 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 3061 base::StringPrintf( | |
| 3062 "[{\"id\": %d," | |
| 3063 " \"state\": {" | 3050 " \"state\": {" |
| 3064 " \"previous\": \"in_progress\"," | 3051 " \"previous\": \"in_progress\"," |
| 3065 " \"current\": \"complete\"}}]", | 3052 " \"current\": \"complete\"}}]", |
| 3066 result_id))); | 3053 result_id))); |
| 3067 } | 3054 } |
| 3068 | 3055 |
| 3069 IN_PROC_BROWSER_TEST_F( | 3056 IN_PROC_BROWSER_TEST_F( |
| 3070 DownloadExtensionTest, | 3057 DownloadExtensionTest, |
| 3071 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) { | 3058 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) { |
| 3072 ASSERT_TRUE(StartEmbeddedTestServer()); | 3059 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3073 ASSERT_TRUE(test_server()->Start()); | |
| 3074 GoOnTheRecord(); | 3060 GoOnTheRecord(); |
| 3075 LoadExtension("downloads_split"); | 3061 LoadExtension("downloads_split"); |
| 3076 AddFilenameDeterminer(); | 3062 AddFilenameDeterminer(); |
| 3077 std::string download_url = test_server()->GetURL("slow?0").spec(); | 3063 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3078 | 3064 |
| 3079 // Start downloading a file. | 3065 // Start downloading a file. |
| 3080 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3066 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 3081 new DownloadsDownloadFunction(), base::StringPrintf( | 3067 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3082 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3068 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3083 ASSERT_TRUE(result.get()); | 3069 ASSERT_TRUE(result.get()); |
| 3084 int result_id = -1; | 3070 int result_id = -1; |
| 3085 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3071 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 3086 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3072 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 3087 ASSERT_TRUE(item); | 3073 ASSERT_TRUE(item); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3110 std::string error; | 3096 std::string error; |
| 3111 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | 3097 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 3112 browser()->profile(), | 3098 browser()->profile(), |
| 3113 false, | 3099 false, |
| 3114 GetExtensionId(), | 3100 GetExtensionId(), |
| 3115 result_id, | 3101 result_id, |
| 3116 base::FilePath(FILE_PATH_LITERAL("..")), | 3102 base::FilePath(FILE_PATH_LITERAL("..")), |
| 3117 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 3103 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 3118 &error)); | 3104 &error)); |
| 3119 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); | 3105 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); |
| 3106 ASSERT_TRUE( |
| 3107 WaitFor(downloads::OnChanged::kEventName, |
| 3108 base::StringPrintf("[{\"id\": %d," |
| 3109 " \"filename\": {" |
| 3110 " \"previous\": \"\"," |
| 3111 " \"current\": \"%s\"}}]", |
| 3112 result_id, GetFilename("slow.txt").c_str()))); |
| 3120 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 3113 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 3121 base::StringPrintf( | 3114 base::StringPrintf( |
| 3122 "[{\"id\": %d," | 3115 "[{\"id\": %d," |
| 3123 " \"filename\": {" | |
| 3124 " \"previous\": \"\"," | |
| 3125 " \"current\": \"%s\"}}]", | |
| 3126 result_id, | |
| 3127 GetFilename("slow.txt").c_str()))); | |
| 3128 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 3129 base::StringPrintf( | |
| 3130 "[{\"id\": %d," | |
| 3131 " \"state\": {" | 3116 " \"state\": {" |
| 3132 " \"previous\": \"in_progress\"," | 3117 " \"previous\": \"in_progress\"," |
| 3133 " \"current\": \"complete\"}}]", | 3118 " \"current\": \"complete\"}}]", |
| 3134 result_id))); | 3119 result_id))); |
| 3135 } | 3120 } |
| 3136 | 3121 |
| 3137 IN_PROC_BROWSER_TEST_F( | 3122 IN_PROC_BROWSER_TEST_F( |
| 3138 DownloadExtensionTest, | 3123 DownloadExtensionTest, |
| 3139 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) { | 3124 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) { |
| 3140 GoOnTheRecord(); | 3125 GoOnTheRecord(); |
| 3141 LoadExtension("downloads_split"); | 3126 LoadExtension("downloads_split"); |
| 3142 AddFilenameDeterminer(); | 3127 AddFilenameDeterminer(); |
| 3143 ASSERT_TRUE(StartEmbeddedTestServer()); | 3128 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3144 ASSERT_TRUE(test_server()->Start()); | 3129 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3145 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 3146 | 3130 |
| 3147 // Start downloading a file. | 3131 // Start downloading a file. |
| 3148 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3132 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 3149 new DownloadsDownloadFunction(), base::StringPrintf( | 3133 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3150 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3134 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3151 ASSERT_TRUE(result.get()); | 3135 ASSERT_TRUE(result.get()); |
| 3152 int result_id = -1; | 3136 int result_id = -1; |
| 3153 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3137 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 3154 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3138 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 3155 ASSERT_TRUE(item); | 3139 ASSERT_TRUE(item); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3179 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | 3163 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 3180 browser()->profile(), | 3164 browser()->profile(), |
| 3181 false, | 3165 false, |
| 3182 GetExtensionId(), | 3166 GetExtensionId(), |
| 3183 result_id, | 3167 result_id, |
| 3184 downloads_directory().Append(FILE_PATH_LITERAL("sneaky.txt")), | 3168 downloads_directory().Append(FILE_PATH_LITERAL("sneaky.txt")), |
| 3185 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 3169 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 3186 &error)); | 3170 &error)); |
| 3187 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); | 3171 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); |
| 3188 | 3172 |
| 3173 ASSERT_TRUE( |
| 3174 WaitFor(downloads::OnChanged::kEventName, |
| 3175 base::StringPrintf("[{\"id\": %d," |
| 3176 " \"filename\": {" |
| 3177 " \"previous\": \"\"," |
| 3178 " \"current\": \"%s\"}}]", |
| 3179 result_id, GetFilename("slow.txt").c_str()))); |
| 3189 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 3180 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 3190 base::StringPrintf( | 3181 base::StringPrintf( |
| 3191 "[{\"id\": %d," | 3182 "[{\"id\": %d," |
| 3192 " \"filename\": {" | |
| 3193 " \"previous\": \"\"," | |
| 3194 " \"current\": \"%s\"}}]", | |
| 3195 result_id, | |
| 3196 GetFilename("slow.txt").c_str()))); | |
| 3197 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 3198 base::StringPrintf( | |
| 3199 "[{\"id\": %d," | |
| 3200 " \"state\": {" | 3183 " \"state\": {" |
| 3201 " \"previous\": \"in_progress\"," | 3184 " \"previous\": \"in_progress\"," |
| 3202 " \"current\": \"complete\"}}]", | 3185 " \"current\": \"complete\"}}]", |
| 3203 result_id))); | 3186 result_id))); |
| 3204 } | 3187 } |
| 3205 | 3188 |
| 3206 IN_PROC_BROWSER_TEST_F( | 3189 IN_PROC_BROWSER_TEST_F( |
| 3207 DownloadExtensionTest, | 3190 DownloadExtensionTest, |
| 3208 DownloadExtensionTest_OnDeterminingFilename_EmptyBasenameInvalid) { | 3191 DownloadExtensionTest_OnDeterminingFilename_EmptyBasenameInvalid) { |
| 3209 GoOnTheRecord(); | 3192 GoOnTheRecord(); |
| 3210 LoadExtension("downloads_split"); | 3193 LoadExtension("downloads_split"); |
| 3211 AddFilenameDeterminer(); | 3194 AddFilenameDeterminer(); |
| 3212 ASSERT_TRUE(StartEmbeddedTestServer()); | 3195 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3213 ASSERT_TRUE(test_server()->Start()); | 3196 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3214 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 3215 | 3197 |
| 3216 // Start downloading a file. | 3198 // Start downloading a file. |
| 3217 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3199 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 3218 new DownloadsDownloadFunction(), base::StringPrintf( | 3200 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3219 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3201 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3220 ASSERT_TRUE(result.get()); | 3202 ASSERT_TRUE(result.get()); |
| 3221 int result_id = -1; | 3203 int result_id = -1; |
| 3222 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3204 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 3223 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3205 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 3224 ASSERT_TRUE(item); | 3206 ASSERT_TRUE(item); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3248 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | 3230 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 3249 browser()->profile(), | 3231 browser()->profile(), |
| 3250 false, | 3232 false, |
| 3251 GetExtensionId(), | 3233 GetExtensionId(), |
| 3252 result_id, | 3234 result_id, |
| 3253 base::FilePath(FILE_PATH_LITERAL("foo/")), | 3235 base::FilePath(FILE_PATH_LITERAL("foo/")), |
| 3254 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 3236 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 3255 &error)); | 3237 &error)); |
| 3256 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); | 3238 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); |
| 3257 | 3239 |
| 3240 ASSERT_TRUE( |
| 3241 WaitFor(downloads::OnChanged::kEventName, |
| 3242 base::StringPrintf("[{\"id\": %d," |
| 3243 " \"filename\": {" |
| 3244 " \"previous\": \"\"," |
| 3245 " \"current\": \"%s\"}}]", |
| 3246 result_id, GetFilename("slow.txt").c_str()))); |
| 3258 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 3247 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 3259 base::StringPrintf( | 3248 base::StringPrintf( |
| 3260 "[{\"id\": %d," | 3249 "[{\"id\": %d," |
| 3261 " \"filename\": {" | |
| 3262 " \"previous\": \"\"," | |
| 3263 " \"current\": \"%s\"}}]", | |
| 3264 result_id, | |
| 3265 GetFilename("slow.txt").c_str()))); | |
| 3266 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 3267 base::StringPrintf( | |
| 3268 "[{\"id\": %d," | |
| 3269 " \"state\": {" | 3250 " \"state\": {" |
| 3270 " \"previous\": \"in_progress\"," | 3251 " \"previous\": \"in_progress\"," |
| 3271 " \"current\": \"complete\"}}]", | 3252 " \"current\": \"complete\"}}]", |
| 3272 result_id))); | 3253 result_id))); |
| 3273 } | 3254 } |
| 3274 | 3255 |
| 3275 // conflictAction may be specified without filename. | 3256 // conflictAction may be specified without filename. |
| 3276 IN_PROC_BROWSER_TEST_F( | 3257 IN_PROC_BROWSER_TEST_F( |
| 3277 DownloadExtensionTest, | 3258 DownloadExtensionTest, |
| 3278 DownloadExtensionTest_OnDeterminingFilename_Overwrite) { | 3259 DownloadExtensionTest_OnDeterminingFilename_Overwrite) { |
| 3279 GoOnTheRecord(); | 3260 GoOnTheRecord(); |
| 3280 LoadExtension("downloads_split"); | 3261 LoadExtension("downloads_split"); |
| 3281 AddFilenameDeterminer(); | 3262 AddFilenameDeterminer(); |
| 3282 ASSERT_TRUE(StartEmbeddedTestServer()); | 3263 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3283 ASSERT_TRUE(test_server()->Start()); | 3264 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3284 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 3285 | 3265 |
| 3286 // Start downloading a file. | 3266 // Start downloading a file. |
| 3287 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3267 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 3288 new DownloadsDownloadFunction(), base::StringPrintf( | 3268 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3289 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3269 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3290 ASSERT_TRUE(result.get()); | 3270 ASSERT_TRUE(result.get()); |
| 3291 int result_id = -1; | 3271 int result_id = -1; |
| 3292 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3272 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 3293 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3273 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 3294 ASSERT_TRUE(item); | 3274 ASSERT_TRUE(item); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3317 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | 3297 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 3318 browser()->profile(), | 3298 browser()->profile(), |
| 3319 false, | 3299 false, |
| 3320 GetExtensionId(), | 3300 GetExtensionId(), |
| 3321 result_id, | 3301 result_id, |
| 3322 base::FilePath(), | 3302 base::FilePath(), |
| 3323 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 3303 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 3324 &error)); | 3304 &error)); |
| 3325 EXPECT_EQ("", error); | 3305 EXPECT_EQ("", error); |
| 3326 | 3306 |
| 3307 ASSERT_TRUE( |
| 3308 WaitFor(downloads::OnChanged::kEventName, |
| 3309 base::StringPrintf("[{\"id\": %d," |
| 3310 " \"filename\": {" |
| 3311 " \"previous\": \"\"," |
| 3312 " \"current\": \"%s\"}}]", |
| 3313 result_id, GetFilename("slow.txt").c_str()))); |
| 3327 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 3314 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 3328 base::StringPrintf( | 3315 base::StringPrintf( |
| 3329 "[{\"id\": %d," | 3316 "[{\"id\": %d," |
| 3330 " \"filename\": {" | |
| 3331 " \"previous\": \"\"," | |
| 3332 " \"current\": \"%s\"}}]", | |
| 3333 result_id, | |
| 3334 GetFilename("slow.txt").c_str()))); | |
| 3335 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 3336 base::StringPrintf( | |
| 3337 "[{\"id\": %d," | |
| 3338 " \"state\": {" | 3317 " \"state\": {" |
| 3339 " \"previous\": \"in_progress\"," | 3318 " \"previous\": \"in_progress\"," |
| 3340 " \"current\": \"complete\"}}]", | 3319 " \"current\": \"complete\"}}]", |
| 3341 result_id))); | 3320 result_id))); |
| 3342 | 3321 |
| 3343 // Start downloading a file. | 3322 // Start downloading a file. |
| 3344 result.reset(RunFunctionAndReturnResult( | 3323 result.reset(RunFunctionAndReturnResult( |
| 3345 new DownloadsDownloadFunction(), base::StringPrintf( | 3324 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3346 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3325 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3347 ASSERT_TRUE(result.get()); | 3326 ASSERT_TRUE(result.get()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3378 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | 3357 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 3379 browser()->profile(), | 3358 browser()->profile(), |
| 3380 false, | 3359 false, |
| 3381 GetExtensionId(), | 3360 GetExtensionId(), |
| 3382 result_id, | 3361 result_id, |
| 3383 base::FilePath(), | 3362 base::FilePath(), |
| 3384 downloads::FILENAME_CONFLICT_ACTION_OVERWRITE, | 3363 downloads::FILENAME_CONFLICT_ACTION_OVERWRITE, |
| 3385 &error)); | 3364 &error)); |
| 3386 EXPECT_EQ("", error); | 3365 EXPECT_EQ("", error); |
| 3387 | 3366 |
| 3367 ASSERT_TRUE( |
| 3368 WaitFor(downloads::OnChanged::kEventName, |
| 3369 base::StringPrintf("[{\"id\": %d," |
| 3370 " \"filename\": {" |
| 3371 " \"previous\": \"\"," |
| 3372 " \"current\": \"%s\"}}]", |
| 3373 result_id, GetFilename("slow.txt").c_str()))); |
| 3388 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 3374 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 3389 base::StringPrintf( | 3375 base::StringPrintf( |
| 3390 "[{\"id\": %d," | 3376 "[{\"id\": %d," |
| 3391 " \"filename\": {" | |
| 3392 " \"previous\": \"\"," | |
| 3393 " \"current\": \"%s\"}}]", | |
| 3394 result_id, | |
| 3395 GetFilename("slow.txt").c_str()))); | |
| 3396 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 3397 base::StringPrintf( | |
| 3398 "[{\"id\": %d," | |
| 3399 " \"state\": {" | 3377 " \"state\": {" |
| 3400 " \"previous\": \"in_progress\"," | 3378 " \"previous\": \"in_progress\"," |
| 3401 " \"current\": \"complete\"}}]", | 3379 " \"current\": \"complete\"}}]", |
| 3402 result_id))); | 3380 result_id))); |
| 3403 } | 3381 } |
| 3404 | 3382 |
| 3405 IN_PROC_BROWSER_TEST_F( | 3383 IN_PROC_BROWSER_TEST_F( |
| 3406 DownloadExtensionTest, | 3384 DownloadExtensionTest, |
| 3407 DownloadExtensionTest_OnDeterminingFilename_Override) { | 3385 DownloadExtensionTest_OnDeterminingFilename_Override) { |
| 3408 GoOnTheRecord(); | 3386 GoOnTheRecord(); |
| 3409 LoadExtension("downloads_split"); | 3387 LoadExtension("downloads_split"); |
| 3410 AddFilenameDeterminer(); | 3388 AddFilenameDeterminer(); |
| 3411 ASSERT_TRUE(StartEmbeddedTestServer()); | 3389 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3412 ASSERT_TRUE(test_server()->Start()); | 3390 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3413 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 3414 | 3391 |
| 3415 // Start downloading a file. | 3392 // Start downloading a file. |
| 3416 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3393 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 3417 new DownloadsDownloadFunction(), base::StringPrintf( | 3394 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3418 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3395 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3419 ASSERT_TRUE(result.get()); | 3396 ASSERT_TRUE(result.get()); |
| 3420 int result_id = -1; | 3397 int result_id = -1; |
| 3421 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3398 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 3422 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3399 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 3423 ASSERT_TRUE(item); | 3400 ASSERT_TRUE(item); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3446 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | 3423 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( |
| 3447 browser()->profile(), | 3424 browser()->profile(), |
| 3448 false, | 3425 false, |
| 3449 GetExtensionId(), | 3426 GetExtensionId(), |
| 3450 result_id, | 3427 result_id, |
| 3451 base::FilePath(), | 3428 base::FilePath(), |
| 3452 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, | 3429 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, |
| 3453 &error)); | 3430 &error)); |
| 3454 EXPECT_EQ("", error); | 3431 EXPECT_EQ("", error); |
| 3455 | 3432 |
| 3433 ASSERT_TRUE( |
| 3434 WaitFor(downloads::OnChanged::kEventName, |
| 3435 base::StringPrintf("[{\"id\": %d," |
| 3436 " \"filename\": {" |
| 3437 " \"previous\": \"\"," |
| 3438 " \"current\": \"%s\"}}]", |
| 3439 result_id, GetFilename("slow.txt").c_str()))); |
| 3456 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 3440 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 3457 base::StringPrintf( | 3441 base::StringPrintf( |
| 3458 "[{\"id\": %d," | 3442 "[{\"id\": %d," |
| 3459 " \"filename\": {" | |
| 3460 " \"previous\": \"\"," | |
| 3461 " \"current\": \"%s\"}}]", | |
| 3462 result_id, | |
| 3463 GetFilename("slow.txt").c_str()))); | |
| 3464 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | |
| 3465 base::StringPrintf( | |
| 3466 "[{\"id\": %d," | |
| 3467 " \"state\": {" | 3443 " \"state\": {" |
| 3468 " \"previous\": \"in_progress\"," | 3444 " \"previous\": \"in_progress\"," |
| 3469 " \"current\": \"complete\"}}]", | 3445 " \"current\": \"complete\"}}]", |
| 3470 result_id))); | 3446 result_id))); |
| 3471 | 3447 |
| 3472 // Start downloading a file. | 3448 // Start downloading a file. |
| 3473 result.reset(RunFunctionAndReturnResult( | 3449 result.reset(RunFunctionAndReturnResult( |
| 3474 new DownloadsDownloadFunction(), base::StringPrintf( | 3450 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3475 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3451 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3476 ASSERT_TRUE(result.get()); | 3452 ASSERT_TRUE(result.get()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3537 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDetermin
er \ | 3513 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDetermin
er \ |
| 3538 DISABLED_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer | 3514 DISABLED_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer |
| 3539 #else | 3515 #else |
| 3540 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDetermin
er \ | 3516 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDetermin
er \ |
| 3541 DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer | 3517 DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer |
| 3542 #endif | 3518 #endif |
| 3543 IN_PROC_BROWSER_TEST_F( | 3519 IN_PROC_BROWSER_TEST_F( |
| 3544 DownloadExtensionTest, | 3520 DownloadExtensionTest, |
| 3545 MAYBE_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer)
{ | 3521 MAYBE_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer)
{ |
| 3546 ASSERT_TRUE(StartEmbeddedTestServer()); | 3522 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3547 ASSERT_TRUE(test_server()->Start()); | |
| 3548 GoOnTheRecord(); | 3523 GoOnTheRecord(); |
| 3549 LoadExtension("downloads_split"); | 3524 LoadExtension("downloads_split"); |
| 3550 content::RenderProcessHost* host = AddFilenameDeterminer(); | 3525 content::RenderProcessHost* host = AddFilenameDeterminer(); |
| 3551 std::string download_url = test_server()->GetURL("slow?0").spec(); | 3526 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3552 | 3527 |
| 3553 // Start downloading a file. | 3528 // Start downloading a file. |
| 3554 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3529 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 3555 new DownloadsDownloadFunction(), base::StringPrintf( | 3530 new DownloadsDownloadFunction(), base::StringPrintf( |
| 3556 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3531 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 3557 ASSERT_TRUE(result.get()); | 3532 ASSERT_TRUE(result.get()); |
| 3558 int result_id = -1; | 3533 int result_id = -1; |
| 3559 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3534 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 3560 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3535 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 3561 ASSERT_TRUE(item); | 3536 ASSERT_TRUE(item); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3590 " \"previous\": \"in_progress\"," | 3565 " \"previous\": \"in_progress\"," |
| 3591 " \"current\": \"complete\"}}]", | 3566 " \"current\": \"complete\"}}]", |
| 3592 result_id))); | 3567 result_id))); |
| 3593 } | 3568 } |
| 3594 | 3569 |
| 3595 IN_PROC_BROWSER_TEST_F( | 3570 IN_PROC_BROWSER_TEST_F( |
| 3596 DownloadExtensionTest, | 3571 DownloadExtensionTest, |
| 3597 DownloadExtensionTest_OnDeterminingFilename_IncognitoSplit) { | 3572 DownloadExtensionTest_OnDeterminingFilename_IncognitoSplit) { |
| 3598 LoadExtension("downloads_split"); | 3573 LoadExtension("downloads_split"); |
| 3599 ASSERT_TRUE(StartEmbeddedTestServer()); | 3574 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3600 ASSERT_TRUE(test_server()->Start()); | 3575 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3601 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 3602 | 3576 |
| 3603 GoOnTheRecord(); | 3577 GoOnTheRecord(); |
| 3604 AddFilenameDeterminer(); | 3578 AddFilenameDeterminer(); |
| 3605 | 3579 |
| 3606 GoOffTheRecord(); | 3580 GoOffTheRecord(); |
| 3607 AddFilenameDeterminer(); | 3581 AddFilenameDeterminer(); |
| 3608 | 3582 |
| 3609 // Start an on-record download. | 3583 // Start an on-record download. |
| 3610 GoOnTheRecord(); | 3584 GoOnTheRecord(); |
| 3611 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3585 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3729 " \"previous\": \"in_progress\"," | 3703 " \"previous\": \"in_progress\"," |
| 3730 " \"current\": \"complete\"}}]", | 3704 " \"current\": \"complete\"}}]", |
| 3731 result_id))); | 3705 result_id))); |
| 3732 } | 3706 } |
| 3733 | 3707 |
| 3734 IN_PROC_BROWSER_TEST_F( | 3708 IN_PROC_BROWSER_TEST_F( |
| 3735 DownloadExtensionTest, | 3709 DownloadExtensionTest, |
| 3736 DownloadExtensionTest_OnDeterminingFilename_IncognitoSpanning) { | 3710 DownloadExtensionTest_OnDeterminingFilename_IncognitoSpanning) { |
| 3737 LoadExtension("downloads_spanning"); | 3711 LoadExtension("downloads_spanning"); |
| 3738 ASSERT_TRUE(StartEmbeddedTestServer()); | 3712 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3739 ASSERT_TRUE(test_server()->Start()); | 3713 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
| 3740 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
| 3741 | 3714 |
| 3742 GoOnTheRecord(); | 3715 GoOnTheRecord(); |
| 3743 AddFilenameDeterminer(); | 3716 AddFilenameDeterminer(); |
| 3744 | 3717 |
| 3745 // There is a single extension renderer that sees both on-record and | 3718 // There is a single extension renderer that sees both on-record and |
| 3746 // off-record events. The extension functions see the on-record profile with | 3719 // off-record events. The extension functions see the on-record profile with |
| 3747 // include_incognito=true. | 3720 // include_incognito=true. |
| 3748 | 3721 |
| 3749 // Start an on-record download. | 3722 // Start an on-record download. |
| 3750 GoOnTheRecord(); | 3723 GoOnTheRecord(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3881 | 3854 |
| 3882 // Test download interruption while extensions determining filename. Should not | 3855 // Test download interruption while extensions determining filename. Should not |
| 3883 // re-dispatch onDeterminingFilename. | 3856 // re-dispatch onDeterminingFilename. |
| 3884 IN_PROC_BROWSER_TEST_F( | 3857 IN_PROC_BROWSER_TEST_F( |
| 3885 DownloadExtensionTest, | 3858 DownloadExtensionTest, |
| 3886 MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume) { | 3859 MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume) { |
| 3887 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 3860 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3888 switches::kEnableDownloadResumption); | 3861 switches::kEnableDownloadResumption); |
| 3889 LoadExtension("downloads_split"); | 3862 LoadExtension("downloads_split"); |
| 3890 ASSERT_TRUE(StartEmbeddedTestServer()); | 3863 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 3891 ASSERT_TRUE(test_server()->Start()); | |
| 3892 GoOnTheRecord(); | 3864 GoOnTheRecord(); |
| 3893 content::RenderProcessHost* host = AddFilenameDeterminer(); | 3865 content::RenderProcessHost* host = AddFilenameDeterminer(); |
| 3894 | 3866 |
| 3895 // Start a download. | 3867 // Start a download. |
| 3896 DownloadItem* item = NULL; | 3868 DownloadItem* item = NULL; |
| 3897 { | 3869 { |
| 3898 DownloadManager* manager = GetCurrentManager(); | 3870 DownloadManager* manager = GetCurrentManager(); |
| 3899 scoped_ptr<content::DownloadTestObserver> observer( | 3871 scoped_ptr<content::DownloadTestObserver> observer( |
| 3900 new JustInProgressDownloadObserver(manager, 1)); | 3872 new JustInProgressDownloadObserver(manager, 1)); |
| 3901 ASSERT_EQ(0, manager->InProgressCount()); | 3873 ASSERT_EQ(0, manager->InProgressCount()); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4178 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 4150 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
| 4179 EXPECT_FALSE(warnings.empty()); | 4151 EXPECT_FALSE(warnings.empty()); |
| 4180 EXPECT_EQ(Warning::kDownloadFilenameConflict, | 4152 EXPECT_EQ(Warning::kDownloadFilenameConflict, |
| 4181 warnings.begin()->warning_type()); | 4153 warnings.begin()->warning_type()); |
| 4182 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4154 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
| 4183 } | 4155 } |
| 4184 | 4156 |
| 4185 } // namespace extensions | 4157 } // namespace extensions |
| 4186 | 4158 |
| 4187 #endif // http://crbug.com/306144 | 4159 #endif // http://crbug.com/306144 |
| OLD | NEW |