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

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

Issue 10696208: Move ExtensionEventRouter and related into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed bug + latest master 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
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"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "chrome/browser/download/download_file_icon_extractor.h" 14 #include "chrome/browser/download/download_file_icon_extractor.h"
15 #include "chrome/browser/download/download_service.h" 15 #include "chrome/browser/download/download_service.h"
16 #include "chrome/browser/download/download_service_factory.h" 16 #include "chrome/browser/download/download_service_factory.h"
17 #include "chrome/browser/download/download_test_observer.h" 17 #include "chrome/browser/download/download_test_observer.h"
18 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 18 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
19 #include "chrome/browser/extensions/event_names.h"
19 #include "chrome/browser/extensions/extension_apitest.h" 20 #include "chrome/browser/extensions/extension_apitest.h"
20 #include "chrome/browser/extensions/extension_event_names.h"
21 #include "chrome/browser/extensions/extension_function_test_utils.h" 21 #include "chrome/browser/extensions/extension_function_test_utils.h"
22 #include "chrome/browser/net/url_request_mock_util.h" 22 #include "chrome/browser/net/url_request_mock_util.h"
23 #include "chrome/browser/prefs/pref_service.h" 23 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_tabstrip.h" 26 #include "chrome/browser/ui/browser_tabstrip.h"
27 #include "chrome/browser/ui/tab_contents/tab_contents.h" 27 #include "chrome/browser/ui/tab_contents/tab_contents.h"
28 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "chrome/test/base/in_process_browser_test.h" 30 #include "chrome/test/base/in_process_browser_test.h"
(...skipping 20 matching lines...) Expand all
51 #include "webkit/fileapi/file_system_context.h" 51 #include "webkit/fileapi/file_system_context.h"
52 #include "webkit/fileapi/file_system_operation_interface.h" 52 #include "webkit/fileapi/file_system_operation_interface.h"
53 #include "webkit/fileapi/file_system_url.h" 53 #include "webkit/fileapi/file_system_url.h"
54 54
55 using content::BrowserContext; 55 using content::BrowserContext;
56 using content::BrowserThread; 56 using content::BrowserThread;
57 using content::DownloadItem; 57 using content::DownloadItem;
58 using content::DownloadManager; 58 using content::DownloadManager;
59 using content::DownloadPersistentStoreInfo; 59 using content::DownloadPersistentStoreInfo;
60 60
61 namespace events = extensions::event_names;
62
61 namespace { 63 namespace {
62 64
63 // Comparator that orders download items by their ID. Can be used with 65 // Comparator that orders download items by their ID. Can be used with
64 // std::sort. 66 // std::sort.
65 struct DownloadIdComparator { 67 struct DownloadIdComparator {
66 bool operator() (DownloadItem* first, DownloadItem* second) { 68 bool operator() (DownloadItem* first, DownloadItem* second) {
67 return first->GetId() < second->GetId(); 69 return first->GetId() < second->GetId();
68 } 70 }
69 }; 71 };
70 72
(...skipping 23 matching lines...) Expand all
94 args_(base::JSONReader::Read(json_args)), 96 args_(base::JSONReader::Read(json_args)),
95 caught_(caught) { 97 caught_(caught) {
96 } 98 }
97 99
98 const base::Time& caught() { return caught_; } 100 const base::Time& caught() { return caught_; }
99 101
100 bool Equals(const Event& other) { 102 bool Equals(const Event& other) {
101 if ((profile_ != other.profile_) || 103 if ((profile_ != other.profile_) ||
102 (event_name_ != other.event_name_)) 104 (event_name_ != other.event_name_))
103 return false; 105 return false;
104 if ((event_name_ == extension_event_names::kOnDownloadCreated || 106 if ((event_name_ == events::kOnDownloadCreated ||
105 event_name_ == extension_event_names::kOnDownloadChanged) && 107 event_name_ == events::kOnDownloadChanged) &&
106 args_.get() && 108 args_.get() &&
107 other.args_.get()) { 109 other.args_.get()) {
108 base::ListValue* left_list = NULL; 110 base::ListValue* left_list = NULL;
109 base::DictionaryValue* left_dict = NULL; 111 base::DictionaryValue* left_dict = NULL;
110 base::ListValue* right_list = NULL; 112 base::ListValue* right_list = NULL;
111 base::DictionaryValue* right_dict = NULL; 113 base::DictionaryValue* right_dict = NULL;
112 if (!args_->GetAsList(&left_list) || 114 if (!args_->GetAsList(&left_list) ||
113 !other.args_->GetAsList(&right_list) || 115 !other.args_->GetAsList(&right_list) ||
114 !left_list->GetDictionary(0, &left_dict) || 116 !left_list->GetDictionary(0, &left_dict) ||
115 !right_list->GetDictionary(0, &right_dict)) 117 !right_list->GetDictionary(0, &right_dict))
116 return false; 118 return false;
117 for (base::DictionaryValue::Iterator iter(*left_dict); 119 for (base::DictionaryValue::Iterator iter(*left_dict);
118 iter.HasNext(); iter.Advance()) { 120 iter.HasNext(); iter.Advance()) {
119 base::Value* right_value = NULL; 121 base::Value* right_value = NULL;
120 if (right_dict->HasKey(iter.key()) && 122 if (right_dict->HasKey(iter.key()) &&
121 right_dict->Get(iter.key(), &right_value) && 123 right_dict->Get(iter.key(), &right_value) &&
122 !iter.value().Equals(right_value)) { 124 !iter.value().Equals(right_value)) {
123 return false; 125 return false;
124 } 126 }
125 } 127 }
126 return true; 128 return true;
127 } else if ((event_name_ == extension_event_names::kOnDownloadErased) && 129 } else if ((event_name_ == events::kOnDownloadErased) &&
128 args_.get() && 130 args_.get() &&
129 other.args_.get()) { 131 other.args_.get()) {
130 int my_id = -1, other_id = -1; 132 int my_id = -1, other_id = -1;
131 return (args_->GetAsInteger(&my_id) && 133 return (args_->GetAsInteger(&my_id) &&
132 other.args_->GetAsInteger(&other_id) && 134 other.args_->GetAsInteger(&other_id) &&
133 my_id == other_id); 135 my_id == other_id);
134 } 136 }
135 return json_args_ == other.json_args_; 137 return json_args_ == other.json_args_;
136 } 138 }
137 139
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 current_browser_ = incognito_browser_; 289 current_browser_ = incognito_browser_;
288 } 290 }
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(events::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 // The item may or may not be interrupted before the onCreated event fires.
300 if (item->IsInterrupted()) { 302 if (item->IsInterrupted()) {
301 scoped_ptr<base::Value> args(base::JSONReader::Read(on_created_event)); 303 scoped_ptr<base::Value> args(base::JSONReader::Read(on_created_event));
302 base::ListValue* args_list = NULL; 304 base::ListValue* args_list = NULL;
303 base::DictionaryValue* args_dict = NULL; 305 base::DictionaryValue* args_dict = NULL;
304 if (!args->GetAsList(&args_list) || 306 if (!args->GetAsList(&args_list) ||
305 !args_list->GetDictionary(0, &args_dict)) 307 !args_list->GetDictionary(0, &args_dict))
306 return false; 308 return false;
307 args_dict->SetString("state", "interrupted"); 309 args_dict->SetString("state", "interrupted");
308 args_dict->SetInteger("error", expected_error); 310 args_dict->SetInteger("error", expected_error);
309 std::string created_error; 311 std::string created_error;
310 base::JSONWriter::Write(args_list, &created_error); 312 base::JSONWriter::Write(args_list, &created_error);
311 // This is not waiting for a different event, it's refining the 313 // This is not waiting for a different event, it's refining the
312 // expectations on the onCreated event that was just caught. Specifically, 314 // expectations on the onCreated event that was just caught. Specifically,
313 // if a DownloadItem is already interrupted by the time the onCreated 315 // if a DownloadItem is already interrupted by the time the onCreated
314 // event fires, then the onCreated event should already describe the 316 // event fires, then the onCreated event should already describe the
315 // error. 317 // error.
316 return WaitFor(extension_event_names::kOnDownloadCreated, created_error); 318 return WaitFor(events::kOnDownloadCreated, created_error);
317 } else { 319 } else {
318 return WaitFor(extension_event_names::kOnDownloadChanged, 320 return WaitFor(events::kOnDownloadChanged,
319 base::StringPrintf("[{\"id\": %d," 321 base::StringPrintf("[{\"id\": %d,"
320 " \"error\": {\"current\": %d}," 322 " \"error\": {\"current\": %d},"
321 " \"state\": {" 323 " \"state\": {"
322 " \"previous\": \"in_progress\"," 324 " \"previous\": \"in_progress\","
323 " \"current\": \"interrupted\"}}]", 325 " \"current\": \"interrupted\"}}]",
324 item->GetId(), 326 item->GetId(),
325 expected_error)); 327 expected_error));
326 } 328 }
327 } 329 }
328 330
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1495 "[{\"url\": \"%s\"}]", download_url.c_str())));
1494 ASSERT_TRUE(result.get()); 1496 ASSERT_TRUE(result.get());
1495 int result_id = -1; 1497 int result_id = -1;
1496 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1498 ASSERT_TRUE(result->GetAsInteger(&result_id));
1497 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1499 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1498 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1500 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1499 ASSERT_TRUE(item); 1501 ASSERT_TRUE(item);
1500 ScopedCancellingItem canceller(item); 1502 ScopedCancellingItem canceller(item);
1501 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1503 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1502 1504
1503 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1505 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1504 base::StringPrintf("[{\"danger\": \"safe\"," 1506 base::StringPrintf("[{\"danger\": \"safe\","
1505 " \"filename\": \"%s\"," 1507 " \"filename\": \"%s\","
1506 " \"incognito\": false," 1508 " \"incognito\": false,"
1507 " \"mime\": \"text/plain\"," 1509 " \"mime\": \"text/plain\","
1508 " \"paused\": false," 1510 " \"paused\": false,"
1509 " \"url\": \"%s\"}]", 1511 " \"url\": \"%s\"}]",
1510 GetFilename("slow.txt.crdownload").c_str(), 1512 GetFilename("slow.txt.crdownload").c_str(),
1511 download_url.c_str()))); 1513 download_url.c_str())));
1512 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1514 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1513 base::StringPrintf("[{\"id\": %d," 1515 base::StringPrintf("[{\"id\": %d,"
1514 " \"filename\": {" 1516 " \"filename\": {"
1515 " \"previous\": \"%s\"," 1517 " \"previous\": \"%s\","
1516 " \"current\": \"%s\"}," 1518 " \"current\": \"%s\"},"
1517 " \"state\": {" 1519 " \"state\": {"
1518 " \"previous\": \"in_progress\"," 1520 " \"previous\": \"in_progress\","
1519 " \"current\": \"complete\"}}]", 1521 " \"current\": \"complete\"}}]",
1520 result_id, 1522 result_id,
1521 GetFilename("slow.txt.crdownload").c_str(), 1523 GetFilename("slow.txt.crdownload").c_str(),
1522 GetFilename("slow.txt").c_str()))); 1524 GetFilename("slow.txt").c_str())));
(...skipping 13 matching lines...) Expand all
1536 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1538 "[{\"url\": \"%s\"}]", download_url.c_str())));
1537 ASSERT_TRUE(result.get()); 1539 ASSERT_TRUE(result.get());
1538 int result_id = -1; 1540 int result_id = -1;
1539 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1541 ASSERT_TRUE(result->GetAsInteger(&result_id));
1540 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1542 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1541 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1543 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1542 ASSERT_TRUE(item); 1544 ASSERT_TRUE(item);
1543 ScopedCancellingItem canceller(item); 1545 ScopedCancellingItem canceller(item);
1544 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1546 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1545 1547
1546 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1548 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1547 base::StringPrintf("[{\"danger\": \"safe\"," 1549 base::StringPrintf("[{\"danger\": \"safe\","
1548 " \"filename\": \"%s\"," 1550 " \"filename\": \"%s\","
1549 " \"incognito\": true," 1551 " \"incognito\": true,"
1550 " \"mime\": \"text/plain\"," 1552 " \"mime\": \"text/plain\","
1551 " \"paused\": false," 1553 " \"paused\": false,"
1552 " \"url\": \"%s\"}]", 1554 " \"url\": \"%s\"}]",
1553 GetFilename("slow.txt.crdownload").c_str(), 1555 GetFilename("slow.txt.crdownload").c_str(),
1554 download_url.c_str()))); 1556 download_url.c_str())));
1555 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1557 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1556 base::StringPrintf("[{\"id\":%d," 1558 base::StringPrintf("[{\"id\":%d,"
1557 " \"filename\": {" 1559 " \"filename\": {"
1558 " \"previous\": \"%s\"," 1560 " \"previous\": \"%s\","
1559 " \"current\": \"%s\"}," 1561 " \"current\": \"%s\"},"
1560 " \"state\": {" 1562 " \"state\": {"
1561 " \"current\": \"complete\"," 1563 " \"current\": \"complete\","
1562 " \"previous\": \"in_progress\"}}]", 1564 " \"previous\": \"in_progress\"}}]",
1563 result_id, 1565 result_id,
1564 GetFilename("slow.txt.crdownload").c_str(), 1566 GetFilename("slow.txt.crdownload").c_str(),
1565 GetFilename("slow.txt").c_str()))); 1567 GetFilename("slow.txt").c_str())));
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1694 "[{\"url\": \"%s\"}]", download_url.c_str())));
1693 ASSERT_TRUE(result.get()); 1695 ASSERT_TRUE(result.get());
1694 int result_id = -1; 1696 int result_id = -1;
1695 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1697 ASSERT_TRUE(result->GetAsInteger(&result_id));
1696 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1698 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1697 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1699 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1698 ASSERT_TRUE(item); 1700 ASSERT_TRUE(item);
1699 ScopedCancellingItem canceller(item); 1701 ScopedCancellingItem canceller(item);
1700 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1702 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1701 1703
1702 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1704 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1703 base::StringPrintf("[{\"danger\": \"safe\"," 1705 base::StringPrintf("[{\"danger\": \"safe\","
1704 " \"filename\": \"%s\"," 1706 " \"filename\": \"%s\","
1705 " \"incognito\": false," 1707 " \"incognito\": false,"
1706 " \"mime\": \"text/plain\"," 1708 " \"mime\": \"text/plain\","
1707 " \"paused\": false," 1709 " \"paused\": false,"
1708 " \"url\": \"%s\"}]", 1710 " \"url\": \"%s\"}]",
1709 GetFilename("slow.txt.crdownload").c_str(), 1711 GetFilename("slow.txt.crdownload").c_str(),
1710 download_url.c_str()))); 1712 download_url.c_str())));
1711 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1713 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1712 base::StringPrintf("[{\"id\": %d," 1714 base::StringPrintf("[{\"id\": %d,"
1713 " \"filename\": {" 1715 " \"filename\": {"
1714 " \"previous\": \"%s\"," 1716 " \"previous\": \"%s\","
1715 " \"current\": \"%s\"}," 1717 " \"current\": \"%s\"},"
1716 " \"state\": {" 1718 " \"state\": {"
1717 " \"previous\": \"in_progress\"," 1719 " \"previous\": \"in_progress\","
1718 " \"current\": \"complete\"}}]", 1720 " \"current\": \"complete\"}}]",
1719 result_id, 1721 result_id,
1720 GetFilename("slow.txt.crdownload").c_str(), 1722 GetFilename("slow.txt.crdownload").c_str(),
1721 GetFilename("slow.txt").c_str()))); 1723 GetFilename("slow.txt").c_str())));
(...skipping 13 matching lines...) Expand all
1735 " \"filename\": \"data.txt\"}]", download_url.c_str()))); 1737 " \"filename\": \"data.txt\"}]", download_url.c_str())));
1736 ASSERT_TRUE(result.get()); 1738 ASSERT_TRUE(result.get());
1737 int result_id = -1; 1739 int result_id = -1;
1738 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1740 ASSERT_TRUE(result->GetAsInteger(&result_id));
1739 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1741 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1740 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1742 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1741 ASSERT_TRUE(item); 1743 ASSERT_TRUE(item);
1742 ScopedCancellingItem canceller(item); 1744 ScopedCancellingItem canceller(item);
1743 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1745 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1744 1746
1745 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1747 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1746 base::StringPrintf("[{\"danger\": \"safe\"," 1748 base::StringPrintf("[{\"danger\": \"safe\","
1747 " \"filename\": \"%s\"," 1749 " \"filename\": \"%s\","
1748 " \"incognito\": false," 1750 " \"incognito\": false,"
1749 " \"mime\": \"text/plain\"," 1751 " \"mime\": \"text/plain\","
1750 " \"paused\": false," 1752 " \"paused\": false,"
1751 " \"url\": \"%s\"}]", 1753 " \"url\": \"%s\"}]",
1752 GetFilename("data.txt.crdownload").c_str(), 1754 GetFilename("data.txt.crdownload").c_str(),
1753 download_url.c_str()))); 1755 download_url.c_str())));
1754 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1756 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1755 base::StringPrintf("[{\"id\": %d," 1757 base::StringPrintf("[{\"id\": %d,"
1756 " \"filename\": {" 1758 " \"filename\": {"
1757 " \"previous\": \"%s\"," 1759 " \"previous\": \"%s\","
1758 " \"current\": \"%s\"}," 1760 " \"current\": \"%s\"},"
1759 " \"state\": {" 1761 " \"state\": {"
1760 " \"previous\": \"in_progress\"," 1762 " \"previous\": \"in_progress\","
1761 " \"current\": \"complete\"}}]", 1763 " \"current\": \"complete\"}}]",
1762 result_id, 1764 result_id,
1763 GetFilename("data.txt.crdownload").c_str(), 1765 GetFilename("data.txt.crdownload").c_str(),
1764 GetFilename("data.txt").c_str()))); 1766 GetFilename("data.txt").c_str())));
(...skipping 16 matching lines...) Expand all
1781 " \"filename\": \"file.txt\"}]", download_url.c_str()))); 1783 " \"filename\": \"file.txt\"}]", download_url.c_str())));
1782 ASSERT_TRUE(result.get()); 1784 ASSERT_TRUE(result.get());
1783 int result_id = -1; 1785 int result_id = -1;
1784 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1786 ASSERT_TRUE(result->GetAsInteger(&result_id));
1785 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1787 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1786 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1788 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1787 ASSERT_TRUE(item); 1789 ASSERT_TRUE(item);
1788 ScopedCancellingItem canceller(item); 1790 ScopedCancellingItem canceller(item);
1789 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1791 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1790 1792
1791 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1793 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1792 base::StringPrintf("[{\"danger\": \"safe\"," 1794 base::StringPrintf("[{\"danger\": \"safe\","
1793 " \"filename\": \"%s\"," 1795 " \"filename\": \"%s\","
1794 " \"incognito\": false," 1796 " \"incognito\": false,"
1795 " \"mime\": \"text/html\"," 1797 " \"mime\": \"text/html\","
1796 " \"paused\": false," 1798 " \"paused\": false,"
1797 " \"url\": \"%s\"}]", 1799 " \"url\": \"%s\"}]",
1798 GetFilename("file.txt.crdownload").c_str(), 1800 GetFilename("file.txt.crdownload").c_str(),
1799 download_url.c_str()))); 1801 download_url.c_str())));
1800 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1802 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1801 base::StringPrintf("[{\"id\": %d," 1803 base::StringPrintf("[{\"id\": %d,"
1802 " \"filename\": {" 1804 " \"filename\": {"
1803 " \"previous\": \"%s\"," 1805 " \"previous\": \"%s\","
1804 " \"current\": \"%s\"}," 1806 " \"current\": \"%s\"},"
1805 " \"state\": {" 1807 " \"state\": {"
1806 " \"previous\": \"in_progress\"," 1808 " \"previous\": \"in_progress\","
1807 " \"current\": \"complete\"}}]", 1809 " \"current\": \"complete\"}}]",
1808 result_id, 1810 result_id,
1809 GetFilename("file.txt.crdownload").c_str(), 1811 GetFilename("file.txt.crdownload").c_str(),
1810 GetFilename("file.txt").c_str()))); 1812 GetFilename("file.txt").c_str())));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 download_url.c_str()))); 1865 download_url.c_str())));
1864 ASSERT_TRUE(result.get()); 1866 ASSERT_TRUE(result.get());
1865 int result_id = -1; 1867 int result_id = -1;
1866 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1868 ASSERT_TRUE(result->GetAsInteger(&result_id));
1867 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1869 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1868 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1870 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1869 ASSERT_TRUE(item); 1871 ASSERT_TRUE(item);
1870 ScopedCancellingItem canceller(item); 1872 ScopedCancellingItem canceller(item);
1871 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1873 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1872 1874
1873 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1875 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1874 base::StringPrintf("[{\"danger\": \"safe\"," 1876 base::StringPrintf("[{\"danger\": \"safe\","
1875 " \"incognito\": false," 1877 " \"incognito\": false,"
1876 " \"mime\": \"application/octet-stream\"," 1878 " \"mime\": \"application/octet-stream\","
1877 " \"paused\": false," 1879 " \"paused\": false,"
1878 " \"url\": \"%s\"}]", 1880 " \"url\": \"%s\"}]",
1879 download_url.c_str()))); 1881 download_url.c_str())));
1880 std::string incomplete_filename = GetFilename( 1882 std::string incomplete_filename = GetFilename(
1881 "headers-succeed.txt.crdownload"); 1883 "headers-succeed.txt.crdownload");
1882 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1884 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1883 base::StringPrintf("[{\"id\": %d," 1885 base::StringPrintf("[{\"id\": %d,"
1884 " \"filename\": {" 1886 " \"filename\": {"
1885 " \"previous\": \"%s\"," 1887 " \"previous\": \"%s\","
1886 " \"current\": \"%s\"}," 1888 " \"current\": \"%s\"},"
1887 " \"state\": {" 1889 " \"state\": {"
1888 " \"previous\": \"in_progress\"," 1890 " \"previous\": \"in_progress\","
1889 " \"current\": \"complete\"}}]", 1891 " \"current\": \"complete\"}}]",
1890 result_id, 1892 result_id,
1891 incomplete_filename.c_str(), 1893 incomplete_filename.c_str(),
1892 GetFilename("headers-succeed.txt").c_str()))); 1894 GetFilename("headers-succeed.txt").c_str())));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 download_url.c_str(), kAuthorization))); 1951 download_url.c_str(), kAuthorization)));
1950 ASSERT_TRUE(result.get()); 1952 ASSERT_TRUE(result.get());
1951 int result_id = -1; 1953 int result_id = -1;
1952 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1954 ASSERT_TRUE(result->GetAsInteger(&result_id));
1953 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1955 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1954 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1956 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1955 ASSERT_TRUE(item); 1957 ASSERT_TRUE(item);
1956 ScopedCancellingItem canceller(item); 1958 ScopedCancellingItem canceller(item);
1957 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1959 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1958 1960
1959 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 1961 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1960 base::StringPrintf("[{\"danger\": \"safe\"," 1962 base::StringPrintf("[{\"danger\": \"safe\","
1961 " \"incognito\": false," 1963 " \"incognito\": false,"
1962 " \"mime\": \"text/html\"," 1964 " \"mime\": \"text/html\","
1963 " \"paused\": false," 1965 " \"paused\": false,"
1964 " \"url\": \"%s\"}]", download_url.c_str()))); 1966 " \"url\": \"%s\"}]", download_url.c_str())));
1965 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 1967 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1966 base::StringPrintf("[{\"id\": %d," 1968 base::StringPrintf("[{\"id\": %d,"
1967 " \"state\": {" 1969 " \"state\": {"
1968 " \"previous\": \"in_progress\"," 1970 " \"previous\": \"in_progress\","
1969 " \"current\": \"complete\"}}]", result_id))); 1971 " \"current\": \"complete\"}}]", result_id)));
1970 } 1972 }
1971 1973
1972 // Test that DownloadsDownloadFunction propagates the |method| and |body| 1974 // Test that DownloadsDownloadFunction propagates the |method| and |body|
1973 // parameters to the URLRequest. 1975 // parameters to the URLRequest.
1974 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1976 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1975 DownloadExtensionTest_Download_Post) { 1977 DownloadExtensionTest_Download_Post) {
(...skipping 12 matching lines...) Expand all
1988 download_url.c_str()))); 1990 download_url.c_str())));
1989 ASSERT_TRUE(result.get()); 1991 ASSERT_TRUE(result.get());
1990 int result_id = -1; 1992 int result_id = -1;
1991 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1993 ASSERT_TRUE(result->GetAsInteger(&result_id));
1992 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 1994 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
1993 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 1995 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
1994 ASSERT_TRUE(item); 1996 ASSERT_TRUE(item);
1995 ScopedCancellingItem canceller(item); 1997 ScopedCancellingItem canceller(item);
1996 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1998 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1997 1999
1998 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 2000 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1999 base::StringPrintf("[{\"danger\": \"safe\"," 2001 base::StringPrintf("[{\"danger\": \"safe\","
2000 " \"incognito\": false," 2002 " \"incognito\": false,"
2001 " \"mime\": \"application/octet-stream\"," 2003 " \"mime\": \"application/octet-stream\","
2002 " \"paused\": false," 2004 " \"paused\": false,"
2003 " \"bytesReceived\": 164," 2005 " \"bytesReceived\": 164,"
2004 " \"url\": \"%s\"}]", download_url.c_str()))); 2006 " \"url\": \"%s\"}]", download_url.c_str())));
2005 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 2007 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2006 base::StringPrintf("[{\"id\": %d," 2008 base::StringPrintf("[{\"id\": %d,"
2007 " \"state\": {" 2009 " \"state\": {"
2008 " \"previous\": \"in_progress\"," 2010 " \"previous\": \"in_progress\","
2009 " \"current\": \"complete\"}}]", result_id))); 2011 " \"current\": \"complete\"}}]", result_id)));
2010 } 2012 }
2011 2013
2012 // Test that downloadPostSuccess would fail if the resource requires the POST 2014 // Test that downloadPostSuccess would fail if the resource requires the POST
2013 // method, and chrome fails to propagate the |method| parameter back to the 2015 // 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 2016 // 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 2017 // fail, and this tests how the downloads extension api exposes the failure to
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2106 "[{\"url\": \"%s\"}]", download_url.c_str())));
2105 ASSERT_TRUE(result.get()); 2107 ASSERT_TRUE(result.get());
2106 int result_id = -1; 2108 int result_id = -1;
2107 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2109 ASSERT_TRUE(result->GetAsInteger(&result_id));
2108 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 2110 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
2109 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 2111 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
2110 ASSERT_TRUE(item); 2112 ASSERT_TRUE(item);
2111 ScopedCancellingItem canceller(item); 2113 ScopedCancellingItem canceller(item);
2112 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2114 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2113 2115
2114 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 2116 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
2115 base::StringPrintf("[{\"danger\": \"safe\"," 2117 base::StringPrintf("[{\"danger\": \"safe\","
2116 " \"incognito\": false," 2118 " \"incognito\": false,"
2117 " \"mime\": \"application/octet-stream\"," 2119 " \"mime\": \"application/octet-stream\","
2118 " \"paused\": false," 2120 " \"paused\": false,"
2119 " \"id\": %d," 2121 " \"id\": %d,"
2120 " \"url\": \"%s\"}]", 2122 " \"url\": \"%s\"}]",
2121 result_id, 2123 result_id,
2122 download_url.c_str()))); 2124 download_url.c_str())));
2123 item->Cancel(true); 2125 item->Cancel(true);
2124 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 2126 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2125 base::StringPrintf("[{\"id\": %d," 2127 base::StringPrintf("[{\"id\": %d,"
2126 " \"error\": {\"current\": 40}," 2128 " \"error\": {\"current\": 40},"
2127 " \"state\": {" 2129 " \"state\": {"
2128 " \"previous\": \"in_progress\"," 2130 " \"previous\": \"in_progress\","
2129 " \"current\": \"interrupted\"}}]", 2131 " \"current\": \"interrupted\"}}]",
2130 result_id))); 2132 result_id)));
2131 } 2133 }
2132 2134
2133 // Test downloading filesystem: URLs. 2135 // Test downloading filesystem: URLs.
2134 // NOTE: chrome disallows creating HTML5 FileSystem Files in incognito. 2136 // NOTE: chrome disallows creating HTML5 FileSystem Files in incognito.
(...skipping 18 matching lines...) Expand all
2153 ASSERT_TRUE(result.get()); 2155 ASSERT_TRUE(result.get());
2154 int result_id = -1; 2156 int result_id = -1;
2155 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2157 ASSERT_TRUE(result->GetAsInteger(&result_id));
2156 2158
2157 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id); 2159 DownloadItem* item = GetCurrentManager()->GetActiveDownloadItem(result_id);
2158 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id); 2160 if (!item) item = GetCurrentManager()->GetDownloadItem(result_id);
2159 ASSERT_TRUE(item); 2161 ASSERT_TRUE(item);
2160 ScopedCancellingItem canceller(item); 2162 ScopedCancellingItem canceller(item);
2161 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2163 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2162 2164
2163 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadCreated, 2165 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
2164 base::StringPrintf("[{\"danger\": \"safe\"," 2166 base::StringPrintf("[{\"danger\": \"safe\","
2165 " \"filename\": \"%s\"," 2167 " \"filename\": \"%s\","
2166 " \"incognito\": false," 2168 " \"incognito\": false,"
2167 " \"mime\": \"text/plain\"," 2169 " \"mime\": \"text/plain\","
2168 " \"paused\": false," 2170 " \"paused\": false,"
2169 " \"url\": \"%s\"}]", 2171 " \"url\": \"%s\"}]",
2170 GetFilename("on_record.txt.crdownload").c_str(), 2172 GetFilename("on_record.txt.crdownload").c_str(),
2171 download_url.c_str()))); 2173 download_url.c_str())));
2172 ASSERT_TRUE(WaitFor(extension_event_names::kOnDownloadChanged, 2174 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2173 base::StringPrintf("[{\"id\": %d," 2175 base::StringPrintf("[{\"id\": %d,"
2174 " \"filename\": {" 2176 " \"filename\": {"
2175 " \"previous\": \"%s\"," 2177 " \"previous\": \"%s\","
2176 " \"current\": \"%s\"}," 2178 " \"current\": \"%s\"},"
2177 " \"state\": {" 2179 " \"state\": {"
2178 " \"previous\": \"in_progress\"," 2180 " \"previous\": \"in_progress\","
2179 " \"current\": \"complete\"}}]", 2181 " \"current\": \"complete\"}}]",
2180 result_id, 2182 result_id,
2181 GetFilename("on_record.txt.crdownload").c_str(), 2183 GetFilename("on_record.txt.crdownload").c_str(),
2182 GetFilename("on_record.txt").c_str()))); 2184 GetFilename("on_record.txt").c_str())));
2183 std::string disk_data; 2185 std::string disk_data;
2184 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2186 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2185 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2187 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2186 } 2188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698