| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 CHECK(StartTestServer()); | 1402 CHECK(StartTestServer()); |
| 1403 std::string download_url = test_server()->GetURL("slow?0").spec(); | 1403 std::string download_url = test_server()->GetURL("slow?0").spec(); |
| 1404 GoOnTheRecord(); | 1404 GoOnTheRecord(); |
| 1405 | 1405 |
| 1406 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1406 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1407 new DownloadsDownloadFunction(), base::StringPrintf( | 1407 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1408 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1408 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 1409 ASSERT_TRUE(result.get()); | 1409 ASSERT_TRUE(result.get()); |
| 1410 int result_id = -1; | 1410 int result_id = -1; |
| 1411 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1411 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1412 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1412 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1413 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1414 ASSERT_TRUE(item); | 1413 ASSERT_TRUE(item); |
| 1415 ScopedCancellingItem canceller(item); | 1414 ScopedCancellingItem canceller(item); |
| 1416 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1415 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1417 | 1416 |
| 1418 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 1417 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 1419 base::StringPrintf("[{\"danger\": \"safe\"," | 1418 base::StringPrintf("[{\"danger\": \"safe\"," |
| 1420 " \"incognito\": false," | 1419 " \"incognito\": false," |
| 1421 " \"mime\": \"text/plain\"," | 1420 " \"mime\": \"text/plain\"," |
| 1422 " \"paused\": false," | 1421 " \"paused\": false," |
| 1423 " \"url\": \"%s\"}]", | 1422 " \"url\": \"%s\"}]", |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1443 CHECK(StartTestServer()); | 1442 CHECK(StartTestServer()); |
| 1444 GoOffTheRecord(); | 1443 GoOffTheRecord(); |
| 1445 std::string download_url = test_server()->GetURL("slow?0").spec(); | 1444 std::string download_url = test_server()->GetURL("slow?0").spec(); |
| 1446 | 1445 |
| 1447 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1446 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1448 new DownloadsDownloadFunction(), base::StringPrintf( | 1447 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1449 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1448 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 1450 ASSERT_TRUE(result.get()); | 1449 ASSERT_TRUE(result.get()); |
| 1451 int result_id = -1; | 1450 int result_id = -1; |
| 1452 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1451 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1453 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1452 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1454 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1455 ASSERT_TRUE(item); | 1453 ASSERT_TRUE(item); |
| 1456 ScopedCancellingItem canceller(item); | 1454 ScopedCancellingItem canceller(item); |
| 1457 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1455 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1458 | 1456 |
| 1459 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 1457 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 1460 base::StringPrintf("[{\"danger\": \"safe\"," | 1458 base::StringPrintf("[{\"danger\": \"safe\"," |
| 1461 " \"incognito\": true," | 1459 " \"incognito\": true," |
| 1462 " \"mime\": \"text/plain\"," | 1460 " \"mime\": \"text/plain\"," |
| 1463 " \"paused\": false," | 1461 " \"paused\": false," |
| 1464 " \"url\": \"%s\"}]", | 1462 " \"url\": \"%s\"}]", |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1597 CHECK(StartTestServer()); | 1595 CHECK(StartTestServer()); |
| 1598 std::string download_url = test_server()->GetURL("slow?0#fragment").spec(); | 1596 std::string download_url = test_server()->GetURL("slow?0#fragment").spec(); |
| 1599 GoOnTheRecord(); | 1597 GoOnTheRecord(); |
| 1600 | 1598 |
| 1601 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1599 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1602 new DownloadsDownloadFunction(), base::StringPrintf( | 1600 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1603 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1601 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 1604 ASSERT_TRUE(result.get()); | 1602 ASSERT_TRUE(result.get()); |
| 1605 int result_id = -1; | 1603 int result_id = -1; |
| 1606 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1604 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1607 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1605 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1608 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1609 ASSERT_TRUE(item); | 1606 ASSERT_TRUE(item); |
| 1610 ScopedCancellingItem canceller(item); | 1607 ScopedCancellingItem canceller(item); |
| 1611 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1608 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1612 | 1609 |
| 1613 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 1610 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 1614 base::StringPrintf("[{\"danger\": \"safe\"," | 1611 base::StringPrintf("[{\"danger\": \"safe\"," |
| 1615 " \"incognito\": false," | 1612 " \"incognito\": false," |
| 1616 " \"mime\": \"text/plain\"," | 1613 " \"mime\": \"text/plain\"," |
| 1617 " \"paused\": false," | 1614 " \"paused\": false," |
| 1618 " \"url\": \"%s\"}]", | 1615 " \"url\": \"%s\"}]", |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1638 std::string download_url = "data:text/plain,hello"; | 1635 std::string download_url = "data:text/plain,hello"; |
| 1639 GoOnTheRecord(); | 1636 GoOnTheRecord(); |
| 1640 | 1637 |
| 1641 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1638 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1642 new DownloadsDownloadFunction(), base::StringPrintf( | 1639 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1643 "[{\"url\": \"%s\"," | 1640 "[{\"url\": \"%s\"," |
| 1644 " \"filename\": \"data.txt\"}]", download_url.c_str()))); | 1641 " \"filename\": \"data.txt\"}]", download_url.c_str()))); |
| 1645 ASSERT_TRUE(result.get()); | 1642 ASSERT_TRUE(result.get()); |
| 1646 int result_id = -1; | 1643 int result_id = -1; |
| 1647 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1644 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1648 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1645 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1649 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1650 ASSERT_TRUE(item); | 1646 ASSERT_TRUE(item); |
| 1651 ScopedCancellingItem canceller(item); | 1647 ScopedCancellingItem canceller(item); |
| 1652 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1648 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1653 | 1649 |
| 1654 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 1650 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 1655 base::StringPrintf("[{\"danger\": \"safe\"," | 1651 base::StringPrintf("[{\"danger\": \"safe\"," |
| 1656 " \"incognito\": false," | 1652 " \"incognito\": false," |
| 1657 " \"mime\": \"text/plain\"," | 1653 " \"mime\": \"text/plain\"," |
| 1658 " \"paused\": false," | 1654 " \"paused\": false," |
| 1659 " \"url\": \"%s\"}]", | 1655 " \"url\": \"%s\"}]", |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1682 download_url += "C:/"; | 1678 download_url += "C:/"; |
| 1683 #endif | 1679 #endif |
| 1684 | 1680 |
| 1685 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1681 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1686 new DownloadsDownloadFunction(), base::StringPrintf( | 1682 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1687 "[{\"url\": \"%s\"," | 1683 "[{\"url\": \"%s\"," |
| 1688 " \"filename\": \"file.txt\"}]", download_url.c_str()))); | 1684 " \"filename\": \"file.txt\"}]", download_url.c_str()))); |
| 1689 ASSERT_TRUE(result.get()); | 1685 ASSERT_TRUE(result.get()); |
| 1690 int result_id = -1; | 1686 int result_id = -1; |
| 1691 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1687 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1692 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1688 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1693 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1694 ASSERT_TRUE(item); | 1689 ASSERT_TRUE(item); |
| 1695 ScopedCancellingItem canceller(item); | 1690 ScopedCancellingItem canceller(item); |
| 1696 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1691 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1697 | 1692 |
| 1698 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 1693 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 1699 base::StringPrintf("[{\"danger\": \"safe\"," | 1694 base::StringPrintf("[{\"danger\": \"safe\"," |
| 1700 " \"incognito\": false," | 1695 " \"incognito\": false," |
| 1701 " \"mime\": \"text/html\"," | 1696 " \"mime\": \"text/html\"," |
| 1702 " \"paused\": false," | 1697 " \"paused\": false," |
| 1703 " \"url\": \"%s\"}]", | 1698 " \"url\": \"%s\"}]", |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1727 GoOnTheRecord(); | 1722 GoOnTheRecord(); |
| 1728 | 1723 |
| 1729 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1724 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1730 new DownloadsDownloadFunction(), base::StringPrintf( | 1725 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1731 "[{\"url\": \"%s\"," | 1726 "[{\"url\": \"%s\"," |
| 1732 " \"filename\": \"auth-basic-fail.txt\"}]", | 1727 " \"filename\": \"auth-basic-fail.txt\"}]", |
| 1733 download_url.c_str()))); | 1728 download_url.c_str()))); |
| 1734 ASSERT_TRUE(result.get()); | 1729 ASSERT_TRUE(result.get()); |
| 1735 int result_id = -1; | 1730 int result_id = -1; |
| 1736 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1731 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1737 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1732 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1738 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1739 ASSERT_TRUE(item); | 1733 ASSERT_TRUE(item); |
| 1740 ScopedCancellingItem canceller(item); | 1734 ScopedCancellingItem canceller(item); |
| 1741 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1735 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1742 | 1736 |
| 1743 ASSERT_TRUE(WaitForInterruption(item, 30, base::StringPrintf( | 1737 ASSERT_TRUE(WaitForInterruption(item, 30, base::StringPrintf( |
| 1744 "[{\"danger\": \"safe\"," | 1738 "[{\"danger\": \"safe\"," |
| 1745 " \"incognito\": false," | 1739 " \"incognito\": false," |
| 1746 " \"mime\": \"text/html\"," | 1740 " \"mime\": \"text/html\"," |
| 1747 " \"paused\": false," | 1741 " \"paused\": false," |
| 1748 " \"url\": \"%s\"}]", | 1742 " \"url\": \"%s\"}]", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1762 new DownloadsDownloadFunction(), base::StringPrintf( | 1756 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1763 "[{\"url\": \"%s\"," | 1757 "[{\"url\": \"%s\"," |
| 1764 " \"filename\": \"headers-succeed.txt\"," | 1758 " \"filename\": \"headers-succeed.txt\"," |
| 1765 " \"headers\": [" | 1759 " \"headers\": [" |
| 1766 " {\"name\": \"Foo\", \"value\": \"bar\"}," | 1760 " {\"name\": \"Foo\", \"value\": \"bar\"}," |
| 1767 " {\"name\": \"Qx\", \"value\":\"yo\"}]}]", | 1761 " {\"name\": \"Qx\", \"value\":\"yo\"}]}]", |
| 1768 download_url.c_str()))); | 1762 download_url.c_str()))); |
| 1769 ASSERT_TRUE(result.get()); | 1763 ASSERT_TRUE(result.get()); |
| 1770 int result_id = -1; | 1764 int result_id = -1; |
| 1771 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1765 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1772 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1766 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1773 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1774 ASSERT_TRUE(item); | 1767 ASSERT_TRUE(item); |
| 1775 ScopedCancellingItem canceller(item); | 1768 ScopedCancellingItem canceller(item); |
| 1776 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1769 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1777 | 1770 |
| 1778 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 1771 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 1779 base::StringPrintf("[{\"danger\": \"safe\"," | 1772 base::StringPrintf("[{\"danger\": \"safe\"," |
| 1780 " \"incognito\": false," | 1773 " \"incognito\": false," |
| 1781 " \"mime\": \"application/octet-stream\"," | 1774 " \"mime\": \"application/octet-stream\"," |
| 1782 " \"paused\": false," | 1775 " \"paused\": false," |
| 1783 " \"url\": \"%s\"}]", | 1776 " \"url\": \"%s\"}]", |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1810 GoOnTheRecord(); | 1803 GoOnTheRecord(); |
| 1811 | 1804 |
| 1812 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1805 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1813 new DownloadsDownloadFunction(), base::StringPrintf( | 1806 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1814 "[{\"url\": \"%s\"," | 1807 "[{\"url\": \"%s\"," |
| 1815 " \"filename\": \"headers-fail.txt\"}]", | 1808 " \"filename\": \"headers-fail.txt\"}]", |
| 1816 download_url.c_str()))); | 1809 download_url.c_str()))); |
| 1817 ASSERT_TRUE(result.get()); | 1810 ASSERT_TRUE(result.get()); |
| 1818 int result_id = -1; | 1811 int result_id = -1; |
| 1819 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1812 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1820 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1813 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1821 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1822 ASSERT_TRUE(item); | 1814 ASSERT_TRUE(item); |
| 1823 ScopedCancellingItem canceller(item); | 1815 ScopedCancellingItem canceller(item); |
| 1824 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1816 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1825 | 1817 |
| 1826 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( | 1818 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( |
| 1827 "[{\"danger\": \"safe\"," | 1819 "[{\"danger\": \"safe\"," |
| 1828 " \"incognito\": false," | 1820 " \"incognito\": false," |
| 1829 " \"bytesReceived\": 0," | 1821 " \"bytesReceived\": 0," |
| 1830 " \"mime\": \"\"," | 1822 " \"mime\": \"\"," |
| 1831 " \"paused\": false," | 1823 " \"paused\": false," |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1848 new DownloadsDownloadFunction(), base::StringPrintf( | 1840 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1849 "[{\"url\": \"%s\"," | 1841 "[{\"url\": \"%s\"," |
| 1850 " \"filename\": \"auth-basic-succeed.txt\"," | 1842 " \"filename\": \"auth-basic-succeed.txt\"," |
| 1851 " \"headers\": [{" | 1843 " \"headers\": [{" |
| 1852 " \"name\": \"Authorization\"," | 1844 " \"name\": \"Authorization\"," |
| 1853 " \"value\": \"Basic %s\"}]}]", | 1845 " \"value\": \"Basic %s\"}]}]", |
| 1854 download_url.c_str(), kAuthorization))); | 1846 download_url.c_str(), kAuthorization))); |
| 1855 ASSERT_TRUE(result.get()); | 1847 ASSERT_TRUE(result.get()); |
| 1856 int result_id = -1; | 1848 int result_id = -1; |
| 1857 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1849 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1858 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1850 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1859 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1860 ASSERT_TRUE(item); | 1851 ASSERT_TRUE(item); |
| 1861 ScopedCancellingItem canceller(item); | 1852 ScopedCancellingItem canceller(item); |
| 1862 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1853 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1863 | 1854 |
| 1864 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 1855 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 1865 base::StringPrintf("[{\"danger\": \"safe\"," | 1856 base::StringPrintf("[{\"danger\": \"safe\"," |
| 1866 " \"incognito\": false," | 1857 " \"incognito\": false," |
| 1867 " \"mime\": \"text/html\"," | 1858 " \"mime\": \"text/html\"," |
| 1868 " \"paused\": false," | 1859 " \"paused\": false," |
| 1869 " \"url\": \"%s\"}]", download_url.c_str()))); | 1860 " \"url\": \"%s\"}]", download_url.c_str()))); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1887 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1878 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1888 new DownloadsDownloadFunction(), base::StringPrintf( | 1879 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1889 "[{\"url\": \"%s\"," | 1880 "[{\"url\": \"%s\"," |
| 1890 " \"filename\": \"post-succeed.txt\"," | 1881 " \"filename\": \"post-succeed.txt\"," |
| 1891 " \"method\": \"POST\"," | 1882 " \"method\": \"POST\"," |
| 1892 " \"body\": \"BODY\"}]", | 1883 " \"body\": \"BODY\"}]", |
| 1893 download_url.c_str()))); | 1884 download_url.c_str()))); |
| 1894 ASSERT_TRUE(result.get()); | 1885 ASSERT_TRUE(result.get()); |
| 1895 int result_id = -1; | 1886 int result_id = -1; |
| 1896 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1887 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1897 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1888 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1898 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1899 ASSERT_TRUE(item); | 1889 ASSERT_TRUE(item); |
| 1900 ScopedCancellingItem canceller(item); | 1890 ScopedCancellingItem canceller(item); |
| 1901 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1891 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1902 | 1892 |
| 1903 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 1893 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 1904 base::StringPrintf("[{\"danger\": \"safe\"," | 1894 base::StringPrintf("[{\"danger\": \"safe\"," |
| 1905 " \"incognito\": false," | 1895 " \"incognito\": false," |
| 1906 " \"mime\": \"application/octet-stream\"," | 1896 " \"mime\": \"application/octet-stream\"," |
| 1907 " \"paused\": false," | 1897 " \"paused\": false," |
| 1908 " \"url\": \"%s\"}]", download_url.c_str()))); | 1898 " \"url\": \"%s\"}]", download_url.c_str()))); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1934 | 1924 |
| 1935 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1925 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1936 new DownloadsDownloadFunction(), base::StringPrintf( | 1926 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1937 "[{\"url\": \"%s\"," | 1927 "[{\"url\": \"%s\"," |
| 1938 " \"body\": \"BODY\"," | 1928 " \"body\": \"BODY\"," |
| 1939 " \"filename\": \"post-get.txt\"}]", | 1929 " \"filename\": \"post-get.txt\"}]", |
| 1940 download_url.c_str()))); | 1930 download_url.c_str()))); |
| 1941 ASSERT_TRUE(result.get()); | 1931 ASSERT_TRUE(result.get()); |
| 1942 int result_id = -1; | 1932 int result_id = -1; |
| 1943 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1933 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1944 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1934 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1945 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1946 ASSERT_TRUE(item); | 1935 ASSERT_TRUE(item); |
| 1947 ScopedCancellingItem canceller(item); | 1936 ScopedCancellingItem canceller(item); |
| 1948 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1937 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1949 | 1938 |
| 1950 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( | 1939 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( |
| 1951 "[{\"danger\": \"safe\"," | 1940 "[{\"danger\": \"safe\"," |
| 1952 " \"incognito\": false," | 1941 " \"incognito\": false," |
| 1953 " \"mime\": \"\"," | 1942 " \"mime\": \"\"," |
| 1954 " \"paused\": false," | 1943 " \"paused\": false," |
| 1955 " \"id\": %d," | 1944 " \"id\": %d," |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1973 | 1962 |
| 1974 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1963 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1975 new DownloadsDownloadFunction(), base::StringPrintf( | 1964 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1976 "[{\"url\": \"%s\"," | 1965 "[{\"url\": \"%s\"," |
| 1977 " \"method\": \"POST\"," | 1966 " \"method\": \"POST\"," |
| 1978 " \"filename\": \"post-nobody.txt\"}]", | 1967 " \"filename\": \"post-nobody.txt\"}]", |
| 1979 download_url.c_str()))); | 1968 download_url.c_str()))); |
| 1980 ASSERT_TRUE(result.get()); | 1969 ASSERT_TRUE(result.get()); |
| 1981 int result_id = -1; | 1970 int result_id = -1; |
| 1982 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1971 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1983 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1972 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1984 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 1985 ASSERT_TRUE(item); | 1973 ASSERT_TRUE(item); |
| 1986 ScopedCancellingItem canceller(item); | 1974 ScopedCancellingItem canceller(item); |
| 1987 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1975 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1988 | 1976 |
| 1989 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( | 1977 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( |
| 1990 "[{\"danger\": \"safe\"," | 1978 "[{\"danger\": \"safe\"," |
| 1991 " \"incognito\": false," | 1979 " \"incognito\": false," |
| 1992 " \"mime\": \"\"," | 1980 " \"mime\": \"\"," |
| 1993 " \"paused\": false," | 1981 " \"paused\": false," |
| 1994 " \"id\": %d," | 1982 " \"id\": %d," |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2008 std::string download_url = test_server()->GetURL( | 1996 std::string download_url = test_server()->GetURL( |
| 2009 "download-known-size").spec(); | 1997 "download-known-size").spec(); |
| 2010 GoOnTheRecord(); | 1998 GoOnTheRecord(); |
| 2011 | 1999 |
| 2012 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2000 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2013 new DownloadsDownloadFunction(), base::StringPrintf( | 2001 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2014 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2002 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2015 ASSERT_TRUE(result.get()); | 2003 ASSERT_TRUE(result.get()); |
| 2016 int result_id = -1; | 2004 int result_id = -1; |
| 2017 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2005 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2018 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 2006 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2019 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 2020 ASSERT_TRUE(item); | 2007 ASSERT_TRUE(item); |
| 2021 ScopedCancellingItem canceller(item); | 2008 ScopedCancellingItem canceller(item); |
| 2022 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2009 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 2023 | 2010 |
| 2024 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 2011 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 2025 base::StringPrintf("[{\"danger\": \"safe\"," | 2012 base::StringPrintf("[{\"danger\": \"safe\"," |
| 2026 " \"incognito\": false," | 2013 " \"incognito\": false," |
| 2027 " \"mime\": \"application/octet-stream\"," | 2014 " \"mime\": \"application/octet-stream\"," |
| 2028 " \"paused\": false," | 2015 " \"paused\": false," |
| 2029 " \"id\": %d," | 2016 " \"id\": %d," |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2057 | 2044 |
| 2058 std::string download_url = "filesystem:" + GetExtensionURL() + | 2045 std::string download_url = "filesystem:" + GetExtensionURL() + |
| 2059 "temporary/on_record.txt"; | 2046 "temporary/on_record.txt"; |
| 2060 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2047 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 2061 new DownloadsDownloadFunction(), base::StringPrintf( | 2048 new DownloadsDownloadFunction(), base::StringPrintf( |
| 2062 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2049 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
| 2063 ASSERT_TRUE(result.get()); | 2050 ASSERT_TRUE(result.get()); |
| 2064 int result_id = -1; | 2051 int result_id = -1; |
| 2065 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2052 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 2066 | 2053 |
| 2067 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 2054 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 2068 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | |
| 2069 ASSERT_TRUE(item); | 2055 ASSERT_TRUE(item); |
| 2070 ScopedCancellingItem canceller(item); | 2056 ScopedCancellingItem canceller(item); |
| 2071 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2057 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 2072 | 2058 |
| 2073 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 2059 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 2074 base::StringPrintf("[{\"danger\": \"safe\"," | 2060 base::StringPrintf("[{\"danger\": \"safe\"," |
| 2075 " \"incognito\": false," | 2061 " \"incognito\": false," |
| 2076 " \"mime\": \"text/plain\"," | 2062 " \"mime\": \"text/plain\"," |
| 2077 " \"paused\": false," | 2063 " \"paused\": false," |
| 2078 " \"url\": \"%s\"}]", | 2064 " \"url\": \"%s\"}]", |
| 2079 download_url.c_str()))); | 2065 download_url.c_str()))); |
| 2080 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | 2066 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, |
| 2081 base::StringPrintf("[{\"id\": %d," | 2067 base::StringPrintf("[{\"id\": %d," |
| 2082 " \"filename\": {" | 2068 " \"filename\": {" |
| 2083 " \"previous\": \"%s\"," | 2069 " \"previous\": \"%s\"," |
| 2084 " \"current\": \"%s\"}," | 2070 " \"current\": \"%s\"}," |
| 2085 " \"state\": {" | 2071 " \"state\": {" |
| 2086 " \"previous\": \"in_progress\"," | 2072 " \"previous\": \"in_progress\"," |
| 2087 " \"current\": \"complete\"}}]", | 2073 " \"current\": \"complete\"}}]", |
| 2088 result_id, | 2074 result_id, |
| 2089 GetFilename("on_record.txt.crdownload").c_str(), | 2075 GetFilename("on_record.txt.crdownload").c_str(), |
| 2090 GetFilename("on_record.txt").c_str()))); | 2076 GetFilename("on_record.txt").c_str()))); |
| 2091 std::string disk_data; | 2077 std::string disk_data; |
| 2092 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2078 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
| 2093 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2079 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
| 2094 } | 2080 } |
| OLD | NEW |