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

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

Issue 16924017: A few minor changes to the chrome.downloads extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r212092 Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO occam move to _browser_test.cc
6
5 #include <algorithm> 7 #include <algorithm>
6 8
7 #include "base/file_util.h" 9 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
10 #include "base/message_loop.h" 12 #include "base/message_loop.h"
11 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
12 #include "base/stl_util.h" 14 #include "base/stl_util.h"
13 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
14 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #include "webkit/common/blob/blob_data.h" 57 #include "webkit/common/blob/blob_data.h"
56 58
57 using content::BrowserContext; 59 using content::BrowserContext;
58 using content::BrowserThread; 60 using content::BrowserThread;
59 using content::DownloadItem; 61 using content::DownloadItem;
60 using content::DownloadManager; 62 using content::DownloadManager;
61 using content::URLRequestSlowDownloadJob; 63 using content::URLRequestSlowDownloadJob;
62 64
63 namespace events = extensions::event_names; 65 namespace events = extensions::event_names;
64 66
67 namespace errors = download_extension_errors;
68
65 namespace { 69 namespace {
66 70
67 // Comparator that orders download items by their ID. Can be used with 71 // Comparator that orders download items by their ID. Can be used with
68 // std::sort. 72 // std::sort.
69 struct DownloadIdComparator { 73 struct DownloadIdComparator {
70 bool operator() (DownloadItem* first, DownloadItem* second) { 74 bool operator() (DownloadItem* first, DownloadItem* second) {
71 return first->GetId() < second->GetId(); 75 return first->GetId() < second->GetId();
72 } 76 }
73 }; 77 };
74 78
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 observer.EnableFileChooser(false); 346 observer.EnableFileChooser(false);
343 } 347 }
344 current_browser_ = incognito_browser_; 348 current_browser_ = incognito_browser_;
345 } 349 }
346 350
347 bool WaitFor(const std::string& event_name, const std::string& json_args) { 351 bool WaitFor(const std::string& event_name, const std::string& json_args) {
348 return events_listener_->WaitFor( 352 return events_listener_->WaitFor(
349 current_browser()->profile(), event_name, json_args); 353 current_browser()->profile(), event_name, json_args);
350 } 354 }
351 355
352 bool WaitForInterruption(DownloadItem* item, int expected_error, 356 bool WaitForInterruption(
353 const std::string& on_created_event) { 357 DownloadItem* item,
358 content::DownloadInterruptReason expected_error,
359 const std::string& on_created_event) {
354 if (!WaitFor(events::kOnDownloadCreated, on_created_event)) 360 if (!WaitFor(events::kOnDownloadCreated, on_created_event))
355 return false; 361 return false;
356 // Now, onCreated is always fired before interruption. 362 // Now, onCreated is always fired before interruption.
357 return WaitFor(events::kOnDownloadChanged, 363 return WaitFor(events::kOnDownloadChanged,
358 base::StringPrintf("[{\"id\": %d," 364 base::StringPrintf("[{\"id\": %d,"
359 " \"error\": {\"current\": %d}," 365 " \"error\": {\"current\": \"%s\"},"
360 " \"state\": {" 366 " \"state\": {"
361 " \"previous\": \"in_progress\"," 367 " \"previous\": \"in_progress\","
362 " \"current\": \"interrupted\"}}]", 368 " \"current\": \"interrupted\"}}]",
363 item->GetId(), 369 item->GetId(),
364 expected_error)); 370 content::InterruptReasonDebugString(
371 expected_error).c_str()));
365 } 372 }
366 373
367 void ClearEvents() { 374 void ClearEvents() {
368 events_listener_->ClearEvents(); 375 events_listener_->ClearEvents();
369 } 376 }
370 377
371 std::string GetExtensionURL() { 378 std::string GetExtensionURL() {
372 return extension_->url().spec(); 379 return extension_->url().spec();
373 } 380 }
374 std::string GetExtensionId() { 381 std::string GetExtensionId() {
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 909
903 bool ItemIsInterrupted(DownloadItem* item) { 910 bool ItemIsInterrupted(DownloadItem* item) {
904 return item->GetState() == DownloadItem::INTERRUPTED; 911 return item->GetState() == DownloadItem::INTERRUPTED;
905 } 912 }
906 913
907 } // namespace 914 } // namespace
908 915
909 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 916 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
910 DownloadExtensionTest_Open) { 917 DownloadExtensionTest_Open) {
911 LoadExtension("downloads_split"); 918 LoadExtension("downloads_split");
912 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 919 EXPECT_STREQ(errors::kInvalidId,
913 RunFunctionAndReturnError( 920 RunFunctionAndReturnError(
914 new DownloadsOpenFunction(), 921 new DownloadsOpenFunction(),
915 "[-42]").c_str()); 922 "[-42]").c_str());
916 923
917 DownloadItem* download_item = CreateSlowTestDownload(); 924 DownloadItem* download_item = CreateSlowTestDownload();
918 ASSERT_TRUE(download_item); 925 ASSERT_TRUE(download_item);
919 EXPECT_FALSE(download_item->GetOpened()); 926 EXPECT_FALSE(download_item->GetOpened());
920 EXPECT_FALSE(download_item->GetOpenWhenComplete()); 927 EXPECT_FALSE(download_item->GetOpenWhenComplete());
921 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, 928 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
922 base::StringPrintf("[{\"danger\": \"safe\"," 929 base::StringPrintf("[{\"danger\": \"safe\","
923 " \"incognito\": false," 930 " \"incognito\": false,"
924 " \"mime\": \"application/octet-stream\"," 931 " \"mime\": \"application/octet-stream\","
925 " \"paused\": false," 932 " \"paused\": false,"
926 " \"url\": \"%s\"}]", 933 " \"url\": \"%s\"}]",
927 download_item->GetURL().spec().c_str()))); 934 download_item->GetURL().spec().c_str())));
928 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 935 EXPECT_STREQ(errors::kNotComplete,
929 RunFunctionAndReturnError( 936 RunFunctionAndReturnError(
930 new DownloadsOpenFunction(), 937 new DownloadsOpenFunction(),
931 DownloadItemIdAsArgList(download_item)).c_str()); 938 DownloadItemIdAsArgList(download_item)).c_str());
932 939
933 FinishPendingSlowDownloads(); 940 FinishPendingSlowDownloads();
934 EXPECT_FALSE(download_item->GetOpened()); 941 EXPECT_FALSE(download_item->GetOpened());
935 EXPECT_TRUE(RunFunction(new DownloadsOpenFunction(), 942 EXPECT_TRUE(RunFunction(new DownloadsOpenFunction(),
936 DownloadItemIdAsArgList(download_item))); 943 DownloadItemIdAsArgList(download_item)));
937 EXPECT_TRUE(download_item->GetOpened()); 944 EXPECT_TRUE(download_item->GetOpened());
938 } 945 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 // And now cancel. 978 // And now cancel.
972 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), 979 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(),
973 DownloadItemIdAsArgList(download_item))); 980 DownloadItemIdAsArgList(download_item)));
974 EXPECT_EQ(DownloadItem::CANCELLED, download_item->GetState()); 981 EXPECT_EQ(DownloadItem::CANCELLED, download_item->GetState());
975 982
976 // Cancel again. Shouldn't have any effect. 983 // Cancel again. Shouldn't have any effect.
977 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), 984 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(),
978 DownloadItemIdAsArgList(download_item))); 985 DownloadItemIdAsArgList(download_item)));
979 EXPECT_EQ(DownloadItem::CANCELLED, download_item->GetState()); 986 EXPECT_EQ(DownloadItem::CANCELLED, download_item->GetState());
980 987
981 // Calling paused on a non-active download yields kInvalidOperationError. 988 // Calling paused on a non-active download yields kInvalidId.
982 std::string error = RunFunctionAndReturnError( 989 std::string error = RunFunctionAndReturnError(
983 new DownloadsPauseFunction(), DownloadItemIdAsArgList(download_item)); 990 new DownloadsPauseFunction(), DownloadItemIdAsArgList(download_item));
984 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 991 EXPECT_STREQ(errors::kNotInProgress, error.c_str());
985 error.c_str());
986 992
987 // Calling resume on a non-active download yields kInvalidOperationError 993 // Calling resume on a non-active download yields kInvalidId
988 error = RunFunctionAndReturnError( 994 error = RunFunctionAndReturnError(
989 new DownloadsResumeFunction(), DownloadItemIdAsArgList(download_item)); 995 new DownloadsResumeFunction(), DownloadItemIdAsArgList(download_item));
990 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 996 EXPECT_STREQ(errors::kNotInProgress, error.c_str());
991 error.c_str());
992 997
993 // Calling paused on a non-existent download yields kInvalidOperationError. 998 // Calling paused on a non-existent download yields kInvalidId.
994 error = RunFunctionAndReturnError( 999 error = RunFunctionAndReturnError(
995 new DownloadsPauseFunction(), "[-42]"); 1000 new DownloadsPauseFunction(), "[-42]");
996 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1001 EXPECT_STREQ(errors::kInvalidId, error.c_str());
997 error.c_str());
998 1002
999 // Calling resume on a non-existent download yields kInvalidOperationError 1003 // Calling resume on a non-existent download yields kInvalidId
1000 error = RunFunctionAndReturnError( 1004 error = RunFunctionAndReturnError(
1001 new DownloadsResumeFunction(), "[-42]"); 1005 new DownloadsResumeFunction(), "[-42]");
1002 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1006 EXPECT_STREQ(errors::kInvalidId, error.c_str());
1003 error.c_str());
1004 1007
1005 int id = download_item->GetId(); 1008 int id = download_item->GetId();
1006 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1009 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1007 new DownloadsEraseFunction(), 1010 new DownloadsEraseFunction(),
1008 base::StringPrintf("[{\"id\": %d}]", id))); 1011 base::StringPrintf("[{\"id\": %d}]", id)));
1009 DownloadManager::DownloadVector items; 1012 DownloadManager::DownloadVector items;
1010 GetCurrentManager()->GetAllDownloads(&items); 1013 GetCurrentManager()->GetAllDownloads(&items);
1011 EXPECT_EQ(0UL, items.size()); 1014 EXPECT_EQ(0UL, items.size());
1012 ASSERT_TRUE(result); 1015 ASSERT_TRUE(result);
1013 download_item = NULL; 1016 download_item = NULL;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 args32, 1092 args32,
1090 &result_string)); 1093 &result_string));
1091 1094
1092 // Simulate an error during icon load by invoking the mock with an empty 1095 // Simulate an error during icon load by invoking the mock with an empty
1093 // result string. 1096 // result string.
1094 std::string error = RunFunctionAndReturnError( 1097 std::string error = RunFunctionAndReturnError(
1095 MockedGetFileIconFunction(download_item->GetTargetFilePath(), 1098 MockedGetFileIconFunction(download_item->GetTargetFilePath(),
1096 IconLoader::NORMAL, 1099 IconLoader::NORMAL,
1097 std::string()), 1100 std::string()),
1098 args32); 1101 args32);
1099 EXPECT_STREQ(download_extension_errors::kIconNotFoundError, error.c_str()); 1102 EXPECT_STREQ(errors::kIconNotFound, error.c_str());
1100 1103
1101 // Once the download item is deleted, we should return kInvalidOperationError. 1104 // Once the download item is deleted, we should return kInvalidId.
1102 int id = download_item->GetId(); 1105 int id = download_item->GetId();
1103 download_item->Remove(); 1106 download_item->Remove();
1104 download_item = NULL; 1107 download_item = NULL;
1105 EXPECT_EQ(static_cast<DownloadItem*>(NULL), 1108 EXPECT_EQ(static_cast<DownloadItem*>(NULL),
1106 GetCurrentManager()->GetDownload(id)); 1109 GetCurrentManager()->GetDownload(id));
1107 error = RunFunctionAndReturnError(new DownloadsGetFileIconFunction(), args32); 1110 error = RunFunctionAndReturnError(new DownloadsGetFileIconFunction(), args32);
1108 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1111 EXPECT_STREQ(errors::kInvalidId,
1109 error.c_str()); 1112 error.c_str());
1110 } 1113 }
1111 1114
1112 // Test that we can acquire file icons for history downloads regardless of 1115 // Test that we can acquire file icons for history downloads regardless of
1113 // whether they exist or not. If the file doesn't exist we should receive a 1116 // whether they exist or not. If the file doesn't exist we should receive a
1114 // generic icon from the OS/toolkit that may or may not be specific to the file 1117 // generic icon from the OS/toolkit that may or may not be specific to the file
1115 // type. 1118 // type.
1116 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1119 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1117 DownloadExtensionTest_FileIcon_History) { 1120 DownloadExtensionTest_FileIcon_History) {
1118 const HistoryDownloadInfo kHistoryInfo[] = { 1121 const HistoryDownloadInfo kHistoryInfo[] = {
(...skipping 20 matching lines...) Expand all
1139 ++iter) { 1142 ++iter) {
1140 std::string result_string; 1143 std::string result_string;
1141 // Use a MockIconExtractorImpl to test if the correct path is being passed 1144 // Use a MockIconExtractorImpl to test if the correct path is being passed
1142 // into the DownloadFileIconExtractor. 1145 // into the DownloadFileIconExtractor.
1143 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction( 1146 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
1144 (*iter)->GetTargetFilePath(), IconLoader::NORMAL, "hello"), 1147 (*iter)->GetTargetFilePath(), IconLoader::NORMAL, "hello"),
1145 base::StringPrintf("[%d, {\"size\": 32}]", (*iter)->GetId()), 1148 base::StringPrintf("[%d, {\"size\": 32}]", (*iter)->GetId()),
1146 &result_string)); 1149 &result_string));
1147 EXPECT_STREQ("hello", result_string.c_str()); 1150 EXPECT_STREQ("hello", result_string.c_str());
1148 } 1151 }
1149
1150 // The temporary files should be cleaned up when the base::ScopedTempDir is re moved.
1151 } 1152 }
1152 1153
1153 // Test passing the empty query to search(). 1154 // Test passing the empty query to search().
1154 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1155 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1155 DownloadExtensionTest_SearchEmptyQuery) { 1156 DownloadExtensionTest_SearchEmptyQuery) {
1156 ScopedCancellingItem item(CreateSlowTestDownload()); 1157 ScopedCancellingItem item(CreateSlowTestDownload());
1157 ASSERT_TRUE(item.get()); 1158 ASSERT_TRUE(item.get());
1158 1159
1159 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1160 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1160 new DownloadsSearchFunction(), "[{}]")); 1161 new DownloadsSearchFunction(), "[{}]"));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, 1238 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS },
1238 { FILE_PATH_LITERAL("baz"), 1239 { FILE_PATH_LITERAL("baz"),
1239 DownloadItem::COMPLETE, 1240 DownloadItem::COMPLETE,
1240 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } 1241 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }
1241 }; 1242 };
1242 DownloadManager::DownloadVector items; 1243 DownloadManager::DownloadVector items;
1243 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), 1244 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo),
1244 &items)); 1245 &items));
1245 1246
1246 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1247 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1247 new DownloadsSearchFunction(), "[{\"orderBy\": \"filename\"}]")); 1248 new DownloadsSearchFunction(), "[{\"orderBy\": [\"filename\"]}]"));
1248 ASSERT_TRUE(result.get()); 1249 ASSERT_TRUE(result.get());
1249 base::ListValue* result_list = NULL; 1250 base::ListValue* result_list = NULL;
1250 ASSERT_TRUE(result->GetAsList(&result_list)); 1251 ASSERT_TRUE(result->GetAsList(&result_list));
1251 ASSERT_EQ(2UL, result_list->GetSize()); 1252 ASSERT_EQ(2UL, result_list->GetSize());
1252 base::DictionaryValue* item0_value = NULL; 1253 base::DictionaryValue* item0_value = NULL;
1253 base::DictionaryValue* item1_value = NULL; 1254 base::DictionaryValue* item1_value = NULL;
1254 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); 1255 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value));
1255 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); 1256 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value));
1256 std::string item0_name, item1_name; 1257 std::string item0_name, item1_name;
1257 ASSERT_TRUE(item0_value->GetString("filename", &item0_name)); 1258 ASSERT_TRUE(item0_value->GetString("filename", &item0_name));
(...skipping 12 matching lines...) Expand all
1270 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, 1271 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS },
1271 { FILE_PATH_LITERAL("baz"), 1272 { FILE_PATH_LITERAL("baz"),
1272 DownloadItem::COMPLETE, 1273 DownloadItem::COMPLETE,
1273 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } 1274 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }
1274 }; 1275 };
1275 DownloadManager::DownloadVector items; 1276 DownloadManager::DownloadVector items;
1276 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), 1277 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo),
1277 &items)); 1278 &items));
1278 1279
1279 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1280 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1280 new DownloadsSearchFunction(), "[{\"orderBy\": \"\"}]")); 1281 new DownloadsSearchFunction(), "[{\"orderBy\": []}]"));
1281 ASSERT_TRUE(result.get()); 1282 ASSERT_TRUE(result.get());
1282 base::ListValue* result_list = NULL; 1283 base::ListValue* result_list = NULL;
1283 ASSERT_TRUE(result->GetAsList(&result_list)); 1284 ASSERT_TRUE(result->GetAsList(&result_list));
1284 ASSERT_EQ(2UL, result_list->GetSize()); 1285 ASSERT_EQ(2UL, result_list->GetSize());
1285 base::DictionaryValue* item0_value = NULL; 1286 base::DictionaryValue* item0_value = NULL;
1286 base::DictionaryValue* item1_value = NULL; 1287 base::DictionaryValue* item1_value = NULL;
1287 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value)); 1288 ASSERT_TRUE(result_list->GetDictionary(0, &item0_value));
1288 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value)); 1289 ASSERT_TRUE(result_list->GetDictionary(1, &item1_value));
1289 std::string item0_name, item1_name; 1290 std::string item0_name, item1_name;
1290 ASSERT_TRUE(item0_value->GetString("filename", &item0_name)); 1291 ASSERT_TRUE(item0_value->GetString("filename", &item0_name));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 base::ListValue* result_list = NULL; 1348 base::ListValue* result_list = NULL;
1348 ASSERT_TRUE(result->GetAsList(&result_list)); 1349 ASSERT_TRUE(result->GetAsList(&result_list));
1349 ASSERT_EQ(1UL, result_list->GetSize()); 1350 ASSERT_EQ(1UL, result_list->GetSize());
1350 } 1351 }
1351 1352
1352 // Test invalid search parameters. 1353 // Test invalid search parameters.
1353 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1354 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1354 DownloadExtensionTest_SearchInvalid) { 1355 DownloadExtensionTest_SearchInvalid) {
1355 std::string error = RunFunctionAndReturnError( 1356 std::string error = RunFunctionAndReturnError(
1356 new DownloadsSearchFunction(), "[{\"filenameRegex\": \"(\"}]"); 1357 new DownloadsSearchFunction(), "[{\"filenameRegex\": \"(\"}]");
1357 EXPECT_STREQ(download_extension_errors::kInvalidFilterError, 1358 EXPECT_STREQ(errors::kInvalidFilter,
1358 error.c_str()); 1359 error.c_str());
1359 error = RunFunctionAndReturnError( 1360 error = RunFunctionAndReturnError(
1360 new DownloadsSearchFunction(), "[{\"orderBy\": \"goat\"}]"); 1361 new DownloadsSearchFunction(), "[{\"orderBy\": [\"goat\"]}]");
1361 EXPECT_STREQ(download_extension_errors::kInvalidOrderByError, 1362 EXPECT_STREQ(errors::kInvalidOrderBy,
1362 error.c_str()); 1363 error.c_str());
1363 error = RunFunctionAndReturnError( 1364 error = RunFunctionAndReturnError(
1364 new DownloadsSearchFunction(), "[{\"limit\": -1}]"); 1365 new DownloadsSearchFunction(), "[{\"limit\": -1}]");
1365 EXPECT_STREQ(download_extension_errors::kInvalidQueryLimit, 1366 EXPECT_STREQ(errors::kInvalidQueryLimit,
1366 error.c_str()); 1367 error.c_str());
1367 } 1368 }
1368 1369
1369 // Test searching using multiple conditions through multiple downloads. 1370 // Test searching using multiple conditions through multiple downloads.
1370 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1371 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1371 DownloadExtensionTest_SearchPlural) { 1372 DownloadExtensionTest_SearchPlural) {
1372 const HistoryDownloadInfo kHistoryInfo[] = { 1373 const HistoryDownloadInfo kHistoryInfo[] = {
1373 { FILE_PATH_LITERAL("aaa"), 1374 { FILE_PATH_LITERAL("aaa"),
1374 DownloadItem::CANCELLED, 1375 DownloadItem::CANCELLED,
1375 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, 1376 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS },
1376 { FILE_PATH_LITERAL("zzz"), 1377 { FILE_PATH_LITERAL("zzz"),
1377 DownloadItem::COMPLETE, 1378 DownloadItem::COMPLETE,
1378 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, 1379 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT },
1379 { FILE_PATH_LITERAL("baz"), 1380 { FILE_PATH_LITERAL("baz"),
1380 DownloadItem::COMPLETE, 1381 DownloadItem::COMPLETE,
1381 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT }, 1382 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT },
1382 }; 1383 };
1383 DownloadManager::DownloadVector items; 1384 DownloadManager::DownloadVector items;
1384 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), 1385 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo),
1385 &items)); 1386 &items));
1386 1387
1387 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1388 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1388 new DownloadsSearchFunction(), "[{" 1389 new DownloadsSearchFunction(), "[{"
1389 "\"state\": \"complete\", " 1390 "\"state\": \"complete\", "
1390 "\"danger\": \"content\", " 1391 "\"danger\": \"content\", "
1391 "\"orderBy\": \"filename\", " 1392 "\"orderBy\": [\"filename\"], "
1392 "\"limit\": 1}]")); 1393 "\"limit\": 1}]"));
1393 ASSERT_TRUE(result.get()); 1394 ASSERT_TRUE(result.get());
1394 base::ListValue* result_list = NULL; 1395 base::ListValue* result_list = NULL;
1395 ASSERT_TRUE(result->GetAsList(&result_list)); 1396 ASSERT_TRUE(result->GetAsList(&result_list));
1396 ASSERT_EQ(1UL, result_list->GetSize()); 1397 ASSERT_EQ(1UL, result_list->GetSize());
1397 base::DictionaryValue* item_value = NULL; 1398 base::DictionaryValue* item_value = NULL;
1398 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); 1399 ASSERT_TRUE(result_list->GetDictionary(0, &item_value));
1399 base::FilePath::StringType item_name; 1400 base::FilePath::StringType item_name;
1400 ASSERT_TRUE(item_value->GetString("filename", &item_name)); 1401 ASSERT_TRUE(item_value->GetString("filename", &item_name));
1401 ASSERT_EQ(items[2]->GetTargetFilePath().value(), item_name); 1402 ASSERT_EQ(items[2]->GetTargetFilePath().value(), item_name);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 ASSERT_EQ(1UL, result_list->GetSize()); 1462 ASSERT_EQ(1UL, result_list->GetSize());
1462 ASSERT_TRUE(result_list->GetDictionary(0, &result_dict)); 1463 ASSERT_TRUE(result_list->GetDictionary(0, &result_dict));
1463 ASSERT_TRUE(result_dict->GetString("filename", &filename)); 1464 ASSERT_TRUE(result_dict->GetString("filename", &filename));
1464 EXPECT_TRUE(on_item->GetTargetFilePath() == base::FilePath(filename)); 1465 EXPECT_TRUE(on_item->GetTargetFilePath() == base::FilePath(filename));
1465 ASSERT_TRUE(result_dict->GetBoolean("incognito", &is_incognito)); 1466 ASSERT_TRUE(result_dict->GetBoolean("incognito", &is_incognito));
1466 EXPECT_FALSE(is_incognito); 1467 EXPECT_FALSE(is_incognito);
1467 1468
1468 // Pausing/Resuming the off-record item while on the record should return an 1469 // Pausing/Resuming the off-record item while on the record should return an
1469 // error. Cancelling "non-existent" downloads is not an error. 1470 // error. Cancelling "non-existent" downloads is not an error.
1470 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), off_item_arg); 1471 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), off_item_arg);
1471 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1472 EXPECT_STREQ(errors::kInvalidId,
1472 error.c_str()); 1473 error.c_str());
1473 error = RunFunctionAndReturnError(new DownloadsResumeFunction(), 1474 error = RunFunctionAndReturnError(new DownloadsResumeFunction(),
1474 off_item_arg); 1475 off_item_arg);
1475 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1476 EXPECT_STREQ(errors::kInvalidId,
1476 error.c_str()); 1477 error.c_str());
1477 error = RunFunctionAndReturnError( 1478 error = RunFunctionAndReturnError(
1478 new DownloadsGetFileIconFunction(), 1479 new DownloadsGetFileIconFunction(),
1479 base::StringPrintf("[%d, {}]", off_item->GetId())); 1480 base::StringPrintf("[%d, {}]", off_item->GetId()));
1480 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1481 EXPECT_STREQ(errors::kInvalidId,
1481 error.c_str()); 1482 error.c_str());
1482 1483
1483 GoOffTheRecord(); 1484 GoOffTheRecord();
1484 1485
1485 // Do the FileIcon test for both the on- and off-items while off the record. 1486 // Do the FileIcon test for both the on- and off-items while off the record.
1486 // NOTE(benjhayden): This does not include the FileIcon test from history, 1487 // NOTE(benjhayden): This does not include the FileIcon test from history,
1487 // just active downloads. This shouldn't be a problem. 1488 // just active downloads. This shouldn't be a problem.
1488 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction( 1489 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
1489 on_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"), 1490 on_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"),
1490 base::StringPrintf("[%d, {}]", on_item->GetId()), &result_string)); 1491 base::StringPrintf("[%d, {}]", on_item->GetId()), &result_string));
(...skipping 11 matching lines...) Expand all
1502 EXPECT_FALSE(on_item->IsPaused()); 1503 EXPECT_FALSE(on_item->IsPaused());
1503 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), on_item_arg)); 1504 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), on_item_arg));
1504 EXPECT_FALSE(on_item->IsPaused()); 1505 EXPECT_FALSE(on_item->IsPaused());
1505 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), on_item_arg)); 1506 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), on_item_arg));
1506 EXPECT_TRUE(on_item->IsPaused()); 1507 EXPECT_TRUE(on_item->IsPaused());
1507 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), on_item_arg)); 1508 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), on_item_arg));
1508 EXPECT_EQ(DownloadItem::CANCELLED, on_item->GetState()); 1509 EXPECT_EQ(DownloadItem::CANCELLED, on_item->GetState());
1509 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), on_item_arg)); 1510 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), on_item_arg));
1510 EXPECT_EQ(DownloadItem::CANCELLED, on_item->GetState()); 1511 EXPECT_EQ(DownloadItem::CANCELLED, on_item->GetState());
1511 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), on_item_arg); 1512 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), on_item_arg);
1512 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1513 EXPECT_STREQ(errors::kNotInProgress,
1513 error.c_str()); 1514 error.c_str());
1514 error = RunFunctionAndReturnError(new DownloadsResumeFunction(), on_item_arg); 1515 error = RunFunctionAndReturnError(new DownloadsResumeFunction(), on_item_arg);
1515 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1516 EXPECT_STREQ(errors::kNotInProgress,
1516 error.c_str()); 1517 error.c_str());
1517 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), off_item_arg)); 1518 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), off_item_arg));
1518 EXPECT_TRUE(off_item->IsPaused()); 1519 EXPECT_TRUE(off_item->IsPaused());
1519 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), off_item_arg)); 1520 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), off_item_arg));
1520 EXPECT_TRUE(off_item->IsPaused()); 1521 EXPECT_TRUE(off_item->IsPaused());
1521 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), off_item_arg)); 1522 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), off_item_arg));
1522 EXPECT_FALSE(off_item->IsPaused()); 1523 EXPECT_FALSE(off_item->IsPaused());
1523 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), off_item_arg)); 1524 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), off_item_arg));
1524 EXPECT_FALSE(off_item->IsPaused()); 1525 EXPECT_FALSE(off_item->IsPaused());
1525 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), off_item_arg)); 1526 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), off_item_arg));
1526 EXPECT_TRUE(off_item->IsPaused()); 1527 EXPECT_TRUE(off_item->IsPaused());
1527 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), off_item_arg)); 1528 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), off_item_arg));
1528 EXPECT_EQ(DownloadItem::CANCELLED, off_item->GetState()); 1529 EXPECT_EQ(DownloadItem::CANCELLED, off_item->GetState());
1529 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), off_item_arg)); 1530 EXPECT_TRUE(RunFunction(new DownloadsCancelFunction(), off_item_arg));
1530 EXPECT_EQ(DownloadItem::CANCELLED, off_item->GetState()); 1531 EXPECT_EQ(DownloadItem::CANCELLED, off_item->GetState());
1531 error = RunFunctionAndReturnError(new DownloadsPauseFunction(), 1532 error = RunFunctionAndReturnError(new DownloadsPauseFunction(),
1532 off_item_arg); 1533 off_item_arg);
1533 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1534 EXPECT_STREQ(errors::kNotInProgress,
1534 error.c_str()); 1535 error.c_str());
1535 error = RunFunctionAndReturnError(new DownloadsResumeFunction(), 1536 error = RunFunctionAndReturnError(new DownloadsResumeFunction(),
1536 off_item_arg); 1537 off_item_arg);
1537 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1538 EXPECT_STREQ(errors::kNotInProgress,
1538 error.c_str()); 1539 error.c_str());
1539 } 1540 }
1540 1541
1541 // Test that we can start a download and that the correct sequence of events is 1542 // Test that we can start a download and that the correct sequence of events is
1542 // fired for it. 1543 // fired for it.
1543 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1544 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1544 DownloadExtensionTest_Download_Basic) { 1545 DownloadExtensionTest_Download_Basic) {
1545 LoadExtension("downloads_split"); 1546 LoadExtension("downloads_split");
1546 ASSERT_TRUE(StartEmbeddedTestServer()); 1547 ASSERT_TRUE(StartEmbeddedTestServer());
1547 ASSERT_TRUE(test_server()->Start()); 1548 ASSERT_TRUE(test_server()->Start());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 "sEc-", 1667 "sEc-",
1667 "pRoxY-probably-not-evil", 1668 "pRoxY-probably-not-evil",
1668 "sEc-probably-not-evil", 1669 "sEc-probably-not-evil",
1669 "oRiGiN", 1670 "oRiGiN",
1670 "Access-Control-Request-Headers", 1671 "Access-Control-Request-Headers",
1671 "Access-Control-Request-Method", 1672 "Access-Control-Request-Method",
1672 }; 1673 };
1673 1674
1674 for (size_t index = 0; index < arraysize(kUnsafeHeaders); ++index) { 1675 for (size_t index = 0; index < arraysize(kUnsafeHeaders); ++index) {
1675 std::string download_url = test_server()->GetURL("slow?0").spec(); 1676 std::string download_url = test_server()->GetURL("slow?0").spec();
1676 EXPECT_STREQ(download_extension_errors::kGenericError, 1677 EXPECT_STREQ(errors::kInvalidHeader,
1677 RunFunctionAndReturnError(new DownloadsDownloadFunction(), 1678 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1678 base::StringPrintf( 1679 base::StringPrintf(
1679 "[{\"url\": \"%s\"," 1680 "[{\"url\": \"%s\","
1680 " \"filename\": \"unsafe-header-%d.txt\"," 1681 " \"filename\": \"unsafe-header-%d.txt\","
1681 " \"headers\": [{" 1682 " \"headers\": [{"
1682 " \"name\": \"%s\"," 1683 " \"name\": \"%s\","
1683 " \"value\": \"unsafe\"}]}]", 1684 " \"value\": \"unsafe\"}]}]",
1684 download_url.c_str(), 1685 download_url.c_str(),
1685 static_cast<int>(index), 1686 static_cast<int>(index),
1686 kUnsafeHeaders[index])).c_str()); 1687 kUnsafeHeaders[index])).c_str());
1687 } 1688 }
1688 } 1689 }
1689 1690
1690 // Test that subdirectories (slashes) are disallowed in filenames.
1691 // TODO(benjhayden) Update this when subdirectories are supported.
1692 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1691 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1693 DownloadExtensionTest_Download_Subdirectory) { 1692 DownloadExtensionTest_Download_Subdirectory) {
1694 LoadExtension("downloads_split"); 1693 LoadExtension("downloads_split");
1695 ASSERT_TRUE(StartEmbeddedTestServer()); 1694 ASSERT_TRUE(StartEmbeddedTestServer());
1696 ASSERT_TRUE(test_server()->Start()); 1695 ASSERT_TRUE(test_server()->Start());
1697 std::string download_url = test_server()->GetURL("slow?0").spec(); 1696 std::string download_url = test_server()->GetURL("slow?0").spec();
1698 GoOnTheRecord(); 1697 GoOnTheRecord();
1699 1698
1700 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, 1699 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1701 RunFunctionAndReturnError(new DownloadsDownloadFunction(), 1700 new DownloadsDownloadFunction(), base::StringPrintf(
1702 base::StringPrintf( 1701 "[{\"url\": \"%s\","
1703 "[{\"url\": \"%s\"," 1702 " \"filename\": \"sub/dir/ect/ory.txt\"}]",
1704 " \"filename\": \"sub/dir/ect/ory.txt\"}]", 1703 download_url.c_str())));
1705 download_url.c_str())).c_str()); 1704 ASSERT_TRUE(result.get());
1705 int result_id = -1;
1706 ASSERT_TRUE(result->GetAsInteger(&result_id));
1707 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1708 ASSERT_TRUE(item);
1709 ScopedCancellingItem canceller(item);
1710 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1711
1712 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
1713 base::StringPrintf("[{\"danger\": \"safe\","
1714 " \"incognito\": false,"
1715 " \"mime\": \"text/plain\","
1716 " \"paused\": false,"
1717 " \"url\": \"%s\"}]",
1718 download_url.c_str())));
1719 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1720 base::StringPrintf("[{\"id\": %d,"
1721 " \"filename\": {"
1722 " \"previous\": \"\","
1723 " \"current\": \"%s\"}}]",
1724 result_id,
1725 GetFilename("sub/dir/ect/ory.txt").c_str())));
1726 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
1727 base::StringPrintf("[{\"id\": %d,"
1728 " \"state\": {"
1729 " \"previous\": \"in_progress\","
1730 " \"current\": \"complete\"}}]",
1731 result_id)));
1706 } 1732 }
1707 1733
1708 // Test that invalid filenames are disallowed. 1734 // Test that invalid filenames are disallowed.
1709 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1735 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1710 DownloadExtensionTest_Download_InvalidFilename) { 1736 DownloadExtensionTest_Download_InvalidFilename) {
1711 LoadExtension("downloads_split"); 1737 LoadExtension("downloads_split");
1712 ASSERT_TRUE(StartEmbeddedTestServer()); 1738 ASSERT_TRUE(StartEmbeddedTestServer());
1713 ASSERT_TRUE(test_server()->Start()); 1739 ASSERT_TRUE(test_server()->Start());
1714 std::string download_url = test_server()->GetURL("slow?0").spec(); 1740 std::string download_url = test_server()->GetURL("slow?0").spec();
1715 GoOnTheRecord(); 1741 GoOnTheRecord();
1716 1742
1717 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, 1743 EXPECT_STREQ(errors::kInvalidFilename,
1718 RunFunctionAndReturnError(new DownloadsDownloadFunction(), 1744 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1719 base::StringPrintf( 1745 base::StringPrintf(
1720 "[{\"url\": \"%s\"," 1746 "[{\"url\": \"%s\","
1721 " \"filename\": \"../../../../../etc/passwd\"}]", 1747 " \"filename\": \"../../../../../etc/passwd\"}]",
1722 download_url.c_str())).c_str()); 1748 download_url.c_str())).c_str());
1723 } 1749 }
1724 1750
1725 // Test that downloading invalid URLs immediately returns kInvalidURLError. 1751 // Test that downloading invalid URLs immediately returns kInvalidURLError.
1726 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1752 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1727 DownloadExtensionTest_Download_InvalidURLs) { 1753 DownloadExtensionTest_Download_InvalidURLs) {
1728 LoadExtension("downloads_split"); 1754 LoadExtension("downloads_split");
1729 GoOnTheRecord(); 1755 GoOnTheRecord();
1730 1756
1731 static const char* kInvalidURLs[] = { 1757 static const char* kInvalidURLs[] = {
1732 "foo bar", 1758 "foo bar",
1733 "../hello", 1759 "../hello",
1734 "/hello", 1760 "/hello",
1735 "google.com/",
1736 "http://", 1761 "http://",
1737 "#frag", 1762 "#frag",
1738 "foo/bar.html#frag", 1763 "foo/bar.html#frag",
1764 "google.com/",
1765 };
1766
1767 for (size_t index = 0; index < arraysize(kInvalidURLs); ++index) {
1768 EXPECT_STREQ(errors::kInvalidURL,
1769 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1770 base::StringPrintf(
1771 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str())
1772 << kInvalidURLs[index];
1773 }
1774
1775 static const char* kNotPermittedURLs[] = {
1739 "javascript:document.write(\\\"hello\\\");", 1776 "javascript:document.write(\\\"hello\\\");",
1740 "javascript:return false;", 1777 "javascript:return false;",
1741 "ftp://example.com/example.txt", 1778 "ftp://example.com/example.txt",
1742 }; 1779 };
1743 1780
1744 for (size_t index = 0; index < arraysize(kInvalidURLs); ++index) { 1781 for (size_t index = 0; index < arraysize(kNotPermittedURLs); ++index) {
1745 EXPECT_STREQ(download_extension_errors::kInvalidURLError, 1782 EXPECT_STREQ(errors::kNotPermittedURL,
1746 RunFunctionAndReturnError(new DownloadsDownloadFunction(), 1783 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1747 base::StringPrintf( 1784 base::StringPrintf(
1748 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str()); 1785 "[{\"url\": \"%s\"}]", kNotPermittedURLs[index])).c_str())
1786 << kNotPermittedURLs[index];
1749 } 1787 }
1750 } 1788 }
1751 1789
1752 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to 1790 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to
1753 // permissions, test downloading from ftp. 1791 // permissions, test downloading from ftp.
1754 1792
1755 // Valid URLs plus fragments are still valid URLs. 1793 // Valid URLs plus fragments are still valid URLs.
1756 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1794 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1757 DownloadExtensionTest_Download_URLFragment) { 1795 DownloadExtensionTest_Download_URLFragment) {
1758 LoadExtension("downloads_split"); 1796 LoadExtension("downloads_split");
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 " \"filename\": \"auth-basic-fail.txt\"}]", 1943 " \"filename\": \"auth-basic-fail.txt\"}]",
1906 download_url.c_str()))); 1944 download_url.c_str())));
1907 ASSERT_TRUE(result.get()); 1945 ASSERT_TRUE(result.get());
1908 int result_id = -1; 1946 int result_id = -1;
1909 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1947 ASSERT_TRUE(result->GetAsInteger(&result_id));
1910 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1948 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1911 ASSERT_TRUE(item); 1949 ASSERT_TRUE(item);
1912 ScopedCancellingItem canceller(item); 1950 ScopedCancellingItem canceller(item);
1913 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1951 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1914 1952
1915 ASSERT_TRUE(WaitForInterruption(item, 30, base::StringPrintf( 1953 ASSERT_TRUE(WaitForInterruption(
1916 "[{\"danger\": \"safe\"," 1954 item,
1917 " \"incognito\": false," 1955 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
1918 " \"mime\": \"text/html\"," 1956 base::StringPrintf("[{\"danger\": \"safe\","
1919 " \"paused\": false," 1957 " \"incognito\": false,"
1920 " \"url\": \"%s\"}]", 1958 " \"mime\": \"text/html\","
1921 download_url.c_str()))); 1959 " \"paused\": false,"
1960 " \"url\": \"%s\"}]",
1961 download_url.c_str())));
1922 } 1962 }
1923 1963
1924 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. 1964 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest.
1925 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1965 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1926 DownloadExtensionTest_Download_Headers) { 1966 DownloadExtensionTest_Download_Headers) {
1927 LoadExtension("downloads_split"); 1967 LoadExtension("downloads_split");
1928 ASSERT_TRUE(StartEmbeddedTestServer()); 1968 ASSERT_TRUE(StartEmbeddedTestServer());
1929 ASSERT_TRUE(test_server()->Start()); 1969 ASSERT_TRUE(test_server()->Start());
1930 std::string download_url = test_server()->GetURL("files/downloads/" 1970 std::string download_url = test_server()->GetURL("files/downloads/"
1931 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec(); 1971 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 " \"filename\": \"headers-fail.txt\"}]", 2028 " \"filename\": \"headers-fail.txt\"}]",
1989 download_url.c_str()))); 2029 download_url.c_str())));
1990 ASSERT_TRUE(result.get()); 2030 ASSERT_TRUE(result.get());
1991 int result_id = -1; 2031 int result_id = -1;
1992 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2032 ASSERT_TRUE(result->GetAsInteger(&result_id));
1993 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2033 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1994 ASSERT_TRUE(item); 2034 ASSERT_TRUE(item);
1995 ScopedCancellingItem canceller(item); 2035 ScopedCancellingItem canceller(item);
1996 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2036 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1997 2037
1998 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( 2038 ASSERT_TRUE(WaitForInterruption(
1999 "[{\"danger\": \"safe\"," 2039 item,
2000 " \"incognito\": false," 2040 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2001 " \"bytesReceived\": 0," 2041 base::StringPrintf("[{\"danger\": \"safe\","
2002 " \"mime\": \"\"," 2042 " \"incognito\": false,"
2003 " \"paused\": false," 2043 " \"bytesReceived\": 0,"
2004 " \"url\": \"%s\"}]", 2044 " \"mime\": \"\","
2005 download_url.c_str()))); 2045 " \"paused\": false,"
2046 " \"url\": \"%s\"}]",
2047 download_url.c_str())));
2006 } 2048 }
2007 2049
2008 // Test that DownloadsDownloadFunction propagates the Authorization header 2050 // Test that DownloadsDownloadFunction propagates the Authorization header
2009 // correctly. 2051 // correctly.
2010 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2052 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2011 DownloadExtensionTest_Download_AuthBasic) { 2053 DownloadExtensionTest_Download_AuthBasic) {
2012 LoadExtension("downloads_split"); 2054 LoadExtension("downloads_split");
2013 ASSERT_TRUE(StartEmbeddedTestServer()); 2055 ASSERT_TRUE(StartEmbeddedTestServer());
2014 ASSERT_TRUE(test_server()->Start()); 2056 ASSERT_TRUE(test_server()->Start());
2015 std::string download_url = test_server()->GetURL("auth-basic").spec(); 2057 std::string download_url = test_server()->GetURL("auth-basic").spec();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 " \"filename\": \"post-get.txt\"}]", 2156 " \"filename\": \"post-get.txt\"}]",
2115 download_url.c_str()))); 2157 download_url.c_str())));
2116 ASSERT_TRUE(result.get()); 2158 ASSERT_TRUE(result.get());
2117 int result_id = -1; 2159 int result_id = -1;
2118 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2160 ASSERT_TRUE(result->GetAsInteger(&result_id));
2119 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2161 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2120 ASSERT_TRUE(item); 2162 ASSERT_TRUE(item);
2121 ScopedCancellingItem canceller(item); 2163 ScopedCancellingItem canceller(item);
2122 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2164 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2123 2165
2124 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( 2166 ASSERT_TRUE(WaitForInterruption(
2125 "[{\"danger\": \"safe\"," 2167 item,
2126 " \"incognito\": false," 2168 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2127 " \"mime\": \"\"," 2169 base::StringPrintf("[{\"danger\": \"safe\","
2128 " \"paused\": false," 2170 " \"incognito\": false,"
2129 " \"id\": %d," 2171 " \"mime\": \"\","
2130 " \"url\": \"%s\"}]", 2172 " \"paused\": false,"
2131 result_id, 2173 " \"id\": %d,"
2132 download_url.c_str()))); 2174 " \"url\": \"%s\"}]",
2175 result_id,
2176 download_url.c_str())));
2133 } 2177 }
2134 2178
2135 // Test that downloadPostSuccess would fail if the resource requires the POST 2179 // Test that downloadPostSuccess would fail if the resource requires the POST
2136 // method, and chrome fails to propagate the |body| parameter back to the 2180 // method, and chrome fails to propagate the |body| parameter back to the
2137 // server. This tests both that testserver.py does not succeed when it should 2181 // server. This tests both that testserver.py does not succeed when it should
2138 // fail, and this tests how the downloads extension api exposes the failure to 2182 // fail, and this tests how the downloads extension api exposes the failure to
2139 // extensions. 2183 // extensions.
2140 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2184 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2141 DownloadExtensionTest_Download_Post_NoBody) { 2185 DownloadExtensionTest_Download_Post_NoBody) {
2142 LoadExtension("downloads_split"); 2186 LoadExtension("downloads_split");
(...skipping 10 matching lines...) Expand all
2153 " \"filename\": \"post-nobody.txt\"}]", 2197 " \"filename\": \"post-nobody.txt\"}]",
2154 download_url.c_str()))); 2198 download_url.c_str())));
2155 ASSERT_TRUE(result.get()); 2199 ASSERT_TRUE(result.get());
2156 int result_id = -1; 2200 int result_id = -1;
2157 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2201 ASSERT_TRUE(result->GetAsInteger(&result_id));
2158 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2202 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2159 ASSERT_TRUE(item); 2203 ASSERT_TRUE(item);
2160 ScopedCancellingItem canceller(item); 2204 ScopedCancellingItem canceller(item);
2161 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2205 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2162 2206
2163 ASSERT_TRUE(WaitForInterruption(item, 33, base::StringPrintf( 2207 ASSERT_TRUE(WaitForInterruption(
2164 "[{\"danger\": \"safe\"," 2208 item,
2165 " \"incognito\": false," 2209 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
2166 " \"mime\": \"\"," 2210 base::StringPrintf("[{\"danger\": \"safe\","
2167 " \"paused\": false," 2211 " \"incognito\": false,"
2168 " \"id\": %d," 2212 " \"mime\": \"\","
2169 " \"url\": \"%s\"}]", 2213 " \"paused\": false,"
2170 result_id, 2214 " \"id\": %d,"
2171 download_url.c_str()))); 2215 " \"url\": \"%s\"}]",
2216 result_id,
2217 download_url.c_str())));
2172 } 2218 }
2173 2219
2174 // Test that cancel()ing an in-progress download causes its state to transition 2220 // Test that cancel()ing an in-progress download causes its state to transition
2175 // to interrupted, and test that that state transition is detectable by an 2221 // to interrupted, and test that that state transition is detectable by an
2176 // onChanged event listener. TODO(benjhayden): Test other sources of 2222 // onChanged event listener. TODO(benjhayden): Test other sources of
2177 // interruptions such as server death. 2223 // interruptions such as server death.
2178 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2224 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2179 DownloadExtensionTest_Download_Cancel) { 2225 DownloadExtensionTest_Download_Cancel) {
2180 LoadExtension("downloads_split"); 2226 LoadExtension("downloads_split");
2181 ASSERT_TRUE(StartEmbeddedTestServer()); 2227 ASSERT_TRUE(StartEmbeddedTestServer());
(...skipping 18 matching lines...) Expand all
2200 " \"incognito\": false," 2246 " \"incognito\": false,"
2201 " \"mime\": \"application/octet-stream\"," 2247 " \"mime\": \"application/octet-stream\","
2202 " \"paused\": false," 2248 " \"paused\": false,"
2203 " \"id\": %d," 2249 " \"id\": %d,"
2204 " \"url\": \"%s\"}]", 2250 " \"url\": \"%s\"}]",
2205 result_id, 2251 result_id,
2206 download_url.c_str()))); 2252 download_url.c_str())));
2207 item->Cancel(true); 2253 item->Cancel(true);
2208 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2254 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2209 base::StringPrintf("[{\"id\": %d," 2255 base::StringPrintf("[{\"id\": %d,"
2210 " \"error\": {\"current\": 40}," 2256 " \"error\": {\"current\":\"USER_CANCELED\"},"
2211 " \"state\": {" 2257 " \"state\": {"
2212 " \"previous\": \"in_progress\"," 2258 " \"previous\": \"in_progress\","
2213 " \"current\": \"interrupted\"}}]", 2259 " \"current\": \"interrupted\"}}]",
2214 result_id))); 2260 result_id)));
2215 } 2261 }
2216 2262
2217 // Test downloading filesystem: URLs. 2263 // Test downloading filesystem: URLs.
2218 // NOTE: chrome disallows creating HTML5 FileSystem Files in incognito. 2264 // NOTE: chrome disallows creating HTML5 FileSystem Files in incognito.
2219 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2265 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2220 DownloadExtensionTest_Download_FileSystemURL) { 2266 DownloadExtensionTest_Download_FileSystemURL) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 result_id, 2430 result_id,
2385 base::FilePath(FILE_PATH_LITERAL("overridden.swf")), 2431 base::FilePath(FILE_PATH_LITERAL("overridden.swf")),
2386 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2432 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2387 &error)); 2433 &error));
2388 EXPECT_EQ("", error); 2434 EXPECT_EQ("", error);
2389 2435
2390 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2436 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2391 base::StringPrintf("[{\"id\": %d," 2437 base::StringPrintf("[{\"id\": %d,"
2392 " \"danger\": {" 2438 " \"danger\": {"
2393 " \"previous\":\"safe\"," 2439 " \"previous\":\"safe\","
2394 " \"current\":\"file\"}," 2440 " \"current\":\"file\"}}]",
2395 " \"dangerAccepted\": {"
2396 " \"current\":false}}]",
2397 result_id))); 2441 result_id)));
2398 2442
2399 item->ValidateDangerousDownload(); 2443 item->ValidateDangerousDownload();
2400 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2444 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2401 base::StringPrintf("[{\"id\": %d," 2445 base::StringPrintf("[{\"id\": %d,"
2402 " \"dangerAccepted\": {" 2446 " \"danger\": {"
2403 " \"previous\":false," 2447 " \"previous\":\"file\","
2404 " \"current\":true}}]", 2448 " \"current\":\"accepted\"}}]",
2405 result_id))); 2449 result_id)));
2406 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2450 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2407 base::StringPrintf("[{\"id\": %d," 2451 base::StringPrintf("[{\"id\": %d,"
2408 " \"state\": {" 2452 " \"state\": {"
2409 " \"previous\": \"in_progress\"," 2453 " \"previous\": \"in_progress\","
2410 " \"current\": \"complete\"}}]", 2454 " \"current\": \"complete\"}}]",
2411 result_id))); 2455 result_id)));
2412 EXPECT_EQ(downloads_directory().AppendASCII("overridden.swf"), 2456 EXPECT_EQ(downloads_directory().AppendASCII("overridden.swf"),
2413 item->GetTargetFilePath()); 2457 item->GetTargetFilePath());
2414 } 2458 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 // Respond to the onDeterminingFilename. 2499 // Respond to the onDeterminingFilename.
2456 std::string error; 2500 std::string error;
2457 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2501 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2458 browser()->profile(), 2502 browser()->profile(),
2459 false, 2503 false,
2460 GetExtensionId(), 2504 GetExtensionId(),
2461 result_id, 2505 result_id,
2462 base::FilePath(FILE_PATH_LITERAL("sneaky/../../sneaky.txt")), 2506 base::FilePath(FILE_PATH_LITERAL("sneaky/../../sneaky.txt")),
2463 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2507 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2464 &error)); 2508 &error));
2465 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, error.c_str()); 2509 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2466 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2510 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2467 base::StringPrintf("[{\"id\": %d," 2511 base::StringPrintf("[{\"id\": %d,"
2468 " \"filename\": {" 2512 " \"filename\": {"
2469 " \"previous\": \"\"," 2513 " \"previous\": \"\","
2470 " \"current\": \"%s\"}}]", 2514 " \"current\": \"%s\"}}]",
2471 result_id, 2515 result_id,
2472 GetFilename("slow.txt").c_str()))); 2516 GetFilename("slow.txt").c_str())));
2473 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2517 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2474 base::StringPrintf("[{\"id\": %d," 2518 base::StringPrintf("[{\"id\": %d,"
2475 " \"state\": {" 2519 " \"state\": {"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 // Respond to the onDeterminingFilename. 2564 // Respond to the onDeterminingFilename.
2521 std::string error; 2565 std::string error;
2522 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2566 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2523 browser()->profile(), 2567 browser()->profile(),
2524 false, 2568 false,
2525 GetExtensionId(), 2569 GetExtensionId(),
2526 result_id, 2570 result_id,
2527 base::FilePath(FILE_PATH_LITERAL("<")), 2571 base::FilePath(FILE_PATH_LITERAL("<")),
2528 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2572 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2529 &error)); 2573 &error));
2530 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, error.c_str()); 2574 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2531 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf( 2575 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf(
2532 "[{\"id\": %d," 2576 "[{\"id\": %d,"
2533 " \"filename\": {" 2577 " \"filename\": {"
2534 " \"previous\": \"\"," 2578 " \"previous\": \"\","
2535 " \"current\": \"%s\"}}]", 2579 " \"current\": \"%s\"}}]",
2536 result_id, 2580 result_id,
2537 GetFilename("slow.txt").c_str()))); 2581 GetFilename("slow.txt").c_str())));
2538 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf( 2582 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf(
2539 "[{\"id\": %d," 2583 "[{\"id\": %d,"
2540 " \"state\": {" 2584 " \"state\": {"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2586 std::string error; 2630 std::string error;
2587 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2631 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2588 browser()->profile(), 2632 browser()->profile(),
2589 false, 2633 false,
2590 GetExtensionId(), 2634 GetExtensionId(),
2591 result_id, 2635 result_id,
2592 base::FilePath(FILE_PATH_LITERAL( 2636 base::FilePath(FILE_PATH_LITERAL(
2593 "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}/foo")), 2637 "My Computer.{20D04FE0-3AEA-1069-A2D8-08002B30309D}/foo")),
2594 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2638 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2595 &error)); 2639 &error));
2596 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, error.c_str()); 2640 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2597 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf( 2641 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf(
2598 "[{\"id\": %d," 2642 "[{\"id\": %d,"
2599 " \"filename\": {" 2643 " \"filename\": {"
2600 " \"previous\": \"\"," 2644 " \"previous\": \"\","
2601 " \"current\": \"%s\"}}]", 2645 " \"current\": \"%s\"}}]",
2602 result_id, 2646 result_id,
2603 GetFilename("slow.txt").c_str()))); 2647 GetFilename("slow.txt").c_str())));
2604 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf( 2648 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf(
2605 "[{\"id\": %d," 2649 "[{\"id\": %d,"
2606 " \"state\": {" 2650 " \"state\": {"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2651 // Respond to the onDeterminingFilename. 2695 // Respond to the onDeterminingFilename.
2652 std::string error; 2696 std::string error;
2653 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2697 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2654 browser()->profile(), 2698 browser()->profile(),
2655 false, 2699 false,
2656 GetExtensionId(), 2700 GetExtensionId(),
2657 result_id, 2701 result_id,
2658 base::FilePath(FILE_PATH_LITERAL("con.foo")), 2702 base::FilePath(FILE_PATH_LITERAL("con.foo")),
2659 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2703 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2660 &error)); 2704 &error));
2661 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, error.c_str()); 2705 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2662 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf( 2706 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf(
2663 "[{\"id\": %d," 2707 "[{\"id\": %d,"
2664 " \"filename\": {" 2708 " \"filename\": {"
2665 " \"previous\": \"\"," 2709 " \"previous\": \"\","
2666 " \"current\": \"%s\"}}]", 2710 " \"current\": \"%s\"}}]",
2667 result_id, 2711 result_id,
2668 GetFilename("slow.txt").c_str()))); 2712 GetFilename("slow.txt").c_str())));
2669 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf( 2713 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, base::StringPrintf(
2670 "[{\"id\": %d," 2714 "[{\"id\": %d,"
2671 " \"state\": {" 2715 " \"state\": {"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2716 // Respond to the onDeterminingFilename. 2760 // Respond to the onDeterminingFilename.
2717 std::string error; 2761 std::string error;
2718 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2762 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2719 browser()->profile(), 2763 browser()->profile(),
2720 false, 2764 false,
2721 GetExtensionId(), 2765 GetExtensionId(),
2722 result_id, 2766 result_id,
2723 base::FilePath(FILE_PATH_LITERAL(".")), 2767 base::FilePath(FILE_PATH_LITERAL(".")),
2724 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2768 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2725 &error)); 2769 &error));
2726 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, error.c_str()); 2770 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2727 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2771 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2728 base::StringPrintf("[{\"id\": %d," 2772 base::StringPrintf("[{\"id\": %d,"
2729 " \"filename\": {" 2773 " \"filename\": {"
2730 " \"previous\": \"\"," 2774 " \"previous\": \"\","
2731 " \"current\": \"%s\"}}]", 2775 " \"current\": \"%s\"}}]",
2732 result_id, 2776 result_id,
2733 GetFilename("slow.txt").c_str()))); 2777 GetFilename("slow.txt").c_str())));
2734 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2778 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2735 base::StringPrintf("[{\"id\": %d," 2779 base::StringPrintf("[{\"id\": %d,"
2736 " \"state\": {" 2780 " \"state\": {"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 // Respond to the onDeterminingFilename. 2825 // Respond to the onDeterminingFilename.
2782 std::string error; 2826 std::string error;
2783 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2827 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2784 browser()->profile(), 2828 browser()->profile(),
2785 false, 2829 false,
2786 GetExtensionId(), 2830 GetExtensionId(),
2787 result_id, 2831 result_id,
2788 base::FilePath(FILE_PATH_LITERAL("..")), 2832 base::FilePath(FILE_PATH_LITERAL("..")),
2789 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2833 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2790 &error)); 2834 &error));
2791 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, error.c_str()); 2835 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2792 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2836 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2793 base::StringPrintf("[{\"id\": %d," 2837 base::StringPrintf("[{\"id\": %d,"
2794 " \"filename\": {" 2838 " \"filename\": {"
2795 " \"previous\": \"\"," 2839 " \"previous\": \"\","
2796 " \"current\": \"%s\"}}]", 2840 " \"current\": \"%s\"}}]",
2797 result_id, 2841 result_id,
2798 GetFilename("slow.txt").c_str()))); 2842 GetFilename("slow.txt").c_str())));
2799 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2843 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2800 base::StringPrintf("[{\"id\": %d," 2844 base::StringPrintf("[{\"id\": %d,"
2801 " \"state\": {" 2845 " \"state\": {"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 // Respond to the onDeterminingFilename. Absolute paths should be rejected. 2890 // Respond to the onDeterminingFilename. Absolute paths should be rejected.
2847 std::string error; 2891 std::string error;
2848 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2892 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2849 browser()->profile(), 2893 browser()->profile(),
2850 false, 2894 false,
2851 GetExtensionId(), 2895 GetExtensionId(),
2852 result_id, 2896 result_id,
2853 downloads_directory().Append(FILE_PATH_LITERAL("sneaky.txt")), 2897 downloads_directory().Append(FILE_PATH_LITERAL("sneaky.txt")),
2854 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2898 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2855 &error)); 2899 &error));
2856 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, error.c_str()); 2900 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2857 2901
2858 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2902 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2859 base::StringPrintf("[{\"id\": %d," 2903 base::StringPrintf("[{\"id\": %d,"
2860 " \"filename\": {" 2904 " \"filename\": {"
2861 " \"previous\": \"\"," 2905 " \"previous\": \"\","
2862 " \"current\": \"%s\"}}]", 2906 " \"current\": \"%s\"}}]",
2863 result_id, 2907 result_id,
2864 GetFilename("slow.txt").c_str()))); 2908 GetFilename("slow.txt").c_str())));
2865 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2909 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2866 base::StringPrintf("[{\"id\": %d," 2910 base::StringPrintf("[{\"id\": %d,"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2912 // Respond to the onDeterminingFilename. Empty basenames should be rejected. 2956 // Respond to the onDeterminingFilename. Empty basenames should be rejected.
2913 std::string error; 2957 std::string error;
2914 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( 2958 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename(
2915 browser()->profile(), 2959 browser()->profile(),
2916 false, 2960 false,
2917 GetExtensionId(), 2961 GetExtensionId(),
2918 result_id, 2962 result_id,
2919 base::FilePath(FILE_PATH_LITERAL("foo/")), 2963 base::FilePath(FILE_PATH_LITERAL("foo/")),
2920 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY, 2964 extensions::api::downloads::FILENAME_CONFLICT_ACTION_UNIQUIFY,
2921 &error)); 2965 &error));
2922 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, error.c_str()); 2966 EXPECT_STREQ(errors::kInvalidFilename, error.c_str());
2923 2967
2924 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2968 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2925 base::StringPrintf("[{\"id\": %d," 2969 base::StringPrintf("[{\"id\": %d,"
2926 " \"filename\": {" 2970 " \"filename\": {"
2927 " \"previous\": \"\"," 2971 " \"previous\": \"\","
2928 " \"current\": \"%s\"}}]", 2972 " \"current\": \"%s\"}}]",
2929 result_id, 2973 result_id,
2930 GetFilename("slow.txt").c_str()))); 2974 GetFilename("slow.txt").c_str())));
2931 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 2975 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
2932 base::StringPrintf("[{\"id\": %d," 2976 base::StringPrintf("[{\"id\": %d,"
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
3472 " \"previous\": \"\"," 3516 " \"previous\": \"\","
3473 " \"current\": \"%s\"}}]", 3517 " \"current\": \"%s\"}}]",
3474 item->GetId(), 3518 item->GetId(),
3475 GetFilename("42.txt").c_str()))); 3519 GetFilename("42.txt").c_str())));
3476 3520
3477 content::DownloadUpdatedObserver interrupted(item, base::Bind( 3521 content::DownloadUpdatedObserver interrupted(item, base::Bind(
3478 ItemIsInterrupted)); 3522 ItemIsInterrupted));
3479 ASSERT_TRUE(interrupted.WaitForEvent()); 3523 ASSERT_TRUE(interrupted.WaitForEvent());
3480 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 3524 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
3481 base::StringPrintf("[{\"id\": %d," 3525 base::StringPrintf("[{\"id\": %d,"
3482 " \"error\":{\"current\":20}," 3526 " \"error\":{\"current\":\"NETWORK_FAILED\"},"
3483 " \"state\":{" 3527 " \"state\":{"
3484 " \"previous\":\"in_progress\"," 3528 " \"previous\":\"in_progress\","
3485 " \"current\":\"interrupted\"}}]", 3529 " \"current\":\"interrupted\"}}]",
3486 item->GetId()))); 3530 item->GetId())));
3487 3531
3488 ClearEvents(); 3532 ClearEvents();
3489 // Downloads that are restarted on resumption trigger another download target 3533 // Downloads that are restarted on resumption trigger another download target
3490 // determination. 3534 // determination.
3491 RemoveFilenameDeterminer(host); 3535 RemoveFilenameDeterminer(host);
3492 item->Resume(); 3536 item->Resume();
3493 3537
3494 // Errors caught before filename determination is complete are delayed until 3538 // Errors caught before filename determination is complete are delayed until
3495 // after filename determination so that, on resumption, filename determination 3539 // after filename determination so that, on resumption, filename determination
3496 // does not need to be re-done. So, there will not be a second 3540 // does not need to be re-done. So, there will not be a second
3497 // onDeterminingFilename event. 3541 // onDeterminingFilename event.
3498 3542
3499 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 3543 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
3500 base::StringPrintf("[{\"id\": %d," 3544 base::StringPrintf("[{\"id\": %d,"
3501 " \"error\":{\"previous\":20}," 3545 " \"error\":{\"previous\":\"NETWORK_FAILED\"},"
3502 " \"state\":{" 3546 " \"state\":{"
3503 " \"previous\":\"interrupted\"," 3547 " \"previous\":\"interrupted\","
3504 " \"current\":\"in_progress\"}}]", 3548 " \"current\":\"in_progress\"}}]",
3505 item->GetId()))); 3549 item->GetId())));
3506 3550
3507 ClearEvents(); 3551 ClearEvents();
3508 FinishPendingSlowDownloads(); 3552 FinishPendingSlowDownloads();
3509 3553
3510 // The download should complete successfully. 3554 // The download should complete successfully.
3511 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 3555 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
(...skipping 15 matching lines...) Expand all
3527 DownloadsApiTest() {} 3571 DownloadsApiTest() {}
3528 virtual ~DownloadsApiTest() {} 3572 virtual ~DownloadsApiTest() {}
3529 private: 3573 private:
3530 DISALLOW_COPY_AND_ASSIGN(DownloadsApiTest); 3574 DISALLOW_COPY_AND_ASSIGN(DownloadsApiTest);
3531 }; 3575 };
3532 3576
3533 3577
3534 IN_PROC_BROWSER_TEST_F(DownloadsApiTest, DownloadsApiTest) { 3578 IN_PROC_BROWSER_TEST_F(DownloadsApiTest, DownloadsApiTest) {
3535 ASSERT_TRUE(RunExtensionTest("downloads")) << message_; 3579 ASSERT_TRUE(RunExtensionTest("downloads")) << message_;
3536 } 3580 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698