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

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

Issue 257983002: Move downloads API to extensions namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error for unittest Created 6 years, 7 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 // Disable everything on windows only. http://crbug.com/306144 5 // Disable everything on windows only. http://crbug.com/306144
6 #ifndef OS_WIN 6 #ifndef OS_WIN
7 7
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "webkit/browser/fileapi/file_system_url.h" 56 #include "webkit/browser/fileapi/file_system_url.h"
57 57
58 using content::BrowserContext; 58 using content::BrowserContext;
59 using content::BrowserThread; 59 using content::BrowserThread;
60 using content::DownloadItem; 60 using content::DownloadItem;
61 using content::DownloadManager; 61 using content::DownloadManager;
62 using content::URLRequestSlowDownloadJob; 62 using content::URLRequestSlowDownloadJob;
63 63
64 namespace errors = download_extension_errors; 64 namespace errors = download_extension_errors;
65 65
66 namespace api = extensions::api::downloads; 66 namespace downloads = extensions::api::downloads;
67
68 namespace extensions {
67 69
68 namespace { 70 namespace {
69 71
70 // Comparator that orders download items by their ID. Can be used with 72 // Comparator that orders download items by their ID. Can be used with
71 // std::sort. 73 // std::sort.
72 struct DownloadIdComparator { 74 struct DownloadIdComparator {
73 bool operator() (DownloadItem* first, DownloadItem* second) { 75 bool operator() (DownloadItem* first, DownloadItem* second) {
74 return first->GetId() < second->GetId(); 76 return first->GetId() < second->GetId();
75 } 77 }
76 }; 78 };
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const base::Time& caught() { return caught_; } 112 const base::Time& caught() { return caught_; }
111 113
112 bool Satisfies(const Event& other) const { 114 bool Satisfies(const Event& other) const {
113 return other.SatisfiedBy(*this); 115 return other.SatisfiedBy(*this);
114 } 116 }
115 117
116 bool SatisfiedBy(const Event& other) const { 118 bool SatisfiedBy(const Event& other) const {
117 if ((profile_ != other.profile_) || 119 if ((profile_ != other.profile_) ||
118 (event_name_ != other.event_name_)) 120 (event_name_ != other.event_name_))
119 return false; 121 return false;
120 if (((event_name_ == api::OnDeterminingFilename::kEventName) || 122 if (((event_name_ == downloads::OnDeterminingFilename::kEventName) ||
121 (event_name_ == api::OnCreated::kEventName) || 123 (event_name_ == downloads::OnCreated::kEventName) ||
122 (event_name_ == api::OnChanged::kEventName)) && 124 (event_name_ == downloads::OnChanged::kEventName)) &&
123 args_.get() && 125 args_.get() && other.args_.get()) {
124 other.args_.get()) {
125 base::ListValue* left_list = NULL; 126 base::ListValue* left_list = NULL;
126 base::DictionaryValue* left_dict = NULL; 127 base::DictionaryValue* left_dict = NULL;
127 base::ListValue* right_list = NULL; 128 base::ListValue* right_list = NULL;
128 base::DictionaryValue* right_dict = NULL; 129 base::DictionaryValue* right_dict = NULL;
129 if (!args_->GetAsList(&left_list) || 130 if (!args_->GetAsList(&left_list) ||
130 !other.args_->GetAsList(&right_list) || 131 !other.args_->GetAsList(&right_list) ||
131 !left_list->GetDictionary(0, &left_dict) || 132 !left_list->GetDictionary(0, &left_dict) ||
132 !right_list->GetDictionary(0, &right_dict)) 133 !right_list->GetDictionary(0, &right_dict))
133 return false; 134 return false;
134 for (base::DictionaryValue::Iterator iter(*left_dict); 135 for (base::DictionaryValue::Iterator iter(*left_dict);
135 !iter.IsAtEnd(); iter.Advance()) { 136 !iter.IsAtEnd(); iter.Advance()) {
136 base::Value* right_value = NULL; 137 base::Value* right_value = NULL;
137 if (!right_dict->HasKey(iter.key()) || 138 if (!right_dict->HasKey(iter.key()) ||
138 (right_dict->Get(iter.key(), &right_value) && 139 (right_dict->Get(iter.key(), &right_value) &&
139 !iter.value().Equals(right_value))) { 140 !iter.value().Equals(right_value))) {
140 return false; 141 return false;
141 } 142 }
142 } 143 }
143 return true; 144 return true;
144 } else if ((event_name_ == api::OnErased::kEventName) && 145 } else if ((event_name_ == downloads::OnErased::kEventName) &&
145 args_.get() && 146 args_.get() && other.args_.get()) {
146 other.args_.get()) {
147 int my_id = -1, other_id = -1; 147 int my_id = -1, other_id = -1;
148 return (args_->GetAsInteger(&my_id) && 148 return (args_->GetAsInteger(&my_id) &&
149 other.args_->GetAsInteger(&other_id) && 149 other.args_->GetAsInteger(&other_id) &&
150 my_id == other_id); 150 my_id == other_id);
151 } 151 }
152 return json_args_ == other.json_args_; 152 return json_args_ == other.json_args_;
153 } 153 }
154 154
155 std::string Debug() { 155 std::string Debug() {
156 return base::StringPrintf("Event(%p, %s, %s, %f)", 156 return base::StringPrintf("Event(%p, %s, %s, %f)",
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // Store the created Extension object so that we can attach it to 270 // Store the created Extension object so that we can attach it to
271 // ExtensionFunctions. Also load the extension in incognito profiles for 271 // ExtensionFunctions. Also load the extension in incognito profiles for
272 // testing incognito. 272 // testing incognito.
273 extension_ = LoadExtensionIncognito(test_data_dir_.AppendASCII(name)); 273 extension_ = LoadExtensionIncognito(test_data_dir_.AppendASCII(name));
274 CHECK(extension_); 274 CHECK(extension_);
275 content::WebContents* tab = chrome::AddSelectedTabWithURL( 275 content::WebContents* tab = chrome::AddSelectedTabWithURL(
276 current_browser(), 276 current_browser(),
277 extension_->GetResourceURL("empty.html"), 277 extension_->GetResourceURL("empty.html"),
278 content::PAGE_TRANSITION_LINK); 278 content::PAGE_TRANSITION_LINK);
279 extensions::EventRouter::Get(current_browser()->profile()) 279 extensions::EventRouter::Get(current_browser()->profile())
280 ->AddEventListener(api::OnCreated::kEventName, 280 ->AddEventListener(downloads::OnCreated::kEventName,
281 tab->GetRenderProcessHost(), 281 tab->GetRenderProcessHost(),
282 GetExtensionId()); 282 GetExtensionId());
283 extensions::EventRouter::Get(current_browser()->profile()) 283 extensions::EventRouter::Get(current_browser()->profile())
284 ->AddEventListener(api::OnChanged::kEventName, 284 ->AddEventListener(downloads::OnChanged::kEventName,
285 tab->GetRenderProcessHost(), 285 tab->GetRenderProcessHost(),
286 GetExtensionId()); 286 GetExtensionId());
287 extensions::EventRouter::Get(current_browser()->profile()) 287 extensions::EventRouter::Get(current_browser()->profile())
288 ->AddEventListener(api::OnErased::kEventName, 288 ->AddEventListener(downloads::OnErased::kEventName,
289 tab->GetRenderProcessHost(), 289 tab->GetRenderProcessHost(),
290 GetExtensionId()); 290 GetExtensionId());
291 } 291 }
292 292
293 content::RenderProcessHost* AddFilenameDeterminer() { 293 content::RenderProcessHost* AddFilenameDeterminer() {
294 content::WebContents* tab = chrome::AddSelectedTabWithURL( 294 content::WebContents* tab = chrome::AddSelectedTabWithURL(
295 current_browser(), 295 current_browser(),
296 extension_->GetResourceURL("empty.html"), 296 extension_->GetResourceURL("empty.html"),
297 content::PAGE_TRANSITION_LINK); 297 content::PAGE_TRANSITION_LINK);
298 extensions::ExtensionSystem::Get(current_browser()->profile())-> 298 extensions::ExtensionSystem::Get(current_browser()->profile())
299 event_router()->AddEventListener( 299 ->event_router()
300 api::OnDeterminingFilename::kEventName, 300 ->AddEventListener(downloads::OnDeterminingFilename::kEventName,
301 tab->GetRenderProcessHost(), 301 tab->GetRenderProcessHost(),
302 GetExtensionId()); 302 GetExtensionId());
303 return tab->GetRenderProcessHost(); 303 return tab->GetRenderProcessHost();
304 } 304 }
305 305
306 void RemoveFilenameDeterminer(content::RenderProcessHost* host) { 306 void RemoveFilenameDeterminer(content::RenderProcessHost* host) {
307 extensions::ExtensionSystem::Get(current_browser()->profile())-> 307 extensions::ExtensionSystem::Get(current_browser()->profile())
308 event_router()->RemoveEventListener( 308 ->event_router()
309 api::OnDeterminingFilename::kEventName, 309 ->RemoveEventListener(downloads::OnDeterminingFilename::kEventName,
310 host, 310 host,
311 GetExtensionId()); 311 GetExtensionId());
312 } 312 }
313 313
314 Browser* current_browser() { return current_browser_; } 314 Browser* current_browser() { return current_browser_; }
315 315
316 // InProcessBrowserTest 316 // InProcessBrowserTest
317 virtual void SetUpOnMainThread() OVERRIDE { 317 virtual void SetUpOnMainThread() OVERRIDE {
318 ExtensionApiTest::SetUpOnMainThread(); 318 ExtensionApiTest::SetUpOnMainThread();
319 BrowserThread::PostTask( 319 BrowserThread::PostTask(
320 BrowserThread::IO, FROM_HERE, 320 BrowserThread::IO, FROM_HERE,
321 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 321 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
(...skipping 24 matching lines...) Expand all
346 346
347 bool WaitFor(const std::string& event_name, const std::string& json_args) { 347 bool WaitFor(const std::string& event_name, const std::string& json_args) {
348 return events_listener_->WaitFor( 348 return events_listener_->WaitFor(
349 current_browser()->profile(), event_name, json_args); 349 current_browser()->profile(), event_name, json_args);
350 } 350 }
351 351
352 bool WaitForInterruption( 352 bool WaitForInterruption(
353 DownloadItem* item, 353 DownloadItem* item,
354 content::DownloadInterruptReason expected_error, 354 content::DownloadInterruptReason expected_error,
355 const std::string& on_created_event) { 355 const std::string& on_created_event) {
356 if (!WaitFor(api::OnCreated::kEventName, on_created_event)) 356 if (!WaitFor(downloads::OnCreated::kEventName, on_created_event))
357 return false; 357 return false;
358 // Now, onCreated is always fired before interruption. 358 // Now, onCreated is always fired before interruption.
359 return WaitFor(api::OnChanged::kEventName, 359 return WaitFor(
360 base::StringPrintf("[{\"id\": %d," 360 downloads::OnChanged::kEventName,
361 " \"error\": {\"current\": \"%s\"}," 361 base::StringPrintf(
362 " \"state\": {" 362 "[{\"id\": %d,"
363 " \"previous\": \"in_progress\"," 363 " \"error\": {\"current\": \"%s\"},"
364 " \"current\": \"interrupted\"}}]", 364 " \"state\": {"
365 item->GetId(), 365 " \"previous\": \"in_progress\","
366 content::DownloadInterruptReasonToString( 366 " \"current\": \"interrupted\"}}]",
367 expected_error).c_str())); 367 item->GetId(),
368 content::DownloadInterruptReasonToString(expected_error).c_str()));
368 } 369 }
369 370
370 void ClearEvents() { 371 void ClearEvents() {
371 events_listener_->ClearEvents(); 372 events_listener_->ClearEvents();
372 } 373 }
373 374
374 std::string GetExtensionURL() { 375 std::string GetExtensionURL() {
375 return extension_->url().spec(); 376 return extension_->url().spec();
376 } 377 }
377 std::string GetExtensionId() { 378 std::string GetExtensionId() {
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 767 }
767 768
768 DISALLOW_COPY_AND_ASSIGN(JustInProgressDownloadObserver); 769 DISALLOW_COPY_AND_ASSIGN(JustInProgressDownloadObserver);
769 }; 770 };
770 771
771 bool ItemIsInterrupted(DownloadItem* item) { 772 bool ItemIsInterrupted(DownloadItem* item) {
772 return item->GetState() == DownloadItem::INTERRUPTED; 773 return item->GetState() == DownloadItem::INTERRUPTED;
773 } 774 }
774 775
775 content::DownloadInterruptReason InterruptReasonExtensionToContent( 776 content::DownloadInterruptReason InterruptReasonExtensionToContent(
776 api::InterruptReason error) { 777 downloads::InterruptReason error) {
777 switch (error) { 778 switch (error) {
778 case api::INTERRUPT_REASON_NONE: 779 case downloads::INTERRUPT_REASON_NONE:
779 return content::DOWNLOAD_INTERRUPT_REASON_NONE; 780 return content::DOWNLOAD_INTERRUPT_REASON_NONE;
780 #define INTERRUPT_REASON(name, value) \ 781 #define INTERRUPT_REASON(name, value) \
781 case api::INTERRUPT_REASON_##name: \ 782 case downloads::INTERRUPT_REASON_##name: \
782 return content::DOWNLOAD_INTERRUPT_REASON_##name; 783 return content::DOWNLOAD_INTERRUPT_REASON_##name;
783 #include "content/public/browser/download_interrupt_reason_values.h" 784 #include "content/public/browser/download_interrupt_reason_values.h"
784 #undef INTERRUPT_REASON 785 #undef INTERRUPT_REASON
785 } 786 }
786 NOTREACHED(); 787 NOTREACHED();
787 return content::DOWNLOAD_INTERRUPT_REASON_NONE; 788 return content::DOWNLOAD_INTERRUPT_REASON_NONE;
788 } 789 }
789 790
790 api::InterruptReason InterruptReasonContentToExtension( 791 downloads::InterruptReason InterruptReasonContentToExtension(
791 content::DownloadInterruptReason error) { 792 content::DownloadInterruptReason error) {
792 switch (error) { 793 switch (error) {
793 case content::DOWNLOAD_INTERRUPT_REASON_NONE: 794 case content::DOWNLOAD_INTERRUPT_REASON_NONE:
794 return api::INTERRUPT_REASON_NONE; 795 return downloads::INTERRUPT_REASON_NONE;
795 #define INTERRUPT_REASON(name, value) \ 796 #define INTERRUPT_REASON(name, value) \
796 case content::DOWNLOAD_INTERRUPT_REASON_##name: \ 797 case content::DOWNLOAD_INTERRUPT_REASON_##name: \
797 return api::INTERRUPT_REASON_##name; 798 return downloads::INTERRUPT_REASON_##name;
798 #include "content/public/browser/download_interrupt_reason_values.h" 799 #include "content/public/browser/download_interrupt_reason_values.h"
799 #undef INTERRUPT_REASON 800 #undef INTERRUPT_REASON
800 } 801 }
801 NOTREACHED(); 802 NOTREACHED();
802 return api::INTERRUPT_REASON_NONE; 803 return downloads::INTERRUPT_REASON_NONE;
803 } 804 }
804 805
805 } // namespace 806 } // namespace
806 807
807 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 808 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
808 DownloadExtensionTest_Open) { 809 DownloadExtensionTest_Open) {
809 LoadExtension("downloads_split"); 810 LoadExtension("downloads_split");
810 DownloadsOpenFunction* open_function = new DownloadsOpenFunction(); 811 DownloadsOpenFunction* open_function = new DownloadsOpenFunction();
811 open_function->set_user_gesture(true); 812 open_function->set_user_gesture(true);
812 EXPECT_STREQ(errors::kInvalidId, 813 EXPECT_STREQ(errors::kInvalidId,
813 RunFunctionAndReturnError( 814 RunFunctionAndReturnError(
814 open_function, 815 open_function,
815 "[-42]").c_str()); 816 "[-42]").c_str());
816 817
817 DownloadItem* download_item = CreateSlowTestDownload(); 818 DownloadItem* download_item = CreateSlowTestDownload();
818 ASSERT_TRUE(download_item); 819 ASSERT_TRUE(download_item);
819 EXPECT_FALSE(download_item->GetOpened()); 820 EXPECT_FALSE(download_item->GetOpened());
820 EXPECT_FALSE(download_item->GetOpenWhenComplete()); 821 EXPECT_FALSE(download_item->GetOpenWhenComplete());
821 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 822 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
822 base::StringPrintf("[{\"danger\": \"safe\"," 823 base::StringPrintf(
823 " \"incognito\": false," 824 "[{\"danger\": \"safe\","
824 " \"mime\": \"application/octet-stream\"," 825 " \"incognito\": false,"
825 " \"paused\": false," 826 " \"mime\": \"application/octet-stream\","
826 " \"url\": \"%s\"}]", 827 " \"paused\": false,"
827 download_item->GetURL().spec().c_str()))); 828 " \"url\": \"%s\"}]",
829 download_item->GetURL().spec().c_str())));
828 open_function = new DownloadsOpenFunction(); 830 open_function = new DownloadsOpenFunction();
829 open_function->set_user_gesture(true); 831 open_function->set_user_gesture(true);
830 EXPECT_STREQ(errors::kNotComplete, 832 EXPECT_STREQ(errors::kNotComplete,
831 RunFunctionAndReturnError( 833 RunFunctionAndReturnError(
832 open_function, 834 open_function,
833 DownloadItemIdAsArgList(download_item)).c_str()); 835 DownloadItemIdAsArgList(download_item)).c_str());
834 836
835 FinishPendingSlowDownloads(); 837 FinishPendingSlowDownloads();
836 EXPECT_FALSE(download_item->GetOpened()); 838 EXPECT_FALSE(download_item->GetOpened());
837 839
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 new DownloadsDownloadFunction(), base::StringPrintf( 1472 new DownloadsDownloadFunction(), base::StringPrintf(
1471 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1473 "[{\"url\": \"%s\"}]", download_url.c_str())));
1472 ASSERT_TRUE(result.get()); 1474 ASSERT_TRUE(result.get());
1473 int result_id = -1; 1475 int result_id = -1;
1474 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1476 ASSERT_TRUE(result->GetAsInteger(&result_id));
1475 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1477 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1476 ASSERT_TRUE(item); 1478 ASSERT_TRUE(item);
1477 ScopedCancellingItem canceller(item); 1479 ScopedCancellingItem canceller(item);
1478 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1480 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1479 1481
1480 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 1482 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1481 base::StringPrintf("[{\"danger\": \"safe\"," 1483 base::StringPrintf(
1482 " \"incognito\": false," 1484 "[{\"danger\": \"safe\","
1483 " \"mime\": \"text/plain\"," 1485 " \"incognito\": false,"
1484 " \"paused\": false," 1486 " \"mime\": \"text/plain\","
1485 " \"url\": \"%s\"}]", 1487 " \"paused\": false,"
1486 download_url.c_str()))); 1488 " \"url\": \"%s\"}]",
1487 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1489 download_url.c_str())));
1488 base::StringPrintf("[{\"id\": %d," 1490 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1489 " \"filename\": {" 1491 base::StringPrintf(
1490 " \"previous\": \"\"," 1492 "[{\"id\": %d,"
1491 " \"current\": \"%s\"}}]", 1493 " \"filename\": {"
1492 result_id, 1494 " \"previous\": \"\","
1493 GetFilename("slow.txt").c_str()))); 1495 " \"current\": \"%s\"}}]",
1494 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1496 result_id,
1495 base::StringPrintf("[{\"id\": %d," 1497 GetFilename("slow.txt").c_str())));
1496 " \"state\": {" 1498 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1497 " \"previous\": \"in_progress\"," 1499 base::StringPrintf(
1498 " \"current\": \"complete\"}}]", 1500 "[{\"id\": %d,"
1499 result_id))); 1501 " \"state\": {"
1502 " \"previous\": \"in_progress\","
1503 " \"current\": \"complete\"}}]",
1504 result_id)));
1500 } 1505 }
1501 1506
1502 // Test that we can start a download from an incognito context, and that the 1507 // Test that we can start a download from an incognito context, and that the
1503 // download knows that it's incognito. 1508 // download knows that it's incognito.
1504 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1509 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1505 DownloadExtensionTest_Download_Incognito) { 1510 DownloadExtensionTest_Download_Incognito) {
1506 LoadExtension("downloads_split"); 1511 LoadExtension("downloads_split");
1507 ASSERT_TRUE(StartEmbeddedTestServer()); 1512 ASSERT_TRUE(StartEmbeddedTestServer());
1508 ASSERT_TRUE(test_server()->Start()); 1513 ASSERT_TRUE(test_server()->Start());
1509 GoOffTheRecord(); 1514 GoOffTheRecord();
1510 std::string download_url = test_server()->GetURL("slow?0").spec(); 1515 std::string download_url = test_server()->GetURL("slow?0").spec();
1511 1516
1512 // Start downloading a file. 1517 // Start downloading a file.
1513 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1518 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1514 new DownloadsDownloadFunction(), base::StringPrintf( 1519 new DownloadsDownloadFunction(), base::StringPrintf(
1515 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1520 "[{\"url\": \"%s\"}]", download_url.c_str())));
1516 ASSERT_TRUE(result.get()); 1521 ASSERT_TRUE(result.get());
1517 int result_id = -1; 1522 int result_id = -1;
1518 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1523 ASSERT_TRUE(result->GetAsInteger(&result_id));
1519 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1524 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1520 ASSERT_TRUE(item); 1525 ASSERT_TRUE(item);
1521 ScopedCancellingItem canceller(item); 1526 ScopedCancellingItem canceller(item);
1522 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1527 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1523 1528
1524 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 1529 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1525 base::StringPrintf("[{\"danger\": \"safe\"," 1530 base::StringPrintf(
1526 " \"incognito\": true," 1531 "[{\"danger\": \"safe\","
1527 " \"mime\": \"text/plain\"," 1532 " \"incognito\": true,"
1528 " \"paused\": false," 1533 " \"mime\": \"text/plain\","
1529 " \"url\": \"%s\"}]", 1534 " \"paused\": false,"
1530 download_url.c_str()))); 1535 " \"url\": \"%s\"}]",
1531 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1536 download_url.c_str())));
1532 base::StringPrintf("[{\"id\":%d," 1537 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1533 " \"filename\": {" 1538 base::StringPrintf(
1534 " \"previous\": \"\"," 1539 "[{\"id\":%d,"
1535 " \"current\": \"%s\"}}]", 1540 " \"filename\": {"
1536 result_id, 1541 " \"previous\": \"\","
1537 GetFilename("slow.txt").c_str()))); 1542 " \"current\": \"%s\"}}]",
1538 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1543 result_id,
1539 base::StringPrintf("[{\"id\":%d," 1544 GetFilename("slow.txt").c_str())));
1540 " \"state\": {" 1545 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1541 " \"current\": \"complete\"," 1546 base::StringPrintf(
1542 " \"previous\": \"in_progress\"}}]", 1547 "[{\"id\":%d,"
1543 result_id))); 1548 " \"state\": {"
1549 " \"current\": \"complete\","
1550 " \"previous\": \"in_progress\"}}]",
1551 result_id)));
1544 } 1552 }
1545 1553
1546 #if defined(OS_WIN) 1554 #if defined(OS_WIN)
1547 // This test is very flaky on Win. http://crbug.com/248438 1555 // This test is very flaky on Win. http://crbug.com/248438
1548 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ 1556 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \
1549 DISABLED_DownloadExtensionTest_Download_UnsafeHeaders 1557 DISABLED_DownloadExtensionTest_Download_UnsafeHeaders
1550 #else 1558 #else
1551 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ 1559 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \
1552 DownloadExtensionTest_Download_UnsafeHeaders 1560 DownloadExtensionTest_Download_UnsafeHeaders
1553 #endif 1561 #endif
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 " \"filename\": \"sub/dir/ect/ory.txt\"}]", 1633 " \"filename\": \"sub/dir/ect/ory.txt\"}]",
1626 download_url.c_str()))); 1634 download_url.c_str())));
1627 ASSERT_TRUE(result.get()); 1635 ASSERT_TRUE(result.get());
1628 int result_id = -1; 1636 int result_id = -1;
1629 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1637 ASSERT_TRUE(result->GetAsInteger(&result_id));
1630 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1638 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1631 ASSERT_TRUE(item); 1639 ASSERT_TRUE(item);
1632 ScopedCancellingItem canceller(item); 1640 ScopedCancellingItem canceller(item);
1633 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1641 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1634 1642
1635 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 1643 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1636 base::StringPrintf("[{\"danger\": \"safe\"," 1644 base::StringPrintf(
1637 " \"incognito\": false," 1645 "[{\"danger\": \"safe\","
1638 " \"mime\": \"text/plain\"," 1646 " \"incognito\": false,"
1639 " \"paused\": false," 1647 " \"mime\": \"text/plain\","
1640 " \"url\": \"%s\"}]", 1648 " \"paused\": false,"
1641 download_url.c_str()))); 1649 " \"url\": \"%s\"}]",
1642 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1650 download_url.c_str())));
1643 base::StringPrintf("[{\"id\": %d," 1651 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1644 " \"filename\": {" 1652 base::StringPrintf(
1645 " \"previous\": \"\"," 1653 "[{\"id\": %d,"
1646 " \"current\": \"%s\"}}]", 1654 " \"filename\": {"
1647 result_id, 1655 " \"previous\": \"\","
1648 GetFilename("sub/dir/ect/ory.txt").c_str()))); 1656 " \"current\": \"%s\"}}]",
1649 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1657 result_id,
1650 base::StringPrintf("[{\"id\": %d," 1658 GetFilename("sub/dir/ect/ory.txt").c_str())));
1651 " \"state\": {" 1659 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1652 " \"previous\": \"in_progress\"," 1660 base::StringPrintf(
1653 " \"current\": \"complete\"}}]", 1661 "[{\"id\": %d,"
1654 result_id))); 1662 " \"state\": {"
1663 " \"previous\": \"in_progress\","
1664 " \"current\": \"complete\"}}]",
1665 result_id)));
1655 } 1666 }
1656 1667
1657 // Test that invalid filenames are disallowed. 1668 // Test that invalid filenames are disallowed.
1658 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1669 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1659 DownloadExtensionTest_Download_InvalidFilename) { 1670 DownloadExtensionTest_Download_InvalidFilename) {
1660 LoadExtension("downloads_split"); 1671 LoadExtension("downloads_split");
1661 ASSERT_TRUE(StartEmbeddedTestServer()); 1672 ASSERT_TRUE(StartEmbeddedTestServer());
1662 ASSERT_TRUE(test_server()->Start()); 1673 ASSERT_TRUE(test_server()->Start());
1663 std::string download_url = test_server()->GetURL("slow?0").spec(); 1674 std::string download_url = test_server()->GetURL("slow?0").spec();
1664 GoOnTheRecord(); 1675 GoOnTheRecord();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 new DownloadsDownloadFunction(), base::StringPrintf( 1733 new DownloadsDownloadFunction(), base::StringPrintf(
1723 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1734 "[{\"url\": \"%s\"}]", download_url.c_str())));
1724 ASSERT_TRUE(result.get()); 1735 ASSERT_TRUE(result.get());
1725 int result_id = -1; 1736 int result_id = -1;
1726 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1737 ASSERT_TRUE(result->GetAsInteger(&result_id));
1727 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1738 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1728 ASSERT_TRUE(item); 1739 ASSERT_TRUE(item);
1729 ScopedCancellingItem canceller(item); 1740 ScopedCancellingItem canceller(item);
1730 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1741 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1731 1742
1732 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 1743 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1733 base::StringPrintf("[{\"danger\": \"safe\"," 1744 base::StringPrintf(
1734 " \"incognito\": false," 1745 "[{\"danger\": \"safe\","
1735 " \"mime\": \"text/plain\"," 1746 " \"incognito\": false,"
1736 " \"paused\": false," 1747 " \"mime\": \"text/plain\","
1737 " \"url\": \"%s\"}]", 1748 " \"paused\": false,"
1738 download_url.c_str()))); 1749 " \"url\": \"%s\"}]",
1739 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1750 download_url.c_str())));
1740 base::StringPrintf("[{\"id\": %d," 1751 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1741 " \"filename\": {" 1752 base::StringPrintf(
1742 " \"previous\": \"\"," 1753 "[{\"id\": %d,"
1743 " \"current\": \"%s\"}}]", 1754 " \"filename\": {"
1744 result_id, 1755 " \"previous\": \"\","
1745 GetFilename("slow.txt").c_str()))); 1756 " \"current\": \"%s\"}}]",
1746 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1757 result_id,
1747 base::StringPrintf("[{\"id\": %d," 1758 GetFilename("slow.txt").c_str())));
1748 " \"state\": {" 1759 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1749 " \"previous\": \"in_progress\"," 1760 base::StringPrintf(
1750 " \"current\": \"complete\"}}]", 1761 "[{\"id\": %d,"
1751 result_id))); 1762 " \"state\": {"
1763 " \"previous\": \"in_progress\","
1764 " \"current\": \"complete\"}}]",
1765 result_id)));
1752 } 1766 }
1753 1767
1754 // conflictAction may be specified without filename. 1768 // conflictAction may be specified without filename.
1755 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1769 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1756 DownloadExtensionTest_Download_ConflictAction) { 1770 DownloadExtensionTest_Download_ConflictAction) {
1757 static char kFilename[] = "download.txt"; 1771 static char kFilename[] = "download.txt";
1758 LoadExtension("downloads_split"); 1772 LoadExtension("downloads_split");
1759 std::string download_url = "data:text/plain,hello"; 1773 std::string download_url = "data:text/plain,hello";
1760 GoOnTheRecord(); 1774 GoOnTheRecord();
1761 1775
1762 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1776 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1763 new DownloadsDownloadFunction(), base::StringPrintf( 1777 new DownloadsDownloadFunction(), base::StringPrintf(
1764 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1778 "[{\"url\": \"%s\"}]", download_url.c_str())));
1765 ASSERT_TRUE(result.get()); 1779 ASSERT_TRUE(result.get());
1766 int result_id = -1; 1780 int result_id = -1;
1767 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1781 ASSERT_TRUE(result->GetAsInteger(&result_id));
1768 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1782 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1769 ASSERT_TRUE(item); 1783 ASSERT_TRUE(item);
1770 ScopedCancellingItem canceller(item); 1784 ScopedCancellingItem canceller(item);
1771 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1785 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1772 1786
1773 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 1787 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1774 base::StringPrintf("[{\"danger\": \"safe\"," 1788 base::StringPrintf(
1775 " \"incognito\": false," 1789 "[{\"danger\": \"safe\","
1776 " \"mime\": \"text/plain\"," 1790 " \"incognito\": false,"
1777 " \"paused\": false," 1791 " \"mime\": \"text/plain\","
1778 " \"url\": \"%s\"}]", 1792 " \"paused\": false,"
1779 download_url.c_str()))); 1793 " \"url\": \"%s\"}]",
1780 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1794 download_url.c_str())));
1781 base::StringPrintf("[{\"id\": %d," 1795 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1782 " \"filename\": {" 1796 base::StringPrintf(
1783 " \"previous\": \"\"," 1797 "[{\"id\": %d,"
1784 " \"current\": \"%s\"}}]", 1798 " \"filename\": {"
1785 result_id, 1799 " \"previous\": \"\","
1786 GetFilename(kFilename).c_str()))); 1800 " \"current\": \"%s\"}}]",
1787 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1801 result_id,
1788 base::StringPrintf("[{\"id\": %d," 1802 GetFilename(kFilename).c_str())));
1789 " \"state\": {" 1803 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1790 " \"previous\": \"in_progress\"," 1804 base::StringPrintf(
1791 " \"current\": \"complete\"}}]", 1805 "[{\"id\": %d,"
1792 result_id))); 1806 " \"state\": {"
1807 " \"previous\": \"in_progress\","
1808 " \"current\": \"complete\"}}]",
1809 result_id)));
1793 1810
1794 result.reset(RunFunctionAndReturnResult( 1811 result.reset(RunFunctionAndReturnResult(
1795 new DownloadsDownloadFunction(), base::StringPrintf( 1812 new DownloadsDownloadFunction(), base::StringPrintf(
1796 "[{\"url\": \"%s\", \"conflictAction\": \"overwrite\"}]", 1813 "[{\"url\": \"%s\", \"conflictAction\": \"overwrite\"}]",
1797 download_url.c_str()))); 1814 download_url.c_str())));
1798 ASSERT_TRUE(result.get()); 1815 ASSERT_TRUE(result.get());
1799 result_id = -1; 1816 result_id = -1;
1800 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1817 ASSERT_TRUE(result->GetAsInteger(&result_id));
1801 item = GetCurrentManager()->GetDownload(result_id); 1818 item = GetCurrentManager()->GetDownload(result_id);
1802 ASSERT_TRUE(item); 1819 ASSERT_TRUE(item);
1803 ScopedCancellingItem canceller2(item); 1820 ScopedCancellingItem canceller2(item);
1804 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1821 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1805 1822
1806 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 1823 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1807 base::StringPrintf("[{\"danger\": \"safe\"," 1824 base::StringPrintf(
1808 " \"incognito\": false," 1825 "[{\"danger\": \"safe\","
1809 " \"mime\": \"text/plain\"," 1826 " \"incognito\": false,"
1810 " \"paused\": false," 1827 " \"mime\": \"text/plain\","
1811 " \"url\": \"%s\"}]", 1828 " \"paused\": false,"
1812 download_url.c_str()))); 1829 " \"url\": \"%s\"}]",
1813 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1830 download_url.c_str())));
1814 base::StringPrintf("[{\"id\": %d," 1831 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1815 " \"filename\": {" 1832 base::StringPrintf(
1816 " \"previous\": \"\"," 1833 "[{\"id\": %d,"
1817 " \"current\": \"%s\"}}]", 1834 " \"filename\": {"
1818 result_id, 1835 " \"previous\": \"\","
1819 GetFilename(kFilename).c_str()))); 1836 " \"current\": \"%s\"}}]",
1820 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1837 result_id,
1821 base::StringPrintf("[{\"id\": %d," 1838 GetFilename(kFilename).c_str())));
1822 " \"state\": {" 1839 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1823 " \"previous\": \"in_progress\"," 1840 base::StringPrintf(
1824 " \"current\": \"complete\"}}]", 1841 "[{\"id\": %d,"
1825 result_id))); 1842 " \"state\": {"
1843 " \"previous\": \"in_progress\","
1844 " \"current\": \"complete\"}}]",
1845 result_id)));
1826 } 1846 }
1827 1847
1828 // Valid data URLs are valid URLs. 1848 // Valid data URLs are valid URLs.
1829 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1849 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1830 DownloadExtensionTest_Download_DataURL) { 1850 DownloadExtensionTest_Download_DataURL) {
1831 LoadExtension("downloads_split"); 1851 LoadExtension("downloads_split");
1832 std::string download_url = "data:text/plain,hello"; 1852 std::string download_url = "data:text/plain,hello";
1833 GoOnTheRecord(); 1853 GoOnTheRecord();
1834 1854
1835 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1855 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1836 new DownloadsDownloadFunction(), base::StringPrintf( 1856 new DownloadsDownloadFunction(), base::StringPrintf(
1837 "[{\"url\": \"%s\"," 1857 "[{\"url\": \"%s\","
1838 " \"filename\": \"data.txt\"}]", download_url.c_str()))); 1858 " \"filename\": \"data.txt\"}]", download_url.c_str())));
1839 ASSERT_TRUE(result.get()); 1859 ASSERT_TRUE(result.get());
1840 int result_id = -1; 1860 int result_id = -1;
1841 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1861 ASSERT_TRUE(result->GetAsInteger(&result_id));
1842 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1862 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1843 ASSERT_TRUE(item); 1863 ASSERT_TRUE(item);
1844 ScopedCancellingItem canceller(item); 1864 ScopedCancellingItem canceller(item);
1845 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1865 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1846 1866
1847 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 1867 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1848 base::StringPrintf("[{\"danger\": \"safe\"," 1868 base::StringPrintf(
1849 " \"incognito\": false," 1869 "[{\"danger\": \"safe\","
1850 " \"mime\": \"text/plain\"," 1870 " \"incognito\": false,"
1851 " \"paused\": false," 1871 " \"mime\": \"text/plain\","
1852 " \"url\": \"%s\"}]", 1872 " \"paused\": false,"
1853 download_url.c_str()))); 1873 " \"url\": \"%s\"}]",
1854 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1874 download_url.c_str())));
1855 base::StringPrintf("[{\"id\": %d," 1875 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1856 " \"filename\": {" 1876 base::StringPrintf(
1857 " \"previous\": \"\"," 1877 "[{\"id\": %d,"
1858 " \"current\": \"%s\"}}]", 1878 " \"filename\": {"
1859 result_id, 1879 " \"previous\": \"\","
1860 GetFilename("data.txt").c_str()))); 1880 " \"current\": \"%s\"}}]",
1861 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1881 result_id,
1862 base::StringPrintf("[{\"id\": %d," 1882 GetFilename("data.txt").c_str())));
1863 " \"state\": {" 1883 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1864 " \"previous\": \"in_progress\"," 1884 base::StringPrintf(
1865 " \"current\": \"complete\"}}]", 1885 "[{\"id\": %d,"
1866 result_id))); 1886 " \"state\": {"
1887 " \"previous\": \"in_progress\","
1888 " \"current\": \"complete\"}}]",
1889 result_id)));
1867 } 1890 }
1868 1891
1869 // Valid file URLs are valid URLs. 1892 // Valid file URLs are valid URLs.
1870 #if defined(OS_WIN) 1893 #if defined(OS_WIN)
1871 // Disabled due to crbug.com/175711 1894 // Disabled due to crbug.com/175711
1872 #define MAYBE_DownloadExtensionTest_Download_File \ 1895 #define MAYBE_DownloadExtensionTest_Download_File \
1873 DISABLED_DownloadExtensionTest_Download_File 1896 DISABLED_DownloadExtensionTest_Download_File
1874 #else 1897 #else
1875 #define MAYBE_DownloadExtensionTest_Download_File \ 1898 #define MAYBE_DownloadExtensionTest_Download_File \
1876 DownloadExtensionTest_Download_File 1899 DownloadExtensionTest_Download_File
(...skipping 12 matching lines...) Expand all
1889 "[{\"url\": \"%s\"," 1912 "[{\"url\": \"%s\","
1890 " \"filename\": \"file.txt\"}]", download_url.c_str()))); 1913 " \"filename\": \"file.txt\"}]", download_url.c_str())));
1891 ASSERT_TRUE(result.get()); 1914 ASSERT_TRUE(result.get());
1892 int result_id = -1; 1915 int result_id = -1;
1893 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1916 ASSERT_TRUE(result->GetAsInteger(&result_id));
1894 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1917 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1895 ASSERT_TRUE(item); 1918 ASSERT_TRUE(item);
1896 ScopedCancellingItem canceller(item); 1919 ScopedCancellingItem canceller(item);
1897 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1920 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1898 1921
1899 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 1922 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1900 base::StringPrintf("[{\"danger\": \"safe\"," 1923 base::StringPrintf(
1924 "[{\"danger\": \"safe\","
1901 " \"incognito\": false," 1925 " \"incognito\": false,"
1902 " \"mime\": \"text/html\"," 1926 " \"mime\": \"text/html\","
1903 " \"paused\": false," 1927 " \"paused\": false,"
1904 " \"url\": \"%s\"}]", 1928 " \"url\": \"%s\"}]",
1905 download_url.c_str()))); 1929 download_url.c_str())));
1906 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1930 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1907 base::StringPrintf("[{\"id\": %d," 1931 base::StringPrintf(
1932 "[{\"id\": %d,"
1908 " \"filename\": {" 1933 " \"filename\": {"
1909 " \"previous\": \"\"," 1934 " \"previous\": \"\","
1910 " \"current\": \"%s\"}}]", 1935 " \"current\": \"%s\"}}]",
1911 result_id, 1936 result_id,
1912 GetFilename("file.txt").c_str()))); 1937 GetFilename("file.txt").c_str())));
1913 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 1938 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1914 base::StringPrintf("[{\"id\": %d," 1939 base::StringPrintf(
1940 "[{\"id\": %d,"
1915 " \"state\": {" 1941 " \"state\": {"
1916 " \"previous\": \"in_progress\"," 1942 " \"previous\": \"in_progress\","
1917 " \"current\": \"complete\"}}]", 1943 " \"current\": \"complete\"}}]",
1918 result_id))); 1944 result_id)));
1919 } 1945 }
1920 1946
1921 // Test that auth-basic-succeed would fail if the resource requires the 1947 // Test that auth-basic-succeed would fail if the resource requires the
1922 // Authorization header and chrome fails to propagate it back to the server. 1948 // Authorization header and chrome fails to propagate it back to the server.
1923 // This tests both that testserver.py does not succeed when it should fail as 1949 // This tests both that testserver.py does not succeed when it should fail as
1924 // well as how the downloads extension API exposes the failure to extensions. 1950 // well as how the downloads extension API exposes the failure to extensions.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 " {\"name\": \"Qx\", \"value\":\"yo\"}]}]", 1999 " {\"name\": \"Qx\", \"value\":\"yo\"}]}]",
1974 download_url.c_str()))); 2000 download_url.c_str())));
1975 ASSERT_TRUE(result.get()); 2001 ASSERT_TRUE(result.get());
1976 int result_id = -1; 2002 int result_id = -1;
1977 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2003 ASSERT_TRUE(result->GetAsInteger(&result_id));
1978 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2004 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1979 ASSERT_TRUE(item); 2005 ASSERT_TRUE(item);
1980 ScopedCancellingItem canceller(item); 2006 ScopedCancellingItem canceller(item);
1981 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2007 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1982 2008
1983 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2009 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
1984 base::StringPrintf("[{\"danger\": \"safe\"," 2010 base::StringPrintf(
1985 " \"incognito\": false," 2011 "[{\"danger\": \"safe\","
1986 " \"mime\": \"application/octet-stream\"," 2012 " \"incognito\": false,"
1987 " \"paused\": false," 2013 " \"mime\": \"application/octet-stream\","
1988 " \"url\": \"%s\"}]", 2014 " \"paused\": false,"
1989 download_url.c_str()))); 2015 " \"url\": \"%s\"}]",
1990 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2016 download_url.c_str())));
1991 base::StringPrintf("[{\"id\": %d," 2017 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
1992 " \"filename\": {" 2018 base::StringPrintf(
1993 " \"previous\": \"\"," 2019 "[{\"id\": %d,"
1994 " \"current\": \"%s\"}}]", 2020 " \"filename\": {"
1995 result_id, 2021 " \"previous\": \"\","
1996 GetFilename("headers-succeed.txt").c_str()))); 2022 " \"current\": \"%s\"}}]",
1997 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2023 result_id,
1998 base::StringPrintf("[{\"id\": %d," 2024 GetFilename("headers-succeed.txt").c_str())));
1999 " \"state\": {" 2025 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2000 " \"previous\": \"in_progress\"," 2026 base::StringPrintf(
2001 " \"current\": \"complete\"}}]", 2027 "[{\"id\": %d,"
2002 result_id))); 2028 " \"state\": {"
2029 " \"previous\": \"in_progress\","
2030 " \"current\": \"complete\"}}]",
2031 result_id)));
2003 } 2032 }
2004 2033
2005 // Test that headers-succeed would fail if the resource requires the headers and 2034 // Test that headers-succeed would fail if the resource requires the headers and
2006 // chrome fails to propagate them back to the server. This tests both that 2035 // chrome fails to propagate them back to the server. This tests both that
2007 // testserver.py does not succeed when it should fail as well as how the 2036 // testserver.py does not succeed when it should fail as well as how the
2008 // downloads extension api exposes the failure to extensions. 2037 // downloads extension api exposes the failure to extensions.
2009 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2038 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2010 DownloadExtensionTest_Download_Headers_Fail) { 2039 DownloadExtensionTest_Download_Headers_Fail) {
2011 LoadExtension("downloads_split"); 2040 LoadExtension("downloads_split");
2012 ASSERT_TRUE(StartEmbeddedTestServer()); 2041 ASSERT_TRUE(StartEmbeddedTestServer());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 " \"value\": \"Basic %s\"}]}]", 2091 " \"value\": \"Basic %s\"}]}]",
2063 download_url.c_str(), kAuthorization))); 2092 download_url.c_str(), kAuthorization)));
2064 ASSERT_TRUE(result.get()); 2093 ASSERT_TRUE(result.get());
2065 int result_id = -1; 2094 int result_id = -1;
2066 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2095 ASSERT_TRUE(result->GetAsInteger(&result_id));
2067 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2096 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2068 ASSERT_TRUE(item); 2097 ASSERT_TRUE(item);
2069 ScopedCancellingItem canceller(item); 2098 ScopedCancellingItem canceller(item);
2070 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2099 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2071 2100
2072 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2101 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2073 base::StringPrintf("[{\"danger\": \"safe\"," 2102 base::StringPrintf(
2074 " \"incognito\": false," 2103 "[{\"danger\": \"safe\","
2075 " \"bytesReceived\": 0.0," 2104 " \"incognito\": false,"
2076 " \"fileSize\": 0.0," 2105 " \"bytesReceived\": 0.0,"
2077 " \"mime\": \"text/html\"," 2106 " \"fileSize\": 0.0,"
2078 " \"paused\": false," 2107 " \"mime\": \"text/html\","
2079 " \"url\": \"%s\"}]", download_url.c_str()))); 2108 " \"paused\": false,"
2080 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2109 " \"url\": \"%s\"}]",
2081 base::StringPrintf("[{\"id\": %d," 2110 download_url.c_str())));
2082 " \"state\": {" 2111 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2083 " \"previous\": \"in_progress\"," 2112 base::StringPrintf(
2084 " \"current\": \"complete\"}}]", result_id))); 2113 "[{\"id\": %d,"
2114 " \"state\": {"
2115 " \"previous\": \"in_progress\","
2116 " \"current\": \"complete\"}}]",
2117 result_id)));
2085 } 2118 }
2086 2119
2087 // Test that DownloadsDownloadFunction propagates the |method| and |body| 2120 // Test that DownloadsDownloadFunction propagates the |method| and |body|
2088 // parameters to the URLRequest. 2121 // parameters to the URLRequest.
2089 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2122 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2090 DownloadExtensionTest_Download_Post) { 2123 DownloadExtensionTest_Download_Post) {
2091 LoadExtension("downloads_split"); 2124 LoadExtension("downloads_split");
2092 ASSERT_TRUE(StartEmbeddedTestServer()); 2125 ASSERT_TRUE(StartEmbeddedTestServer());
2093 ASSERT_TRUE(test_server()->Start()); 2126 ASSERT_TRUE(test_server()->Start());
2094 std::string download_url = test_server()->GetURL("files/post/downloads/" 2127 std::string download_url = test_server()->GetURL("files/post/downloads/"
2095 "a_zip_file.zip?expected_body=BODY").spec(); 2128 "a_zip_file.zip?expected_body=BODY").spec();
2096 GoOnTheRecord(); 2129 GoOnTheRecord();
2097 2130
2098 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2131 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2099 new DownloadsDownloadFunction(), base::StringPrintf( 2132 new DownloadsDownloadFunction(), base::StringPrintf(
2100 "[{\"url\": \"%s\"," 2133 "[{\"url\": \"%s\","
2101 " \"filename\": \"post-succeed.txt\"," 2134 " \"filename\": \"post-succeed.txt\","
2102 " \"method\": \"POST\"," 2135 " \"method\": \"POST\","
2103 " \"body\": \"BODY\"}]", 2136 " \"body\": \"BODY\"}]",
2104 download_url.c_str()))); 2137 download_url.c_str())));
2105 ASSERT_TRUE(result.get()); 2138 ASSERT_TRUE(result.get());
2106 int result_id = -1; 2139 int result_id = -1;
2107 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2140 ASSERT_TRUE(result->GetAsInteger(&result_id));
2108 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2141 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2109 ASSERT_TRUE(item); 2142 ASSERT_TRUE(item);
2110 ScopedCancellingItem canceller(item); 2143 ScopedCancellingItem canceller(item);
2111 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2144 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2112 2145
2113 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2146 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2114 base::StringPrintf("[{\"danger\": \"safe\"," 2147 base::StringPrintf(
2115 " \"incognito\": false," 2148 "[{\"danger\": \"safe\","
2116 " \"mime\": \"application/octet-stream\"," 2149 " \"incognito\": false,"
2117 " \"paused\": false," 2150 " \"mime\": \"application/octet-stream\","
2118 " \"url\": \"%s\"}]", download_url.c_str()))); 2151 " \"paused\": false,"
2119 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2152 " \"url\": \"%s\"}]",
2120 base::StringPrintf("[{\"id\": %d," 2153 download_url.c_str())));
2121 " \"filename\": {" 2154 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2122 " \"previous\": \"\"," 2155 base::StringPrintf(
2123 " \"current\": \"%s\"}}]", 2156 "[{\"id\": %d,"
2124 result_id, 2157 " \"filename\": {"
2125 GetFilename("post-succeed.txt").c_str()))); 2158 " \"previous\": \"\","
2126 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2159 " \"current\": \"%s\"}}]",
2127 base::StringPrintf("[{\"id\": %d," 2160 result_id,
2128 " \"state\": {" 2161 GetFilename("post-succeed.txt").c_str())));
2129 " \"previous\": \"in_progress\"," 2162 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2130 " \"current\": \"complete\"}}]", 2163 base::StringPrintf(
2131 result_id))); 2164 "[{\"id\": %d,"
2165 " \"state\": {"
2166 " \"previous\": \"in_progress\","
2167 " \"current\": \"complete\"}}]",
2168 result_id)));
2132 } 2169 }
2133 2170
2134 // Test that downloadPostSuccess would fail if the resource requires the POST 2171 // Test that downloadPostSuccess would fail if the resource requires the POST
2135 // method, and chrome fails to propagate the |method| parameter back to the 2172 // method, and chrome fails to propagate the |method| parameter back to the
2136 // server. This tests both that testserver.py does not succeed when it should 2173 // server. This tests both that testserver.py does not succeed when it should
2137 // fail, and this tests how the downloads extension api exposes the failure to 2174 // fail, and this tests how the downloads extension api exposes the failure to
2138 // extensions. 2175 // extensions.
2139 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2176 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2140 DownloadExtensionTest_Download_Post_Get) { 2177 DownloadExtensionTest_Download_Post_Get) {
2141 LoadExtension("downloads_split"); 2178 LoadExtension("downloads_split");
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 new DownloadsDownloadFunction(), base::StringPrintf( 2267 new DownloadsDownloadFunction(), base::StringPrintf(
2231 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2268 "[{\"url\": \"%s\"}]", download_url.c_str())));
2232 ASSERT_TRUE(result.get()); 2269 ASSERT_TRUE(result.get());
2233 int result_id = -1; 2270 int result_id = -1;
2234 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2271 ASSERT_TRUE(result->GetAsInteger(&result_id));
2235 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2272 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2236 ASSERT_TRUE(item); 2273 ASSERT_TRUE(item);
2237 ScopedCancellingItem canceller(item); 2274 ScopedCancellingItem canceller(item);
2238 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2275 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2239 2276
2240 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2277 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2241 base::StringPrintf("[{\"danger\": \"safe\"," 2278 base::StringPrintf(
2279 "[{\"danger\": \"safe\","
2242 " \"incognito\": false," 2280 " \"incognito\": false,"
2243 " \"mime\": \"application/octet-stream\"," 2281 " \"mime\": \"application/octet-stream\","
2244 " \"paused\": false," 2282 " \"paused\": false,"
2245 " \"id\": %d," 2283 " \"id\": %d,"
2246 " \"url\": \"%s\"}]", 2284 " \"url\": \"%s\"}]",
2247 result_id, 2285 result_id,
2248 download_url.c_str()))); 2286 download_url.c_str())));
2249 item->Cancel(true); 2287 item->Cancel(true);
2250 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2288 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2251 base::StringPrintf("[{\"id\": %d," 2289 base::StringPrintf(
2290 "[{\"id\": %d,"
2252 " \"error\": {\"current\":\"USER_CANCELED\"}," 2291 " \"error\": {\"current\":\"USER_CANCELED\"},"
2253 " \"state\": {" 2292 " \"state\": {"
2254 " \"previous\": \"in_progress\"," 2293 " \"previous\": \"in_progress\","
2255 " \"current\": \"interrupted\"}}]", 2294 " \"current\": \"interrupted\"}}]",
2256 result_id))); 2295 result_id)));
2257 } 2296 }
2258 2297
2259 // Test downloading filesystem: URLs. 2298 // Test downloading filesystem: URLs.
2260 // NOTE: chrome disallows creating HTML5 FileSystem Files in incognito. 2299 // NOTE: chrome disallows creating HTML5 FileSystem Files in incognito.
2261 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2300 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
(...skipping 18 matching lines...) Expand all
2280 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2319 "[{\"url\": \"%s\"}]", download_url.c_str())));
2281 ASSERT_TRUE(result.get()); 2320 ASSERT_TRUE(result.get());
2282 int result_id = -1; 2321 int result_id = -1;
2283 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2322 ASSERT_TRUE(result->GetAsInteger(&result_id));
2284 2323
2285 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2324 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2286 ASSERT_TRUE(item); 2325 ASSERT_TRUE(item);
2287 ScopedCancellingItem canceller(item); 2326 ScopedCancellingItem canceller(item);
2288 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2327 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2289 2328
2290 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2329 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2291 base::StringPrintf("[{\"danger\": \"safe\"," 2330 base::StringPrintf(
2331 "[{\"danger\": \"safe\","
2292 " \"incognito\": false," 2332 " \"incognito\": false,"
2293 " \"mime\": \"text/plain\"," 2333 " \"mime\": \"text/plain\","
2294 " \"paused\": false," 2334 " \"paused\": false,"
2295 " \"url\": \"%s\"}]", 2335 " \"url\": \"%s\"}]",
2296 download_url.c_str()))); 2336 download_url.c_str())));
2297 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2337 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2298 base::StringPrintf("[{\"id\": %d," 2338 base::StringPrintf(
2339 "[{\"id\": %d,"
2299 " \"filename\": {" 2340 " \"filename\": {"
2300 " \"previous\": \"\"," 2341 " \"previous\": \"\","
2301 " \"current\": \"%s\"}}]", 2342 " \"current\": \"%s\"}}]",
2302 result_id, 2343 result_id,
2303 GetFilename("on_record.txt").c_str()))); 2344 GetFilename("on_record.txt").c_str())));
2304 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2345 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2305 base::StringPrintf("[{\"id\": %d," 2346 base::StringPrintf(
2347 "[{\"id\": %d,"
2306 " \"state\": {" 2348 " \"state\": {"
2307 " \"previous\": \"in_progress\"," 2349 " \"previous\": \"in_progress\","
2308 " \"current\": \"complete\"}}]", 2350 " \"current\": \"complete\"}}]",
2309 result_id))); 2351 result_id)));
2310 std::string disk_data; 2352 std::string disk_data;
2311 EXPECT_TRUE(base::ReadFileToString(item->GetTargetFilePath(), &disk_data)); 2353 EXPECT_TRUE(base::ReadFileToString(item->GetTargetFilePath(), &disk_data));
2312 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2354 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2313 } 2355 }
2314 2356
2315 // Test is flaky: http://crbug.com/302071 2357 // Test is flaky: http://crbug.com/302071
(...skipping 12 matching lines...) Expand all
2328 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2370 "[{\"url\": \"%s\"}]", download_url.c_str())));
2329 ASSERT_TRUE(result.get()); 2371 ASSERT_TRUE(result.get());
2330 int result_id = -1; 2372 int result_id = -1;
2331 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2373 ASSERT_TRUE(result->GetAsInteger(&result_id));
2332 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2374 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2333 ASSERT_TRUE(item); 2375 ASSERT_TRUE(item);
2334 ScopedCancellingItem canceller(item); 2376 ScopedCancellingItem canceller(item);
2335 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2377 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2336 2378
2337 // Wait for the onCreated and onDeterminingFilename events. 2379 // Wait for the onCreated and onDeterminingFilename events.
2338 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2380 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2339 base::StringPrintf("[{\"danger\": \"safe\"," 2381 base::StringPrintf(
2382 "[{\"danger\": \"safe\","
2340 " \"incognito\": false," 2383 " \"incognito\": false,"
2341 " \"id\": %d," 2384 " \"id\": %d,"
2342 " \"mime\": \"text/plain\"," 2385 " \"mime\": \"text/plain\","
2343 " \"paused\": false," 2386 " \"paused\": false,"
2344 " \"url\": \"%s\"}]", 2387 " \"url\": \"%s\"}]",
2345 result_id, 2388 result_id,
2346 download_url.c_str()))); 2389 download_url.c_str())));
2347 ASSERT_TRUE(WaitFor( 2390 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2348 api::OnDeterminingFilename::kEventName, 2391 base::StringPrintf(
2349 base::StringPrintf("[{\"id\": %d," 2392 "[{\"id\": %d,"
2350 " \"filename\":\"slow.txt\"}]", 2393 " \"filename\":\"slow.txt\"}]",
2351 result_id))); 2394 result_id)));
2352 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2395 ASSERT_TRUE(item->GetTargetFilePath().empty());
2353 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2396 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2354 2397
2355 // Respond to the onDeterminingFilename. 2398 // Respond to the onDeterminingFilename.
2356 std::string error; 2399 std::string error;
2357 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 2400 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
2358 browser()->profile(), 2401 browser()->profile(),
2359 false, 2402 false,
2360 GetExtensionId(), 2403 GetExtensionId(),
2361 result_id, 2404 result_id,
2362 base::FilePath(), 2405 base::FilePath(),
2363 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2406 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2364 &error)); 2407 &error));
2365 EXPECT_EQ("", error); 2408 EXPECT_EQ("", error);
2366 2409
2367 // The download should complete successfully. 2410 // The download should complete successfully.
2368 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2411 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2369 base::StringPrintf("[{\"id\": %d," 2412 base::StringPrintf(
2370 " \"filename\": {" 2413 "[{\"id\": %d,"
2371 " \"previous\": \"\"," 2414 " \"filename\": {"
2372 " \"current\": \"%s\"}}]", 2415 " \"previous\": \"\","
2373 result_id, 2416 " \"current\": \"%s\"}}]",
2374 GetFilename("slow.txt").c_str()))); 2417 result_id,
2375 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2418 GetFilename("slow.txt").c_str())));
2376 base::StringPrintf("[{\"id\": %d," 2419 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2377 " \"state\": {" 2420 base::StringPrintf(
2378 " \"previous\": \"in_progress\"," 2421 "[{\"id\": %d,"
2379 " \"current\": \"complete\"}}]", 2422 " \"state\": {"
2380 result_id))); 2423 " \"previous\": \"in_progress\","
2424 " \"current\": \"complete\"}}]",
2425 result_id)));
2381 } 2426 }
2382 2427
2383 IN_PROC_BROWSER_TEST_F( 2428 IN_PROC_BROWSER_TEST_F(
2384 DownloadExtensionTest, 2429 DownloadExtensionTest,
2385 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) { 2430 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) {
2386 GoOnTheRecord(); 2431 GoOnTheRecord();
2387 LoadExtension("downloads_split"); 2432 LoadExtension("downloads_split");
2388 AddFilenameDeterminer(); 2433 AddFilenameDeterminer();
2389 ASSERT_TRUE(StartEmbeddedTestServer()); 2434 ASSERT_TRUE(StartEmbeddedTestServer());
2390 ASSERT_TRUE(test_server()->Start()); 2435 ASSERT_TRUE(test_server()->Start());
2391 std::string download_url = test_server()->GetURL("slow?0").spec(); 2436 std::string download_url = test_server()->GetURL("slow?0").spec();
2392 2437
2393 // Start downloading a file. 2438 // Start downloading a file.
2394 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2439 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2395 new DownloadsDownloadFunction(), base::StringPrintf( 2440 new DownloadsDownloadFunction(), base::StringPrintf(
2396 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2441 "[{\"url\": \"%s\"}]", download_url.c_str())));
2397 ASSERT_TRUE(result.get()); 2442 ASSERT_TRUE(result.get());
2398 int result_id = -1; 2443 int result_id = -1;
2399 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2444 ASSERT_TRUE(result->GetAsInteger(&result_id));
2400 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2445 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2401 ASSERT_TRUE(item); 2446 ASSERT_TRUE(item);
2402 ScopedCancellingItem canceller(item); 2447 ScopedCancellingItem canceller(item);
2403 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2448 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2404 2449
2405 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2450 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2406 base::StringPrintf("[{\"danger\": \"safe\"," 2451 base::StringPrintf(
2452 "[{\"danger\": \"safe\","
2407 " \"incognito\": false," 2453 " \"incognito\": false,"
2408 " \"id\": %d," 2454 " \"id\": %d,"
2409 " \"mime\": \"text/plain\"," 2455 " \"mime\": \"text/plain\","
2410 " \"paused\": false," 2456 " \"paused\": false,"
2411 " \"url\": \"%s\"}]", 2457 " \"url\": \"%s\"}]",
2412 result_id, 2458 result_id,
2413 download_url.c_str()))); 2459 download_url.c_str())));
2414 ASSERT_TRUE(WaitFor( 2460 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2415 api::OnDeterminingFilename::kEventName, 2461 base::StringPrintf(
2416 base::StringPrintf("[{\"id\": %d," 2462 "[{\"id\": %d,"
2417 " \"filename\":\"slow.txt\"}]", 2463 " \"filename\":\"slow.txt\"}]",
2418 result_id))); 2464 result_id)));
2419 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2465 ASSERT_TRUE(item->GetTargetFilePath().empty());
2420 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2466 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2421 2467
2422 // Respond to the onDeterminingFilename. 2468 // Respond to the onDeterminingFilename.
2423 std::string error; 2469 std::string error;
2424 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 2470 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
2425 browser()->profile(), 2471 browser()->profile(),
2426 false, 2472 false,
2427 GetExtensionId(), 2473 GetExtensionId(),
2428 result_id, 2474 result_id,
2429 base::FilePath(FILE_PATH_LITERAL("overridden.swf")), 2475 base::FilePath(FILE_PATH_LITERAL("overridden.swf")),
2430 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2476 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2431 &error)); 2477 &error));
2432 EXPECT_EQ("", error); 2478 EXPECT_EQ("", error);
2433 2479
2434 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2480 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2435 base::StringPrintf("[{\"id\": %d," 2481 base::StringPrintf(
2436 " \"danger\": {" 2482 "[{\"id\": %d,"
2437 " \"previous\":\"safe\"," 2483 " \"danger\": {"
2438 " \"current\":\"file\"}}]", 2484 " \"previous\":\"safe\","
2439 result_id))); 2485 " \"current\":\"file\"}}]",
2486 result_id)));
2440 2487
2441 item->ValidateDangerousDownload(); 2488 item->ValidateDangerousDownload();
2442 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2489 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2443 base::StringPrintf("[{\"id\": %d," 2490 base::StringPrintf(
2444 " \"danger\": {" 2491 "[{\"id\": %d,"
2445 " \"previous\":\"file\"," 2492 " \"danger\": {"
2446 " \"current\":\"accepted\"}}]", 2493 " \"previous\":\"file\","
2447 result_id))); 2494 " \"current\":\"accepted\"}}]",
2448 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2495 result_id)));
2449 base::StringPrintf("[{\"id\": %d," 2496 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2497 base::StringPrintf(
2498 "[{\"id\": %d,"
2450 " \"state\": {" 2499 " \"state\": {"
2451 " \"previous\": \"in_progress\"," 2500 " \"previous\": \"in_progress\","
2452 " \"current\": \"complete\"}}]", 2501 " \"current\": \"complete\"}}]",
2453 result_id))); 2502 result_id)));
2454 EXPECT_EQ(downloads_directory().AppendASCII("overridden.swf"), 2503 EXPECT_EQ(downloads_directory().AppendASCII("overridden.swf"),
2455 item->GetTargetFilePath()); 2504 item->GetTargetFilePath());
2456 } 2505 }
2457 2506
2458 IN_PROC_BROWSER_TEST_F( 2507 IN_PROC_BROWSER_TEST_F(
2459 DownloadExtensionTest, 2508 DownloadExtensionTest,
(...skipping 10 matching lines...) Expand all
2470 new DownloadsDownloadFunction(), base::StringPrintf( 2519 new DownloadsDownloadFunction(), base::StringPrintf(
2471 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2520 "[{\"url\": \"%s\"}]", download_url.c_str())));
2472 ASSERT_TRUE(result.get()); 2521 ASSERT_TRUE(result.get());
2473 int result_id = -1; 2522 int result_id = -1;
2474 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2523 ASSERT_TRUE(result->GetAsInteger(&result_id));
2475 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2524 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2476 ASSERT_TRUE(item); 2525 ASSERT_TRUE(item);
2477 ScopedCancellingItem canceller(item); 2526 ScopedCancellingItem canceller(item);
2478 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2527 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2479 2528
2480 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2529 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2481 base::StringPrintf("[{\"danger\": \"safe\"," 2530 base::StringPrintf(
2531 "[{\"danger\": \"safe\","
2482 " \"incognito\": false," 2532 " \"incognito\": false,"
2483 " \"id\": %d," 2533 " \"id\": %d,"
2484 " \"mime\": \"text/plain\"," 2534 " \"mime\": \"text/plain\","
2485 " \"paused\": false," 2535 " \"paused\": false,"
2486 " \"url\": \"%s\"}]", 2536 " \"url\": \"%s\"}]",
2487 result_id, 2537 result_id,
2488 download_url.c_str()))); 2538 download_url.c_str())));
2489 ASSERT_TRUE(WaitFor( 2539 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2490 api::OnDeterminingFilename::kEventName, 2540 base::StringPrintf(
2491 base::StringPrintf("[{\"id\": %d," 2541 "[{\"id\": %d,"
2492 " \"filename\":\"slow.txt\"}]", 2542 " \"filename\":\"slow.txt\"}]",
2493 result_id))); 2543 result_id)));
2494 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2544 ASSERT_TRUE(item->GetTargetFilePath().empty());
2495 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2545 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2496 2546
2497 // Respond to the onDeterminingFilename. 2547 // Respond to the onDeterminingFilename.
2498 std::string error; 2548 std::string error;
2499 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2549 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2500 browser()->profile(), 2550 browser()->profile(),
2501 false, 2551 false,
2502 GetExtensionId(), 2552 GetExtensionId(),
2503 result_id, 2553 result_id,
2504 base::FilePath(FILE_PATH_LITERAL("sneaky/../../sneaky.txt")), 2554 base::FilePath(FILE_PATH_LITERAL("sneaky/../../sneaky.txt")),
2505 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2555 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2506 &error)); 2556 &error));
2507 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); 2557 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2508 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2558 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2509 base::StringPrintf("[{\"id\": %d," 2559 base::StringPrintf(
2560 "[{\"id\": %d,"
2510 " \"filename\": {" 2561 " \"filename\": {"
2511 " \"previous\": \"\"," 2562 " \"previous\": \"\","
2512 " \"current\": \"%s\"}}]", 2563 " \"current\": \"%s\"}}]",
2513 result_id, 2564 result_id,
2514 GetFilename("slow.txt").c_str()))); 2565 GetFilename("slow.txt").c_str())));
2515 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2566 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2516 base::StringPrintf("[{\"id\": %d," 2567 base::StringPrintf(
2568 "[{\"id\": %d,"
2517 " \"state\": {" 2569 " \"state\": {"
2518 " \"previous\": \"in_progress\"," 2570 " \"previous\": \"in_progress\","
2519 " \"current\": \"complete\"}}]", 2571 " \"current\": \"complete\"}}]",
2520 result_id))); 2572 result_id)));
2521 } 2573 }
2522 2574
2523 IN_PROC_BROWSER_TEST_F( 2575 IN_PROC_BROWSER_TEST_F(
2524 DownloadExtensionTest, 2576 DownloadExtensionTest,
2525 DownloadExtensionTest_OnDeterminingFilename_IllegalFilename) { 2577 DownloadExtensionTest_OnDeterminingFilename_IllegalFilename) {
2526 GoOnTheRecord(); 2578 GoOnTheRecord();
2527 LoadExtension("downloads_split"); 2579 LoadExtension("downloads_split");
2528 AddFilenameDeterminer(); 2580 AddFilenameDeterminer();
2529 ASSERT_TRUE(StartEmbeddedTestServer()); 2581 ASSERT_TRUE(StartEmbeddedTestServer());
2530 ASSERT_TRUE(test_server()->Start()); 2582 ASSERT_TRUE(test_server()->Start());
2531 std::string download_url = test_server()->GetURL("slow?0").spec(); 2583 std::string download_url = test_server()->GetURL("slow?0").spec();
2532 2584
2533 // Start downloading a file. 2585 // Start downloading a file.
2534 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2586 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2535 new DownloadsDownloadFunction(), base::StringPrintf( 2587 new DownloadsDownloadFunction(), base::StringPrintf(
2536 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2588 "[{\"url\": \"%s\"}]", download_url.c_str())));
2537 ASSERT_TRUE(result.get()); 2589 ASSERT_TRUE(result.get());
2538 int result_id = -1; 2590 int result_id = -1;
2539 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2591 ASSERT_TRUE(result->GetAsInteger(&result_id));
2540 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2592 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2541 ASSERT_TRUE(item); 2593 ASSERT_TRUE(item);
2542 ScopedCancellingItem canceller(item); 2594 ScopedCancellingItem canceller(item);
2543 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2595 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2544 2596
2545 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2597 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2546 base::StringPrintf("[{\"danger\": \"safe\"," 2598 base::StringPrintf(
2599 "[{\"danger\": \"safe\","
2547 " \"incognito\": false," 2600 " \"incognito\": false,"
2548 " \"id\": %d," 2601 " \"id\": %d,"
2549 " \"mime\": \"text/plain\"," 2602 " \"mime\": \"text/plain\","
2550 " \"paused\": false," 2603 " \"paused\": false,"
2551 " \"url\": \"%s\"}]", 2604 " \"url\": \"%s\"}]",
2552 result_id, 2605 result_id,
2553 download_url.c_str()))); 2606 download_url.c_str())));
2554 ASSERT_TRUE(WaitFor( 2607 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2555 api::OnDeterminingFilename::kEventName, 2608 base::StringPrintf(
2556 base::StringPrintf("[{\"id\": %d," 2609 "[{\"id\": %d,"
2557 " \"filename\":\"slow.txt\"}]", 2610 " \"filename\":\"slow.txt\"}]",
2558 result_id))); 2611 result_id)));
2559 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2612 ASSERT_TRUE(item->GetTargetFilePath().empty());
2560 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2613 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2561 2614
2562 // Respond to the onDeterminingFilename. 2615 // Respond to the onDeterminingFilename.
2563 std::string error; 2616 std::string error;
2564 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2617 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2565 browser()->profile(), 2618 browser()->profile(),
2566 false, 2619 false,
2567 GetExtensionId(), 2620 GetExtensionId(),
2568 result_id, 2621 result_id,
2569 base::FilePath(FILE_PATH_LITERAL("<")), 2622 base::FilePath(FILE_PATH_LITERAL("<")),
2570 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2623 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2571 &error)); 2624 &error));
2572 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); 2625 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2573 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, base::StringPrintf( 2626 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2574 "[{\"id\": %d," 2627 base::StringPrintf(
2575 " \"filename\": {" 2628 "[{\"id\": %d,"
2576 " \"previous\": \"\"," 2629 " \"filename\": {"
2577 " \"current\": \"%s\"}}]", 2630 " \"previous\": \"\","
2578 result_id, 2631 " \"current\": \"%s\"}}]",
2579 GetFilename("slow.txt").c_str()))); 2632 result_id,
2580 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, base::StringPrintf( 2633 GetFilename("slow.txt").c_str())));
2581 "[{\"id\": %d," 2634 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2582 " \"state\": {" 2635 base::StringPrintf(
2583 " \"previous\": \"in_progress\"," 2636 "[{\"id\": %d,"
2584 " \"current\": \"complete\"}}]", 2637 " \"state\": {"
2585 result_id))); 2638 " \"previous\": \"in_progress\","
2639 " \"current\": \"complete\"}}]",
2640 result_id)));
2586 } 2641 }
2587 2642
2588 IN_PROC_BROWSER_TEST_F( 2643 IN_PROC_BROWSER_TEST_F(
2589 DownloadExtensionTest, 2644 DownloadExtensionTest,
2590 DownloadExtensionTest_OnDeterminingFilename_IllegalFilenameExtension) { 2645 DownloadExtensionTest_OnDeterminingFilename_IllegalFilenameExtension) {
2591 GoOnTheRecord(); 2646 GoOnTheRecord();
2592 LoadExtension("downloads_split"); 2647 LoadExtension("downloads_split");
2593 AddFilenameDeterminer(); 2648 AddFilenameDeterminer();
2594 ASSERT_TRUE(StartEmbeddedTestServer()); 2649 ASSERT_TRUE(StartEmbeddedTestServer());
2595 ASSERT_TRUE(test_server()->Start()); 2650 ASSERT_TRUE(test_server()->Start());
2596 std::string download_url = test_server()->GetURL("slow?0").spec(); 2651 std::string download_url = test_server()->GetURL("slow?0").spec();
2597 2652
2598 // Start downloading a file. 2653 // Start downloading a file.
2599 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2654 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2600 new DownloadsDownloadFunction(), base::StringPrintf( 2655 new DownloadsDownloadFunction(), base::StringPrintf(
2601 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2656 "[{\"url\": \"%s\"}]", download_url.c_str())));
2602 ASSERT_TRUE(result.get()); 2657 ASSERT_TRUE(result.get());
2603 int result_id = -1; 2658 int result_id = -1;
2604 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2659 ASSERT_TRUE(result->GetAsInteger(&result_id));
2605 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2660 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2606 ASSERT_TRUE(item); 2661 ASSERT_TRUE(item);
2607 ScopedCancellingItem canceller(item); 2662 ScopedCancellingItem canceller(item);
2608 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2663 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2609 2664
2610 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2665 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2611 base::StringPrintf("[{\"danger\": \"safe\"," 2666 base::StringPrintf(
2667 "[{\"danger\": \"safe\","
2612 " \"incognito\": false," 2668 " \"incognito\": false,"
2613 " \"id\": %d," 2669 " \"id\": %d,"
2614 " \"mime\": \"text/plain\"," 2670 " \"mime\": \"text/plain\","
2615 " \"paused\": false," 2671 " \"paused\": false,"
2616 " \"url\": \"%s\"}]", 2672 " \"url\": \"%s\"}]",
2617 result_id, 2673 result_id,
2618 download_url.c_str()))); 2674 download_url.c_str())));
2619 ASSERT_TRUE(WaitFor( 2675 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2620 api::OnDeterminingFilename::kEventName, 2676 base::StringPrintf(
2621 base::StringPrintf("[{\"id\": %d," 2677 "[{\"id\": %d,"
2622 " \"filename\":\"slow.txt\"}]", 2678 " \"filename\":\"slow.txt\"}]",
2623 result_id))); 2679 result_id)));
2624 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2680 ASSERT_TRUE(item->GetTargetFilePath().empty());
2625 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2681 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2626 2682
2627 // Respond to the onDeterminingFilename. 2683 // Respond to the onDeterminingFilename.
2628 std::string error; 2684 std::string error;
2629 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2685 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2630 browser()->profile(), 2686 browser()->profile(),
2631 false, 2687 false,
2632 GetExtensionId(), 2688 GetExtensionId(),
2633 result_id, 2689 result_id,
2634 base::FilePath(FILE_PATH_LITERAL( 2690 base::FilePath(FILE_PATH_LITERAL(
2635 "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}/foo")), 2691 "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}/foo")),
2636 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2692 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2637 &error)); 2693 &error));
2638 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); 2694 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2639 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, base::StringPrintf( 2695 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2640 "[{\"id\": %d," 2696 base::StringPrintf(
2641 " \"filename\": {" 2697 "[{\"id\": %d,"
2642 " \"previous\": \"\"," 2698 " \"filename\": {"
2643 " \"current\": \"%s\"}}]", 2699 " \"previous\": \"\","
2644 result_id, 2700 " \"current\": \"%s\"}}]",
2645 GetFilename("slow.txt").c_str()))); 2701 result_id,
2646 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, base::StringPrintf( 2702 GetFilename("slow.txt").c_str())));
2647 "[{\"id\": %d," 2703 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2648 " \"state\": {" 2704 base::StringPrintf(
2649 " \"previous\": \"in_progress\"," 2705 "[{\"id\": %d,"
2650 " \"current\": \"complete\"}}]", 2706 " \"state\": {"
2651 result_id))); 2707 " \"previous\": \"in_progress\","
2708 " \"current\": \"complete\"}}]",
2709 result_id)));
2652 } 2710 }
2653 #if defined(OS_WIN) 2711 #if defined(OS_WIN)
2654 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename\ 2712 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename\
2655 DISABLED_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename 2713 DISABLED_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename
2656 #else 2714 #else
2657 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename\ 2715 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename\
2658 DownloadExtensionTest_OnDeterminingFilename_ReservedFilename 2716 DownloadExtensionTest_OnDeterminingFilename_ReservedFilename
2659 #endif 2717 #endif
2660 IN_PROC_BROWSER_TEST_F( 2718 IN_PROC_BROWSER_TEST_F(
2661 DownloadExtensionTest, 2719 DownloadExtensionTest,
(...skipping 10 matching lines...) Expand all
2672 new DownloadsDownloadFunction(), base::StringPrintf( 2730 new DownloadsDownloadFunction(), base::StringPrintf(
2673 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2731 "[{\"url\": \"%s\"}]", download_url.c_str())));
2674 ASSERT_TRUE(result.get()); 2732 ASSERT_TRUE(result.get());
2675 int result_id = -1; 2733 int result_id = -1;
2676 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2734 ASSERT_TRUE(result->GetAsInteger(&result_id));
2677 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2735 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2678 ASSERT_TRUE(item); 2736 ASSERT_TRUE(item);
2679 ScopedCancellingItem canceller(item); 2737 ScopedCancellingItem canceller(item);
2680 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2738 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2681 2739
2682 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2740 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2683 base::StringPrintf("[{\"danger\": \"safe\"," 2741 base::StringPrintf(
2742 "[{\"danger\": \"safe\","
2684 " \"incognito\": false," 2743 " \"incognito\": false,"
2685 " \"id\": %d," 2744 " \"id\": %d,"
2686 " \"mime\": \"text/plain\"," 2745 " \"mime\": \"text/plain\","
2687 " \"paused\": false," 2746 " \"paused\": false,"
2688 " \"url\": \"%s\"}]", 2747 " \"url\": \"%s\"}]",
2689 result_id, 2748 result_id,
2690 download_url.c_str()))); 2749 download_url.c_str())));
2691 ASSERT_TRUE(WaitFor( 2750 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2692 api::OnDeterminingFilename::kEventName, 2751 base::StringPrintf(
2693 base::StringPrintf("[{\"id\": %d," 2752 "[{\"id\": %d,"
2694 " \"filename\":\"slow.txt\"}]", 2753 " \"filename\":\"slow.txt\"}]",
2695 result_id))); 2754 result_id)));
2696 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2755 ASSERT_TRUE(item->GetTargetFilePath().empty());
2697 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2756 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2698 2757
2699 // Respond to the onDeterminingFilename. 2758 // Respond to the onDeterminingFilename.
2700 std::string error; 2759 std::string error;
2701 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2760 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2702 browser()->profile(), 2761 browser()->profile(),
2703 false, 2762 false,
2704 GetExtensionId(), 2763 GetExtensionId(),
2705 result_id, 2764 result_id,
2706 base::FilePath(FILE_PATH_LITERAL("con.foo")), 2765 base::FilePath(FILE_PATH_LITERAL("con.foo")),
2707 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2766 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2708 &error)); 2767 &error));
2709 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); 2768 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2710 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, base::StringPrintf( 2769 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2711 "[{\"id\": %d," 2770 base::StringPrintf(
2712 " \"filename\": {" 2771 "[{\"id\": %d,"
2713 " \"previous\": \"\"," 2772 " \"filename\": {"
2714 " \"current\": \"%s\"}}]", 2773 " \"previous\": \"\","
2715 result_id, 2774 " \"current\": \"%s\"}}]",
2716 GetFilename("slow.txt").c_str()))); 2775 result_id,
2717 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, base::StringPrintf( 2776 GetFilename("slow.txt").c_str())));
2718 "[{\"id\": %d," 2777 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2719 " \"state\": {" 2778 base::StringPrintf(
2720 " \"previous\": \"in_progress\"," 2779 "[{\"id\": %d,"
2721 " \"current\": \"complete\"}}]", 2780 " \"state\": {"
2722 result_id))); 2781 " \"previous\": \"in_progress\","
2782 " \"current\": \"complete\"}}]",
2783 result_id)));
2723 } 2784 }
2724 2785
2725 IN_PROC_BROWSER_TEST_F( 2786 IN_PROC_BROWSER_TEST_F(
2726 DownloadExtensionTest, 2787 DownloadExtensionTest,
2727 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) { 2788 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) {
2728 GoOnTheRecord(); 2789 GoOnTheRecord();
2729 LoadExtension("downloads_split"); 2790 LoadExtension("downloads_split");
2730 AddFilenameDeterminer(); 2791 AddFilenameDeterminer();
2731 ASSERT_TRUE(StartEmbeddedTestServer()); 2792 ASSERT_TRUE(StartEmbeddedTestServer());
2732 ASSERT_TRUE(test_server()->Start()); 2793 ASSERT_TRUE(test_server()->Start());
2733 std::string download_url = test_server()->GetURL("slow?0").spec(); 2794 std::string download_url = test_server()->GetURL("slow?0").spec();
2734 2795
2735 // Start downloading a file. 2796 // Start downloading a file.
2736 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2797 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2737 new DownloadsDownloadFunction(), base::StringPrintf( 2798 new DownloadsDownloadFunction(), base::StringPrintf(
2738 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2799 "[{\"url\": \"%s\"}]", download_url.c_str())));
2739 ASSERT_TRUE(result.get()); 2800 ASSERT_TRUE(result.get());
2740 int result_id = -1; 2801 int result_id = -1;
2741 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2802 ASSERT_TRUE(result->GetAsInteger(&result_id));
2742 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2803 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2743 ASSERT_TRUE(item); 2804 ASSERT_TRUE(item);
2744 ScopedCancellingItem canceller(item); 2805 ScopedCancellingItem canceller(item);
2745 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2806 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2746 2807
2747 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2808 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2748 base::StringPrintf("[{\"danger\": \"safe\"," 2809 base::StringPrintf(
2810 "[{\"danger\": \"safe\","
2749 " \"incognito\": false," 2811 " \"incognito\": false,"
2750 " \"id\": %d," 2812 " \"id\": %d,"
2751 " \"mime\": \"text/plain\"," 2813 " \"mime\": \"text/plain\","
2752 " \"paused\": false," 2814 " \"paused\": false,"
2753 " \"url\": \"%s\"}]", 2815 " \"url\": \"%s\"}]",
2754 result_id, 2816 result_id,
2755 download_url.c_str()))); 2817 download_url.c_str())));
2756 ASSERT_TRUE(WaitFor( 2818 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2757 api::OnDeterminingFilename::kEventName, 2819 base::StringPrintf(
2758 base::StringPrintf("[{\"id\": %d," 2820 "[{\"id\": %d,"
2759 " \"filename\":\"slow.txt\"}]", 2821 " \"filename\":\"slow.txt\"}]",
2760 result_id))); 2822 result_id)));
2761 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2823 ASSERT_TRUE(item->GetTargetFilePath().empty());
2762 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2824 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2763 2825
2764 // Respond to the onDeterminingFilename. 2826 // Respond to the onDeterminingFilename.
2765 std::string error; 2827 std::string error;
2766 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2828 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2767 browser()->profile(), 2829 browser()->profile(),
2768 false, 2830 false,
2769 GetExtensionId(), 2831 GetExtensionId(),
2770 result_id, 2832 result_id,
2771 base::FilePath(FILE_PATH_LITERAL(".")), 2833 base::FilePath(FILE_PATH_LITERAL(".")),
2772 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2834 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2773 &error)); 2835 &error));
2774 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); 2836 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2775 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2837 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2776 base::StringPrintf("[{\"id\": %d," 2838 base::StringPrintf(
2777 " \"filename\": {" 2839 "[{\"id\": %d,"
2778 " \"previous\": \"\"," 2840 " \"filename\": {"
2779 " \"current\": \"%s\"}}]", 2841 " \"previous\": \"\","
2780 result_id, 2842 " \"current\": \"%s\"}}]",
2781 GetFilename("slow.txt").c_str()))); 2843 result_id,
2782 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2844 GetFilename("slow.txt").c_str())));
2783 base::StringPrintf("[{\"id\": %d," 2845 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2784 " \"state\": {" 2846 base::StringPrintf(
2785 " \"previous\": \"in_progress\"," 2847 "[{\"id\": %d,"
2786 " \"current\": \"complete\"}}]", 2848 " \"state\": {"
2787 result_id))); 2849 " \"previous\": \"in_progress\","
2850 " \"current\": \"complete\"}}]",
2851 result_id)));
2788 } 2852 }
2789 2853
2790 IN_PROC_BROWSER_TEST_F( 2854 IN_PROC_BROWSER_TEST_F(
2791 DownloadExtensionTest, 2855 DownloadExtensionTest,
2792 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) { 2856 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) {
2793 ASSERT_TRUE(StartEmbeddedTestServer()); 2857 ASSERT_TRUE(StartEmbeddedTestServer());
2794 ASSERT_TRUE(test_server()->Start()); 2858 ASSERT_TRUE(test_server()->Start());
2795 GoOnTheRecord(); 2859 GoOnTheRecord();
2796 LoadExtension("downloads_split"); 2860 LoadExtension("downloads_split");
2797 AddFilenameDeterminer(); 2861 AddFilenameDeterminer();
2798 std::string download_url = test_server()->GetURL("slow?0").spec(); 2862 std::string download_url = test_server()->GetURL("slow?0").spec();
2799 2863
2800 // Start downloading a file. 2864 // Start downloading a file.
2801 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2865 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2802 new DownloadsDownloadFunction(), base::StringPrintf( 2866 new DownloadsDownloadFunction(), base::StringPrintf(
2803 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2867 "[{\"url\": \"%s\"}]", download_url.c_str())));
2804 ASSERT_TRUE(result.get()); 2868 ASSERT_TRUE(result.get());
2805 int result_id = -1; 2869 int result_id = -1;
2806 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2870 ASSERT_TRUE(result->GetAsInteger(&result_id));
2807 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2871 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2808 ASSERT_TRUE(item); 2872 ASSERT_TRUE(item);
2809 ScopedCancellingItem canceller(item); 2873 ScopedCancellingItem canceller(item);
2810 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2874 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2811 2875
2812 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2876 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2813 base::StringPrintf("[{\"danger\": \"safe\"," 2877 base::StringPrintf(
2878 "[{\"danger\": \"safe\","
2814 " \"incognito\": false," 2879 " \"incognito\": false,"
2815 " \"id\": %d," 2880 " \"id\": %d,"
2816 " \"mime\": \"text/plain\"," 2881 " \"mime\": \"text/plain\","
2817 " \"paused\": false," 2882 " \"paused\": false,"
2818 " \"url\": \"%s\"}]", 2883 " \"url\": \"%s\"}]",
2819 result_id, 2884 result_id,
2820 download_url.c_str()))); 2885 download_url.c_str())));
2821 ASSERT_TRUE(WaitFor( 2886 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2822 api::OnDeterminingFilename::kEventName, 2887 base::StringPrintf(
2823 base::StringPrintf("[{\"id\": %d," 2888 "[{\"id\": %d,"
2824 " \"filename\":\"slow.txt\"}]", 2889 " \"filename\":\"slow.txt\"}]",
2825 result_id))); 2890 result_id)));
2826 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2891 ASSERT_TRUE(item->GetTargetFilePath().empty());
2827 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2892 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2828 2893
2829 // Respond to the onDeterminingFilename. 2894 // Respond to the onDeterminingFilename.
2830 std::string error; 2895 std::string error;
2831 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2896 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2832 browser()->profile(), 2897 browser()->profile(),
2833 false, 2898 false,
2834 GetExtensionId(), 2899 GetExtensionId(),
2835 result_id, 2900 result_id,
2836 base::FilePath(FILE_PATH_LITERAL("..")), 2901 base::FilePath(FILE_PATH_LITERAL("..")),
2837 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2902 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2838 &error)); 2903 &error));
2839 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); 2904 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2840 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2905 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2841 base::StringPrintf("[{\"id\": %d," 2906 base::StringPrintf(
2842 " \"filename\": {" 2907 "[{\"id\": %d,"
2843 " \"previous\": \"\"," 2908 " \"filename\": {"
2844 " \"current\": \"%s\"}}]", 2909 " \"previous\": \"\","
2845 result_id, 2910 " \"current\": \"%s\"}}]",
2846 GetFilename("slow.txt").c_str()))); 2911 result_id,
2847 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2912 GetFilename("slow.txt").c_str())));
2848 base::StringPrintf("[{\"id\": %d," 2913 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2849 " \"state\": {" 2914 base::StringPrintf(
2850 " \"previous\": \"in_progress\"," 2915 "[{\"id\": %d,"
2851 " \"current\": \"complete\"}}]", 2916 " \"state\": {"
2852 result_id))); 2917 " \"previous\": \"in_progress\","
2918 " \"current\": \"complete\"}}]",
2919 result_id)));
2853 } 2920 }
2854 2921
2855 IN_PROC_BROWSER_TEST_F( 2922 IN_PROC_BROWSER_TEST_F(
2856 DownloadExtensionTest, 2923 DownloadExtensionTest,
2857 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) { 2924 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) {
2858 GoOnTheRecord(); 2925 GoOnTheRecord();
2859 LoadExtension("downloads_split"); 2926 LoadExtension("downloads_split");
2860 AddFilenameDeterminer(); 2927 AddFilenameDeterminer();
2861 ASSERT_TRUE(StartEmbeddedTestServer()); 2928 ASSERT_TRUE(StartEmbeddedTestServer());
2862 ASSERT_TRUE(test_server()->Start()); 2929 ASSERT_TRUE(test_server()->Start());
2863 std::string download_url = test_server()->GetURL("slow?0").spec(); 2930 std::string download_url = test_server()->GetURL("slow?0").spec();
2864 2931
2865 // Start downloading a file. 2932 // Start downloading a file.
2866 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2933 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2867 new DownloadsDownloadFunction(), base::StringPrintf( 2934 new DownloadsDownloadFunction(), base::StringPrintf(
2868 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2935 "[{\"url\": \"%s\"}]", download_url.c_str())));
2869 ASSERT_TRUE(result.get()); 2936 ASSERT_TRUE(result.get());
2870 int result_id = -1; 2937 int result_id = -1;
2871 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2938 ASSERT_TRUE(result->GetAsInteger(&result_id));
2872 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2939 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2873 ASSERT_TRUE(item); 2940 ASSERT_TRUE(item);
2874 ScopedCancellingItem canceller(item); 2941 ScopedCancellingItem canceller(item);
2875 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2942 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2876 2943
2877 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 2944 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2878 base::StringPrintf("[{\"danger\": \"safe\"," 2945 base::StringPrintf(
2946 "[{\"danger\": \"safe\","
2879 " \"incognito\": false," 2947 " \"incognito\": false,"
2880 " \"id\": %d," 2948 " \"id\": %d,"
2881 " \"mime\": \"text/plain\"," 2949 " \"mime\": \"text/plain\","
2882 " \"paused\": false," 2950 " \"paused\": false,"
2883 " \"url\": \"%s\"}]", 2951 " \"url\": \"%s\"}]",
2884 result_id, 2952 result_id,
2885 download_url.c_str()))); 2953 download_url.c_str())));
2886 ASSERT_TRUE(WaitFor( 2954 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2887 api::OnDeterminingFilename::kEventName, 2955 base::StringPrintf(
2888 base::StringPrintf("[{\"id\": %d," 2956 "[{\"id\": %d,"
2889 " \"filename\":\"slow.txt\"}]", 2957 " \"filename\":\"slow.txt\"}]",
2890 result_id))); 2958 result_id)));
2891 ASSERT_TRUE(item->GetTargetFilePath().empty()); 2959 ASSERT_TRUE(item->GetTargetFilePath().empty());
2892 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 2960 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2893 2961
2894 // Respond to the onDeterminingFilename. Absolute paths should be rejected. 2962 // Respond to the onDeterminingFilename. Absolute paths should be rejected.
2895 std::string error; 2963 std::string error;
2896 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2964 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2897 browser()->profile(), 2965 browser()->profile(),
2898 false, 2966 false,
2899 GetExtensionId(), 2967 GetExtensionId(),
2900 result_id, 2968 result_id,
2901 downloads_directory().Append(FILE_PATH_LITERAL("sneaky.txt")), 2969 downloads_directory().Append(FILE_PATH_LITERAL("sneaky.txt")),
2902 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2970 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2903 &error)); 2971 &error));
2904 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); 2972 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2905 2973
2906 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2974 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2907 base::StringPrintf("[{\"id\": %d," 2975 base::StringPrintf(
2976 "[{\"id\": %d,"
2908 " \"filename\": {" 2977 " \"filename\": {"
2909 " \"previous\": \"\"," 2978 " \"previous\": \"\","
2910 " \"current\": \"%s\"}}]", 2979 " \"current\": \"%s\"}}]",
2911 result_id, 2980 result_id,
2912 GetFilename("slow.txt").c_str()))); 2981 GetFilename("slow.txt").c_str())));
2913 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 2982 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2914 base::StringPrintf("[{\"id\": %d," 2983 base::StringPrintf(
2984 "[{\"id\": %d,"
2915 " \"state\": {" 2985 " \"state\": {"
2916 " \"previous\": \"in_progress\"," 2986 " \"previous\": \"in_progress\","
2917 " \"current\": \"complete\"}}]", 2987 " \"current\": \"complete\"}}]",
2918 result_id))); 2988 result_id)));
2919 } 2989 }
2920 2990
2921 IN_PROC_BROWSER_TEST_F( 2991 IN_PROC_BROWSER_TEST_F(
2922 DownloadExtensionTest, 2992 DownloadExtensionTest,
2923 DownloadExtensionTest_OnDeterminingFilename_EmptyBasenameInvalid) { 2993 DownloadExtensionTest_OnDeterminingFilename_EmptyBasenameInvalid) {
2924 GoOnTheRecord(); 2994 GoOnTheRecord();
2925 LoadExtension("downloads_split"); 2995 LoadExtension("downloads_split");
2926 AddFilenameDeterminer(); 2996 AddFilenameDeterminer();
2927 ASSERT_TRUE(StartEmbeddedTestServer()); 2997 ASSERT_TRUE(StartEmbeddedTestServer());
2928 ASSERT_TRUE(test_server()->Start()); 2998 ASSERT_TRUE(test_server()->Start());
2929 std::string download_url = test_server()->GetURL("slow?0").spec(); 2999 std::string download_url = test_server()->GetURL("slow?0").spec();
2930 3000
2931 // Start downloading a file. 3001 // Start downloading a file.
2932 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 3002 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2933 new DownloadsDownloadFunction(), base::StringPrintf( 3003 new DownloadsDownloadFunction(), base::StringPrintf(
2934 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3004 "[{\"url\": \"%s\"}]", download_url.c_str())));
2935 ASSERT_TRUE(result.get()); 3005 ASSERT_TRUE(result.get());
2936 int result_id = -1; 3006 int result_id = -1;
2937 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3007 ASSERT_TRUE(result->GetAsInteger(&result_id));
2938 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 3008 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2939 ASSERT_TRUE(item); 3009 ASSERT_TRUE(item);
2940 ScopedCancellingItem canceller(item); 3010 ScopedCancellingItem canceller(item);
2941 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3011 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2942 3012
2943 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3013 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
2944 base::StringPrintf("[{\"danger\": \"safe\"," 3014 base::StringPrintf(
3015 "[{\"danger\": \"safe\","
2945 " \"incognito\": false," 3016 " \"incognito\": false,"
2946 " \"id\": %d," 3017 " \"id\": %d,"
2947 " \"mime\": \"text/plain\"," 3018 " \"mime\": \"text/plain\","
2948 " \"paused\": false," 3019 " \"paused\": false,"
2949 " \"url\": \"%s\"}]", 3020 " \"url\": \"%s\"}]",
2950 result_id, 3021 result_id,
2951 download_url.c_str()))); 3022 download_url.c_str())));
2952 ASSERT_TRUE(WaitFor( 3023 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
2953 api::OnDeterminingFilename::kEventName, 3024 base::StringPrintf(
2954 base::StringPrintf("[{\"id\": %d," 3025 "[{\"id\": %d,"
2955 " \"filename\":\"slow.txt\"}]", 3026 " \"filename\":\"slow.txt\"}]",
2956 result_id))); 3027 result_id)));
2957 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3028 ASSERT_TRUE(item->GetTargetFilePath().empty());
2958 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3029 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
2959 3030
2960 // Respond to the onDeterminingFilename. Empty basenames should be rejected. 3031 // Respond to the onDeterminingFilename. Empty basenames should be rejected.
2961 std::string error; 3032 std::string error;
2962 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 3033 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2963 browser()->profile(), 3034 browser()->profile(),
2964 false, 3035 false,
2965 GetExtensionId(), 3036 GetExtensionId(),
2966 result_id, 3037 result_id,
2967 base::FilePath(FILE_PATH_LITERAL("foo/")), 3038 base::FilePath(FILE_PATH_LITERAL("foo/")),
2968 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 3039 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2969 &error)); 3040 &error));
2970 EXPECT_STREQ(errors::kInvalidFilename, error.c_str()); 3041 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2971 3042
2972 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3043 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2973 base::StringPrintf("[{\"id\": %d," 3044 base::StringPrintf(
2974 " \"filename\": {" 3045 "[{\"id\": %d,"
2975 " \"previous\": \"\"," 3046 " \"filename\": {"
2976 " \"current\": \"%s\"}}]", 3047 " \"previous\": \"\","
2977 result_id, 3048 " \"current\": \"%s\"}}]",
2978 GetFilename("slow.txt").c_str()))); 3049 result_id,
2979 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3050 GetFilename("slow.txt").c_str())));
2980 base::StringPrintf("[{\"id\": %d," 3051 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
2981 " \"state\": {" 3052 base::StringPrintf(
2982 " \"previous\": \"in_progress\"," 3053 "[{\"id\": %d,"
2983 " \"current\": \"complete\"}}]", 3054 " \"state\": {"
2984 result_id))); 3055 " \"previous\": \"in_progress\","
3056 " \"current\": \"complete\"}}]",
3057 result_id)));
2985 } 3058 }
2986 3059
2987 // conflictAction may be specified without filename. 3060 // conflictAction may be specified without filename.
2988 IN_PROC_BROWSER_TEST_F( 3061 IN_PROC_BROWSER_TEST_F(
2989 DownloadExtensionTest, 3062 DownloadExtensionTest,
2990 DownloadExtensionTest_OnDeterminingFilename_Overwrite) { 3063 DownloadExtensionTest_OnDeterminingFilename_Overwrite) {
2991 GoOnTheRecord(); 3064 GoOnTheRecord();
2992 LoadExtension("downloads_split"); 3065 LoadExtension("downloads_split");
2993 AddFilenameDeterminer(); 3066 AddFilenameDeterminer();
2994 ASSERT_TRUE(StartEmbeddedTestServer()); 3067 ASSERT_TRUE(StartEmbeddedTestServer());
2995 ASSERT_TRUE(test_server()->Start()); 3068 ASSERT_TRUE(test_server()->Start());
2996 std::string download_url = test_server()->GetURL("slow?0").spec(); 3069 std::string download_url = test_server()->GetURL("slow?0").spec();
2997 3070
2998 // Start downloading a file. 3071 // Start downloading a file.
2999 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 3072 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
3000 new DownloadsDownloadFunction(), base::StringPrintf( 3073 new DownloadsDownloadFunction(), base::StringPrintf(
3001 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3074 "[{\"url\": \"%s\"}]", download_url.c_str())));
3002 ASSERT_TRUE(result.get()); 3075 ASSERT_TRUE(result.get());
3003 int result_id = -1; 3076 int result_id = -1;
3004 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3077 ASSERT_TRUE(result->GetAsInteger(&result_id));
3005 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 3078 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
3006 ASSERT_TRUE(item); 3079 ASSERT_TRUE(item);
3007 ScopedCancellingItem canceller(item); 3080 ScopedCancellingItem canceller(item);
3008 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3081 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3009 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3082 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3010 base::StringPrintf("[{\"danger\": \"safe\"," 3083 base::StringPrintf(
3011 " \"incognito\": false," 3084 "[{\"danger\": \"safe\","
3012 " \"id\": %d," 3085 " \"incognito\": false,"
3013 " \"mime\": \"text/plain\"," 3086 " \"id\": %d,"
3014 " \"paused\": false," 3087 " \"mime\": \"text/plain\","
3015 " \"url\": \"%s\"}]", 3088 " \"paused\": false,"
3016 result_id, 3089 " \"url\": \"%s\"}]",
3017 download_url.c_str()))); 3090 result_id,
3018 ASSERT_TRUE(WaitFor( 3091 download_url.c_str())));
3019 api::OnDeterminingFilename::kEventName, 3092 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3020 base::StringPrintf("[{\"id\": %d," 3093 base::StringPrintf(
3021 " \"filename\":\"slow.txt\"}]", 3094 "[{\"id\": %d,"
3022 result_id))); 3095 " \"filename\":\"slow.txt\"}]",
3096 result_id)));
3023 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3097 ASSERT_TRUE(item->GetTargetFilePath().empty());
3024 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3098 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3025 3099
3026 // Respond to the onDeterminingFilename. 3100 // Respond to the onDeterminingFilename.
3027 std::string error; 3101 std::string error;
3028 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3102 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3029 browser()->profile(), 3103 browser()->profile(),
3030 false, 3104 false,
3031 GetExtensionId(), 3105 GetExtensionId(),
3032 result_id, 3106 result_id,
3033 base::FilePath(), 3107 base::FilePath(),
3034 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 3108 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
3035 &error)); 3109 &error));
3036 EXPECT_EQ("", error); 3110 EXPECT_EQ("", error);
3037 3111
3038 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3112 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3039 base::StringPrintf("[{\"id\": %d," 3113 base::StringPrintf(
3040 " \"filename\": {" 3114 "[{\"id\": %d,"
3041 " \"previous\": \"\"," 3115 " \"filename\": {"
3042 " \"current\": \"%s\"}}]", 3116 " \"previous\": \"\","
3043 result_id, 3117 " \"current\": \"%s\"}}]",
3044 GetFilename("slow.txt").c_str()))); 3118 result_id,
3045 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3119 GetFilename("slow.txt").c_str())));
3046 base::StringPrintf("[{\"id\": %d," 3120 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3047 " \"state\": {" 3121 base::StringPrintf(
3048 " \"previous\": \"in_progress\"," 3122 "[{\"id\": %d,"
3049 " \"current\": \"complete\"}}]", 3123 " \"state\": {"
3050 result_id))); 3124 " \"previous\": \"in_progress\","
3125 " \"current\": \"complete\"}}]",
3126 result_id)));
3051 3127
3052 // Start downloading a file. 3128 // Start downloading a file.
3053 result.reset(RunFunctionAndReturnResult( 3129 result.reset(RunFunctionAndReturnResult(
3054 new DownloadsDownloadFunction(), base::StringPrintf( 3130 new DownloadsDownloadFunction(), base::StringPrintf(
3055 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3131 "[{\"url\": \"%s\"}]", download_url.c_str())));
3056 ASSERT_TRUE(result.get()); 3132 ASSERT_TRUE(result.get());
3057 result_id = -1; 3133 result_id = -1;
3058 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3134 ASSERT_TRUE(result->GetAsInteger(&result_id));
3059 item = GetCurrentManager()->GetDownload(result_id); 3135 item = GetCurrentManager()->GetDownload(result_id);
3060 ASSERT_TRUE(item); 3136 ASSERT_TRUE(item);
3061 ScopedCancellingItem canceller2(item); 3137 ScopedCancellingItem canceller2(item);
3062 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3138 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3063 3139
3064 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3140 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3065 base::StringPrintf("[{\"danger\": \"safe\"," 3141 base::StringPrintf(
3066 " \"incognito\": false," 3142 "[{\"danger\": \"safe\","
3067 " \"id\": %d," 3143 " \"incognito\": false,"
3068 " \"mime\": \"text/plain\"," 3144 " \"id\": %d,"
3069 " \"paused\": false," 3145 " \"mime\": \"text/plain\","
3070 " \"url\": \"%s\"}]", 3146 " \"paused\": false,"
3071 result_id, 3147 " \"url\": \"%s\"}]",
3072 download_url.c_str()))); 3148 result_id,
3073 ASSERT_TRUE(WaitFor( 3149 download_url.c_str())));
3074 api::OnDeterminingFilename::kEventName, 3150 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3075 base::StringPrintf("[{\"id\": %d," 3151 base::StringPrintf(
3076 " \"filename\":\"slow.txt\"}]", 3152 "[{\"id\": %d,"
3077 result_id))); 3153 " \"filename\":\"slow.txt\"}]",
3154 result_id)));
3078 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3155 ASSERT_TRUE(item->GetTargetFilePath().empty());
3079 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3156 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3080 3157
3081 // Respond to the onDeterminingFilename. 3158 // Respond to the onDeterminingFilename.
3082 // Also test that DetermineFilename allows (chrome) extensions to set 3159 // Also test that DetermineFilename allows (chrome) extensions to set
3083 // filenames without (filename) extensions. (Don't ask about v8 extensions or 3160 // filenames without (filename) extensions. (Don't ask about v8 extensions or
3084 // python extensions or kernel extensions or firefox extensions...) 3161 // python extensions or kernel extensions or firefox extensions...)
3085 error = ""; 3162 error = "";
3086 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3163 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3087 browser()->profile(), 3164 browser()->profile(),
3088 false, 3165 false,
3089 GetExtensionId(), 3166 GetExtensionId(),
3090 result_id, 3167 result_id,
3091 base::FilePath(), 3168 base::FilePath(),
3092 api::FILENAME_CONFLICT_ACTION_OVERWRITE, 3169 downloads::FILENAME_CONFLICT_ACTION_OVERWRITE,
3093 &error)); 3170 &error));
3094 EXPECT_EQ("", error); 3171 EXPECT_EQ("", error);
3095 3172
3096 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3173 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3097 base::StringPrintf("[{\"id\": %d," 3174 base::StringPrintf(
3098 " \"filename\": {" 3175 "[{\"id\": %d,"
3099 " \"previous\": \"\"," 3176 " \"filename\": {"
3100 " \"current\": \"%s\"}}]", 3177 " \"previous\": \"\","
3101 result_id, 3178 " \"current\": \"%s\"}}]",
3102 GetFilename("slow.txt").c_str()))); 3179 result_id,
3103 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3180 GetFilename("slow.txt").c_str())));
3104 base::StringPrintf("[{\"id\": %d," 3181 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3105 " \"state\": {" 3182 base::StringPrintf(
3106 " \"previous\": \"in_progress\"," 3183 "[{\"id\": %d,"
3107 " \"current\": \"complete\"}}]", 3184 " \"state\": {"
3108 result_id))); 3185 " \"previous\": \"in_progress\","
3186 " \"current\": \"complete\"}}]",
3187 result_id)));
3109 } 3188 }
3110 3189
3111 IN_PROC_BROWSER_TEST_F( 3190 IN_PROC_BROWSER_TEST_F(
3112 DownloadExtensionTest, 3191 DownloadExtensionTest,
3113 DownloadExtensionTest_OnDeterminingFilename_Override) { 3192 DownloadExtensionTest_OnDeterminingFilename_Override) {
3114 GoOnTheRecord(); 3193 GoOnTheRecord();
3115 LoadExtension("downloads_split"); 3194 LoadExtension("downloads_split");
3116 AddFilenameDeterminer(); 3195 AddFilenameDeterminer();
3117 ASSERT_TRUE(StartEmbeddedTestServer()); 3196 ASSERT_TRUE(StartEmbeddedTestServer());
3118 ASSERT_TRUE(test_server()->Start()); 3197 ASSERT_TRUE(test_server()->Start());
3119 std::string download_url = test_server()->GetURL("slow?0").spec(); 3198 std::string download_url = test_server()->GetURL("slow?0").spec();
3120 3199
3121 // Start downloading a file. 3200 // Start downloading a file.
3122 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 3201 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
3123 new DownloadsDownloadFunction(), base::StringPrintf( 3202 new DownloadsDownloadFunction(), base::StringPrintf(
3124 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3203 "[{\"url\": \"%s\"}]", download_url.c_str())));
3125 ASSERT_TRUE(result.get()); 3204 ASSERT_TRUE(result.get());
3126 int result_id = -1; 3205 int result_id = -1;
3127 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3206 ASSERT_TRUE(result->GetAsInteger(&result_id));
3128 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 3207 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
3129 ASSERT_TRUE(item); 3208 ASSERT_TRUE(item);
3130 ScopedCancellingItem canceller(item); 3209 ScopedCancellingItem canceller(item);
3131 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3210 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3132 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3211 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3133 base::StringPrintf("[{\"danger\": \"safe\"," 3212 base::StringPrintf(
3134 " \"incognito\": false," 3213 "[{\"danger\": \"safe\","
3135 " \"id\": %d," 3214 " \"incognito\": false,"
3136 " \"mime\": \"text/plain\"," 3215 " \"id\": %d,"
3137 " \"paused\": false," 3216 " \"mime\": \"text/plain\","
3138 " \"url\": \"%s\"}]", 3217 " \"paused\": false,"
3139 result_id, 3218 " \"url\": \"%s\"}]",
3140 download_url.c_str()))); 3219 result_id,
3141 ASSERT_TRUE(WaitFor( 3220 download_url.c_str())));
3142 api::OnDeterminingFilename::kEventName, 3221 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3143 base::StringPrintf("[{\"id\": %d," 3222 base::StringPrintf(
3144 " \"filename\":\"slow.txt\"}]", 3223 "[{\"id\": %d,"
3145 result_id))); 3224 " \"filename\":\"slow.txt\"}]",
3225 result_id)));
3146 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3226 ASSERT_TRUE(item->GetTargetFilePath().empty());
3147 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3227 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3148 3228
3149 // Respond to the onDeterminingFilename. 3229 // Respond to the onDeterminingFilename.
3150 std::string error; 3230 std::string error;
3151 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3231 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3152 browser()->profile(), 3232 browser()->profile(),
3153 false, 3233 false,
3154 GetExtensionId(), 3234 GetExtensionId(),
3155 result_id, 3235 result_id,
3156 base::FilePath(), 3236 base::FilePath(),
3157 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 3237 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
3158 &error)); 3238 &error));
3159 EXPECT_EQ("", error); 3239 EXPECT_EQ("", error);
3160 3240
3161 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3241 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3162 base::StringPrintf("[{\"id\": %d," 3242 base::StringPrintf(
3163 " \"filename\": {" 3243 "[{\"id\": %d,"
3164 " \"previous\": \"\"," 3244 " \"filename\": {"
3165 " \"current\": \"%s\"}}]", 3245 " \"previous\": \"\","
3166 result_id, 3246 " \"current\": \"%s\"}}]",
3167 GetFilename("slow.txt").c_str()))); 3247 result_id,
3168 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3248 GetFilename("slow.txt").c_str())));
3169 base::StringPrintf("[{\"id\": %d," 3249 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3170 " \"state\": {" 3250 base::StringPrintf(
3171 " \"previous\": \"in_progress\"," 3251 "[{\"id\": %d,"
3172 " \"current\": \"complete\"}}]", 3252 " \"state\": {"
3173 result_id))); 3253 " \"previous\": \"in_progress\","
3254 " \"current\": \"complete\"}}]",
3255 result_id)));
3174 3256
3175 // Start downloading a file. 3257 // Start downloading a file.
3176 result.reset(RunFunctionAndReturnResult( 3258 result.reset(RunFunctionAndReturnResult(
3177 new DownloadsDownloadFunction(), base::StringPrintf( 3259 new DownloadsDownloadFunction(), base::StringPrintf(
3178 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3260 "[{\"url\": \"%s\"}]", download_url.c_str())));
3179 ASSERT_TRUE(result.get()); 3261 ASSERT_TRUE(result.get());
3180 result_id = -1; 3262 result_id = -1;
3181 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3263 ASSERT_TRUE(result->GetAsInteger(&result_id));
3182 item = GetCurrentManager()->GetDownload(result_id); 3264 item = GetCurrentManager()->GetDownload(result_id);
3183 ASSERT_TRUE(item); 3265 ASSERT_TRUE(item);
3184 ScopedCancellingItem canceller2(item); 3266 ScopedCancellingItem canceller2(item);
3185 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3267 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3186 3268
3187 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3269 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3188 base::StringPrintf("[{\"danger\": \"safe\"," 3270 base::StringPrintf(
3189 " \"incognito\": false," 3271 "[{\"danger\": \"safe\","
3190 " \"id\": %d," 3272 " \"incognito\": false,"
3191 " \"mime\": \"text/plain\"," 3273 " \"id\": %d,"
3192 " \"paused\": false," 3274 " \"mime\": \"text/plain\","
3193 " \"url\": \"%s\"}]", 3275 " \"paused\": false,"
3194 result_id, 3276 " \"url\": \"%s\"}]",
3195 download_url.c_str()))); 3277 result_id,
3196 ASSERT_TRUE(WaitFor( 3278 download_url.c_str())));
3197 api::OnDeterminingFilename::kEventName, 3279 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3198 base::StringPrintf("[{\"id\": %d," 3280 base::StringPrintf(
3199 " \"filename\":\"slow.txt\"}]", 3281 "[{\"id\": %d,"
3200 result_id))); 3282 " \"filename\":\"slow.txt\"}]",
3283 result_id)));
3201 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3284 ASSERT_TRUE(item->GetTargetFilePath().empty());
3202 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3285 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3203 3286
3204 // Respond to the onDeterminingFilename. 3287 // Respond to the onDeterminingFilename.
3205 // Also test that DetermineFilename allows (chrome) extensions to set 3288 // Also test that DetermineFilename allows (chrome) extensions to set
3206 // filenames without (filename) extensions. (Don't ask about v8 extensions or 3289 // filenames without (filename) extensions. (Don't ask about v8 extensions or
3207 // python extensions or kernel extensions or firefox extensions...) 3290 // python extensions or kernel extensions or firefox extensions...)
3208 error = ""; 3291 error = "";
3209 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3292 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3210 browser()->profile(), 3293 browser()->profile(),
3211 false, 3294 false,
3212 GetExtensionId(), 3295 GetExtensionId(),
3213 result_id, 3296 result_id,
3214 base::FilePath(FILE_PATH_LITERAL("foo")), 3297 base::FilePath(FILE_PATH_LITERAL("foo")),
3215 api::FILENAME_CONFLICT_ACTION_OVERWRITE, 3298 downloads::FILENAME_CONFLICT_ACTION_OVERWRITE,
3216 &error)); 3299 &error));
3217 EXPECT_EQ("", error); 3300 EXPECT_EQ("", error);
3218 3301
3219 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3302 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3220 base::StringPrintf("[{\"id\": %d," 3303 base::StringPrintf(
3221 " \"filename\": {" 3304 "[{\"id\": %d,"
3222 " \"previous\": \"\"," 3305 " \"filename\": {"
3223 " \"current\": \"%s\"}}]", 3306 " \"previous\": \"\","
3224 result_id, 3307 " \"current\": \"%s\"}}]",
3225 GetFilename("foo").c_str()))); 3308 result_id,
3226 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3309 GetFilename("foo").c_str())));
3227 base::StringPrintf("[{\"id\": %d," 3310 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3228 " \"state\": {" 3311 base::StringPrintf(
3229 " \"previous\": \"in_progress\"," 3312 "[{\"id\": %d,"
3230 " \"current\": \"complete\"}}]", 3313 " \"state\": {"
3231 result_id))); 3314 " \"previous\": \"in_progress\","
3315 " \"current\": \"complete\"}}]",
3316 result_id)));
3232 } 3317 }
3233 3318
3234 // TODO test precedence rules: install_time 3319 // TODO test precedence rules: install_time
3235 3320
3236 IN_PROC_BROWSER_TEST_F( 3321 IN_PROC_BROWSER_TEST_F(
3237 DownloadExtensionTest, 3322 DownloadExtensionTest,
3238 DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer) { 3323 DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer) {
3239 ASSERT_TRUE(StartEmbeddedTestServer()); 3324 ASSERT_TRUE(StartEmbeddedTestServer());
3240 ASSERT_TRUE(test_server()->Start()); 3325 ASSERT_TRUE(test_server()->Start());
3241 GoOnTheRecord(); 3326 GoOnTheRecord();
3242 LoadExtension("downloads_split"); 3327 LoadExtension("downloads_split");
3243 content::RenderProcessHost* host = AddFilenameDeterminer(); 3328 content::RenderProcessHost* host = AddFilenameDeterminer();
3244 std::string download_url = test_server()->GetURL("slow?0").spec(); 3329 std::string download_url = test_server()->GetURL("slow?0").spec();
3245 3330
3246 // Start downloading a file. 3331 // Start downloading a file.
3247 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 3332 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
3248 new DownloadsDownloadFunction(), base::StringPrintf( 3333 new DownloadsDownloadFunction(), base::StringPrintf(
3249 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3334 "[{\"url\": \"%s\"}]", download_url.c_str())));
3250 ASSERT_TRUE(result.get()); 3335 ASSERT_TRUE(result.get());
3251 int result_id = -1; 3336 int result_id = -1;
3252 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3337 ASSERT_TRUE(result->GetAsInteger(&result_id));
3253 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 3338 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
3254 ASSERT_TRUE(item); 3339 ASSERT_TRUE(item);
3255 ScopedCancellingItem canceller(item); 3340 ScopedCancellingItem canceller(item);
3256 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3341 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3257 3342
3258 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3343 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3259 base::StringPrintf("[{\"danger\": \"safe\"," 3344 base::StringPrintf(
3345 "[{\"danger\": \"safe\","
3260 " \"incognito\": false," 3346 " \"incognito\": false,"
3261 " \"id\": %d," 3347 " \"id\": %d,"
3262 " \"mime\": \"text/plain\"," 3348 " \"mime\": \"text/plain\","
3263 " \"paused\": false," 3349 " \"paused\": false,"
3264 " \"url\": \"%s\"}]", 3350 " \"url\": \"%s\"}]",
3265 result_id, 3351 result_id,
3266 download_url.c_str()))); 3352 download_url.c_str())));
3267 ASSERT_TRUE(WaitFor( 3353 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3268 api::OnDeterminingFilename::kEventName, 3354 base::StringPrintf(
3269 base::StringPrintf("[{\"id\": %d," 3355 "[{\"id\": %d,"
3270 " \"filename\":\"slow.txt\"}]", 3356 " \"filename\":\"slow.txt\"}]",
3271 result_id))); 3357 result_id)));
3272 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3358 ASSERT_TRUE(item->GetTargetFilePath().empty());
3273 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3359 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3274 3360
3275 // Remove a determiner while waiting for it. 3361 // Remove a determiner while waiting for it.
3276 RemoveFilenameDeterminer(host); 3362 RemoveFilenameDeterminer(host);
3277 3363
3278 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3364 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3279 base::StringPrintf("[{\"id\": %d," 3365 base::StringPrintf(
3280 " \"state\": {" 3366 "[{\"id\": %d,"
3281 " \"previous\": \"in_progress\"," 3367 " \"state\": {"
3282 " \"current\": \"complete\"}}]", 3368 " \"previous\": \"in_progress\","
3283 result_id))); 3369 " \"current\": \"complete\"}}]",
3370 result_id)));
3284 } 3371 }
3285 3372
3286 IN_PROC_BROWSER_TEST_F( 3373 IN_PROC_BROWSER_TEST_F(
3287 DownloadExtensionTest, 3374 DownloadExtensionTest,
3288 DownloadExtensionTest_OnDeterminingFilename_IncognitoSplit) { 3375 DownloadExtensionTest_OnDeterminingFilename_IncognitoSplit) {
3289 LoadExtension("downloads_split"); 3376 LoadExtension("downloads_split");
3290 ASSERT_TRUE(StartEmbeddedTestServer()); 3377 ASSERT_TRUE(StartEmbeddedTestServer());
3291 ASSERT_TRUE(test_server()->Start()); 3378 ASSERT_TRUE(test_server()->Start());
3292 std::string download_url = test_server()->GetURL("slow?0").spec(); 3379 std::string download_url = test_server()->GetURL("slow?0").spec();
3293 3380
(...skipping 10 matching lines...) Expand all
3304 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3391 "[{\"url\": \"%s\"}]", download_url.c_str())));
3305 ASSERT_TRUE(result.get()); 3392 ASSERT_TRUE(result.get());
3306 int result_id = -1; 3393 int result_id = -1;
3307 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3394 ASSERT_TRUE(result->GetAsInteger(&result_id));
3308 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 3395 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
3309 ASSERT_TRUE(item); 3396 ASSERT_TRUE(item);
3310 ScopedCancellingItem canceller(item); 3397 ScopedCancellingItem canceller(item);
3311 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3398 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3312 3399
3313 // Wait for the onCreated and onDeterminingFilename events. 3400 // Wait for the onCreated and onDeterminingFilename events.
3314 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3401 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3315 base::StringPrintf("[{\"danger\": \"safe\"," 3402 base::StringPrintf(
3403 "[{\"danger\": \"safe\","
3316 " \"incognito\": false," 3404 " \"incognito\": false,"
3317 " \"id\": %d," 3405 " \"id\": %d,"
3318 " \"mime\": \"text/plain\"," 3406 " \"mime\": \"text/plain\","
3319 " \"paused\": false," 3407 " \"paused\": false,"
3320 " \"url\": \"%s\"}]", 3408 " \"url\": \"%s\"}]",
3321 result_id, 3409 result_id,
3322 download_url.c_str()))); 3410 download_url.c_str())));
3323 ASSERT_TRUE(WaitFor( 3411 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3324 api::OnDeterminingFilename::kEventName, 3412 base::StringPrintf(
3325 base::StringPrintf("[{\"id\": %d," 3413 "[{\"id\": %d,"
3326 " \"incognito\": false," 3414 " \"incognito\": false,"
3327 " \"filename\":\"slow.txt\"}]", 3415 " \"filename\":\"slow.txt\"}]",
3328 result_id))); 3416 result_id)));
3329 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3417 ASSERT_TRUE(item->GetTargetFilePath().empty());
3330 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3418 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3331 3419
3332 // Respond to the onDeterminingFilename events. 3420 // Respond to the onDeterminingFilename events.
3333 std::string error; 3421 std::string error;
3334 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3422 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3335 current_browser()->profile(), 3423 current_browser()->profile(),
3336 false, 3424 false,
3337 GetExtensionId(), 3425 GetExtensionId(),
3338 result_id, 3426 result_id,
3339 base::FilePath(FILE_PATH_LITERAL("42.txt")), 3427 base::FilePath(FILE_PATH_LITERAL("42.txt")),
3340 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 3428 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
3341 &error)); 3429 &error));
3342 EXPECT_EQ("", error); 3430 EXPECT_EQ("", error);
3343 3431
3344 // The download should complete successfully. 3432 // The download should complete successfully.
3345 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3433 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3346 base::StringPrintf("[{\"id\": %d," 3434 base::StringPrintf(
3347 " \"filename\": {" 3435 "[{\"id\": %d,"
3348 " \"previous\": \"\"," 3436 " \"filename\": {"
3349 " \"current\": \"%s\"}}]", 3437 " \"previous\": \"\","
3350 result_id, 3438 " \"current\": \"%s\"}}]",
3351 GetFilename("42.txt").c_str()))); 3439 result_id,
3352 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3440 GetFilename("42.txt").c_str())));
3353 base::StringPrintf("[{\"id\": %d," 3441 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3354 " \"state\": {" 3442 base::StringPrintf(
3355 " \"previous\": \"in_progress\"," 3443 "[{\"id\": %d,"
3356 " \"current\": \"complete\"}}]", 3444 " \"state\": {"
3357 result_id))); 3445 " \"previous\": \"in_progress\","
3446 " \"current\": \"complete\"}}]",
3447 result_id)));
3358 3448
3359 // Start an incognito download for comparison. 3449 // Start an incognito download for comparison.
3360 GoOffTheRecord(); 3450 GoOffTheRecord();
3361 result.reset(RunFunctionAndReturnResult( 3451 result.reset(RunFunctionAndReturnResult(
3362 new DownloadsDownloadFunction(), base::StringPrintf( 3452 new DownloadsDownloadFunction(), base::StringPrintf(
3363 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3453 "[{\"url\": \"%s\"}]", download_url.c_str())));
3364 ASSERT_TRUE(result.get()); 3454 ASSERT_TRUE(result.get());
3365 result_id = -1; 3455 result_id = -1;
3366 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3456 ASSERT_TRUE(result->GetAsInteger(&result_id));
3367 item = GetCurrentManager()->GetDownload(result_id); 3457 item = GetCurrentManager()->GetDownload(result_id);
3368 ASSERT_TRUE(item); 3458 ASSERT_TRUE(item);
3369 ScopedCancellingItem canceller2(item); 3459 ScopedCancellingItem canceller2(item);
3370 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3460 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3371 3461
3372 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3462 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3373 base::StringPrintf("[{\"danger\": \"safe\"," 3463 base::StringPrintf(
3374 " \"incognito\": true," 3464 "[{\"danger\": \"safe\","
3375 " \"id\": %d," 3465 " \"incognito\": true,"
3376 " \"mime\": \"text/plain\"," 3466 " \"id\": %d,"
3377 " \"paused\": false," 3467 " \"mime\": \"text/plain\","
3378 " \"url\": \"%s\"}]", 3468 " \"paused\": false,"
3379 result_id, 3469 " \"url\": \"%s\"}]",
3380 download_url.c_str()))); 3470 result_id,
3471 download_url.c_str())));
3381 // On-Record renderers should not see events for off-record items. 3472 // On-Record renderers should not see events for off-record items.
3382 ASSERT_TRUE(WaitFor( 3473 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3383 api::OnDeterminingFilename::kEventName, 3474 base::StringPrintf(
3384 base::StringPrintf("[{\"id\": %d," 3475 "[{\"id\": %d,"
3385 " \"incognito\": true," 3476 " \"incognito\": true,"
3386 " \"filename\":\"slow.txt\"}]", 3477 " \"filename\":\"slow.txt\"}]",
3387 result_id))); 3478 result_id)));
3388 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3479 ASSERT_TRUE(item->GetTargetFilePath().empty());
3389 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3480 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3390 3481
3391 // Respond to the onDeterminingFilename. 3482 // Respond to the onDeterminingFilename.
3392 error = ""; 3483 error = "";
3393 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3484 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3394 current_browser()->profile(), 3485 current_browser()->profile(),
3395 false, 3486 false,
3396 GetExtensionId(), 3487 GetExtensionId(),
3397 result_id, 3488 result_id,
3398 base::FilePath(FILE_PATH_LITERAL("5.txt")), 3489 base::FilePath(FILE_PATH_LITERAL("5.txt")),
3399 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 3490 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
3400 &error)); 3491 &error));
3401 EXPECT_EQ("", error); 3492 EXPECT_EQ("", error);
3402 3493
3403 // The download should complete successfully. 3494 // The download should complete successfully.
3404 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3495 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3405 base::StringPrintf("[{\"id\": %d," 3496 base::StringPrintf(
3406 " \"filename\": {" 3497 "[{\"id\": %d,"
3407 " \"previous\": \"\"," 3498 " \"filename\": {"
3408 " \"current\": \"%s\"}}]", 3499 " \"previous\": \"\","
3409 result_id, 3500 " \"current\": \"%s\"}}]",
3410 GetFilename("5.txt").c_str()))); 3501 result_id,
3411 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3502 GetFilename("5.txt").c_str())));
3412 base::StringPrintf("[{\"id\": %d," 3503 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3413 " \"state\": {" 3504 base::StringPrintf(
3414 " \"previous\": \"in_progress\"," 3505 "[{\"id\": %d,"
3415 " \"current\": \"complete\"}}]", 3506 " \"state\": {"
3416 result_id))); 3507 " \"previous\": \"in_progress\","
3508 " \"current\": \"complete\"}}]",
3509 result_id)));
3417 } 3510 }
3418 3511
3419 IN_PROC_BROWSER_TEST_F( 3512 IN_PROC_BROWSER_TEST_F(
3420 DownloadExtensionTest, 3513 DownloadExtensionTest,
3421 DownloadExtensionTest_OnDeterminingFilename_IncognitoSpanning) { 3514 DownloadExtensionTest_OnDeterminingFilename_IncognitoSpanning) {
3422 LoadExtension("downloads_spanning"); 3515 LoadExtension("downloads_spanning");
3423 ASSERT_TRUE(StartEmbeddedTestServer()); 3516 ASSERT_TRUE(StartEmbeddedTestServer());
3424 ASSERT_TRUE(test_server()->Start()); 3517 ASSERT_TRUE(test_server()->Start());
3425 std::string download_url = test_server()->GetURL("slow?0").spec(); 3518 std::string download_url = test_server()->GetURL("slow?0").spec();
3426 3519
(...skipping 11 matching lines...) Expand all
3438 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3531 "[{\"url\": \"%s\"}]", download_url.c_str())));
3439 ASSERT_TRUE(result.get()); 3532 ASSERT_TRUE(result.get());
3440 int result_id = -1; 3533 int result_id = -1;
3441 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3534 ASSERT_TRUE(result->GetAsInteger(&result_id));
3442 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 3535 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
3443 ASSERT_TRUE(item); 3536 ASSERT_TRUE(item);
3444 ScopedCancellingItem canceller(item); 3537 ScopedCancellingItem canceller(item);
3445 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3538 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3446 3539
3447 // Wait for the onCreated and onDeterminingFilename events. 3540 // Wait for the onCreated and onDeterminingFilename events.
3448 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3541 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3449 base::StringPrintf("[{\"danger\": \"safe\"," 3542 base::StringPrintf(
3543 "[{\"danger\": \"safe\","
3450 " \"incognito\": false," 3544 " \"incognito\": false,"
3451 " \"id\": %d," 3545 " \"id\": %d,"
3452 " \"mime\": \"text/plain\"," 3546 " \"mime\": \"text/plain\","
3453 " \"paused\": false," 3547 " \"paused\": false,"
3454 " \"url\": \"%s\"}]", 3548 " \"url\": \"%s\"}]",
3455 result_id, 3549 result_id,
3456 download_url.c_str()))); 3550 download_url.c_str())));
3457 ASSERT_TRUE(WaitFor( 3551 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3458 api::OnDeterminingFilename::kEventName, 3552 base::StringPrintf(
3459 base::StringPrintf("[{\"id\": %d," 3553 "[{\"id\": %d,"
3460 " \"incognito\": false," 3554 " \"incognito\": false,"
3461 " \"filename\":\"slow.txt\"}]", 3555 " \"filename\":\"slow.txt\"}]",
3462 result_id))); 3556 result_id)));
3463 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3557 ASSERT_TRUE(item->GetTargetFilePath().empty());
3464 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3558 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3465 3559
3466 // Respond to the onDeterminingFilename events. 3560 // Respond to the onDeterminingFilename events.
3467 std::string error; 3561 std::string error;
3468 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3562 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3469 current_browser()->profile(), 3563 current_browser()->profile(),
3470 true, 3564 true,
3471 GetExtensionId(), 3565 GetExtensionId(),
3472 result_id, 3566 result_id,
3473 base::FilePath(FILE_PATH_LITERAL("42.txt")), 3567 base::FilePath(FILE_PATH_LITERAL("42.txt")),
3474 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 3568 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
3475 &error)); 3569 &error));
3476 EXPECT_EQ("", error); 3570 EXPECT_EQ("", error);
3477 3571
3478 // The download should complete successfully. 3572 // The download should complete successfully.
3479 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3573 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3480 base::StringPrintf("[{\"id\": %d," 3574 base::StringPrintf(
3481 " \"filename\": {" 3575 "[{\"id\": %d,"
3482 " \"previous\": \"\"," 3576 " \"filename\": {"
3483 " \"current\": \"%s\"}}]", 3577 " \"previous\": \"\","
3484 result_id, 3578 " \"current\": \"%s\"}}]",
3485 GetFilename("42.txt").c_str()))); 3579 result_id,
3486 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3580 GetFilename("42.txt").c_str())));
3487 base::StringPrintf("[{\"id\": %d," 3581 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3488 " \"state\": {" 3582 base::StringPrintf(
3489 " \"previous\": \"in_progress\"," 3583 "[{\"id\": %d,"
3490 " \"current\": \"complete\"}}]", 3584 " \"state\": {"
3491 result_id))); 3585 " \"previous\": \"in_progress\","
3586 " \"current\": \"complete\"}}]",
3587 result_id)));
3492 3588
3493 // Start an incognito download for comparison. 3589 // Start an incognito download for comparison.
3494 GoOffTheRecord(); 3590 GoOffTheRecord();
3495 result.reset(RunFunctionAndReturnResult( 3591 result.reset(RunFunctionAndReturnResult(
3496 new DownloadsDownloadFunction(), base::StringPrintf( 3592 new DownloadsDownloadFunction(), base::StringPrintf(
3497 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3593 "[{\"url\": \"%s\"}]", download_url.c_str())));
3498 ASSERT_TRUE(result.get()); 3594 ASSERT_TRUE(result.get());
3499 result_id = -1; 3595 result_id = -1;
3500 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3596 ASSERT_TRUE(result->GetAsInteger(&result_id));
3501 item = GetCurrentManager()->GetDownload(result_id); 3597 item = GetCurrentManager()->GetDownload(result_id);
3502 ASSERT_TRUE(item); 3598 ASSERT_TRUE(item);
3503 ScopedCancellingItem canceller2(item); 3599 ScopedCancellingItem canceller2(item);
3504 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 3600 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
3505 3601
3506 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3602 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3507 base::StringPrintf("[{\"danger\": \"safe\"," 3603 base::StringPrintf(
3508 " \"incognito\": true," 3604 "[{\"danger\": \"safe\","
3509 " \"id\": %d," 3605 " \"incognito\": true,"
3510 " \"mime\": \"text/plain\"," 3606 " \"id\": %d,"
3511 " \"paused\": false," 3607 " \"mime\": \"text/plain\","
3512 " \"url\": \"%s\"}]", 3608 " \"paused\": false,"
3513 result_id, 3609 " \"url\": \"%s\"}]",
3514 download_url.c_str()))); 3610 result_id,
3515 ASSERT_TRUE(WaitFor( 3611 download_url.c_str())));
3516 api::OnDeterminingFilename::kEventName, 3612 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3517 base::StringPrintf("[{\"id\": %d," 3613 base::StringPrintf(
3518 " \"incognito\": true," 3614 "[{\"id\": %d,"
3519 " \"filename\":\"slow.txt\"}]", 3615 " \"incognito\": true,"
3520 result_id))); 3616 " \"filename\":\"slow.txt\"}]",
3617 result_id)));
3521 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3618 ASSERT_TRUE(item->GetTargetFilePath().empty());
3522 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3619 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3523 3620
3524 // Respond to the onDeterminingFilename. 3621 // Respond to the onDeterminingFilename.
3525 error = ""; 3622 error = "";
3526 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3623 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3527 current_browser()->profile(), 3624 current_browser()->profile(),
3528 true, 3625 true,
3529 GetExtensionId(), 3626 GetExtensionId(),
3530 result_id, 3627 result_id,
3531 base::FilePath(FILE_PATH_LITERAL("42.txt")), 3628 base::FilePath(FILE_PATH_LITERAL("42.txt")),
3532 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 3629 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
3533 &error)); 3630 &error));
3534 EXPECT_EQ("", error); 3631 EXPECT_EQ("", error);
3535 3632
3536 // The download should complete successfully. 3633 // The download should complete successfully.
3537 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3634 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3538 base::StringPrintf("[{\"id\": %d," 3635 base::StringPrintf(
3539 " \"filename\": {" 3636 "[{\"id\": %d,"
3540 " \"previous\": \"\"," 3637 " \"filename\": {"
3541 " \"current\": \"%s\"}}]", 3638 " \"previous\": \"\","
3542 result_id, 3639 " \"current\": \"%s\"}}]",
3543 GetFilename("42 (1).txt").c_str()))); 3640 result_id,
3544 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3641 GetFilename("42 (1).txt").c_str())));
3545 base::StringPrintf("[{\"id\": %d," 3642 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3546 " \"state\": {" 3643 base::StringPrintf(
3547 " \"previous\": \"in_progress\"," 3644 "[{\"id\": %d,"
3548 " \"current\": \"complete\"}}]", 3645 " \"state\": {"
3549 result_id))); 3646 " \"previous\": \"in_progress\","
3647 " \"current\": \"complete\"}}]",
3648 result_id)));
3550 } 3649 }
3551 3650
3552 #if defined(OS_WIN) 3651 #if defined(OS_WIN)
3553 // This test is very flaky on Win XP and Aura. http://crbug.com/248438 3652 // This test is very flaky on Win XP and Aura. http://crbug.com/248438
3554 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume \ 3653 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume \
3555 DISABLED_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume 3654 DISABLED_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume
3556 #else 3655 #else
3557 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume \ 3656 #define MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume \
3558 DownloadExtensionTest_OnDeterminingFilename_InterruptedResume 3657 DownloadExtensionTest_OnDeterminingFilename_InterruptedResume
3559 #endif 3658 #endif
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3597 // There should be only one IN_PROGRESS item. 3696 // There should be only one IN_PROGRESS item.
3598 EXPECT_EQ(NULL, item); 3697 EXPECT_EQ(NULL, item);
3599 item = *iter; 3698 item = *iter;
3600 } 3699 }
3601 } 3700 }
3602 ASSERT_TRUE(item); 3701 ASSERT_TRUE(item);
3603 } 3702 }
3604 ScopedCancellingItem canceller(item); 3703 ScopedCancellingItem canceller(item);
3605 3704
3606 // Wait for the onCreated and onDeterminingFilename event. 3705 // Wait for the onCreated and onDeterminingFilename event.
3607 ASSERT_TRUE(WaitFor(api::OnCreated::kEventName, 3706 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName,
3608 base::StringPrintf("[{\"danger\": \"safe\"," 3707 base::StringPrintf(
3609 " \"incognito\": false," 3708 "[{\"danger\": \"safe\","
3610 " \"id\": %d," 3709 " \"incognito\": false,"
3611 " \"mime\": \"application/octet-stream\"," 3710 " \"id\": %d,"
3612 " \"paused\": false}]", 3711 " \"mime\": \"application/octet-stream\","
3613 item->GetId()))); 3712 " \"paused\": false}]",
3614 ASSERT_TRUE(WaitFor( 3713 item->GetId())));
3615 api::OnDeterminingFilename::kEventName, 3714 ASSERT_TRUE(WaitFor(downloads::OnDeterminingFilename::kEventName,
3616 base::StringPrintf("[{\"id\": %d," 3715 base::StringPrintf(
3617 " \"incognito\": false," 3716 "[{\"id\": %d,"
3618 " \"filename\":\"download-unknown-size\"}]", 3717 " \"incognito\": false,"
3619 item->GetId()))); 3718 " \"filename\":\"download-unknown-size\"}]",
3719 item->GetId())));
3620 ASSERT_TRUE(item->GetTargetFilePath().empty()); 3720 ASSERT_TRUE(item->GetTargetFilePath().empty());
3621 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 3721 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
3622 3722
3623 ClearEvents(); 3723 ClearEvents();
3624 ui_test_utils::NavigateToURLWithDisposition( 3724 ui_test_utils::NavigateToURLWithDisposition(
3625 current_browser(), 3725 current_browser(),
3626 GURL(URLRequestSlowDownloadJob::kErrorDownloadUrl), 3726 GURL(URLRequestSlowDownloadJob::kErrorDownloadUrl),
3627 NEW_BACKGROUND_TAB, 3727 NEW_BACKGROUND_TAB,
3628 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 3728 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
3629 3729
3630 // Errors caught before filename determination are delayed until after 3730 // Errors caught before filename determination are delayed until after
3631 // filename determination. 3731 // filename determination.
3632 std::string error; 3732 std::string error;
3633 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( 3733 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename(
3634 current_browser()->profile(), 3734 current_browser()->profile(),
3635 false, 3735 false,
3636 GetExtensionId(), 3736 GetExtensionId(),
3637 item->GetId(), 3737 item->GetId(),
3638 base::FilePath(FILE_PATH_LITERAL("42.txt")), 3738 base::FilePath(FILE_PATH_LITERAL("42.txt")),
3639 api::FILENAME_CONFLICT_ACTION_UNIQUIFY, 3739 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
3640 &error)) << error; 3740 &error))
3741 << error;
3641 EXPECT_EQ("", error); 3742 EXPECT_EQ("", error);
3642 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3743 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3643 base::StringPrintf("[{\"id\": %d," 3744 base::StringPrintf(
3644 " \"filename\": {" 3745 "[{\"id\": %d,"
3645 " \"previous\": \"\"," 3746 " \"filename\": {"
3646 " \"current\": \"%s\"}}]", 3747 " \"previous\": \"\","
3647 item->GetId(), 3748 " \"current\": \"%s\"}}]",
3648 GetFilename("42.txt").c_str()))); 3749 item->GetId(),
3750 GetFilename("42.txt").c_str())));
3649 3751
3650 content::DownloadUpdatedObserver interrupted(item, base::Bind( 3752 content::DownloadUpdatedObserver interrupted(item, base::Bind(
3651 ItemIsInterrupted)); 3753 ItemIsInterrupted));
3652 ASSERT_TRUE(interrupted.WaitForEvent()); 3754 ASSERT_TRUE(interrupted.WaitForEvent());
3653 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3755 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3654 base::StringPrintf("[{\"id\": %d," 3756 base::StringPrintf(
3655 " \"error\":{\"current\":\"NETWORK_FAILED\"}," 3757 "[{\"id\": %d,"
3656 " \"state\":{" 3758 " \"error\":{\"current\":\"NETWORK_FAILED\"},"
3657 " \"previous\":\"in_progress\"," 3759 " \"state\":{"
3658 " \"current\":\"interrupted\"}}]", 3760 " \"previous\":\"in_progress\","
3659 item->GetId()))); 3761 " \"current\":\"interrupted\"}}]",
3762 item->GetId())));
3660 3763
3661 ClearEvents(); 3764 ClearEvents();
3662 // Downloads that are restarted on resumption trigger another download target 3765 // Downloads that are restarted on resumption trigger another download target
3663 // determination. 3766 // determination.
3664 RemoveFilenameDeterminer(host); 3767 RemoveFilenameDeterminer(host);
3665 item->Resume(); 3768 item->Resume();
3666 3769
3667 // Errors caught before filename determination is complete are delayed until 3770 // Errors caught before filename determination is complete are delayed until
3668 // after filename determination so that, on resumption, filename determination 3771 // after filename determination so that, on resumption, filename determination
3669 // does not need to be re-done. So, there will not be a second 3772 // does not need to be re-done. So, there will not be a second
3670 // onDeterminingFilename event. 3773 // onDeterminingFilename event.
3671 3774
3672 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3775 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3673 base::StringPrintf("[{\"id\": %d," 3776 base::StringPrintf(
3674 " \"error\":{\"previous\":\"NETWORK_FAILED\"}," 3777 "[{\"id\": %d,"
3675 " \"state\":{" 3778 " \"error\":{\"previous\":\"NETWORK_FAILED\"},"
3676 " \"previous\":\"interrupted\"," 3779 " \"state\":{"
3677 " \"current\":\"in_progress\"}}]", 3780 " \"previous\":\"interrupted\","
3678 item->GetId()))); 3781 " \"current\":\"in_progress\"}}]",
3782 item->GetId())));
3679 3783
3680 ClearEvents(); 3784 ClearEvents();
3681 FinishPendingSlowDownloads(); 3785 FinishPendingSlowDownloads();
3682 3786
3683 // The download should complete successfully. 3787 // The download should complete successfully.
3684 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, 3788 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3685 base::StringPrintf("[{\"id\": %d," 3789 base::StringPrintf(
3686 " \"state\": {" 3790 "[{\"id\": %d,"
3687 " \"previous\": \"in_progress\"," 3791 " \"state\": {"
3688 " \"current\": \"complete\"}}]", 3792 " \"previous\": \"in_progress\","
3689 item->GetId()))); 3793 " \"current\": \"complete\"}}]",
3794 item->GetId())));
3690 } 3795 }
3691 3796
3692 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 3797 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
3693 DownloadExtensionTest_SetShelfEnabled) { 3798 DownloadExtensionTest_SetShelfEnabled) {
3694 LoadExtension("downloads_split"); 3799 LoadExtension("downloads_split");
3695 EXPECT_TRUE(RunFunction(new DownloadsSetShelfEnabledFunction(), "[false]")); 3800 EXPECT_TRUE(RunFunction(new DownloadsSetShelfEnabledFunction(), "[false]"));
3696 EXPECT_FALSE(DownloadServiceFactory::GetForBrowserContext( 3801 EXPECT_FALSE(DownloadServiceFactory::GetForBrowserContext(
3697 browser()->profile())->IsShelfEnabled()); 3802 browser()->profile())->IsShelfEnabled());
3698 EXPECT_TRUE(RunFunction(new DownloadsSetShelfEnabledFunction(), "[true]")); 3803 EXPECT_TRUE(RunFunction(new DownloadsSetShelfEnabledFunction(), "[true]"));
3699 EXPECT_TRUE(DownloadServiceFactory::GetForBrowserContext( 3804 EXPECT_TRUE(DownloadServiceFactory::GetForBrowserContext(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3731 // button; wait until the download completes. 3836 // button; wait until the download completes.
3732 LoadExtension("downloads_split"); 3837 LoadExtension("downloads_split");
3733 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 3838 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
3734 new DownloadsDownloadFunction(), 3839 new DownloadsDownloadFunction(),
3735 "[{\"url\": \"data:,\", \"filename\": \"dangerous.swf\"}]")); 3840 "[{\"url\": \"data:,\", \"filename\": \"dangerous.swf\"}]"));
3736 ASSERT_TRUE(result.get()); 3841 ASSERT_TRUE(result.get());
3737 int result_id = -1; 3842 int result_id = -1;
3738 ASSERT_TRUE(result->GetAsInteger(&result_id)); 3843 ASSERT_TRUE(result->GetAsInteger(&result_id));
3739 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 3844 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
3740 ASSERT_TRUE(item); 3845 ASSERT_TRUE(item);
3741 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, base::StringPrintf( 3846 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName,
3742 "[{\"id\": %d, " 3847 base::StringPrintf(
3743 " \"danger\": {" 3848 "[{\"id\": %d, "
3744 " \"previous\": \"safe\"," 3849 " \"danger\": {"
3745 " \"current\": \"file\"}}]", 3850 " \"previous\": \"safe\","
3746 result_id))); 3851 " \"current\": \"file\"}}]",
3852 result_id)));
3747 ASSERT_TRUE(item->IsDangerous()); 3853 ASSERT_TRUE(item->IsDangerous());
3748 ScopedCancellingItem canceller(item); 3854 ScopedCancellingItem canceller(item);
3749 scoped_ptr<content::DownloadTestObserver> observer( 3855 scoped_ptr<content::DownloadTestObserver> observer(
3750 new content::DownloadTestObserverTerminal( 3856 new content::DownloadTestObserverTerminal(
3751 GetCurrentManager(), 1, 3857 GetCurrentManager(), 1,
3752 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); 3858 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE));
3753 DownloadsAcceptDangerFunction::OnPromptCreatedCallback callback = 3859 DownloadsAcceptDangerFunction::OnPromptCreatedCallback callback =
3754 base::Bind(&OnDangerPromptCreated); 3860 base::Bind(&OnDangerPromptCreated);
3755 DownloadsAcceptDangerFunction::OnPromptCreatedForTesting( 3861 DownloadsAcceptDangerFunction::OnPromptCreatedForTesting(
3756 &callback); 3862 &callback);
3757 BrowserActionTestUtil(browser()).Press(0); 3863 BrowserActionTestUtil(browser()).Press(0);
3758 observer->WaitForFinished(); 3864 observer->WaitForFinished();
3759 } 3865 }
3760 3866
3761 class DownloadsApiTest : public ExtensionApiTest { 3867 class DownloadsApiTest : public ExtensionApiTest {
3762 public: 3868 public:
3763 DownloadsApiTest() {} 3869 DownloadsApiTest() {}
3764 virtual ~DownloadsApiTest() {} 3870 virtual ~DownloadsApiTest() {}
3765 private: 3871 private:
3766 DISALLOW_COPY_AND_ASSIGN(DownloadsApiTest); 3872 DISALLOW_COPY_AND_ASSIGN(DownloadsApiTest);
3767 }; 3873 };
3768 3874
3769 3875
3770 IN_PROC_BROWSER_TEST_F(DownloadsApiTest, DownloadsApiTest) { 3876 IN_PROC_BROWSER_TEST_F(DownloadsApiTest, DownloadsApiTest) {
3771 ASSERT_TRUE(RunExtensionTest("downloads")) << message_; 3877 ASSERT_TRUE(RunExtensionTest("downloads")) << message_;
3772 } 3878 }
3773 3879
3774 TEST(DownloadInterruptReasonEnumsSynced, 3880 TEST(DownloadInterruptReasonEnumsSynced,
3775 DownloadInterruptReasonEnumsSynced) { 3881 DownloadInterruptReasonEnumsSynced) {
3776 #define INTERRUPT_REASON(name, value) \ 3882 #define INTERRUPT_REASON(name, value) \
3777 EXPECT_EQ(InterruptReasonContentToExtension( \ 3883 EXPECT_EQ(InterruptReasonContentToExtension( \
3778 content::DOWNLOAD_INTERRUPT_REASON_##name), \ 3884 content::DOWNLOAD_INTERRUPT_REASON_##name), \
3779 api::INTERRUPT_REASON_##name); \ 3885 downloads::INTERRUPT_REASON_##name); \
3780 EXPECT_EQ(InterruptReasonExtensionToContent( \ 3886 EXPECT_EQ( \
3781 api::INTERRUPT_REASON_##name), \ 3887 InterruptReasonExtensionToContent(downloads::INTERRUPT_REASON_##name), \
3782 content::DOWNLOAD_INTERRUPT_REASON_##name); 3888 content::DOWNLOAD_INTERRUPT_REASON_##name);
3783 #include "content/public/browser/download_interrupt_reason_values.h" 3889 #include "content/public/browser/download_interrupt_reason_values.h"
3784 #undef INTERRUPT_REASON 3890 #undef INTERRUPT_REASON
3785 } 3891 }
3786 3892
3787 TEST(ExtensionDetermineDownloadFilenameInternal, 3893 TEST(ExtensionDetermineDownloadFilenameInternal,
3788 ExtensionDetermineDownloadFilenameInternal) { 3894 ExtensionDetermineDownloadFilenameInternal) {
3789
3790 std::string winner_id; 3895 std::string winner_id;
3791 base::FilePath filename; 3896 base::FilePath filename;
3792 extensions::api::downloads::FilenameConflictAction conflict_action = 3897 downloads::FilenameConflictAction conflict_action =
3793 api::FILENAME_CONFLICT_ACTION_UNIQUIFY; 3898 downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY;
3794 extensions::ExtensionWarningSet warnings; 3899 extensions::ExtensionWarningSet warnings;
3795 3900
3796 // Empty incumbent determiner 3901 // Empty incumbent determiner
3797 warnings.clear(); 3902 warnings.clear();
3798 ExtensionDownloadsEventRouter::DetermineFilenameInternal( 3903 ExtensionDownloadsEventRouter::DetermineFilenameInternal(
3799 base::FilePath(FILE_PATH_LITERAL("a")), 3904 base::FilePath(FILE_PATH_LITERAL("a")),
3800 api::FILENAME_CONFLICT_ACTION_OVERWRITE, 3905 downloads::FILENAME_CONFLICT_ACTION_OVERWRITE,
3801 "suggester", 3906 "suggester",
3802 base::Time::Now(), 3907 base::Time::Now(),
3803 "", 3908 "",
3804 base::Time(), 3909 base::Time(),
3805 &winner_id, 3910 &winner_id,
3806 &filename, 3911 &filename,
3807 &conflict_action, 3912 &conflict_action,
3808 &warnings); 3913 &warnings);
3809 EXPECT_EQ("suggester", winner_id); 3914 EXPECT_EQ("suggester", winner_id);
3810 EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value()); 3915 EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value());
3811 EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action); 3916 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action);
3812 EXPECT_TRUE(warnings.empty()); 3917 EXPECT_TRUE(warnings.empty());
3813 3918
3814 // Incumbent wins 3919 // Incumbent wins
3815 warnings.clear(); 3920 warnings.clear();
3816 ExtensionDownloadsEventRouter::DetermineFilenameInternal( 3921 ExtensionDownloadsEventRouter::DetermineFilenameInternal(
3817 base::FilePath(FILE_PATH_LITERAL("b")), 3922 base::FilePath(FILE_PATH_LITERAL("b")),
3818 api::FILENAME_CONFLICT_ACTION_PROMPT, 3923 downloads::FILENAME_CONFLICT_ACTION_PROMPT,
3819 "suggester", 3924 "suggester",
3820 base::Time::Now() - base::TimeDelta::FromDays(1), 3925 base::Time::Now() - base::TimeDelta::FromDays(1),
3821 "incumbent", 3926 "incumbent",
3822 base::Time::Now(), 3927 base::Time::Now(),
3823 &winner_id, 3928 &winner_id,
3824 &filename, 3929 &filename,
3825 &conflict_action, 3930 &conflict_action,
3826 &warnings); 3931 &warnings);
3827 EXPECT_EQ("incumbent", winner_id); 3932 EXPECT_EQ("incumbent", winner_id);
3828 EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value()); 3933 EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value());
3829 EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action); 3934 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action);
3830 EXPECT_FALSE(warnings.empty()); 3935 EXPECT_FALSE(warnings.empty());
3831 EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict, 3936 EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict,
3832 warnings.begin()->warning_type()); 3937 warnings.begin()->warning_type());
3833 EXPECT_EQ("suggester", warnings.begin()->extension_id()); 3938 EXPECT_EQ("suggester", warnings.begin()->extension_id());
3834 3939
3835 // Suggester wins 3940 // Suggester wins
3836 warnings.clear(); 3941 warnings.clear();
3837 ExtensionDownloadsEventRouter::DetermineFilenameInternal( 3942 ExtensionDownloadsEventRouter::DetermineFilenameInternal(
3838 base::FilePath(FILE_PATH_LITERAL("b")), 3943 base::FilePath(FILE_PATH_LITERAL("b")),
3839 api::FILENAME_CONFLICT_ACTION_PROMPT, 3944 downloads::FILENAME_CONFLICT_ACTION_PROMPT,
3840 "suggester", 3945 "suggester",
3841 base::Time::Now(), 3946 base::Time::Now(),
3842 "incumbent", 3947 "incumbent",
3843 base::Time::Now() - base::TimeDelta::FromDays(1), 3948 base::Time::Now() - base::TimeDelta::FromDays(1),
3844 &winner_id, 3949 &winner_id,
3845 &filename, 3950 &filename,
3846 &conflict_action, 3951 &conflict_action,
3847 &warnings); 3952 &warnings);
3848 EXPECT_EQ("suggester", winner_id); 3953 EXPECT_EQ("suggester", winner_id);
3849 EXPECT_EQ(FILE_PATH_LITERAL("b"), filename.value()); 3954 EXPECT_EQ(FILE_PATH_LITERAL("b"), filename.value());
3850 EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); 3955 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action);
3851 EXPECT_FALSE(warnings.empty()); 3956 EXPECT_FALSE(warnings.empty());
3852 EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict, 3957 EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict,
3853 warnings.begin()->warning_type()); 3958 warnings.begin()->warning_type());
3854 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); 3959 EXPECT_EQ("incumbent", warnings.begin()->extension_id());
3855 } 3960 }
3856 3961
3962 } // namespace extensions
3963
3857 #endif // http://crbug.com/3061144 3964 #endif // http://crbug.com/3061144
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | chrome/browser/ui/webui/downloads_dom_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698