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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698