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

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

Issue 10735089: DownloadManager::Observer::OnDownloadCreated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 switch (type) { 161 switch (type) {
162 case chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT: 162 case chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT:
163 { 163 {
164 DownloadsNotificationSource* dns = 164 DownloadsNotificationSource* dns =
165 content::Source<DownloadsNotificationSource>(source).ptr(); 165 content::Source<DownloadsNotificationSource>(source).ptr();
166 Event* new_event = new Event( 166 Event* new_event = new Event(
167 dns->profile, 167 dns->profile,
168 dns->event_name, 168 dns->event_name,
169 *content::Details<std::string>(details).ptr(), base::Time::Now()); 169 *content::Details<std::string>(details).ptr(), base::Time::Now());
170 events_.push_back(new_event); 170 events_.push_back(new_event);
171 LOG(INFO) << "occam caught " << new_event->Debug();
Randy Smith (Not in Mondays) 2012/07/23 18:40:50 Was this intended to be in the CL proposed for lan
benjhayden 2012/07/23 18:54:22 Sorry, was having trouble repro-ing trybot failure
171 if (waiting_ && 172 if (waiting_ &&
172 waiting_for_.get() && 173 waiting_for_.get() &&
173 waiting_for_->Equals(*new_event)) { 174 waiting_for_->Equals(*new_event)) {
174 waiting_ = false; 175 waiting_ = false;
175 MessageLoopForUI::current()->Quit(); 176 MessageLoopForUI::current()->Quit();
176 } 177 }
177 break; 178 break;
178 } 179 }
179 default: 180 default:
180 NOTREACHED(); 181 NOTREACHED();
181 } 182 }
182 } 183 }
183 184
184 bool WaitFor(Profile* profile, 185 bool WaitFor(Profile* profile,
185 const std::string& event_name, 186 const std::string& event_name,
186 const std::string& json_args) { 187 const std::string& json_args) {
187 waiting_for_.reset(new Event(profile, event_name, json_args, base::Time())); 188 waiting_for_.reset(new Event(profile, event_name, json_args, base::Time()));
188 for (std::deque<Event*>::const_iterator iter = events_.begin(); 189 for (std::deque<Event*>::const_iterator iter = events_.begin();
189 iter != events_.end(); ++iter) { 190 iter != events_.end(); ++iter) {
190 if ((*iter)->Equals(*waiting_for_.get())) 191 if ((*iter)->Equals(*waiting_for_.get()))
191 return true; 192 return true;
192 } 193 }
194 LOG(INFO) << "occam waiting " << waiting_for_->Debug();
Randy Smith (Not in Mondays) 2012/07/23 18:40:50 Ditto.
benjhayden 2012/07/23 18:54:22 Done.
193 waiting_ = true; 195 waiting_ = true;
194 ui_test_utils::RunMessageLoop(); 196 ui_test_utils::RunMessageLoop();
195 bool success = !waiting_; 197 bool success = !waiting_;
196 if (waiting_) { 198 if (waiting_) {
197 // Print the events that were caught since the last WaitFor() call to help 199 // Print the events that were caught since the last WaitFor() call to help
198 // find the erroneous event. 200 // find the erroneous event.
199 // TODO(benjhayden) Fuzzy-match and highlight the erroneous event. 201 // TODO(benjhayden) Fuzzy-match and highlight the erroneous event.
200 for (std::deque<Event*>::const_iterator iter = events_.begin(); 202 for (std::deque<Event*>::const_iterator iter = events_.begin();
201 iter != events_.end(); ++iter) { 203 iter != events_.end(); ++iter) {
202 if ((*iter)->caught() > last_wait_) { 204 if ((*iter)->caught() > last_wait_) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 291
290 bool WaitFor(const std::string& event_name, const std::string& json_args) { 292 bool WaitFor(const std::string& event_name, const std::string& json_args) {
291 return events_listener_->WaitFor( 293 return events_listener_->WaitFor(
292 current_browser()->profile(), event_name, json_args); 294 current_browser()->profile(), event_name, json_args);
293 } 295 }
294 296
295 bool WaitForInterruption(DownloadItem* item, int expected_error, 297 bool WaitForInterruption(DownloadItem* item, int expected_error,
296 const std::string& on_created_event) { 298 const std::string& on_created_event) {
297 if (!WaitFor(extension_event_names::kOnDownloadCreated, on_created_event)) 299 if (!WaitFor(extension_event_names::kOnDownloadCreated, on_created_event))
298 return false; 300 return false;
299 // The item may or may not be interrupted before the onCreated event fires. 301 // Now, onCreated is always fired before interruption.
300 if (item->IsInterrupted()) { 302 return WaitFor(extension_event_names::kOnDownloadChanged,
301 scoped_ptr<base::Value> args(base::JSONReader::Read(on_created_event)); 303 base::StringPrintf("[{\"id\": %d,"
302 base::ListValue* args_list = NULL; 304 " \"error\": {\"current\": %d},"
303 base::DictionaryValue* args_dict = NULL; 305 " \"state\": {"
304 if (!args->GetAsList(&args_list) || 306 " \"previous\": \"in_progress\","
305 !args_list->GetDictionary(0, &args_dict)) 307 " \"current\": \"interrupted\"}}]",
306 return false; 308 item->GetId(),
307 args_dict->SetString("state", "interrupted"); 309 expected_error));
308 args_dict->SetInteger("error", expected_error);
309 std::string created_error;
310 base::JSONWriter::Write(args_list, &created_error);
311 // This is not waiting for a different event, it's refining the
312 // expectations on the onCreated event that was just caught. Specifically,
313 // if a DownloadItem is already interrupted by the time the onCreated
314 // event fires, then the onCreated event should already describe the
315 // error.
316 return WaitFor(extension_event_names::kOnDownloadCreated, created_error);
317 } else {
318 return WaitFor(extension_event_names::kOnDownloadChanged,
319 base::StringPrintf("[{\"id\": %d,"
320 " \"error\": {\"current\": %d},"
321 " \"state\": {"
322 " \"previous\": \"in_progress\","
323 " \"current\": \"interrupted\"}}]",
324 item->GetId(),
325 expected_error));
326 }
327 } 310 }
328 311
329 std::string GetExtensionURL() { 312 std::string GetExtensionURL() {
330 return extension_->url().spec(); 313 return extension_->url().spec();
331 } 314 }
332 315
333 std::string GetFilename(const char* path) { 316 std::string GetFilename(const char* path) {
334 std::string result = 317 std::string result =
335 downloads_directory_.path().AppendASCII(path).AsUTF8Unsafe(); 318 downloads_directory_.path().AppendASCII(path).AsUTF8Unsafe();
336 #if defined(OS_WIN) 319 #if defined(OS_WIN)
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 int result_id = -1; 1478 int result_id = -1;
1496 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1479 ASSERT_TRUE(result->GetAsInteger(&result_id));
1497 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1480 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1498 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1481 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1499 ASSERT_TRUE(item); 1482 ASSERT_TRUE(item);
1500 ScopedCancellingItem canceller(item); 1483 ScopedCancellingItem canceller(item);
1501 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1484 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1502 1485
1503 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1486 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated,
1504 base::StringPrintf("[{\"danger\": \"safe\"," 1487 base::StringPrintf("[{\"danger\": \"safe\","
1505 " \"filename\": \"%s\","
1506 " \"incognito\": false," 1488 " \"incognito\": false,"
1507 " \"mime\": \"text/plain\"," 1489 " \"mime\": \"text/plain\","
1508 " \"paused\": false," 1490 " \"paused\": false,"
1509 " \"url\": \"%s\"}]", 1491 " \"url\": \"%s\"}]",
1510 GetFilename("slow.txt.crdownload").c_str(),
1511 download_url.c_str()))); 1492 download_url.c_str())));
1512 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1493 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged,
1513 base::StringPrintf("[{\"id\": %d," 1494 base::StringPrintf("[{\"id\": %d,"
1514 " \"filename\": {" 1495 " \"filename\": {"
1515 " \"previous\": \"%s\"," 1496 " \"previous\": \"%s\","
1516 " \"current\": \"%s\"}," 1497 " \"current\": \"%s\"},"
1517 " \"state\": {" 1498 " \"state\": {"
1518 " \"previous\": \"in_progress\"," 1499 " \"previous\": \"in_progress\","
1519 " \"current\": \"complete\"}}]", 1500 " \"current\": \"complete\"}}]",
1520 result_id, 1501 result_id,
(...skipping 17 matching lines...) Expand all
1538 int result_id = -1; 1519 int result_id = -1;
1539 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1520 ASSERT_TRUE(result->GetAsInteger(&result_id));
1540 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1521 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1541 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1522 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1542 ASSERT_TRUE(item); 1523 ASSERT_TRUE(item);
1543 ScopedCancellingItem canceller(item); 1524 ScopedCancellingItem canceller(item);
1544 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1525 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1545 1526
1546 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1527 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated,
1547 base::StringPrintf("[{\"danger\": \"safe\"," 1528 base::StringPrintf("[{\"danger\": \"safe\","
1548 " \"filename\": \"%s\","
1549 " \"incognito\": true," 1529 " \"incognito\": true,"
1550 " \"mime\": \"text/plain\"," 1530 " \"mime\": \"text/plain\","
1551 " \"paused\": false," 1531 " \"paused\": false,"
1552 " \"url\": \"%s\"}]", 1532 " \"url\": \"%s\"}]",
1553 GetFilename("slow.txt.crdownload").c_str(),
1554 download_url.c_str()))); 1533 download_url.c_str())));
1555 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1534 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged,
1556 base::StringPrintf("[{\"id\":%d," 1535 base::StringPrintf("[{\"id\":%d,"
1557 " \"filename\": {" 1536 " \"filename\": {"
1558 " \"previous\": \"%s\"," 1537 " \"previous\": \"%s\","
1559 " \"current\": \"%s\"}," 1538 " \"current\": \"%s\"},"
1560 " \"state\": {" 1539 " \"state\": {"
1561 " \"current\": \"complete\"," 1540 " \"current\": \"complete\","
1562 " \"previous\": \"in_progress\"}}]", 1541 " \"previous\": \"in_progress\"}}]",
1563 result_id, 1542 result_id,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 int result_id = -1; 1673 int result_id = -1;
1695 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1674 ASSERT_TRUE(result->GetAsInteger(&result_id));
1696 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1675 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1697 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1676 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1698 ASSERT_TRUE(item); 1677 ASSERT_TRUE(item);
1699 ScopedCancellingItem canceller(item); 1678 ScopedCancellingItem canceller(item);
1700 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1679 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1701 1680
1702 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1681 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated,
1703 base::StringPrintf("[{\"danger\": \"safe\"," 1682 base::StringPrintf("[{\"danger\": \"safe\","
1704 " \"filename\": \"%s\","
1705 " \"incognito\": false," 1683 " \"incognito\": false,"
1706 " \"mime\": \"text/plain\"," 1684 " \"mime\": \"text/plain\","
1707 " \"paused\": false," 1685 " \"paused\": false,"
1708 " \"url\": \"%s\"}]", 1686 " \"url\": \"%s\"}]",
1709 GetFilename("slow.txt.crdownload").c_str(),
1710 download_url.c_str()))); 1687 download_url.c_str())));
1711 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1688 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged,
1712 base::StringPrintf("[{\"id\": %d," 1689 base::StringPrintf("[{\"id\": %d,"
1713 " \"filename\": {" 1690 " \"filename\": {"
1714 " \"previous\": \"%s\"," 1691 " \"previous\": \"%s\","
1715 " \"current\": \"%s\"}," 1692 " \"current\": \"%s\"},"
1716 " \"state\": {" 1693 " \"state\": {"
1717 " \"previous\": \"in_progress\"," 1694 " \"previous\": \"in_progress\","
1718 " \"current\": \"complete\"}}]", 1695 " \"current\": \"complete\"}}]",
1719 result_id, 1696 result_id,
(...skipping 17 matching lines...) Expand all
1737 int result_id = -1; 1714 int result_id = -1;
1738 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1715 ASSERT_TRUE(result->GetAsInteger(&result_id));
1739 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1716 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1740 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1717 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1741 ASSERT_TRUE(item); 1718 ASSERT_TRUE(item);
1742 ScopedCancellingItem canceller(item); 1719 ScopedCancellingItem canceller(item);
1743 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1720 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1744 1721
1745 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1722 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated,
1746 base::StringPrintf("[{\"danger\": \"safe\"," 1723 base::StringPrintf("[{\"danger\": \"safe\","
1747 " \"filename\": \"%s\","
1748 " \"incognito\": false," 1724 " \"incognito\": false,"
1749 " \"mime\": \"text/plain\"," 1725 " \"mime\": \"text/plain\","
1750 " \"paused\": false," 1726 " \"paused\": false,"
1751 " \"url\": \"%s\"}]", 1727 " \"url\": \"%s\"}]",
1752 GetFilename("data.txt.crdownload").c_str(),
1753 download_url.c_str()))); 1728 download_url.c_str())));
1754 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1729 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged,
1755 base::StringPrintf("[{\"id\": %d," 1730 base::StringPrintf("[{\"id\": %d,"
1756 " \"filename\": {" 1731 " \"filename\": {"
1757 " \"previous\": \"%s\"," 1732 " \"previous\": \"%s\","
1758 " \"current\": \"%s\"}," 1733 " \"current\": \"%s\"},"
1759 " \"state\": {" 1734 " \"state\": {"
1760 " \"previous\": \"in_progress\"," 1735 " \"previous\": \"in_progress\","
1761 " \"current\": \"complete\"}}]", 1736 " \"current\": \"complete\"}}]",
1762 result_id, 1737 result_id,
(...skipping 20 matching lines...) Expand all
1783 int result_id = -1; 1758 int result_id = -1;
1784 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1759 ASSERT_TRUE(result->GetAsInteger(&result_id));
1785 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1760 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1786 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1761 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1787 ASSERT_TRUE(item); 1762 ASSERT_TRUE(item);
1788 ScopedCancellingItem canceller(item); 1763 ScopedCancellingItem canceller(item);
1789 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1764 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1790 1765
1791 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1766 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated,
1792 base::StringPrintf("[{\"danger\": \"safe\"," 1767 base::StringPrintf("[{\"danger\": \"safe\","
1793 " \"filename\": \"%s\","
1794 " \"incognito\": false," 1768 " \"incognito\": false,"
1795 " \"mime\": \"text/html\"," 1769 " \"mime\": \"text/html\","
1796 " \"paused\": false," 1770 " \"paused\": false,"
1797 " \"url\": \"%s\"}]", 1771 " \"url\": \"%s\"}]",
1798 GetFilename("file.txt.crdownload").c_str(),
1799 download_url.c_str()))); 1772 download_url.c_str())));
1800 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1773 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged,
1801 base::StringPrintf("[{\"id\": %d," 1774 base::StringPrintf("[{\"id\": %d,"
1802 " \"filename\": {" 1775 " \"filename\": {"
1803 " \"previous\": \"%s\"," 1776 " \"previous\": \"%s\","
1804 " \"current\": \"%s\"}," 1777 " \"current\": \"%s\"},"
1805 " \"state\": {" 1778 " \"state\": {"
1806 " \"previous\": \"in_progress\"," 1779 " \"previous\": \"in_progress\","
1807 " \"current\": \"complete\"}}]", 1780 " \"current\": \"complete\"}}]",
1808 result_id, 1781 result_id,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 int result_id = -1; 1963 int result_id = -1;
1991 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1964 ASSERT_TRUE(result->GetAsInteger(&result_id));
1992 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1965 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1993 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1966 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1994 ASSERT_TRUE(item); 1967 ASSERT_TRUE(item);
1995 ScopedCancellingItem canceller(item); 1968 ScopedCancellingItem canceller(item);
1996 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1969 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1997 1970
1998 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1971 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated,
1999 base::StringPrintf("[{\"danger\": \"safe\"," 1972 base::StringPrintf("[{\"danger\": \"safe\","
2000 " \"incognito\": false," 1973 " \"incognito\": false,"
2001 " \"mime\": \"application/octet-stream\"," 1974 " \"mime\": \"application/octet-stream\","
2002 " \"paused\": false," 1975 " \"paused\": false,"
2003 " \"bytesReceived\": 164," 1976 " \"url\": \"%s\"}]", download_url.c_str())));
2004 " \"url\": \"%s\"}]", download_url.c_str())));
2005 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1977 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged,
2006 base::StringPrintf("[{\"id\": %d," 1978 base::StringPrintf("[{\"id\": %d,"
2007 " \"state\": {" 1979 " \"state\": {"
2008 " \"previous\": \"in_progress\"," 1980 " \"previous\": \"in_progress\","
2009 " \"current\": \"complete\"}}]", result_id))); 1981 " \"current\": \"complete\"},"
1982 " \"filename\": {"
1983 " \"previous\": \"%s\","
1984 " \"current\": \"%s\"}}]",
1985 result_id,
1986 GetFilename("post-succeed.txt.crdownload").c_str(),
1987 GetFilename("post-succeed.txt").c_str())));
2010 } 1988 }
2011 1989
2012 // Test that downloadPostSuccess would fail if the resource requires the POST 1990 // Test that downloadPostSuccess would fail if the resource requires the POST
2013 // method, and chrome fails to propagate the |method| parameter back to the 1991 // method, and chrome fails to propagate the |method| parameter back to the
2014 // server. This tests both that testserver.py does not succeed when it should 1992 // server. This tests both that testserver.py does not succeed when it should
2015 // fail, and this tests how the downloads extension api exposes the failure to 1993 // fail, and this tests how the downloads extension api exposes the failure to
2016 // extensions. 1994 // extensions.
2017 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1995 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2018 DownloadExtensionTest_Download_Post_Get) { 1996 DownloadExtensionTest_Download_Post_Get) {
2019 LoadExtension("downloads_split"); 1997 LoadExtension("downloads_split");
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2133 ASSERT_TRUE(result->GetAsInteger(&result_id));
2156 2134
2157 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 2135 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
2158 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 2136 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
2159 ASSERT_TRUE(item); 2137 ASSERT_TRUE(item);
2160 ScopedCancellingItem canceller(item); 2138 ScopedCancellingItem canceller(item);
2161 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2139 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2162 2140
2163 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 2141 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated,
2164 base::StringPrintf("[{\"danger\": \"safe\"," 2142 base::StringPrintf("[{\"danger\": \"safe\","
2165 " \"filename\": \"%s\","
2166 " \"incognito\": false," 2143 " \"incognito\": false,"
2167 " \"mime\": \"text/plain\"," 2144 " \"mime\": \"text/plain\","
2168 " \"paused\": false," 2145 " \"paused\": false,"
2169 " \"url\": \"%s\"}]", 2146 " \"url\": \"%s\"}]",
2170 GetFilename("on_record.txt.crdownload").c_str(),
2171 download_url.c_str()))); 2147 download_url.c_str())));
2172 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 2148 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged,
2173 base::StringPrintf("[{\"id\": %d," 2149 base::StringPrintf("[{\"id\": %d,"
2174 " \"filename\": {" 2150 " \"filename\": {"
2175 " \"previous\": \"%s\"," 2151 " \"previous\": \"%s\","
2176 " \"current\": \"%s\"}," 2152 " \"current\": \"%s\"},"
2177 " \"state\": {" 2153 " \"state\": {"
2178 " \"previous\": \"in_progress\"," 2154 " \"previous\": \"in_progress\","
2179 " \"current\": \"complete\"}}]", 2155 " \"current\": \"complete\"}}]",
2180 result_id, 2156 result_id,
2181 GetFilename("on_record.txt.crdownload").c_str(), 2157 GetFilename("on_record.txt.crdownload").c_str(),
2182 GetFilename("on_record.txt").c_str()))); 2158 GetFilename("on_record.txt").c_str())));
2183 std::string disk_data; 2159 std::string disk_data;
2184 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2160 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2185 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2161 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2186 } 2162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698