OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // 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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 profile_, | 161 profile_, |
162 event_name_.c_str(), | 162 event_name_.c_str(), |
163 json_args_.c_str(), | 163 json_args_.c_str(), |
164 caught_.ToJsTime()); | 164 caught_.ToJsTime()); |
165 } | 165 } |
166 | 166 |
167 private: | 167 private: |
168 Profile* profile_; | 168 Profile* profile_; |
169 std::string event_name_; | 169 std::string event_name_; |
170 std::string json_args_; | 170 std::string json_args_; |
171 scoped_ptr<base::Value> args_; | 171 std::unique_ptr<base::Value> args_; |
172 base::Time caught_; | 172 base::Time caught_; |
173 | 173 |
174 DISALLOW_COPY_AND_ASSIGN(Event); | 174 DISALLOW_COPY_AND_ASSIGN(Event); |
175 }; | 175 }; |
176 | 176 |
177 typedef ExtensionDownloadsEventRouter::DownloadsNotificationSource | 177 typedef ExtensionDownloadsEventRouter::DownloadsNotificationSource |
178 DownloadsNotificationSource; | 178 DownloadsNotificationSource; |
179 | 179 |
180 void Observe(int type, | 180 void Observe(int type, |
181 const content::NotificationSource& source, | 181 const content::NotificationSource& source, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 waiting_ = false; | 230 waiting_ = false; |
231 } | 231 } |
232 waiting_for_.reset(); | 232 waiting_for_.reset(); |
233 last_wait_ = base::Time::Now(); | 233 last_wait_ = base::Time::Now(); |
234 return success; | 234 return success; |
235 } | 235 } |
236 | 236 |
237 private: | 237 private: |
238 bool waiting_; | 238 bool waiting_; |
239 base::Time last_wait_; | 239 base::Time last_wait_; |
240 scoped_ptr<Event> waiting_for_; | 240 std::unique_ptr<Event> waiting_for_; |
241 content::NotificationRegistrar registrar_; | 241 content::NotificationRegistrar registrar_; |
242 std::deque<Event*> events_; | 242 std::deque<Event*> events_; |
243 | 243 |
244 DISALLOW_COPY_AND_ASSIGN(DownloadsEventsListener); | 244 DISALLOW_COPY_AND_ASSIGN(DownloadsEventsListener); |
245 }; | 245 }; |
246 | 246 |
247 class DownloadExtensionTest : public ExtensionApiTest { | 247 class DownloadExtensionTest : public ExtensionApiTest { |
248 public: | 248 public: |
249 DownloadExtensionTest() | 249 DownloadExtensionTest() |
250 : extension_(NULL), | 250 : extension_(NULL), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 void RemoveFilenameDeterminer(content::RenderProcessHost* host) { | 309 void RemoveFilenameDeterminer(content::RenderProcessHost* host) { |
310 EventRouter::Get(current_browser()->profile())->RemoveEventListener( | 310 EventRouter::Get(current_browser()->profile())->RemoveEventListener( |
311 downloads::OnDeterminingFilename::kEventName, host, GetExtensionId()); | 311 downloads::OnDeterminingFilename::kEventName, host, 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 void SetUpOnMainThread() override { | 317 void SetUpOnMainThread() override { |
318 base::FeatureList::ClearInstanceForTesting(); | 318 base::FeatureList::ClearInstanceForTesting(); |
319 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | 319 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
320 feature_list->InitializeFromCommandLine( | 320 feature_list->InitializeFromCommandLine( |
321 features::kDownloadResumption.name, std::string()); | 321 features::kDownloadResumption.name, std::string()); |
322 base::FeatureList::SetInstance(std::move(feature_list)); | 322 base::FeatureList::SetInstance(std::move(feature_list)); |
323 | 323 |
324 ExtensionApiTest::SetUpOnMainThread(); | 324 ExtensionApiTest::SetUpOnMainThread(); |
325 BrowserThread::PostTask( | 325 BrowserThread::PostTask( |
326 BrowserThread::IO, FROM_HERE, | 326 BrowserThread::IO, FROM_HERE, |
327 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 327 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
328 InProcessBrowserTest::SetUpOnMainThread(); | 328 InProcessBrowserTest::SetUpOnMainThread(); |
329 GoOnTheRecord(); | 329 GoOnTheRecord(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 } | 452 } |
453 | 453 |
454 // Order by ID so that they are in the order that we created them. | 454 // Order by ID so that they are in the order that we created them. |
455 std::sort(items->begin(), items->end(), download_id_comparator); | 455 std::sort(items->begin(), items->end(), download_id_comparator); |
456 return true; | 456 return true; |
457 } | 457 } |
458 | 458 |
459 void CreateSlowTestDownloads( | 459 void CreateSlowTestDownloads( |
460 size_t count, DownloadManager::DownloadVector* items) { | 460 size_t count, DownloadManager::DownloadVector* items) { |
461 for (size_t i = 0; i < count; ++i) { | 461 for (size_t i = 0; i < count; ++i) { |
462 scoped_ptr<content::DownloadTestObserver> observer( | 462 std::unique_ptr<content::DownloadTestObserver> observer( |
463 CreateInProgressDownloadObserver(1)); | 463 CreateInProgressDownloadObserver(1)); |
464 GURL slow_download_url(net::URLRequestSlowDownloadJob::kUnknownSizeUrl); | 464 GURL slow_download_url(net::URLRequestSlowDownloadJob::kUnknownSizeUrl); |
465 ui_test_utils::NavigateToURL(current_browser(), slow_download_url); | 465 ui_test_utils::NavigateToURL(current_browser(), slow_download_url); |
466 observer->WaitForFinished(); | 466 observer->WaitForFinished(); |
467 EXPECT_EQ( | 467 EXPECT_EQ( |
468 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); | 468 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); |
469 } | 469 } |
470 GetCurrentManager()->GetAllDownloads(items); | 470 GetCurrentManager()->GetAllDownloads(items); |
471 ASSERT_EQ(count, items->size()); | 471 ASSERT_EQ(count, items->size()); |
472 } | 472 } |
473 | 473 |
474 DownloadItem* CreateSlowTestDownload() { | 474 DownloadItem* CreateSlowTestDownload() { |
475 scoped_ptr<content::DownloadTestObserver> observer( | 475 std::unique_ptr<content::DownloadTestObserver> observer( |
476 CreateInProgressDownloadObserver(1)); | 476 CreateInProgressDownloadObserver(1)); |
477 GURL slow_download_url(net::URLRequestSlowDownloadJob::kUnknownSizeUrl); | 477 GURL slow_download_url(net::URLRequestSlowDownloadJob::kUnknownSizeUrl); |
478 DownloadManager* manager = GetCurrentManager(); | 478 DownloadManager* manager = GetCurrentManager(); |
479 | 479 |
480 EXPECT_EQ(0, manager->NonMaliciousInProgressCount()); | 480 EXPECT_EQ(0, manager->NonMaliciousInProgressCount()); |
481 EXPECT_EQ(0, manager->InProgressCount()); | 481 EXPECT_EQ(0, manager->InProgressCount()); |
482 if (manager->InProgressCount() != 0) | 482 if (manager->InProgressCount() != 0) |
483 return NULL; | 483 return NULL; |
484 | 484 |
485 ui_test_utils::NavigateToURL(current_browser(), slow_download_url); | 485 ui_test_utils::NavigateToURL(current_browser(), slow_download_url); |
(...skipping 10 matching lines...) Expand all Loading... |
496 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { | 496 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { |
497 // There should be only one IN_PROGRESS item. | 497 // There should be only one IN_PROGRESS item. |
498 EXPECT_EQ(NULL, new_item); | 498 EXPECT_EQ(NULL, new_item); |
499 new_item = *iter; | 499 new_item = *iter; |
500 } | 500 } |
501 } | 501 } |
502 return new_item; | 502 return new_item; |
503 } | 503 } |
504 | 504 |
505 void FinishPendingSlowDownloads() { | 505 void FinishPendingSlowDownloads() { |
506 scoped_ptr<content::DownloadTestObserver> observer( | 506 std::unique_ptr<content::DownloadTestObserver> observer( |
507 CreateDownloadObserver(1)); | 507 CreateDownloadObserver(1)); |
508 GURL finish_url(net::URLRequestSlowDownloadJob::kFinishDownloadUrl); | 508 GURL finish_url(net::URLRequestSlowDownloadJob::kFinishDownloadUrl); |
509 ui_test_utils::NavigateToURLWithDisposition( | 509 ui_test_utils::NavigateToURLWithDisposition( |
510 current_browser(), finish_url, NEW_FOREGROUND_TAB, | 510 current_browser(), finish_url, NEW_FOREGROUND_TAB, |
511 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 511 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
512 observer->WaitForFinished(); | 512 observer->WaitForFinished(); |
513 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 513 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
514 } | 514 } |
515 | 515 |
516 content::DownloadTestObserver* CreateDownloadObserver(size_t download_count) { | 516 content::DownloadTestObserver* CreateDownloadObserver(size_t download_count) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 SetUpExtensionFunction(function.get()); | 561 SetUpExtensionFunction(function.get()); |
562 return extension_function_test_utils::RunFunctionAndReturnError( | 562 return extension_function_test_utils::RunFunctionAndReturnError( |
563 function.get(), args, browser(), GetFlags()); | 563 function.get(), args, browser(), GetFlags()); |
564 } | 564 } |
565 | 565 |
566 bool RunFunctionAndReturnString( | 566 bool RunFunctionAndReturnString( |
567 scoped_refptr<UIThreadExtensionFunction> function, | 567 scoped_refptr<UIThreadExtensionFunction> function, |
568 const std::string& args, | 568 const std::string& args, |
569 std::string* result_string) { | 569 std::string* result_string) { |
570 SetUpExtensionFunction(function.get()); | 570 SetUpExtensionFunction(function.get()); |
571 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(function, args)); | 571 std::unique_ptr<base::Value> result( |
| 572 RunFunctionAndReturnResult(function, args)); |
572 EXPECT_TRUE(result.get()); | 573 EXPECT_TRUE(result.get()); |
573 return result.get() && result->GetAsString(result_string); | 574 return result.get() && result->GetAsString(result_string); |
574 } | 575 } |
575 | 576 |
576 std::string DownloadItemIdAsArgList(const DownloadItem* download_item) { | 577 std::string DownloadItemIdAsArgList(const DownloadItem* download_item) { |
577 return base::StringPrintf("[%d]", download_item->GetId()); | 578 return base::StringPrintf("[%d]", download_item->GetId()); |
578 } | 579 } |
579 | 580 |
580 const base::FilePath& downloads_directory() { | 581 const base::FilePath& downloads_directory() { |
581 return downloads_directory_.path(); | 582 return downloads_directory_.path(); |
(...skipping 18 matching lines...) Expand all Loading... |
600 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); | 601 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); |
601 current_browser()->profile()->GetPrefs()->SetFilePath( | 602 current_browser()->profile()->GetPrefs()->SetFilePath( |
602 prefs::kDownloadDefaultDirectory, | 603 prefs::kDownloadDefaultDirectory, |
603 downloads_directory_.path()); | 604 downloads_directory_.path()); |
604 } | 605 } |
605 | 606 |
606 base::ScopedTempDir downloads_directory_; | 607 base::ScopedTempDir downloads_directory_; |
607 const Extension* extension_; | 608 const Extension* extension_; |
608 Browser* incognito_browser_; | 609 Browser* incognito_browser_; |
609 Browser* current_browser_; | 610 Browser* current_browser_; |
610 scoped_ptr<DownloadsEventsListener> events_listener_; | 611 std::unique_ptr<DownloadsEventsListener> events_listener_; |
611 | 612 |
612 DISALLOW_COPY_AND_ASSIGN(DownloadExtensionTest); | 613 DISALLOW_COPY_AND_ASSIGN(DownloadExtensionTest); |
613 }; | 614 }; |
614 | 615 |
615 class MockIconExtractorImpl : public DownloadFileIconExtractor { | 616 class MockIconExtractorImpl : public DownloadFileIconExtractor { |
616 public: | 617 public: |
617 MockIconExtractorImpl(const base::FilePath& path, | 618 MockIconExtractorImpl(const base::FilePath& path, |
618 IconLoader::IconSize icon_size, | 619 IconLoader::IconSize icon_size, |
619 const std::string& response) | 620 const std::string& response) |
620 : expected_path_(path), | 621 : expected_path_(path), |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 error = RunFunctionAndReturnError( | 928 error = RunFunctionAndReturnError( |
928 new DownloadsResumeFunction(), "[-42]"); | 929 new DownloadsResumeFunction(), "[-42]"); |
929 EXPECT_STREQ(errors::kInvalidId, error.c_str()); | 930 EXPECT_STREQ(errors::kInvalidId, error.c_str()); |
930 | 931 |
931 // Calling removeFile on a non-existent download yields kInvalidId. | 932 // Calling removeFile on a non-existent download yields kInvalidId. |
932 error = RunFunctionAndReturnError( | 933 error = RunFunctionAndReturnError( |
933 new DownloadsRemoveFileFunction(), "[-42]"); | 934 new DownloadsRemoveFileFunction(), "[-42]"); |
934 EXPECT_STREQ(errors::kInvalidId, error.c_str()); | 935 EXPECT_STREQ(errors::kInvalidId, error.c_str()); |
935 | 936 |
936 int id = download_item->GetId(); | 937 int id = download_item->GetId(); |
937 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 938 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
938 new DownloadsEraseFunction(), | 939 new DownloadsEraseFunction(), base::StringPrintf("[{\"id\": %d}]", id))); |
939 base::StringPrintf("[{\"id\": %d}]", id))); | |
940 DownloadManager::DownloadVector items; | 940 DownloadManager::DownloadVector items; |
941 GetCurrentManager()->GetAllDownloads(&items); | 941 GetCurrentManager()->GetAllDownloads(&items); |
942 EXPECT_EQ(0UL, items.size()); | 942 EXPECT_EQ(0UL, items.size()); |
943 ASSERT_TRUE(result); | 943 ASSERT_TRUE(result); |
944 download_item = NULL; | 944 download_item = NULL; |
945 base::ListValue* result_list = NULL; | 945 base::ListValue* result_list = NULL; |
946 ASSERT_TRUE(result->GetAsList(&result_list)); | 946 ASSERT_TRUE(result->GetAsList(&result_list)); |
947 ASSERT_EQ(1UL, result_list->GetSize()); | 947 ASSERT_EQ(1UL, result_list->GetSize()); |
948 int element = -1; | 948 int element = -1; |
949 ASSERT_TRUE(result_list->GetInteger(0, &element)); | 949 ASSERT_TRUE(result_list->GetInteger(0, &element)); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 EXPECT_STREQ("hello", result_string.c_str()); | 1078 EXPECT_STREQ("hello", result_string.c_str()); |
1079 } | 1079 } |
1080 } | 1080 } |
1081 | 1081 |
1082 // Test passing the empty query to search(). | 1082 // Test passing the empty query to search(). |
1083 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1083 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1084 DownloadExtensionTest_SearchEmptyQuery) { | 1084 DownloadExtensionTest_SearchEmptyQuery) { |
1085 ScopedCancellingItem item(CreateSlowTestDownload()); | 1085 ScopedCancellingItem item(CreateSlowTestDownload()); |
1086 ASSERT_TRUE(item.get()); | 1086 ASSERT_TRUE(item.get()); |
1087 | 1087 |
1088 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1088 std::unique_ptr<base::Value> result( |
1089 new DownloadsSearchFunction(), "[{}]")); | 1089 RunFunctionAndReturnResult(new DownloadsSearchFunction(), "[{}]")); |
1090 ASSERT_TRUE(result.get()); | 1090 ASSERT_TRUE(result.get()); |
1091 base::ListValue* result_list = NULL; | 1091 base::ListValue* result_list = NULL; |
1092 ASSERT_TRUE(result->GetAsList(&result_list)); | 1092 ASSERT_TRUE(result->GetAsList(&result_list)); |
1093 ASSERT_EQ(1UL, result_list->GetSize()); | 1093 ASSERT_EQ(1UL, result_list->GetSize()); |
1094 } | 1094 } |
1095 | 1095 |
1096 // Test the |filenameRegex| parameter for search(). | 1096 // Test the |filenameRegex| parameter for search(). |
1097 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1097 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1098 DownloadExtensionTest_SearchFilenameRegex) { | 1098 DownloadExtensionTest_SearchFilenameRegex) { |
1099 const HistoryDownloadInfo kHistoryInfo[] = { | 1099 const HistoryDownloadInfo kHistoryInfo[] = { |
1100 { FILE_PATH_LITERAL("foobar"), | 1100 { FILE_PATH_LITERAL("foobar"), |
1101 DownloadItem::COMPLETE, | 1101 DownloadItem::COMPLETE, |
1102 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, | 1102 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, |
1103 { FILE_PATH_LITERAL("baz"), | 1103 { FILE_PATH_LITERAL("baz"), |
1104 DownloadItem::COMPLETE, | 1104 DownloadItem::COMPLETE, |
1105 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 1105 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
1106 }; | 1106 }; |
1107 DownloadManager::DownloadVector all_downloads; | 1107 DownloadManager::DownloadVector all_downloads; |
1108 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 1108 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
1109 &all_downloads)); | 1109 &all_downloads)); |
1110 | 1110 |
1111 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1111 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1112 new DownloadsSearchFunction(), "[{\"filenameRegex\": \"foobar\"}]")); | 1112 new DownloadsSearchFunction(), "[{\"filenameRegex\": \"foobar\"}]")); |
1113 ASSERT_TRUE(result.get()); | 1113 ASSERT_TRUE(result.get()); |
1114 base::ListValue* result_list = NULL; | 1114 base::ListValue* result_list = NULL; |
1115 ASSERT_TRUE(result->GetAsList(&result_list)); | 1115 ASSERT_TRUE(result->GetAsList(&result_list)); |
1116 ASSERT_EQ(1UL, result_list->GetSize()); | 1116 ASSERT_EQ(1UL, result_list->GetSize()); |
1117 base::DictionaryValue* item_value = NULL; | 1117 base::DictionaryValue* item_value = NULL; |
1118 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); | 1118 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); |
1119 int item_id = -1; | 1119 int item_id = -1; |
1120 ASSERT_TRUE(item_value->GetInteger("id", &item_id)); | 1120 ASSERT_TRUE(item_value->GetInteger("id", &item_id)); |
1121 ASSERT_EQ(all_downloads[0]->GetId(), static_cast<uint32_t>(item_id)); | 1121 ASSERT_EQ(all_downloads[0]->GetId(), static_cast<uint32_t>(item_id)); |
1122 } | 1122 } |
1123 | 1123 |
1124 // Test the |id| parameter for search(). | 1124 // Test the |id| parameter for search(). |
1125 // | 1125 // |
1126 // http://crbug.com/508949 | 1126 // http://crbug.com/508949 |
1127 #if defined(MEMORY_SANITIZER) | 1127 #if defined(MEMORY_SANITIZER) |
1128 #define MAYBE_DownloadExtensionTest_SearchId DISABLED_DownloadExtensionTest_Sear
chId | 1128 #define MAYBE_DownloadExtensionTest_SearchId DISABLED_DownloadExtensionTest_Sear
chId |
1129 #else | 1129 #else |
1130 #define MAYBE_DownloadExtensionTest_SearchId DownloadExtensionTest_SearchId | 1130 #define MAYBE_DownloadExtensionTest_SearchId DownloadExtensionTest_SearchId |
1131 #endif | 1131 #endif |
1132 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1132 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1133 MAYBE_DownloadExtensionTest_SearchId) { | 1133 MAYBE_DownloadExtensionTest_SearchId) { |
1134 DownloadManager::DownloadVector items; | 1134 DownloadManager::DownloadVector items; |
1135 CreateSlowTestDownloads(2, &items); | 1135 CreateSlowTestDownloads(2, &items); |
1136 ScopedItemVectorCanceller delete_items(&items); | 1136 ScopedItemVectorCanceller delete_items(&items); |
1137 | 1137 |
1138 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1138 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1139 new DownloadsSearchFunction(), base::StringPrintf( | 1139 new DownloadsSearchFunction(), |
1140 "[{\"id\": %u}]", items[0]->GetId()))); | 1140 base::StringPrintf("[{\"id\": %u}]", items[0]->GetId()))); |
1141 ASSERT_TRUE(result.get()); | 1141 ASSERT_TRUE(result.get()); |
1142 base::ListValue* result_list = NULL; | 1142 base::ListValue* result_list = NULL; |
1143 ASSERT_TRUE(result->GetAsList(&result_list)); | 1143 ASSERT_TRUE(result->GetAsList(&result_list)); |
1144 ASSERT_EQ(1UL, result_list->GetSize()); | 1144 ASSERT_EQ(1UL, result_list->GetSize()); |
1145 base::DictionaryValue* item_value = NULL; | 1145 base::DictionaryValue* item_value = NULL; |
1146 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); | 1146 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); |
1147 int item_id = -1; | 1147 int item_id = -1; |
1148 ASSERT_TRUE(item_value->GetInteger("id", &item_id)); | 1148 ASSERT_TRUE(item_value->GetInteger("id", &item_id)); |
1149 ASSERT_EQ(items[0]->GetId(), static_cast<uint32_t>(item_id)); | 1149 ASSERT_EQ(items[0]->GetId(), static_cast<uint32_t>(item_id)); |
1150 } | 1150 } |
1151 | 1151 |
1152 // Test specifying both the |id| and |filename| parameters for search(). | 1152 // Test specifying both the |id| and |filename| parameters for search(). |
1153 // | 1153 // |
1154 // http://crbug.com/508949 | 1154 // http://crbug.com/508949 |
1155 #if defined(MEMORY_SANITIZER) | 1155 #if defined(MEMORY_SANITIZER) |
1156 #define MAYBE_DownloadExtensionTest_SearchIdAndFilename DISABLED_DownloadExtensi
onTest_SearchIdAndFilename | 1156 #define MAYBE_DownloadExtensionTest_SearchIdAndFilename DISABLED_DownloadExtensi
onTest_SearchIdAndFilename |
1157 #else | 1157 #else |
1158 #define MAYBE_DownloadExtensionTest_SearchIdAndFilename DownloadExtensionTest_Se
archIdAndFilename | 1158 #define MAYBE_DownloadExtensionTest_SearchIdAndFilename DownloadExtensionTest_Se
archIdAndFilename |
1159 #endif | 1159 #endif |
1160 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1160 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1161 MAYBE_DownloadExtensionTest_SearchIdAndFilename) { | 1161 MAYBE_DownloadExtensionTest_SearchIdAndFilename) { |
1162 DownloadManager::DownloadVector items; | 1162 DownloadManager::DownloadVector items; |
1163 CreateSlowTestDownloads(2, &items); | 1163 CreateSlowTestDownloads(2, &items); |
1164 ScopedItemVectorCanceller delete_items(&items); | 1164 ScopedItemVectorCanceller delete_items(&items); |
1165 | 1165 |
1166 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1166 std::unique_ptr<base::Value> result( |
1167 new DownloadsSearchFunction(), | 1167 RunFunctionAndReturnResult(new DownloadsSearchFunction(), |
1168 "[{\"id\": 0, \"filename\": \"foobar\"}]")); | 1168 "[{\"id\": 0, \"filename\": \"foobar\"}]")); |
1169 ASSERT_TRUE(result.get()); | 1169 ASSERT_TRUE(result.get()); |
1170 base::ListValue* result_list = NULL; | 1170 base::ListValue* result_list = NULL; |
1171 ASSERT_TRUE(result->GetAsList(&result_list)); | 1171 ASSERT_TRUE(result->GetAsList(&result_list)); |
1172 ASSERT_EQ(0UL, result_list->GetSize()); | 1172 ASSERT_EQ(0UL, result_list->GetSize()); |
1173 } | 1173 } |
1174 | 1174 |
1175 // Test a single |orderBy| parameter for search(). | 1175 // Test a single |orderBy| parameter for search(). |
1176 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1176 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1177 DownloadExtensionTest_SearchOrderBy) { | 1177 DownloadExtensionTest_SearchOrderBy) { |
1178 const HistoryDownloadInfo kHistoryInfo[] = { | 1178 const HistoryDownloadInfo kHistoryInfo[] = { |
1179 { FILE_PATH_LITERAL("zzz"), | 1179 { FILE_PATH_LITERAL("zzz"), |
1180 DownloadItem::COMPLETE, | 1180 DownloadItem::COMPLETE, |
1181 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, | 1181 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, |
1182 { FILE_PATH_LITERAL("baz"), | 1182 { FILE_PATH_LITERAL("baz"), |
1183 DownloadItem::COMPLETE, | 1183 DownloadItem::COMPLETE, |
1184 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 1184 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
1185 }; | 1185 }; |
1186 DownloadManager::DownloadVector items; | 1186 DownloadManager::DownloadVector items; |
1187 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 1187 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
1188 &items)); | 1188 &items)); |
1189 | 1189 |
1190 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1190 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1191 new DownloadsSearchFunction(), "[{\"orderBy\": [\"filename\"]}]")); | 1191 new DownloadsSearchFunction(), "[{\"orderBy\": [\"filename\"]}]")); |
1192 ASSERT_TRUE(result.get()); | 1192 ASSERT_TRUE(result.get()); |
1193 base::ListValue* result_list = NULL; | 1193 base::ListValue* result_list = NULL; |
1194 ASSERT_TRUE(result->GetAsList(&result_list)); | 1194 ASSERT_TRUE(result->GetAsList(&result_list)); |
1195 ASSERT_EQ(2UL, result_list->GetSize()); | 1195 ASSERT_EQ(2UL, result_list->GetSize()); |
1196 base::DictionaryValue* item0_value = NULL; | 1196 base::DictionaryValue* item0_value = NULL; |
1197 base::DictionaryValue* item1_value = NULL; | 1197 base::DictionaryValue* item1_value = NULL; |
1198 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); | 1198 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); |
1199 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); | 1199 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); |
1200 std::string item0_name, item1_name; | 1200 std::string item0_name, item1_name; |
(...skipping 12 matching lines...) Expand all Loading... |
1213 DownloadItem::COMPLETE, | 1213 DownloadItem::COMPLETE, |
1214 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, | 1214 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, |
1215 { FILE_PATH_LITERAL("baz"), | 1215 { FILE_PATH_LITERAL("baz"), |
1216 DownloadItem::COMPLETE, | 1216 DownloadItem::COMPLETE, |
1217 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 1217 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
1218 }; | 1218 }; |
1219 DownloadManager::DownloadVector items; | 1219 DownloadManager::DownloadVector items; |
1220 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 1220 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
1221 &items)); | 1221 &items)); |
1222 | 1222 |
1223 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1223 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1224 new DownloadsSearchFunction(), "[{\"orderBy\": []}]")); | 1224 new DownloadsSearchFunction(), "[{\"orderBy\": []}]")); |
1225 ASSERT_TRUE(result.get()); | 1225 ASSERT_TRUE(result.get()); |
1226 base::ListValue* result_list = NULL; | 1226 base::ListValue* result_list = NULL; |
1227 ASSERT_TRUE(result->GetAsList(&result_list)); | 1227 ASSERT_TRUE(result->GetAsList(&result_list)); |
1228 ASSERT_EQ(2UL, result_list->GetSize()); | 1228 ASSERT_EQ(2UL, result_list->GetSize()); |
1229 base::DictionaryValue* item0_value = NULL; | 1229 base::DictionaryValue* item0_value = NULL; |
1230 base::DictionaryValue* item1_value = NULL; | 1230 base::DictionaryValue* item1_value = NULL; |
1231 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); | 1231 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); |
1232 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); | 1232 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); |
1233 std::string item0_name, item1_name; | 1233 std::string item0_name, item1_name; |
(...skipping 16 matching lines...) Expand all Loading... |
1250 DownloadItem::COMPLETE, | 1250 DownloadItem::COMPLETE, |
1251 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, | 1251 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, |
1252 { FILE_PATH_LITERAL("baz"), | 1252 { FILE_PATH_LITERAL("baz"), |
1253 DownloadItem::COMPLETE, | 1253 DownloadItem::COMPLETE, |
1254 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } | 1254 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } |
1255 }; | 1255 }; |
1256 DownloadManager::DownloadVector items; | 1256 DownloadManager::DownloadVector items; |
1257 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 1257 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
1258 &items)); | 1258 &items)); |
1259 | 1259 |
1260 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1260 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1261 new DownloadsSearchFunction(), "[{\"danger\": \"content\"}]")); | 1261 new DownloadsSearchFunction(), "[{\"danger\": \"content\"}]")); |
1262 ASSERT_TRUE(result.get()); | 1262 ASSERT_TRUE(result.get()); |
1263 base::ListValue* result_list = NULL; | 1263 base::ListValue* result_list = NULL; |
1264 ASSERT_TRUE(result->GetAsList(&result_list)); | 1264 ASSERT_TRUE(result->GetAsList(&result_list)); |
1265 ASSERT_EQ(1UL, result_list->GetSize()); | 1265 ASSERT_EQ(1UL, result_list->GetSize()); |
1266 } | 1266 } |
1267 | 1267 |
1268 // Test the |state| option for search(). | 1268 // Test the |state| option for search(). |
1269 // | 1269 // |
1270 // http://crbug.com/508949 | 1270 // http://crbug.com/508949 |
1271 #if defined(MEMORY_SANITIZER) | 1271 #if defined(MEMORY_SANITIZER) |
1272 #define MAYBE_DownloadExtensionTest_SearchState DISABLED_DownloadExtensionTest_S
earchState | 1272 #define MAYBE_DownloadExtensionTest_SearchState DISABLED_DownloadExtensionTest_S
earchState |
1273 #else | 1273 #else |
1274 #define MAYBE_DownloadExtensionTest_SearchState DownloadExtensionTest_SearchStat
e | 1274 #define MAYBE_DownloadExtensionTest_SearchState DownloadExtensionTest_SearchStat
e |
1275 #endif | 1275 #endif |
1276 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1276 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1277 MAYBE_DownloadExtensionTest_SearchState) { | 1277 MAYBE_DownloadExtensionTest_SearchState) { |
1278 DownloadManager::DownloadVector items; | 1278 DownloadManager::DownloadVector items; |
1279 CreateSlowTestDownloads(2, &items); | 1279 CreateSlowTestDownloads(2, &items); |
1280 ScopedItemVectorCanceller delete_items(&items); | 1280 ScopedItemVectorCanceller delete_items(&items); |
1281 | 1281 |
1282 items[0]->Cancel(true); | 1282 items[0]->Cancel(true); |
1283 | 1283 |
1284 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1284 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1285 new DownloadsSearchFunction(), "[{\"state\": \"in_progress\"}]")); | 1285 new DownloadsSearchFunction(), "[{\"state\": \"in_progress\"}]")); |
1286 ASSERT_TRUE(result.get()); | 1286 ASSERT_TRUE(result.get()); |
1287 base::ListValue* result_list = NULL; | 1287 base::ListValue* result_list = NULL; |
1288 ASSERT_TRUE(result->GetAsList(&result_list)); | 1288 ASSERT_TRUE(result->GetAsList(&result_list)); |
1289 ASSERT_EQ(1UL, result_list->GetSize()); | 1289 ASSERT_EQ(1UL, result_list->GetSize()); |
1290 } | 1290 } |
1291 | 1291 |
1292 // Test the |limit| option for search(). | 1292 // Test the |limit| option for search(). |
1293 // | 1293 // |
1294 // http://crbug.com/508949 | 1294 // http://crbug.com/508949 |
1295 #if defined(MEMORY_SANITIZER) | 1295 #if defined(MEMORY_SANITIZER) |
1296 #define MAYBE_DownloadExtensionTest_SearchLimit DISABLED_DownloadExtensionTest_S
earchLimit | 1296 #define MAYBE_DownloadExtensionTest_SearchLimit DISABLED_DownloadExtensionTest_S
earchLimit |
1297 #else | 1297 #else |
1298 #define MAYBE_DownloadExtensionTest_SearchLimit DownloadExtensionTest_SearchLimi
t | 1298 #define MAYBE_DownloadExtensionTest_SearchLimit DownloadExtensionTest_SearchLimi
t |
1299 #endif | 1299 #endif |
1300 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1300 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1301 MAYBE_DownloadExtensionTest_SearchLimit) { | 1301 MAYBE_DownloadExtensionTest_SearchLimit) { |
1302 DownloadManager::DownloadVector items; | 1302 DownloadManager::DownloadVector items; |
1303 CreateSlowTestDownloads(2, &items); | 1303 CreateSlowTestDownloads(2, &items); |
1304 ScopedItemVectorCanceller delete_items(&items); | 1304 ScopedItemVectorCanceller delete_items(&items); |
1305 | 1305 |
1306 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1306 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1307 new DownloadsSearchFunction(), "[{\"limit\": 1}]")); | 1307 new DownloadsSearchFunction(), "[{\"limit\": 1}]")); |
1308 ASSERT_TRUE(result.get()); | 1308 ASSERT_TRUE(result.get()); |
1309 base::ListValue* result_list = NULL; | 1309 base::ListValue* result_list = NULL; |
1310 ASSERT_TRUE(result->GetAsList(&result_list)); | 1310 ASSERT_TRUE(result->GetAsList(&result_list)); |
1311 ASSERT_EQ(1UL, result_list->GetSize()); | 1311 ASSERT_EQ(1UL, result_list->GetSize()); |
1312 } | 1312 } |
1313 | 1313 |
1314 // Test invalid search parameters. | 1314 // Test invalid search parameters. |
1315 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1315 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1316 DownloadExtensionTest_SearchInvalid) { | 1316 DownloadExtensionTest_SearchInvalid) { |
(...skipping 22 matching lines...) Expand all Loading... |
1339 DownloadItem::COMPLETE, | 1339 DownloadItem::COMPLETE, |
1340 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, | 1340 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, |
1341 { FILE_PATH_LITERAL("baz"), | 1341 { FILE_PATH_LITERAL("baz"), |
1342 DownloadItem::COMPLETE, | 1342 DownloadItem::COMPLETE, |
1343 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, | 1343 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, |
1344 }; | 1344 }; |
1345 DownloadManager::DownloadVector items; | 1345 DownloadManager::DownloadVector items; |
1346 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), | 1346 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), |
1347 &items)); | 1347 &items)); |
1348 | 1348 |
1349 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1349 std::unique_ptr<base::Value> result( |
1350 new DownloadsSearchFunction(), "[{" | 1350 RunFunctionAndReturnResult(new DownloadsSearchFunction(), |
1351 "\"state\": \"complete\", " | 1351 "[{" |
1352 "\"danger\": \"content\", " | 1352 "\"state\": \"complete\", " |
1353 "\"orderBy\": [\"filename\"], " | 1353 "\"danger\": \"content\", " |
1354 "\"limit\": 1}]")); | 1354 "\"orderBy\": [\"filename\"], " |
| 1355 "\"limit\": 1}]")); |
1355 ASSERT_TRUE(result.get()); | 1356 ASSERT_TRUE(result.get()); |
1356 base::ListValue* result_list = NULL; | 1357 base::ListValue* result_list = NULL; |
1357 ASSERT_TRUE(result->GetAsList(&result_list)); | 1358 ASSERT_TRUE(result->GetAsList(&result_list)); |
1358 ASSERT_EQ(1UL, result_list->GetSize()); | 1359 ASSERT_EQ(1UL, result_list->GetSize()); |
1359 base::DictionaryValue* item_value = NULL; | 1360 base::DictionaryValue* item_value = NULL; |
1360 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); | 1361 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); |
1361 base::FilePath::StringType item_name; | 1362 base::FilePath::StringType item_name; |
1362 ASSERT_TRUE(item_value->GetString("filename", &item_name)); | 1363 ASSERT_TRUE(item_value->GetString("filename", &item_name)); |
1363 ASSERT_EQ(items[2]->GetTargetFilePath().value(), item_name); | 1364 ASSERT_EQ(items[2]->GetTargetFilePath().value(), item_name); |
1364 } | 1365 } |
1365 | 1366 |
1366 // Test that incognito downloads are only visible in incognito contexts, and | 1367 // Test that incognito downloads are only visible in incognito contexts, and |
1367 // test that on-record downloads are visible in both incognito and on-record | 1368 // test that on-record downloads are visible in both incognito and on-record |
1368 // contexts, for DownloadsSearchFunction, DownloadsPauseFunction, | 1369 // contexts, for DownloadsSearchFunction, DownloadsPauseFunction, |
1369 // DownloadsResumeFunction, and DownloadsCancelFunction. | 1370 // DownloadsResumeFunction, and DownloadsCancelFunction. |
1370 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1371 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1371 DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito) { | 1372 DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito) { |
1372 scoped_ptr<base::Value> result_value; | 1373 std::unique_ptr<base::Value> result_value; |
1373 base::ListValue* result_list = NULL; | 1374 base::ListValue* result_list = NULL; |
1374 base::DictionaryValue* result_dict = NULL; | 1375 base::DictionaryValue* result_dict = NULL; |
1375 base::FilePath::StringType filename; | 1376 base::FilePath::StringType filename; |
1376 bool is_incognito = false; | 1377 bool is_incognito = false; |
1377 std::string error; | 1378 std::string error; |
1378 std::string on_item_arg; | 1379 std::string on_item_arg; |
1379 std::string off_item_arg; | 1380 std::string off_item_arg; |
1380 std::string result_string; | 1381 std::string result_string; |
1381 | 1382 |
1382 // Set up one on-record item and one off-record item. | 1383 // Set up one on-record item and one off-record item. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 // Test that we can start a download and that the correct sequence of events is | 1499 // Test that we can start a download and that the correct sequence of events is |
1499 // fired for it. | 1500 // fired for it. |
1500 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1501 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1501 DownloadExtensionTest_Download_Basic) { | 1502 DownloadExtensionTest_Download_Basic) { |
1502 LoadExtension("downloads_split"); | 1503 LoadExtension("downloads_split"); |
1503 ASSERT_TRUE(StartEmbeddedTestServer()); | 1504 ASSERT_TRUE(StartEmbeddedTestServer()); |
1504 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 1505 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
1505 GoOnTheRecord(); | 1506 GoOnTheRecord(); |
1506 | 1507 |
1507 // Start downloading a file. | 1508 // Start downloading a file. |
1508 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1509 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1509 new DownloadsDownloadFunction(), base::StringPrintf( | 1510 new DownloadsDownloadFunction(), |
1510 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1511 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
1511 ASSERT_TRUE(result.get()); | 1512 ASSERT_TRUE(result.get()); |
1512 int result_id = -1; | 1513 int result_id = -1; |
1513 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1514 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1514 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1515 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
1515 ASSERT_TRUE(item); | 1516 ASSERT_TRUE(item); |
1516 ScopedCancellingItem canceller(item); | 1517 ScopedCancellingItem canceller(item); |
1517 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1518 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1518 | 1519 |
1519 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1520 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
1520 base::StringPrintf( | 1521 base::StringPrintf( |
(...skipping 22 matching lines...) Expand all Loading... |
1543 // Test that we can start a download from an incognito context, and that the | 1544 // Test that we can start a download from an incognito context, and that the |
1544 // download knows that it's incognito. | 1545 // download knows that it's incognito. |
1545 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1546 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1546 DownloadExtensionTest_Download_Incognito) { | 1547 DownloadExtensionTest_Download_Incognito) { |
1547 LoadExtension("downloads_split"); | 1548 LoadExtension("downloads_split"); |
1548 ASSERT_TRUE(StartEmbeddedTestServer()); | 1549 ASSERT_TRUE(StartEmbeddedTestServer()); |
1549 GoOffTheRecord(); | 1550 GoOffTheRecord(); |
1550 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 1551 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
1551 | 1552 |
1552 // Start downloading a file. | 1553 // Start downloading a file. |
1553 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1554 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1554 new DownloadsDownloadFunction(), base::StringPrintf( | 1555 new DownloadsDownloadFunction(), |
1555 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1556 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
1556 ASSERT_TRUE(result.get()); | 1557 ASSERT_TRUE(result.get()); |
1557 int result_id = -1; | 1558 int result_id = -1; |
1558 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1559 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1559 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1560 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
1560 ASSERT_TRUE(item); | 1561 ASSERT_TRUE(item); |
1561 ScopedCancellingItem canceller(item); | 1562 ScopedCancellingItem canceller(item); |
1562 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1563 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1563 | 1564 |
1564 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1565 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
1565 base::StringPrintf( | 1566 base::StringPrintf( |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\ | 1681 #define MAYBE_DownloadExtensionTest_Download_Subdirectory\ |
1681 DownloadExtensionTest_Download_Subdirectory | 1682 DownloadExtensionTest_Download_Subdirectory |
1682 #endif | 1683 #endif |
1683 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1684 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1684 MAYBE_DownloadExtensionTest_Download_Subdirectory) { | 1685 MAYBE_DownloadExtensionTest_Download_Subdirectory) { |
1685 LoadExtension("downloads_split"); | 1686 LoadExtension("downloads_split"); |
1686 ASSERT_TRUE(StartEmbeddedTestServer()); | 1687 ASSERT_TRUE(StartEmbeddedTestServer()); |
1687 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 1688 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
1688 GoOnTheRecord(); | 1689 GoOnTheRecord(); |
1689 | 1690 |
1690 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1691 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1691 new DownloadsDownloadFunction(), base::StringPrintf( | 1692 new DownloadsDownloadFunction(), |
1692 "[{\"url\": \"%s\"," | 1693 base::StringPrintf("[{\"url\": \"%s\"," |
1693 " \"filename\": \"sub/dir/ect/ory.txt\"}]", | 1694 " \"filename\": \"sub/dir/ect/ory.txt\"}]", |
1694 download_url.c_str()))); | 1695 download_url.c_str()))); |
1695 ASSERT_TRUE(result.get()); | 1696 ASSERT_TRUE(result.get()); |
1696 int result_id = -1; | 1697 int result_id = -1; |
1697 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1698 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1698 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1699 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
1699 ASSERT_TRUE(item); | 1700 ASSERT_TRUE(item); |
1700 ScopedCancellingItem canceller(item); | 1701 ScopedCancellingItem canceller(item); |
1701 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1702 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1702 | 1703 |
1703 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1704 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
1704 base::StringPrintf( | 1705 base::StringPrintf( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 | 1769 |
1769 for (size_t index = 0; index < arraysize(kInvalidURLs); ++index) { | 1770 for (size_t index = 0; index < arraysize(kInvalidURLs); ++index) { |
1770 EXPECT_STREQ(errors::kInvalidURL, | 1771 EXPECT_STREQ(errors::kInvalidURL, |
1771 RunFunctionAndReturnError(new DownloadsDownloadFunction(), | 1772 RunFunctionAndReturnError(new DownloadsDownloadFunction(), |
1772 base::StringPrintf( | 1773 base::StringPrintf( |
1773 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str()) | 1774 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str()) |
1774 << kInvalidURLs[index]; | 1775 << kInvalidURLs[index]; |
1775 } | 1776 } |
1776 | 1777 |
1777 int result_id = -1; | 1778 int result_id = -1; |
1778 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1779 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1779 new DownloadsDownloadFunction(), | 1780 new DownloadsDownloadFunction(), |
1780 "[{\"url\": \"javascript:document.write(\\\"hello\\\");\"}]")); | 1781 "[{\"url\": \"javascript:document.write(\\\"hello\\\");\"}]")); |
1781 ASSERT_TRUE(result.get()); | 1782 ASSERT_TRUE(result.get()); |
1782 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1783 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1783 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1784 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
1784 ASSERT_TRUE(item); | 1785 ASSERT_TRUE(item); |
1785 ASSERT_TRUE(WaitForInterruption( | 1786 ASSERT_TRUE(WaitForInterruption( |
1786 item, content::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST, | 1787 item, content::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST, |
1787 "[{\"state\": \"in_progress\"," | 1788 "[{\"state\": \"in_progress\"," |
1788 " \"url\": \"javascript:document.write(\\\"hello\\\");\"}]")); | 1789 " \"url\": \"javascript:document.write(\\\"hello\\\");\"}]")); |
(...skipping 28 matching lines...) Expand all Loading... |
1817 | 1818 |
1818 // Valid URLs plus fragments are still valid URLs. | 1819 // Valid URLs plus fragments are still valid URLs. |
1819 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1820 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1820 DownloadExtensionTest_Download_URLFragment) { | 1821 DownloadExtensionTest_Download_URLFragment) { |
1821 LoadExtension("downloads_split"); | 1822 LoadExtension("downloads_split"); |
1822 ASSERT_TRUE(StartEmbeddedTestServer()); | 1823 ASSERT_TRUE(StartEmbeddedTestServer()); |
1823 std::string download_url = | 1824 std::string download_url = |
1824 embedded_test_server()->GetURL("/slow?0#fragment").spec(); | 1825 embedded_test_server()->GetURL("/slow?0#fragment").spec(); |
1825 GoOnTheRecord(); | 1826 GoOnTheRecord(); |
1826 | 1827 |
1827 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1828 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1828 new DownloadsDownloadFunction(), base::StringPrintf( | 1829 new DownloadsDownloadFunction(), |
1829 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1830 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
1830 ASSERT_TRUE(result.get()); | 1831 ASSERT_TRUE(result.get()); |
1831 int result_id = -1; | 1832 int result_id = -1; |
1832 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1833 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1833 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1834 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
1834 ASSERT_TRUE(item); | 1835 ASSERT_TRUE(item); |
1835 ScopedCancellingItem canceller(item); | 1836 ScopedCancellingItem canceller(item); |
1836 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1837 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1837 | 1838 |
1838 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1839 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
1839 base::StringPrintf( | 1840 base::StringPrintf( |
(...skipping 20 matching lines...) Expand all Loading... |
1860 } | 1861 } |
1861 | 1862 |
1862 // conflictAction may be specified without filename. | 1863 // conflictAction may be specified without filename. |
1863 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1864 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1864 DownloadExtensionTest_Download_ConflictAction) { | 1865 DownloadExtensionTest_Download_ConflictAction) { |
1865 static char kFilename[] = "download.txt"; | 1866 static char kFilename[] = "download.txt"; |
1866 LoadExtension("downloads_split"); | 1867 LoadExtension("downloads_split"); |
1867 std::string download_url = "data:text/plain,hello"; | 1868 std::string download_url = "data:text/plain,hello"; |
1868 GoOnTheRecord(); | 1869 GoOnTheRecord(); |
1869 | 1870 |
1870 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1871 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1871 new DownloadsDownloadFunction(), base::StringPrintf( | 1872 new DownloadsDownloadFunction(), |
1872 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 1873 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
1873 ASSERT_TRUE(result.get()); | 1874 ASSERT_TRUE(result.get()); |
1874 int result_id = -1; | 1875 int result_id = -1; |
1875 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1876 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1876 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1877 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
1877 ASSERT_TRUE(item); | 1878 ASSERT_TRUE(item); |
1878 ScopedCancellingItem canceller(item); | 1879 ScopedCancellingItem canceller(item); |
1879 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1880 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1880 | 1881 |
1881 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1882 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
1882 base::StringPrintf( | 1883 base::StringPrintf( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1939 result_id))); | 1940 result_id))); |
1940 } | 1941 } |
1941 | 1942 |
1942 // Valid data URLs are valid URLs. | 1943 // Valid data URLs are valid URLs. |
1943 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1944 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1944 DownloadExtensionTest_Download_DataURL) { | 1945 DownloadExtensionTest_Download_DataURL) { |
1945 LoadExtension("downloads_split"); | 1946 LoadExtension("downloads_split"); |
1946 std::string download_url = "data:text/plain,hello"; | 1947 std::string download_url = "data:text/plain,hello"; |
1947 GoOnTheRecord(); | 1948 GoOnTheRecord(); |
1948 | 1949 |
1949 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1950 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1950 new DownloadsDownloadFunction(), base::StringPrintf( | 1951 new DownloadsDownloadFunction(), |
1951 "[{\"url\": \"%s\"," | 1952 base::StringPrintf("[{\"url\": \"%s\"," |
1952 " \"filename\": \"data.txt\"}]", download_url.c_str()))); | 1953 " \"filename\": \"data.txt\"}]", |
| 1954 download_url.c_str()))); |
1953 ASSERT_TRUE(result.get()); | 1955 ASSERT_TRUE(result.get()); |
1954 int result_id = -1; | 1956 int result_id = -1; |
1955 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1957 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1956 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1958 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
1957 ASSERT_TRUE(item); | 1959 ASSERT_TRUE(item); |
1958 ScopedCancellingItem canceller(item); | 1960 ScopedCancellingItem canceller(item); |
1959 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1961 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1960 | 1962 |
1961 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1963 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
1962 base::StringPrintf( | 1964 base::StringPrintf( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1994 #endif | 1996 #endif |
1995 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1997 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1996 MAYBE_DownloadExtensionTest_Download_File) { | 1998 MAYBE_DownloadExtensionTest_Download_File) { |
1997 GoOnTheRecord(); | 1999 GoOnTheRecord(); |
1998 LoadExtension("downloads_split"); | 2000 LoadExtension("downloads_split"); |
1999 std::string download_url = "file:///"; | 2001 std::string download_url = "file:///"; |
2000 #if defined(OS_WIN) | 2002 #if defined(OS_WIN) |
2001 download_url += "C:/"; | 2003 download_url += "C:/"; |
2002 #endif | 2004 #endif |
2003 | 2005 |
2004 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2006 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2005 new DownloadsDownloadFunction(), base::StringPrintf( | 2007 new DownloadsDownloadFunction(), |
2006 "[{\"url\": \"%s\"," | 2008 base::StringPrintf("[{\"url\": \"%s\"," |
2007 " \"filename\": \"file.txt\"}]", download_url.c_str()))); | 2009 " \"filename\": \"file.txt\"}]", |
| 2010 download_url.c_str()))); |
2008 ASSERT_TRUE(result.get()); | 2011 ASSERT_TRUE(result.get()); |
2009 int result_id = -1; | 2012 int result_id = -1; |
2010 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2013 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2011 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2014 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2012 ASSERT_TRUE(item); | 2015 ASSERT_TRUE(item); |
2013 ScopedCancellingItem canceller(item); | 2016 ScopedCancellingItem canceller(item); |
2014 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2017 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2015 | 2018 |
2016 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2019 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2017 base::StringPrintf( | 2020 base::StringPrintf( |
(...skipping 25 matching lines...) Expand all Loading... |
2043 // This tests both that testserver.py does not succeed when it should fail as | 2046 // This tests both that testserver.py does not succeed when it should fail as |
2044 // well as how the downloads extension API exposes the failure to extensions. | 2047 // well as how the downloads extension API exposes the failure to extensions. |
2045 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2048 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2046 DownloadExtensionTest_Download_AuthBasic_Fail) { | 2049 DownloadExtensionTest_Download_AuthBasic_Fail) { |
2047 LoadExtension("downloads_split"); | 2050 LoadExtension("downloads_split"); |
2048 ASSERT_TRUE(StartEmbeddedTestServer()); | 2051 ASSERT_TRUE(StartEmbeddedTestServer()); |
2049 std::string download_url = | 2052 std::string download_url = |
2050 embedded_test_server()->GetURL("/auth-basic").spec(); | 2053 embedded_test_server()->GetURL("/auth-basic").spec(); |
2051 GoOnTheRecord(); | 2054 GoOnTheRecord(); |
2052 | 2055 |
2053 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2056 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2054 new DownloadsDownloadFunction(), base::StringPrintf( | 2057 new DownloadsDownloadFunction(), |
2055 "[{\"url\": \"%s\"," | 2058 base::StringPrintf("[{\"url\": \"%s\"," |
2056 " \"filename\": \"auth-basic-fail.txt\"}]", | 2059 " \"filename\": \"auth-basic-fail.txt\"}]", |
2057 download_url.c_str()))); | 2060 download_url.c_str()))); |
2058 ASSERT_TRUE(result.get()); | 2061 ASSERT_TRUE(result.get()); |
2059 int result_id = -1; | 2062 int result_id = -1; |
2060 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2063 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2061 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2064 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2062 ASSERT_TRUE(item); | 2065 ASSERT_TRUE(item); |
2063 ScopedCancellingItem canceller(item); | 2066 ScopedCancellingItem canceller(item); |
2064 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2067 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2065 | 2068 |
2066 ASSERT_TRUE(WaitForInterruption( | 2069 ASSERT_TRUE(WaitForInterruption( |
2067 item, | 2070 item, |
(...skipping 11 matching lines...) Expand all Loading... |
2079 LoadExtension("downloads_split"); | 2082 LoadExtension("downloads_split"); |
2080 ASSERT_TRUE(StartEmbeddedTestServer()); | 2083 ASSERT_TRUE(StartEmbeddedTestServer()); |
2081 std::string download_url = | 2084 std::string download_url = |
2082 embedded_test_server() | 2085 embedded_test_server() |
2083 ->GetURL( | 2086 ->GetURL( |
2084 "/downloads/" | 2087 "/downloads/" |
2085 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo") | 2088 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo") |
2086 .spec(); | 2089 .spec(); |
2087 GoOnTheRecord(); | 2090 GoOnTheRecord(); |
2088 | 2091 |
2089 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2092 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2090 new DownloadsDownloadFunction(), base::StringPrintf( | 2093 new DownloadsDownloadFunction(), |
2091 "[{\"url\": \"%s\"," | 2094 base::StringPrintf("[{\"url\": \"%s\"," |
2092 " \"filename\": \"headers-succeed.txt\"," | 2095 " \"filename\": \"headers-succeed.txt\"," |
2093 " \"headers\": [" | 2096 " \"headers\": [" |
2094 " {\"name\": \"Foo\", \"value\": \"bar\"}," | 2097 " {\"name\": \"Foo\", \"value\": \"bar\"}," |
2095 " {\"name\": \"Qx\", \"value\":\"yo\"}]}]", | 2098 " {\"name\": \"Qx\", \"value\":\"yo\"}]}]", |
2096 download_url.c_str()))); | 2099 download_url.c_str()))); |
2097 ASSERT_TRUE(result.get()); | 2100 ASSERT_TRUE(result.get()); |
2098 int result_id = -1; | 2101 int result_id = -1; |
2099 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2102 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2100 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2103 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2101 ASSERT_TRUE(item); | 2104 ASSERT_TRUE(item); |
2102 ScopedCancellingItem canceller(item); | 2105 ScopedCancellingItem canceller(item); |
2103 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2106 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2104 | 2107 |
2105 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2108 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2106 base::StringPrintf( | 2109 base::StringPrintf( |
(...skipping 29 matching lines...) Expand all Loading... |
2136 LoadExtension("downloads_split"); | 2139 LoadExtension("downloads_split"); |
2137 ASSERT_TRUE(StartEmbeddedTestServer()); | 2140 ASSERT_TRUE(StartEmbeddedTestServer()); |
2138 std::string download_url = | 2141 std::string download_url = |
2139 embedded_test_server() | 2142 embedded_test_server() |
2140 ->GetURL( | 2143 ->GetURL( |
2141 "/downloads/" | 2144 "/downloads/" |
2142 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo") | 2145 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo") |
2143 .spec(); | 2146 .spec(); |
2144 GoOnTheRecord(); | 2147 GoOnTheRecord(); |
2145 | 2148 |
2146 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2149 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2147 new DownloadsDownloadFunction(), base::StringPrintf( | 2150 new DownloadsDownloadFunction(), |
2148 "[{\"url\": \"%s\"," | 2151 base::StringPrintf("[{\"url\": \"%s\"," |
2149 " \"filename\": \"headers-fail.txt\"}]", | 2152 " \"filename\": \"headers-fail.txt\"}]", |
2150 download_url.c_str()))); | 2153 download_url.c_str()))); |
2151 ASSERT_TRUE(result.get()); | 2154 ASSERT_TRUE(result.get()); |
2152 int result_id = -1; | 2155 int result_id = -1; |
2153 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2156 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2154 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2157 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2155 ASSERT_TRUE(item); | 2158 ASSERT_TRUE(item); |
2156 ScopedCancellingItem canceller(item); | 2159 ScopedCancellingItem canceller(item); |
2157 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2160 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2158 | 2161 |
2159 ASSERT_TRUE(WaitForInterruption( | 2162 ASSERT_TRUE(WaitForInterruption( |
2160 item, | 2163 item, |
(...skipping 13 matching lines...) Expand all Loading... |
2174 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2177 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2175 DownloadExtensionTest_Download_AuthBasic) { | 2178 DownloadExtensionTest_Download_AuthBasic) { |
2176 LoadExtension("downloads_split"); | 2179 LoadExtension("downloads_split"); |
2177 ASSERT_TRUE(StartEmbeddedTestServer()); | 2180 ASSERT_TRUE(StartEmbeddedTestServer()); |
2178 std::string download_url = | 2181 std::string download_url = |
2179 embedded_test_server()->GetURL("/auth-basic").spec(); | 2182 embedded_test_server()->GetURL("/auth-basic").spec(); |
2180 // This is just base64 of 'username:secret'. | 2183 // This is just base64 of 'username:secret'. |
2181 static const char kAuthorization[] = "dXNlcm5hbWU6c2VjcmV0"; | 2184 static const char kAuthorization[] = "dXNlcm5hbWU6c2VjcmV0"; |
2182 GoOnTheRecord(); | 2185 GoOnTheRecord(); |
2183 | 2186 |
2184 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2187 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2185 new DownloadsDownloadFunction(), base::StringPrintf( | 2188 new DownloadsDownloadFunction(), |
2186 "[{\"url\": \"%s\"," | 2189 base::StringPrintf("[{\"url\": \"%s\"," |
2187 " \"filename\": \"auth-basic-succeed.txt\"," | 2190 " \"filename\": \"auth-basic-succeed.txt\"," |
2188 " \"headers\": [{" | 2191 " \"headers\": [{" |
2189 " \"name\": \"Authorization\"," | 2192 " \"name\": \"Authorization\"," |
2190 " \"value\": \"Basic %s\"}]}]", | 2193 " \"value\": \"Basic %s\"}]}]", |
2191 download_url.c_str(), kAuthorization))); | 2194 download_url.c_str(), kAuthorization))); |
2192 ASSERT_TRUE(result.get()); | 2195 ASSERT_TRUE(result.get()); |
2193 int result_id = -1; | 2196 int result_id = -1; |
2194 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2197 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2195 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2198 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2196 ASSERT_TRUE(item); | 2199 ASSERT_TRUE(item); |
2197 ScopedCancellingItem canceller(item); | 2200 ScopedCancellingItem canceller(item); |
2198 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2201 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2199 | 2202 |
2200 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2203 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2201 base::StringPrintf( | 2204 base::StringPrintf( |
(...skipping 19 matching lines...) Expand all Loading... |
2221 DownloadExtensionTest_Download_Post) { | 2224 DownloadExtensionTest_Download_Post) { |
2222 LoadExtension("downloads_split"); | 2225 LoadExtension("downloads_split"); |
2223 ASSERT_TRUE(StartEmbeddedTestServer()); | 2226 ASSERT_TRUE(StartEmbeddedTestServer()); |
2224 std::string download_url = embedded_test_server() | 2227 std::string download_url = embedded_test_server() |
2225 ->GetURL( | 2228 ->GetURL( |
2226 "/post/downloads/" | 2229 "/post/downloads/" |
2227 "a_zip_file.zip?expected_body=BODY") | 2230 "a_zip_file.zip?expected_body=BODY") |
2228 .spec(); | 2231 .spec(); |
2229 GoOnTheRecord(); | 2232 GoOnTheRecord(); |
2230 | 2233 |
2231 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2234 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2232 new DownloadsDownloadFunction(), base::StringPrintf( | 2235 new DownloadsDownloadFunction(), |
2233 "[{\"url\": \"%s\"," | 2236 base::StringPrintf("[{\"url\": \"%s\"," |
2234 " \"filename\": \"post-succeed.txt\"," | 2237 " \"filename\": \"post-succeed.txt\"," |
2235 " \"method\": \"POST\"," | 2238 " \"method\": \"POST\"," |
2236 " \"body\": \"BODY\"}]", | 2239 " \"body\": \"BODY\"}]", |
2237 download_url.c_str()))); | 2240 download_url.c_str()))); |
2238 ASSERT_TRUE(result.get()); | 2241 ASSERT_TRUE(result.get()); |
2239 int result_id = -1; | 2242 int result_id = -1; |
2240 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2243 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2241 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2244 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2242 ASSERT_TRUE(item); | 2245 ASSERT_TRUE(item); |
2243 ScopedCancellingItem canceller(item); | 2246 ScopedCancellingItem canceller(item); |
2244 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2247 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2245 | 2248 |
2246 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2249 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2247 base::StringPrintf( | 2250 base::StringPrintf( |
(...skipping 29 matching lines...) Expand all Loading... |
2277 DownloadExtensionTest_Download_Post_Get) { | 2280 DownloadExtensionTest_Download_Post_Get) { |
2278 LoadExtension("downloads_split"); | 2281 LoadExtension("downloads_split"); |
2279 ASSERT_TRUE(StartEmbeddedTestServer()); | 2282 ASSERT_TRUE(StartEmbeddedTestServer()); |
2280 std::string download_url = embedded_test_server() | 2283 std::string download_url = embedded_test_server() |
2281 ->GetURL( | 2284 ->GetURL( |
2282 "/post/downloads/" | 2285 "/post/downloads/" |
2283 "a_zip_file.zip?expected_body=BODY") | 2286 "a_zip_file.zip?expected_body=BODY") |
2284 .spec(); | 2287 .spec(); |
2285 GoOnTheRecord(); | 2288 GoOnTheRecord(); |
2286 | 2289 |
2287 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2290 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2288 new DownloadsDownloadFunction(), base::StringPrintf( | 2291 new DownloadsDownloadFunction(), |
2289 "[{\"url\": \"%s\"," | 2292 base::StringPrintf("[{\"url\": \"%s\"," |
2290 " \"body\": \"BODY\"," | 2293 " \"body\": \"BODY\"," |
2291 " \"filename\": \"post-get.txt\"}]", | 2294 " \"filename\": \"post-get.txt\"}]", |
2292 download_url.c_str()))); | 2295 download_url.c_str()))); |
2293 ASSERT_TRUE(result.get()); | 2296 ASSERT_TRUE(result.get()); |
2294 int result_id = -1; | 2297 int result_id = -1; |
2295 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2298 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2296 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2299 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2297 ASSERT_TRUE(item); | 2300 ASSERT_TRUE(item); |
2298 ScopedCancellingItem canceller(item); | 2301 ScopedCancellingItem canceller(item); |
2299 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2302 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2300 | 2303 |
2301 ASSERT_TRUE(WaitForInterruption( | 2304 ASSERT_TRUE(WaitForInterruption( |
2302 item, | 2305 item, |
(...skipping 17 matching lines...) Expand all Loading... |
2320 DownloadExtensionTest_Download_Post_NoBody) { | 2323 DownloadExtensionTest_Download_Post_NoBody) { |
2321 LoadExtension("downloads_split"); | 2324 LoadExtension("downloads_split"); |
2322 ASSERT_TRUE(StartEmbeddedTestServer()); | 2325 ASSERT_TRUE(StartEmbeddedTestServer()); |
2323 std::string download_url = embedded_test_server() | 2326 std::string download_url = embedded_test_server() |
2324 ->GetURL( | 2327 ->GetURL( |
2325 "/post/downloads/" | 2328 "/post/downloads/" |
2326 "a_zip_file.zip?expected_body=BODY") | 2329 "a_zip_file.zip?expected_body=BODY") |
2327 .spec(); | 2330 .spec(); |
2328 GoOnTheRecord(); | 2331 GoOnTheRecord(); |
2329 | 2332 |
2330 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2333 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2331 new DownloadsDownloadFunction(), base::StringPrintf( | 2334 new DownloadsDownloadFunction(), |
2332 "[{\"url\": \"%s\"," | 2335 base::StringPrintf("[{\"url\": \"%s\"," |
2333 " \"method\": \"POST\"," | 2336 " \"method\": \"POST\"," |
2334 " \"filename\": \"post-nobody.txt\"}]", | 2337 " \"filename\": \"post-nobody.txt\"}]", |
2335 download_url.c_str()))); | 2338 download_url.c_str()))); |
2336 ASSERT_TRUE(result.get()); | 2339 ASSERT_TRUE(result.get()); |
2337 int result_id = -1; | 2340 int result_id = -1; |
2338 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2341 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2339 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2342 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2340 ASSERT_TRUE(item); | 2343 ASSERT_TRUE(item); |
2341 ScopedCancellingItem canceller(item); | 2344 ScopedCancellingItem canceller(item); |
2342 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2345 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2343 | 2346 |
2344 ASSERT_TRUE(WaitForInterruption( | 2347 ASSERT_TRUE(WaitForInterruption( |
2345 item, | 2348 item, |
(...skipping 14 matching lines...) Expand all Loading... |
2360 // interruptions such as server death. | 2363 // interruptions such as server death. |
2361 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2364 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2362 DownloadExtensionTest_Download_Cancel) { | 2365 DownloadExtensionTest_Download_Cancel) { |
2363 LoadExtension("downloads_split"); | 2366 LoadExtension("downloads_split"); |
2364 ASSERT_TRUE(StartEmbeddedTestServer()); | 2367 ASSERT_TRUE(StartEmbeddedTestServer()); |
2365 ASSERT_TRUE(spawned_test_server()->Start()); | 2368 ASSERT_TRUE(spawned_test_server()->Start()); |
2366 std::string download_url = | 2369 std::string download_url = |
2367 spawned_test_server()->GetURL("download-known-size").spec(); | 2370 spawned_test_server()->GetURL("download-known-size").spec(); |
2368 GoOnTheRecord(); | 2371 GoOnTheRecord(); |
2369 | 2372 |
2370 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2373 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2371 new DownloadsDownloadFunction(), base::StringPrintf( | 2374 new DownloadsDownloadFunction(), |
2372 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2375 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2373 ASSERT_TRUE(result.get()); | 2376 ASSERT_TRUE(result.get()); |
2374 int result_id = -1; | 2377 int result_id = -1; |
2375 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2378 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2376 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2379 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2377 ASSERT_TRUE(item); | 2380 ASSERT_TRUE(item); |
2378 ScopedCancellingItem canceller(item); | 2381 ScopedCancellingItem canceller(item); |
2379 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2382 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2380 | 2383 |
2381 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2384 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2382 base::StringPrintf( | 2385 base::StringPrintf( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 | 2424 |
2422 // Setup a file in the filesystem which we can download. | 2425 // Setup a file in the filesystem which we can download. |
2423 ASSERT_TRUE(HTML5FileWriter::CreateFileForTesting( | 2426 ASSERT_TRUE(HTML5FileWriter::CreateFileForTesting( |
2424 BrowserContext::GetDefaultStoragePartition(browser()->profile()) | 2427 BrowserContext::GetDefaultStoragePartition(browser()->profile()) |
2425 ->GetFileSystemContext(), | 2428 ->GetFileSystemContext(), |
2426 storage::FileSystemURL::CreateForTest(GURL(download_url)), | 2429 storage::FileSystemURL::CreateForTest(GURL(download_url)), |
2427 kPayloadData, | 2430 kPayloadData, |
2428 strlen(kPayloadData))); | 2431 strlen(kPayloadData))); |
2429 | 2432 |
2430 // Now download it. | 2433 // Now download it. |
2431 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2434 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2432 new DownloadsDownloadFunction(), base::StringPrintf( | 2435 new DownloadsDownloadFunction(), |
2433 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2436 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2434 ASSERT_TRUE(result.get()); | 2437 ASSERT_TRUE(result.get()); |
2435 int result_id = -1; | 2438 int result_id = -1; |
2436 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2439 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2437 | 2440 |
2438 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2441 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2439 ASSERT_TRUE(item); | 2442 ASSERT_TRUE(item); |
2440 ScopedCancellingItem canceller(item); | 2443 ScopedCancellingItem canceller(item); |
2441 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2444 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2442 | 2445 |
2443 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2446 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
(...skipping 26 matching lines...) Expand all Loading... |
2470 | 2473 |
2471 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2474 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2472 DownloadExtensionTest_OnDeterminingFilename_NoChange) { | 2475 DownloadExtensionTest_OnDeterminingFilename_NoChange) { |
2473 GoOnTheRecord(); | 2476 GoOnTheRecord(); |
2474 LoadExtension("downloads_split"); | 2477 LoadExtension("downloads_split"); |
2475 AddFilenameDeterminer(); | 2478 AddFilenameDeterminer(); |
2476 ASSERT_TRUE(StartEmbeddedTestServer()); | 2479 ASSERT_TRUE(StartEmbeddedTestServer()); |
2477 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 2480 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
2478 | 2481 |
2479 // Start downloading a file. | 2482 // Start downloading a file. |
2480 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2483 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2481 new DownloadsDownloadFunction(), base::StringPrintf( | 2484 new DownloadsDownloadFunction(), |
2482 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2485 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2483 ASSERT_TRUE(result.get()); | 2486 ASSERT_TRUE(result.get()); |
2484 int result_id = -1; | 2487 int result_id = -1; |
2485 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2488 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2486 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2489 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2487 ASSERT_TRUE(item); | 2490 ASSERT_TRUE(item); |
2488 ScopedCancellingItem canceller(item); | 2491 ScopedCancellingItem canceller(item); |
2489 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2492 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2490 | 2493 |
2491 // Wait for the onCreated and onDeterminingFilename events. | 2494 // Wait for the onCreated and onDeterminingFilename events. |
2492 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2495 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2543 GoOnTheRecord(); | 2546 GoOnTheRecord(); |
2544 LoadExtension("downloads_split"); | 2547 LoadExtension("downloads_split"); |
2545 AddFilenameDeterminer(); | 2548 AddFilenameDeterminer(); |
2546 ASSERT_TRUE(StartEmbeddedTestServer()); | 2549 ASSERT_TRUE(StartEmbeddedTestServer()); |
2547 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 2550 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
2548 | 2551 |
2549 ExtensionDownloadsEventRouter::SetDetermineFilenameTimeoutSecondsForTesting( | 2552 ExtensionDownloadsEventRouter::SetDetermineFilenameTimeoutSecondsForTesting( |
2550 0); | 2553 0); |
2551 | 2554 |
2552 // Start downloading a file. | 2555 // Start downloading a file. |
2553 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2556 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2554 new DownloadsDownloadFunction(), base::StringPrintf( | 2557 new DownloadsDownloadFunction(), |
2555 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2558 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2556 ASSERT_TRUE(result.get()); | 2559 ASSERT_TRUE(result.get()); |
2557 int result_id = -1; | 2560 int result_id = -1; |
2558 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2561 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2559 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2562 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2560 ASSERT_TRUE(item); | 2563 ASSERT_TRUE(item); |
2561 ScopedCancellingItem canceller(item); | 2564 ScopedCancellingItem canceller(item); |
2562 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2565 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2563 | 2566 |
2564 // Wait for the onCreated and onDeterminingFilename events. | 2567 // Wait for the onCreated and onDeterminingFilename events. |
2565 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2568 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2599 | 2602 |
2600 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2603 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2601 DownloadExtensionTest_OnDeterminingFilename_Twice) { | 2604 DownloadExtensionTest_OnDeterminingFilename_Twice) { |
2602 GoOnTheRecord(); | 2605 GoOnTheRecord(); |
2603 LoadExtension("downloads_split"); | 2606 LoadExtension("downloads_split"); |
2604 AddFilenameDeterminer(); | 2607 AddFilenameDeterminer(); |
2605 ASSERT_TRUE(StartEmbeddedTestServer()); | 2608 ASSERT_TRUE(StartEmbeddedTestServer()); |
2606 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 2609 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
2607 | 2610 |
2608 // Start downloading a file. | 2611 // Start downloading a file. |
2609 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2612 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2610 new DownloadsDownloadFunction(), base::StringPrintf( | 2613 new DownloadsDownloadFunction(), |
2611 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2614 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2612 ASSERT_TRUE(result.get()); | 2615 ASSERT_TRUE(result.get()); |
2613 int result_id = -1; | 2616 int result_id = -1; |
2614 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2617 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2615 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2618 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2616 ASSERT_TRUE(item); | 2619 ASSERT_TRUE(item); |
2617 ScopedCancellingItem canceller(item); | 2620 ScopedCancellingItem canceller(item); |
2618 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2621 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2619 | 2622 |
2620 // Wait for the onCreated and onDeterminingFilename events. | 2623 // Wait for the onCreated and onDeterminingFilename events. |
2621 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2624 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2678 IN_PROC_BROWSER_TEST_F( | 2681 IN_PROC_BROWSER_TEST_F( |
2679 DownloadExtensionTest, | 2682 DownloadExtensionTest, |
2680 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) { | 2683 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) { |
2681 GoOnTheRecord(); | 2684 GoOnTheRecord(); |
2682 LoadExtension("downloads_split"); | 2685 LoadExtension("downloads_split"); |
2683 AddFilenameDeterminer(); | 2686 AddFilenameDeterminer(); |
2684 ASSERT_TRUE(StartEmbeddedTestServer()); | 2687 ASSERT_TRUE(StartEmbeddedTestServer()); |
2685 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 2688 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
2686 | 2689 |
2687 // Start downloading a file. | 2690 // Start downloading a file. |
2688 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2691 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2689 new DownloadsDownloadFunction(), base::StringPrintf( | 2692 new DownloadsDownloadFunction(), |
2690 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2693 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2691 ASSERT_TRUE(result.get()); | 2694 ASSERT_TRUE(result.get()); |
2692 int result_id = -1; | 2695 int result_id = -1; |
2693 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2696 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2694 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2697 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2695 ASSERT_TRUE(item); | 2698 ASSERT_TRUE(item); |
2696 ScopedCancellingItem canceller(item); | 2699 ScopedCancellingItem canceller(item); |
2697 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2700 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2698 | 2701 |
2699 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2702 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2700 base::StringPrintf( | 2703 base::StringPrintf( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2756 IN_PROC_BROWSER_TEST_F( | 2759 IN_PROC_BROWSER_TEST_F( |
2757 DownloadExtensionTest, | 2760 DownloadExtensionTest, |
2758 DownloadExtensionTest_OnDeterminingFilename_ReferencesParentInvalid) { | 2761 DownloadExtensionTest_OnDeterminingFilename_ReferencesParentInvalid) { |
2759 GoOnTheRecord(); | 2762 GoOnTheRecord(); |
2760 LoadExtension("downloads_split"); | 2763 LoadExtension("downloads_split"); |
2761 AddFilenameDeterminer(); | 2764 AddFilenameDeterminer(); |
2762 ASSERT_TRUE(StartEmbeddedTestServer()); | 2765 ASSERT_TRUE(StartEmbeddedTestServer()); |
2763 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 2766 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
2764 | 2767 |
2765 // Start downloading a file. | 2768 // Start downloading a file. |
2766 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2769 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2767 new DownloadsDownloadFunction(), base::StringPrintf( | 2770 new DownloadsDownloadFunction(), |
2768 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2771 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2769 ASSERT_TRUE(result.get()); | 2772 ASSERT_TRUE(result.get()); |
2770 int result_id = -1; | 2773 int result_id = -1; |
2771 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2774 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2772 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2775 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2773 ASSERT_TRUE(item); | 2776 ASSERT_TRUE(item); |
2774 ScopedCancellingItem canceller(item); | 2777 ScopedCancellingItem canceller(item); |
2775 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2778 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2776 | 2779 |
2777 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2780 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2778 base::StringPrintf( | 2781 base::StringPrintf( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2822 IN_PROC_BROWSER_TEST_F( | 2825 IN_PROC_BROWSER_TEST_F( |
2823 DownloadExtensionTest, | 2826 DownloadExtensionTest, |
2824 DownloadExtensionTest_OnDeterminingFilename_IllegalFilename) { | 2827 DownloadExtensionTest_OnDeterminingFilename_IllegalFilename) { |
2825 GoOnTheRecord(); | 2828 GoOnTheRecord(); |
2826 LoadExtension("downloads_split"); | 2829 LoadExtension("downloads_split"); |
2827 AddFilenameDeterminer(); | 2830 AddFilenameDeterminer(); |
2828 ASSERT_TRUE(StartEmbeddedTestServer()); | 2831 ASSERT_TRUE(StartEmbeddedTestServer()); |
2829 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 2832 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
2830 | 2833 |
2831 // Start downloading a file. | 2834 // Start downloading a file. |
2832 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2835 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2833 new DownloadsDownloadFunction(), base::StringPrintf( | 2836 new DownloadsDownloadFunction(), |
2834 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2837 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2835 ASSERT_TRUE(result.get()); | 2838 ASSERT_TRUE(result.get()); |
2836 int result_id = -1; | 2839 int result_id = -1; |
2837 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2840 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2838 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2841 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2839 ASSERT_TRUE(item); | 2842 ASSERT_TRUE(item); |
2840 ScopedCancellingItem canceller(item); | 2843 ScopedCancellingItem canceller(item); |
2841 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2844 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2842 | 2845 |
2843 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2846 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2844 base::StringPrintf( | 2847 base::StringPrintf( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2888 IN_PROC_BROWSER_TEST_F( | 2891 IN_PROC_BROWSER_TEST_F( |
2889 DownloadExtensionTest, | 2892 DownloadExtensionTest, |
2890 DownloadExtensionTest_OnDeterminingFilename_IllegalFilenameExtension) { | 2893 DownloadExtensionTest_OnDeterminingFilename_IllegalFilenameExtension) { |
2891 GoOnTheRecord(); | 2894 GoOnTheRecord(); |
2892 LoadExtension("downloads_split"); | 2895 LoadExtension("downloads_split"); |
2893 AddFilenameDeterminer(); | 2896 AddFilenameDeterminer(); |
2894 ASSERT_TRUE(StartEmbeddedTestServer()); | 2897 ASSERT_TRUE(StartEmbeddedTestServer()); |
2895 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 2898 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
2896 | 2899 |
2897 // Start downloading a file. | 2900 // Start downloading a file. |
2898 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2901 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2899 new DownloadsDownloadFunction(), base::StringPrintf( | 2902 new DownloadsDownloadFunction(), |
2900 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2903 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2901 ASSERT_TRUE(result.get()); | 2904 ASSERT_TRUE(result.get()); |
2902 int result_id = -1; | 2905 int result_id = -1; |
2903 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2906 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2904 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2907 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2905 ASSERT_TRUE(item); | 2908 ASSERT_TRUE(item); |
2906 ScopedCancellingItem canceller(item); | 2909 ScopedCancellingItem canceller(item); |
2907 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2910 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2908 | 2911 |
2909 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2912 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2910 base::StringPrintf( | 2913 base::StringPrintf( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2961 IN_PROC_BROWSER_TEST_F( | 2964 IN_PROC_BROWSER_TEST_F( |
2962 DownloadExtensionTest, | 2965 DownloadExtensionTest, |
2963 MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename) { | 2966 MAYBE_DownloadExtensionTest_OnDeterminingFilename_ReservedFilename) { |
2964 GoOnTheRecord(); | 2967 GoOnTheRecord(); |
2965 LoadExtension("downloads_split"); | 2968 LoadExtension("downloads_split"); |
2966 AddFilenameDeterminer(); | 2969 AddFilenameDeterminer(); |
2967 ASSERT_TRUE(StartEmbeddedTestServer()); | 2970 ASSERT_TRUE(StartEmbeddedTestServer()); |
2968 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 2971 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
2969 | 2972 |
2970 // Start downloading a file. | 2973 // Start downloading a file. |
2971 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2974 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
2972 new DownloadsDownloadFunction(), base::StringPrintf( | 2975 new DownloadsDownloadFunction(), |
2973 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2976 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
2974 ASSERT_TRUE(result.get()); | 2977 ASSERT_TRUE(result.get()); |
2975 int result_id = -1; | 2978 int result_id = -1; |
2976 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2979 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2977 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2980 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2978 ASSERT_TRUE(item); | 2981 ASSERT_TRUE(item); |
2979 ScopedCancellingItem canceller(item); | 2982 ScopedCancellingItem canceller(item); |
2980 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2983 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2981 | 2984 |
2982 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 2985 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
2983 base::StringPrintf( | 2986 base::StringPrintf( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3027 IN_PROC_BROWSER_TEST_F( | 3030 IN_PROC_BROWSER_TEST_F( |
3028 DownloadExtensionTest, | 3031 DownloadExtensionTest, |
3029 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) { | 3032 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) { |
3030 GoOnTheRecord(); | 3033 GoOnTheRecord(); |
3031 LoadExtension("downloads_split"); | 3034 LoadExtension("downloads_split"); |
3032 AddFilenameDeterminer(); | 3035 AddFilenameDeterminer(); |
3033 ASSERT_TRUE(StartEmbeddedTestServer()); | 3036 ASSERT_TRUE(StartEmbeddedTestServer()); |
3034 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 3037 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
3035 | 3038 |
3036 // Start downloading a file. | 3039 // Start downloading a file. |
3037 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3040 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3038 new DownloadsDownloadFunction(), base::StringPrintf( | 3041 new DownloadsDownloadFunction(), |
3039 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3042 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3040 ASSERT_TRUE(result.get()); | 3043 ASSERT_TRUE(result.get()); |
3041 int result_id = -1; | 3044 int result_id = -1; |
3042 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3045 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3043 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3046 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3044 ASSERT_TRUE(item); | 3047 ASSERT_TRUE(item); |
3045 ScopedCancellingItem canceller(item); | 3048 ScopedCancellingItem canceller(item); |
3046 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3049 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3047 | 3050 |
3048 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3051 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
3049 base::StringPrintf( | 3052 base::StringPrintf( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3093 IN_PROC_BROWSER_TEST_F( | 3096 IN_PROC_BROWSER_TEST_F( |
3094 DownloadExtensionTest, | 3097 DownloadExtensionTest, |
3095 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) { | 3098 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) { |
3096 ASSERT_TRUE(StartEmbeddedTestServer()); | 3099 ASSERT_TRUE(StartEmbeddedTestServer()); |
3097 GoOnTheRecord(); | 3100 GoOnTheRecord(); |
3098 LoadExtension("downloads_split"); | 3101 LoadExtension("downloads_split"); |
3099 AddFilenameDeterminer(); | 3102 AddFilenameDeterminer(); |
3100 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 3103 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
3101 | 3104 |
3102 // Start downloading a file. | 3105 // Start downloading a file. |
3103 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3106 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3104 new DownloadsDownloadFunction(), base::StringPrintf( | 3107 new DownloadsDownloadFunction(), |
3105 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3108 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3106 ASSERT_TRUE(result.get()); | 3109 ASSERT_TRUE(result.get()); |
3107 int result_id = -1; | 3110 int result_id = -1; |
3108 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3111 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3109 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3112 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3110 ASSERT_TRUE(item); | 3113 ASSERT_TRUE(item); |
3111 ScopedCancellingItem canceller(item); | 3114 ScopedCancellingItem canceller(item); |
3112 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3115 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3113 | 3116 |
3114 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3117 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
3115 base::StringPrintf( | 3118 base::StringPrintf( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3159 IN_PROC_BROWSER_TEST_F( | 3162 IN_PROC_BROWSER_TEST_F( |
3160 DownloadExtensionTest, | 3163 DownloadExtensionTest, |
3161 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) { | 3164 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) { |
3162 GoOnTheRecord(); | 3165 GoOnTheRecord(); |
3163 LoadExtension("downloads_split"); | 3166 LoadExtension("downloads_split"); |
3164 AddFilenameDeterminer(); | 3167 AddFilenameDeterminer(); |
3165 ASSERT_TRUE(StartEmbeddedTestServer()); | 3168 ASSERT_TRUE(StartEmbeddedTestServer()); |
3166 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 3169 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
3167 | 3170 |
3168 // Start downloading a file. | 3171 // Start downloading a file. |
3169 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3172 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3170 new DownloadsDownloadFunction(), base::StringPrintf( | 3173 new DownloadsDownloadFunction(), |
3171 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3174 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3172 ASSERT_TRUE(result.get()); | 3175 ASSERT_TRUE(result.get()); |
3173 int result_id = -1; | 3176 int result_id = -1; |
3174 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3177 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3175 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3178 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3176 ASSERT_TRUE(item); | 3179 ASSERT_TRUE(item); |
3177 ScopedCancellingItem canceller(item); | 3180 ScopedCancellingItem canceller(item); |
3178 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3181 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3179 | 3182 |
3180 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3183 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
3181 base::StringPrintf( | 3184 base::StringPrintf( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3226 IN_PROC_BROWSER_TEST_F( | 3229 IN_PROC_BROWSER_TEST_F( |
3227 DownloadExtensionTest, | 3230 DownloadExtensionTest, |
3228 DownloadExtensionTest_OnDeterminingFilename_EmptyBasenameInvalid) { | 3231 DownloadExtensionTest_OnDeterminingFilename_EmptyBasenameInvalid) { |
3229 GoOnTheRecord(); | 3232 GoOnTheRecord(); |
3230 LoadExtension("downloads_split"); | 3233 LoadExtension("downloads_split"); |
3231 AddFilenameDeterminer(); | 3234 AddFilenameDeterminer(); |
3232 ASSERT_TRUE(StartEmbeddedTestServer()); | 3235 ASSERT_TRUE(StartEmbeddedTestServer()); |
3233 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 3236 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
3234 | 3237 |
3235 // Start downloading a file. | 3238 // Start downloading a file. |
3236 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3239 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3237 new DownloadsDownloadFunction(), base::StringPrintf( | 3240 new DownloadsDownloadFunction(), |
3238 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3241 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3239 ASSERT_TRUE(result.get()); | 3242 ASSERT_TRUE(result.get()); |
3240 int result_id = -1; | 3243 int result_id = -1; |
3241 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3244 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3242 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3245 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3243 ASSERT_TRUE(item); | 3246 ASSERT_TRUE(item); |
3244 ScopedCancellingItem canceller(item); | 3247 ScopedCancellingItem canceller(item); |
3245 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3248 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3246 | 3249 |
3247 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3250 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
3248 base::StringPrintf( | 3251 base::StringPrintf( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3294 IN_PROC_BROWSER_TEST_F( | 3297 IN_PROC_BROWSER_TEST_F( |
3295 DownloadExtensionTest, | 3298 DownloadExtensionTest, |
3296 DownloadExtensionTest_OnDeterminingFilename_Overwrite) { | 3299 DownloadExtensionTest_OnDeterminingFilename_Overwrite) { |
3297 GoOnTheRecord(); | 3300 GoOnTheRecord(); |
3298 LoadExtension("downloads_split"); | 3301 LoadExtension("downloads_split"); |
3299 AddFilenameDeterminer(); | 3302 AddFilenameDeterminer(); |
3300 ASSERT_TRUE(StartEmbeddedTestServer()); | 3303 ASSERT_TRUE(StartEmbeddedTestServer()); |
3301 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 3304 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
3302 | 3305 |
3303 // Start downloading a file. | 3306 // Start downloading a file. |
3304 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3307 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3305 new DownloadsDownloadFunction(), base::StringPrintf( | 3308 new DownloadsDownloadFunction(), |
3306 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3309 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3307 ASSERT_TRUE(result.get()); | 3310 ASSERT_TRUE(result.get()); |
3308 int result_id = -1; | 3311 int result_id = -1; |
3309 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3312 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3310 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3313 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3311 ASSERT_TRUE(item); | 3314 ASSERT_TRUE(item); |
3312 ScopedCancellingItem canceller(item); | 3315 ScopedCancellingItem canceller(item); |
3313 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3316 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3314 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3317 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
3315 base::StringPrintf( | 3318 base::StringPrintf( |
3316 "[{\"danger\": \"safe\"," | 3319 "[{\"danger\": \"safe\"," |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3420 IN_PROC_BROWSER_TEST_F( | 3423 IN_PROC_BROWSER_TEST_F( |
3421 DownloadExtensionTest, | 3424 DownloadExtensionTest, |
3422 DownloadExtensionTest_OnDeterminingFilename_Override) { | 3425 DownloadExtensionTest_OnDeterminingFilename_Override) { |
3423 GoOnTheRecord(); | 3426 GoOnTheRecord(); |
3424 LoadExtension("downloads_split"); | 3427 LoadExtension("downloads_split"); |
3425 AddFilenameDeterminer(); | 3428 AddFilenameDeterminer(); |
3426 ASSERT_TRUE(StartEmbeddedTestServer()); | 3429 ASSERT_TRUE(StartEmbeddedTestServer()); |
3427 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 3430 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
3428 | 3431 |
3429 // Start downloading a file. | 3432 // Start downloading a file. |
3430 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3433 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3431 new DownloadsDownloadFunction(), base::StringPrintf( | 3434 new DownloadsDownloadFunction(), |
3432 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3435 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3433 ASSERT_TRUE(result.get()); | 3436 ASSERT_TRUE(result.get()); |
3434 int result_id = -1; | 3437 int result_id = -1; |
3435 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3438 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3436 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3439 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3437 ASSERT_TRUE(item); | 3440 ASSERT_TRUE(item); |
3438 ScopedCancellingItem canceller(item); | 3441 ScopedCancellingItem canceller(item); |
3439 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3442 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3440 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3443 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
3441 base::StringPrintf( | 3444 base::StringPrintf( |
3442 "[{\"danger\": \"safe\"," | 3445 "[{\"danger\": \"safe\"," |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3556 IN_PROC_BROWSER_TEST_F( | 3559 IN_PROC_BROWSER_TEST_F( |
3557 DownloadExtensionTest, | 3560 DownloadExtensionTest, |
3558 MAYBE_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer)
{ | 3561 MAYBE_DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer)
{ |
3559 ASSERT_TRUE(StartEmbeddedTestServer()); | 3562 ASSERT_TRUE(StartEmbeddedTestServer()); |
3560 GoOnTheRecord(); | 3563 GoOnTheRecord(); |
3561 LoadExtension("downloads_split"); | 3564 LoadExtension("downloads_split"); |
3562 content::RenderProcessHost* host = AddFilenameDeterminer(); | 3565 content::RenderProcessHost* host = AddFilenameDeterminer(); |
3563 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 3566 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
3564 | 3567 |
3565 // Start downloading a file. | 3568 // Start downloading a file. |
3566 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3569 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3567 new DownloadsDownloadFunction(), base::StringPrintf( | 3570 new DownloadsDownloadFunction(), |
3568 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3571 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3569 ASSERT_TRUE(result.get()); | 3572 ASSERT_TRUE(result.get()); |
3570 int result_id = -1; | 3573 int result_id = -1; |
3571 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3574 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3572 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3575 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3573 ASSERT_TRUE(item); | 3576 ASSERT_TRUE(item); |
3574 ScopedCancellingItem canceller(item); | 3577 ScopedCancellingItem canceller(item); |
3575 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3578 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3576 | 3579 |
3577 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3580 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
3578 base::StringPrintf( | 3581 base::StringPrintf( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3612 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 3615 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
3613 | 3616 |
3614 GoOnTheRecord(); | 3617 GoOnTheRecord(); |
3615 AddFilenameDeterminer(); | 3618 AddFilenameDeterminer(); |
3616 | 3619 |
3617 GoOffTheRecord(); | 3620 GoOffTheRecord(); |
3618 AddFilenameDeterminer(); | 3621 AddFilenameDeterminer(); |
3619 | 3622 |
3620 // Start an on-record download. | 3623 // Start an on-record download. |
3621 GoOnTheRecord(); | 3624 GoOnTheRecord(); |
3622 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3625 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3623 new DownloadsDownloadFunction(), base::StringPrintf( | 3626 new DownloadsDownloadFunction(), |
3624 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3627 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3625 ASSERT_TRUE(result.get()); | 3628 ASSERT_TRUE(result.get()); |
3626 int result_id = -1; | 3629 int result_id = -1; |
3627 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3630 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3628 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3631 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3629 ASSERT_TRUE(item); | 3632 ASSERT_TRUE(item); |
3630 ScopedCancellingItem canceller(item); | 3633 ScopedCancellingItem canceller(item); |
3631 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3634 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3632 | 3635 |
3633 // Wait for the onCreated and onDeterminingFilename events. | 3636 // Wait for the onCreated and onDeterminingFilename events. |
3634 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3637 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3751 | 3754 |
3752 GoOnTheRecord(); | 3755 GoOnTheRecord(); |
3753 AddFilenameDeterminer(); | 3756 AddFilenameDeterminer(); |
3754 | 3757 |
3755 // There is a single extension renderer that sees both on-record and | 3758 // There is a single extension renderer that sees both on-record and |
3756 // off-record events. The extension functions see the on-record profile with | 3759 // off-record events. The extension functions see the on-record profile with |
3757 // include_incognito=true. | 3760 // include_incognito=true. |
3758 | 3761 |
3759 // Start an on-record download. | 3762 // Start an on-record download. |
3760 GoOnTheRecord(); | 3763 GoOnTheRecord(); |
3761 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 3764 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
3762 new DownloadsDownloadFunction(), base::StringPrintf( | 3765 new DownloadsDownloadFunction(), |
3763 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 3766 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
3764 ASSERT_TRUE(result.get()); | 3767 ASSERT_TRUE(result.get()); |
3765 int result_id = -1; | 3768 int result_id = -1; |
3766 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 3769 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
3767 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 3770 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
3768 ASSERT_TRUE(item); | 3771 ASSERT_TRUE(item); |
3769 ScopedCancellingItem canceller(item); | 3772 ScopedCancellingItem canceller(item); |
3770 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 3773 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
3771 | 3774 |
3772 // Wait for the onCreated and onDeterminingFilename events. | 3775 // Wait for the onCreated and onDeterminingFilename events. |
3773 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 3776 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3896 MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume) { | 3899 MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume) { |
3897 LoadExtension("downloads_split"); | 3900 LoadExtension("downloads_split"); |
3898 ASSERT_TRUE(StartEmbeddedTestServer()); | 3901 ASSERT_TRUE(StartEmbeddedTestServer()); |
3899 GoOnTheRecord(); | 3902 GoOnTheRecord(); |
3900 content::RenderProcessHost* host = AddFilenameDeterminer(); | 3903 content::RenderProcessHost* host = AddFilenameDeterminer(); |
3901 | 3904 |
3902 // Start a download. | 3905 // Start a download. |
3903 DownloadItem* item = NULL; | 3906 DownloadItem* item = NULL; |
3904 { | 3907 { |
3905 DownloadManager* manager = GetCurrentManager(); | 3908 DownloadManager* manager = GetCurrentManager(); |
3906 scoped_ptr<content::DownloadTestObserver> observer( | 3909 std::unique_ptr<content::DownloadTestObserver> observer( |
3907 new JustInProgressDownloadObserver(manager, 1)); | 3910 new JustInProgressDownloadObserver(manager, 1)); |
3908 ASSERT_EQ(0, manager->InProgressCount()); | 3911 ASSERT_EQ(0, manager->InProgressCount()); |
3909 ASSERT_EQ(0, manager->NonMaliciousInProgressCount()); | 3912 ASSERT_EQ(0, manager->NonMaliciousInProgressCount()); |
3910 // Tabs created just for a download are automatically closed, invalidating | 3913 // Tabs created just for a download are automatically closed, invalidating |
3911 // the download's WebContents. Downloads without WebContents cannot be | 3914 // the download's WebContents. Downloads without WebContents cannot be |
3912 // resumed. http://crbug.com/225901 | 3915 // resumed. http://crbug.com/225901 |
3913 ui_test_utils::NavigateToURLWithDisposition( | 3916 ui_test_utils::NavigateToURLWithDisposition( |
3914 current_browser(), | 3917 current_browser(), |
3915 GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl), | 3918 GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl), |
3916 CURRENT_TAB, | 3919 CURRENT_TAB, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4057 #else | 4060 #else |
4058 #define MAYBE_DownloadExtensionTest_AcceptDanger DownloadExtensionTest_AcceptDan
ger | 4061 #define MAYBE_DownloadExtensionTest_AcceptDanger DownloadExtensionTest_AcceptDan
ger |
4059 #endif | 4062 #endif |
4060 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 4063 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
4061 MAYBE_DownloadExtensionTest_AcceptDanger) { | 4064 MAYBE_DownloadExtensionTest_AcceptDanger) { |
4062 // Download a file that will be marked dangerous; click the browser action | 4065 // Download a file that will be marked dangerous; click the browser action |
4063 // button; the browser action poup will call acceptDanger(); when the | 4066 // button; the browser action poup will call acceptDanger(); when the |
4064 // DownloadDangerPrompt is created, pretend that the user clicks the Accept | 4067 // DownloadDangerPrompt is created, pretend that the user clicks the Accept |
4065 // button; wait until the download completes. | 4068 // button; wait until the download completes. |
4066 LoadExtension("downloads_split"); | 4069 LoadExtension("downloads_split"); |
4067 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 4070 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
4068 new DownloadsDownloadFunction(), | 4071 new DownloadsDownloadFunction(), |
4069 "[{\"url\": \"data:,\", \"filename\": \"dangerous.swf\"}]")); | 4072 "[{\"url\": \"data:,\", \"filename\": \"dangerous.swf\"}]")); |
4070 ASSERT_TRUE(result.get()); | 4073 ASSERT_TRUE(result.get()); |
4071 int result_id = -1; | 4074 int result_id = -1; |
4072 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 4075 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
4073 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 4076 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
4074 ASSERT_TRUE(item); | 4077 ASSERT_TRUE(item); |
4075 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 4078 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
4076 base::StringPrintf( | 4079 base::StringPrintf( |
4077 "[{\"id\": %d, " | 4080 "[{\"id\": %d, " |
4078 " \"danger\": {" | 4081 " \"danger\": {" |
4079 " \"previous\": \"safe\"," | 4082 " \"previous\": \"safe\"," |
4080 " \"current\": \"file\"}}]", | 4083 " \"current\": \"file\"}}]", |
4081 result_id))); | 4084 result_id))); |
4082 ASSERT_TRUE(item->IsDangerous()); | 4085 ASSERT_TRUE(item->IsDangerous()); |
4083 ScopedCancellingItem canceller(item); | 4086 ScopedCancellingItem canceller(item); |
4084 scoped_ptr<content::DownloadTestObserver> observer( | 4087 std::unique_ptr<content::DownloadTestObserver> observer( |
4085 new content::DownloadTestObserverTerminal( | 4088 new content::DownloadTestObserverTerminal( |
4086 GetCurrentManager(), 1, | 4089 GetCurrentManager(), 1, |
4087 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); | 4090 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); |
4088 DownloadsAcceptDangerFunction::OnPromptCreatedCallback callback = | 4091 DownloadsAcceptDangerFunction::OnPromptCreatedCallback callback = |
4089 base::Bind(&OnDangerPromptCreated); | 4092 base::Bind(&OnDangerPromptCreated); |
4090 DownloadsAcceptDangerFunction::OnPromptCreatedForTesting( | 4093 DownloadsAcceptDangerFunction::OnPromptCreatedForTesting( |
4091 &callback); | 4094 &callback); |
4092 BrowserActionTestUtil(browser()).Press(0); | 4095 BrowserActionTestUtil(browser()).Press(0); |
4093 observer->WaitForFinished(); | 4096 observer->WaitForFinished(); |
4094 } | 4097 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4185 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 4188 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
4186 EXPECT_FALSE(warnings.empty()); | 4189 EXPECT_FALSE(warnings.empty()); |
4187 EXPECT_EQ(Warning::kDownloadFilenameConflict, | 4190 EXPECT_EQ(Warning::kDownloadFilenameConflict, |
4188 warnings.begin()->warning_type()); | 4191 warnings.begin()->warning_type()); |
4189 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4192 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
4190 } | 4193 } |
4191 | 4194 |
4192 } // namespace extensions | 4195 } // namespace extensions |
4193 | 4196 |
4194 #endif // http://crbug.com/306144 | 4197 #endif // http://crbug.com/306144 |
OLD | NEW |