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 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 int result_id = -1; | 1469 int result_id = -1; |
1470 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1470 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1471 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1471 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); |
1472 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | 1472 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); |
1473 ASSERT_TRUE(item); | 1473 ASSERT_TRUE(item); |
1474 ScopedCancellingItem canceller(item); | 1474 ScopedCancellingItem canceller(item); |
1475 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1475 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1476 | 1476 |
1477 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, | 1477 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, |
1478 base::StringPrintf("[{\"danger\": \"safe\"," | 1478 base::StringPrintf("[{\"danger\": \"safe\"," |
1479 " \"filename\": \"%s\"," | |
1480 " \"incognito\": false," | 1479 " \"incognito\": false," |
1481 " \"mime\": \"text/plain\"," | 1480 " \"mime\": \"text/plain\"," |
1482 " \"paused\": false," | 1481 " \"paused\": false," |
1483 " \"url\": \"%s\"}]", | 1482 " \"url\": \"%s\"}]", |
1484 GetFilename("slow.txt.crdownload").c_str(), | |
1485 download_url.c_str()))); | 1483 download_url.c_str()))); |
1486 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, | 1484 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, |
1487 base::StringPrintf("[{\"id\": %d," | 1485 base::StringPrintf("[{\"id\": %d," |
1488 " \"filename\": {" | 1486 " \"filename\": {" |
1489 " \"previous\": \"%s\"," | 1487 " \"previous\": \"%s\"," |
1490 " \"current\": \"%s\"}," | 1488 " \"current\": \"%s\"}," |
1491 " \"state\": {" | 1489 " \"state\": {" |
1492 " \"previous\": \"in_progress\"," | 1490 " \"previous\": \"in_progress\"," |
1493 " \"current\": \"complete\"}}]", | 1491 " \"current\": \"complete\"}}]", |
1494 result_id, | 1492 result_id, |
(...skipping 17 matching lines...) Expand all Loading... |
1512 int result_id = -1; | 1510 int result_id = -1; |
1513 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1511 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1514 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1512 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); |
1515 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | 1513 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); |
1516 ASSERT_TRUE(item); | 1514 ASSERT_TRUE(item); |
1517 ScopedCancellingItem canceller(item); | 1515 ScopedCancellingItem canceller(item); |
1518 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1516 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1519 | 1517 |
1520 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, | 1518 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, |
1521 base::StringPrintf("[{\"danger\": \"safe\"," | 1519 base::StringPrintf("[{\"danger\": \"safe\"," |
1522 " \"filename\": \"%s\"," | |
1523 " \"incognito\": true," | 1520 " \"incognito\": true," |
1524 " \"mime\": \"text/plain\"," | 1521 " \"mime\": \"text/plain\"," |
1525 " \"paused\": false," | 1522 " \"paused\": false," |
1526 " \"url\": \"%s\"}]", | 1523 " \"url\": \"%s\"}]", |
1527 GetFilename("slow.txt.crdownload").c_str(), | |
1528 download_url.c_str()))); | 1524 download_url.c_str()))); |
1529 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, | 1525 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, |
1530 base::StringPrintf("[{\"id\":%d," | 1526 base::StringPrintf("[{\"id\":%d," |
1531 " \"filename\": {" | 1527 " \"filename\": {" |
1532 " \"previous\": \"%s\"," | 1528 " \"previous\": \"%s\"," |
1533 " \"current\": \"%s\"}," | 1529 " \"current\": \"%s\"}," |
1534 " \"state\": {" | 1530 " \"state\": {" |
1535 " \"current\": \"complete\"," | 1531 " \"current\": \"complete\"," |
1536 " \"previous\": \"in_progress\"}}]", | 1532 " \"previous\": \"in_progress\"}}]", |
1537 result_id, | 1533 result_id, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 int result_id = -1; | 1664 int result_id = -1; |
1669 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1665 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1670 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1666 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); |
1671 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | 1667 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); |
1672 ASSERT_TRUE(item); | 1668 ASSERT_TRUE(item); |
1673 ScopedCancellingItem canceller(item); | 1669 ScopedCancellingItem canceller(item); |
1674 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1670 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1675 | 1671 |
1676 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, | 1672 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, |
1677 base::StringPrintf("[{\"danger\": \"safe\"," | 1673 base::StringPrintf("[{\"danger\": \"safe\"," |
1678 " \"filename\": \"%s\"," | |
1679 " \"incognito\": false," | 1674 " \"incognito\": false," |
1680 " \"mime\": \"text/plain\"," | 1675 " \"mime\": \"text/plain\"," |
1681 " \"paused\": false," | 1676 " \"paused\": false," |
1682 " \"url\": \"%s\"}]", | 1677 " \"url\": \"%s\"}]", |
1683 GetFilename("slow.txt.crdownload").c_str(), | |
1684 download_url.c_str()))); | 1678 download_url.c_str()))); |
1685 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, | 1679 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, |
1686 base::StringPrintf("[{\"id\": %d," | 1680 base::StringPrintf("[{\"id\": %d," |
1687 " \"filename\": {" | 1681 " \"filename\": {" |
1688 " \"previous\": \"%s\"," | 1682 " \"previous\": \"%s\"," |
1689 " \"current\": \"%s\"}," | 1683 " \"current\": \"%s\"}," |
1690 " \"state\": {" | 1684 " \"state\": {" |
1691 " \"previous\": \"in_progress\"," | 1685 " \"previous\": \"in_progress\"," |
1692 " \"current\": \"complete\"}}]", | 1686 " \"current\": \"complete\"}}]", |
1693 result_id, | 1687 result_id, |
(...skipping 17 matching lines...) Expand all Loading... |
1711 int result_id = -1; | 1705 int result_id = -1; |
1712 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1706 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1713 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1707 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); |
1714 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | 1708 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); |
1715 ASSERT_TRUE(item); | 1709 ASSERT_TRUE(item); |
1716 ScopedCancellingItem canceller(item); | 1710 ScopedCancellingItem canceller(item); |
1717 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1711 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1718 | 1712 |
1719 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, | 1713 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, |
1720 base::StringPrintf("[{\"danger\": \"safe\"," | 1714 base::StringPrintf("[{\"danger\": \"safe\"," |
1721 " \"filename\": \"%s\"," | |
1722 " \"incognito\": false," | 1715 " \"incognito\": false," |
1723 " \"mime\": \"text/plain\"," | 1716 " \"mime\": \"text/plain\"," |
1724 " \"paused\": false," | 1717 " \"paused\": false," |
1725 " \"url\": \"%s\"}]", | 1718 " \"url\": \"%s\"}]", |
1726 GetFilename("data.txt.crdownload").c_str(), | |
1727 download_url.c_str()))); | 1719 download_url.c_str()))); |
1728 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, | 1720 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, |
1729 base::StringPrintf("[{\"id\": %d," | 1721 base::StringPrintf("[{\"id\": %d," |
1730 " \"filename\": {" | 1722 " \"filename\": {" |
1731 " \"previous\": \"%s\"," | 1723 " \"previous\": \"%s\"," |
1732 " \"current\": \"%s\"}," | 1724 " \"current\": \"%s\"}," |
1733 " \"state\": {" | 1725 " \"state\": {" |
1734 " \"previous\": \"in_progress\"," | 1726 " \"previous\": \"in_progress\"," |
1735 " \"current\": \"complete\"}}]", | 1727 " \"current\": \"complete\"}}]", |
1736 result_id, | 1728 result_id, |
(...skipping 20 matching lines...) Expand all Loading... |
1757 int result_id = -1; | 1749 int result_id = -1; |
1758 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1750 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1759 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1751 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); |
1760 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | 1752 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); |
1761 ASSERT_TRUE(item); | 1753 ASSERT_TRUE(item); |
1762 ScopedCancellingItem canceller(item); | 1754 ScopedCancellingItem canceller(item); |
1763 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1755 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1764 | 1756 |
1765 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, | 1757 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, |
1766 base::StringPrintf("[{\"danger\": \"safe\"," | 1758 base::StringPrintf("[{\"danger\": \"safe\"," |
1767 " \"filename\": \"%s\"," | |
1768 " \"incognito\": false," | 1759 " \"incognito\": false," |
1769 " \"mime\": \"text/html\"," | 1760 " \"mime\": \"text/html\"," |
1770 " \"paused\": false," | 1761 " \"paused\": false," |
1771 " \"url\": \"%s\"}]", | 1762 " \"url\": \"%s\"}]", |
1772 GetFilename("file.txt.crdownload").c_str(), | |
1773 download_url.c_str()))); | 1763 download_url.c_str()))); |
1774 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, | 1764 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, |
1775 base::StringPrintf("[{\"id\": %d," | 1765 base::StringPrintf("[{\"id\": %d," |
1776 " \"filename\": {" | 1766 " \"filename\": {" |
1777 " \"previous\": \"%s\"," | 1767 " \"previous\": \"%s\"," |
1778 " \"current\": \"%s\"}," | 1768 " \"current\": \"%s\"}," |
1779 " \"state\": {" | 1769 " \"state\": {" |
1780 " \"previous\": \"in_progress\"," | 1770 " \"previous\": \"in_progress\"," |
1781 " \"current\": \"complete\"}}]", | 1771 " \"current\": \"complete\"}}]", |
1782 result_id, | 1772 result_id, |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1964 int result_id = -1; | 1954 int result_id = -1; |
1965 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1955 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1966 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 1956 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); |
1967 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | 1957 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); |
1968 ASSERT_TRUE(item); | 1958 ASSERT_TRUE(item); |
1969 ScopedCancellingItem canceller(item); | 1959 ScopedCancellingItem canceller(item); |
1970 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1960 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1971 | 1961 |
1972 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, | 1962 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, |
1973 base::StringPrintf("[{\"danger\": \"safe\"," | 1963 base::StringPrintf("[{\"danger\": \"safe\"," |
1974 " \"incognito\": false," | 1964 " \"incognito\": false," |
1975 " \"mime\": \"application/octet-stream\"," | 1965 " \"mime\": \"application/octet-stream\"," |
1976 " \"paused\": false," | 1966 " \"paused\": false," |
1977 " \"bytesReceived\": 164," | 1967 " \"url\": \"%s\"}]", download_url.c_str()))); |
1978 " \"url\": \"%s\"}]", download_url.c_str()))); | |
1979 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, | 1968 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, |
1980 base::StringPrintf("[{\"id\": %d," | 1969 base::StringPrintf("[{\"id\": %d," |
1981 " \"state\": {" | 1970 " \"state\": {" |
1982 " \"previous\": \"in_progress\"," | 1971 " \"previous\": \"in_progress\"," |
1983 " \"current\": \"complete\"}}]", result_id))); | 1972 " \"current\": \"complete\"}," |
| 1973 " \"filename\": {" |
| 1974 " \"previous\": \"%s\"," |
| 1975 " \"current\": \"%s\"}}]", |
| 1976 result_id, |
| 1977 GetFilename("post-succeed.txt.crdownload").c_str(), |
| 1978 GetFilename("post-succeed.txt").c_str()))); |
1984 } | 1979 } |
1985 | 1980 |
1986 // Test that downloadPostSuccess would fail if the resource requires the POST | 1981 // Test that downloadPostSuccess would fail if the resource requires the POST |
1987 // method, and chrome fails to propagate the |method| parameter back to the | 1982 // method, and chrome fails to propagate the |method| parameter back to the |
1988 // server. This tests both that testserver.py does not succeed when it should | 1983 // server. This tests both that testserver.py does not succeed when it should |
1989 // fail, and this tests how the downloads extension api exposes the failure to | 1984 // fail, and this tests how the downloads extension api exposes the failure to |
1990 // extensions. | 1985 // extensions. |
1991 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1986 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1992 DownloadExtensionTest_Download_Post_Get) { | 1987 DownloadExtensionTest_Download_Post_Get) { |
1993 LoadExtension("downloads_split"); | 1988 LoadExtension("downloads_split"); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2129 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2124 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2130 | 2125 |
2131 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); | 2126 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); |
2132 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); | 2127 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); |
2133 ASSERT_TRUE(item); | 2128 ASSERT_TRUE(item); |
2134 ScopedCancellingItem canceller(item); | 2129 ScopedCancellingItem canceller(item); |
2135 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2130 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2136 | 2131 |
2137 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, | 2132 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, |
2138 base::StringPrintf("[{\"danger\": \"safe\"," | 2133 base::StringPrintf("[{\"danger\": \"safe\"," |
2139 " \"filename\": \"%s\"," | |
2140 " \"incognito\": false," | 2134 " \"incognito\": false," |
2141 " \"mime\": \"text/plain\"," | 2135 " \"mime\": \"text/plain\"," |
2142 " \"paused\": false," | 2136 " \"paused\": false," |
2143 " \"url\": \"%s\"}]", | 2137 " \"url\": \"%s\"}]", |
2144 GetFilename("on_record.txt.crdownload").c_str(), | |
2145 download_url.c_str()))); | 2138 download_url.c_str()))); |
2146 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, | 2139 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, |
2147 base::StringPrintf("[{\"id\": %d," | 2140 base::StringPrintf("[{\"id\": %d," |
2148 " \"filename\": {" | 2141 " \"filename\": {" |
2149 " \"previous\": \"%s\"," | 2142 " \"previous\": \"%s\"," |
2150 " \"current\": \"%s\"}," | 2143 " \"current\": \"%s\"}," |
2151 " \"state\": {" | 2144 " \"state\": {" |
2152 " \"previous\": \"in_progress\"," | 2145 " \"previous\": \"in_progress\"," |
2153 " \"current\": \"complete\"}}]", | 2146 " \"current\": \"complete\"}}]", |
2154 result_id, | 2147 result_id, |
2155 GetFilename("on_record.txt.crdownload").c_str(), | 2148 GetFilename("on_record.txt.crdownload").c_str(), |
2156 GetFilename("on_record.txt").c_str()))); | 2149 GetFilename("on_record.txt").c_str()))); |
2157 std::string disk_data; | 2150 std::string disk_data; |
2158 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2151 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
2159 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2152 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
2160 } | 2153 } |
OLD | NEW |