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

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

Issue 10828372: Deflakify DownloadExtensionTest by not depending on the icon loader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 27 matching lines...) Expand all
38 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
39 #include "content/public/common/page_transition_types.h" 39 #include "content/public/common/page_transition_types.h"
40 #include "content/public/test/download_test_observer.h" 40 #include "content/public/test/download_test_observer.h"
41 #include "content/test/net/url_request_slow_download_job.h" 41 #include "content/test/net/url_request_slow_download_job.h"
42 #include "net/base/data_url.h" 42 #include "net/base/data_url.h"
43 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
44 #include "net/url_request/url_request.h" 44 #include "net/url_request/url_request.h"
45 #include "net/url_request/url_request_context.h" 45 #include "net/url_request/url_request_context.h"
46 #include "net/url_request/url_request_job.h" 46 #include "net/url_request/url_request_job.h"
47 #include "net/url_request/url_request_job_factory.h" 47 #include "net/url_request/url_request_job_factory.h"
48 #include "ui/gfx/codec/png_codec.h"
49 #include "webkit/blob/blob_data.h" 48 #include "webkit/blob/blob_data.h"
50 #include "webkit/blob/blob_storage_controller.h" 49 #include "webkit/blob/blob_storage_controller.h"
51 #include "webkit/blob/blob_url_request_job.h" 50 #include "webkit/blob/blob_url_request_job.h"
52 #include "webkit/fileapi/file_system_context.h" 51 #include "webkit/fileapi/file_system_context.h"
53 #include "webkit/fileapi/file_system_operation_interface.h" 52 #include "webkit/fileapi/file_system_operation_interface.h"
54 #include "webkit/fileapi/file_system_url.h" 53 #include "webkit/fileapi/file_system_url.h"
55 54
56 using content::BrowserContext; 55 using content::BrowserContext;
57 using content::BrowserThread; 56 using content::BrowserThread;
58 using content::DownloadItem; 57 using content::DownloadItem;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 SetUpExtensionFunction(function); 499 SetUpExtensionFunction(function);
501 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(function, args)); 500 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(function, args));
502 EXPECT_TRUE(result.get()); 501 EXPECT_TRUE(result.get());
503 return result.get() && result->GetAsString(result_string); 502 return result.get() && result->GetAsString(result_string);
504 } 503 }
505 504
506 std::string DownloadItemIdAsArgList(const DownloadItem* download_item) { 505 std::string DownloadItemIdAsArgList(const DownloadItem* download_item) {
507 return base::StringPrintf("[%d]", download_item->GetId()); 506 return base::StringPrintf("[%d]", download_item->GetId());
508 } 507 }
509 508
510 // Checks if a data URL encoded image is a PNG of a given size.
511 void ExpectDataURLIsPNGWithSize(const std::string& url, int expected_size) {
512 std::string mime_type;
513 std::string charset;
514 std::string data;
515 EXPECT_FALSE(url.empty());
516 EXPECT_TRUE(net::DataURL::Parse(GURL(url), &mime_type, &charset, &data));
517 EXPECT_STREQ("image/png", mime_type.c_str());
518 EXPECT_FALSE(data.empty());
519
520 if (data.empty())
521 return;
522
523 int width = -1, height = -1;
524 std::vector<unsigned char> decoded_data;
525 EXPECT_TRUE(gfx::PNGCodec::Decode(
526 reinterpret_cast<const unsigned char*>(data.c_str()), data.length(),
527 gfx::PNGCodec::FORMAT_RGBA, &decoded_data,
528 &width, &height));
529 EXPECT_EQ(expected_size, width);
530 EXPECT_EQ(expected_size, height);
531 }
532
533 const FilePath& downloads_directory() { 509 const FilePath& downloads_directory() {
534 return downloads_directory_.path(); 510 return downloads_directory_.path();
535 } 511 }
536 512
537 DownloadsEventsListener* events_listener() { return events_listener_.get(); } 513 DownloadsEventsListener* events_listener() { return events_listener_.get(); }
538 514
539 private: 515 private:
540 void SetUpExtensionFunction(UIThreadExtensionFunction* function) { 516 void SetUpExtensionFunction(UIThreadExtensionFunction* function) {
541 if (extension_) { 517 if (extension_) {
542 // Recreate the tab each time for insulation. 518 // Recreate the tab each time for insulation.
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 866 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
891 error.c_str()); 867 error.c_str());
892 868
893 // Calling resume on a non-existent download yields kInvalidOperationError 869 // Calling resume on a non-existent download yields kInvalidOperationError
894 error = RunFunctionAndReturnError( 870 error = RunFunctionAndReturnError(
895 new DownloadsResumeFunction(), "[-42]"); 871 new DownloadsResumeFunction(), "[-42]");
896 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 872 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
897 error.c_str()); 873 error.c_str());
898 } 874 }
899 875
876 UIThreadExtensionFunction* MockedGetFileIconFunction(
877 const FilePath& expected_path,
878 IconLoader::IconSize icon_size,
879 const std::string& response) {
880 scoped_refptr<DownloadsGetFileIconFunction> function(
881 new DownloadsGetFileIconFunction());
882 function->SetIconExtractorForTesting(new MockIconExtractorImpl(
883 expected_path, icon_size, response));
884 return function.release();
885 }
886
900 // Test downloads.getFileIcon() on in-progress, finished, cancelled and deleted 887 // Test downloads.getFileIcon() on in-progress, finished, cancelled and deleted
901 // download items. 888 // download items.
902 // The test fails under ASan, see http://crbug.com/138211
903 #if defined(ADDRESS_SANITIZER)
904 #define MAYBE_DownloadExtensionTest_FileIcon_Active \
905 DISABLED_DownloadExtensionTest_FileIcon_Active
906 #else
907 #define MAYBE_DownloadExtensionTest_FileIcon_Active \
908 DownloadExtensionTest_FileIcon_Active
909 #endif
910 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 889 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
911 MAYBE_DownloadExtensionTest_FileIcon_Active) { 890 DownloadExtensionTest_FileIcon_Active) {
912 DownloadItem* download_item = CreateSlowTestDownload(); 891 DownloadItem* download_item = CreateSlowTestDownload();
913 ASSERT_TRUE(download_item); 892 ASSERT_TRUE(download_item);
893 std::string args32(base::StringPrintf("[%d, {\"size\": 32}]",
894 download_item->GetId()));
895 std::string result_string;
914 896
915 // Get the icon for the in-progress download. This call should succeed even 897 // Get the icon for the in-progress download. This call should succeed even
916 // if the file type isn't registered. 898 // if the file type isn't registered.
917 std::string args = base::StringPrintf("[%d, {}]", download_item->GetId());
918 std::string result_string;
919 EXPECT_TRUE(RunFunctionAndReturnString(new DownloadsGetFileIconFunction(),
920 args, &result_string));
921
922 // Note: We are checking if the result is a Data URL that has encoded
923 // image/png data for an icon of a specific size. Of these, only the icon size
924 // is specified in the API contract. The image type (image/png) and URL type
925 // (Data) are implementation details.
926
927 // The default size for icons returned by getFileIcon() is 32x32.
928 ExpectDataURLIsPNGWithSize(result_string, 32);
929
930 // Test whether the correct path is being pased into the icon extractor. 899 // Test whether the correct path is being pased into the icon extractor.
931 FilePath expected_path(download_item->GetTargetFilePath()); 900 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
932 scoped_refptr<DownloadsGetFileIconFunction> function( 901 download_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"),
933 new DownloadsGetFileIconFunction()); 902 base::StringPrintf("[%d, {}]", download_item->GetId()), &result_string));
934 function->SetIconExtractorForTesting(new MockIconExtractorImpl(
935 expected_path, IconLoader::NORMAL, "foo"));
936 EXPECT_TRUE(RunFunctionAndReturnString(function.release(), args,
937 &result_string));
938 903
939 // Now try a 16x16 icon. 904 // Now try a 16x16 icon.
940 args = base::StringPrintf("[%d, {\"size\": 16}]", download_item->GetId()); 905 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
941 EXPECT_TRUE(RunFunctionAndReturnString(new DownloadsGetFileIconFunction(), 906 download_item->GetTargetFilePath(), IconLoader::SMALL, "foo"),
942 args, &result_string)); 907 base::StringPrintf("[%d, {\"size\": 16}]", download_item->GetId()),
943 ExpectDataURLIsPNGWithSize(result_string, 16); 908 &result_string));
944 909
945 // Explicitly asking for 32x32 should give us a 32x32 icon. 910 // Explicitly asking for 32x32 should give us a 32x32 icon.
946 args = base::StringPrintf("[%d, {\"size\": 32}]", download_item->GetId()); 911 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
947 EXPECT_TRUE(RunFunctionAndReturnString(new DownloadsGetFileIconFunction(), 912 download_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"),
948 args, &result_string)); 913 args32, &result_string));
949 ExpectDataURLIsPNGWithSize(result_string, 32);
950 914
951 // Finish the download and try again. 915 // Finish the download and try again.
952 FinishPendingSlowDownloads(); 916 FinishPendingSlowDownloads();
953 EXPECT_EQ(DownloadItem::COMPLETE, download_item->GetState()); 917 EXPECT_EQ(DownloadItem::COMPLETE, download_item->GetState());
954 EXPECT_TRUE(RunFunctionAndReturnString(new DownloadsGetFileIconFunction(), 918 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
955 args, &result_string)); 919 download_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"),
956 ExpectDataURLIsPNGWithSize(result_string, 32); 920 args32, &result_string));
957 921
958 // Check the path passed to the icon extractor post-completion. 922 // Check the path passed to the icon extractor post-completion.
959 function = new DownloadsGetFileIconFunction(); 923 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
960 function->SetIconExtractorForTesting(new MockIconExtractorImpl( 924 download_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"),
961 expected_path, IconLoader::NORMAL, "foo")); 925 args32, &result_string));
962 EXPECT_TRUE(RunFunctionAndReturnString(function.release(), args,
963 &result_string));
964 926
965 // Now create another download. 927 // Now create another download.
966 download_item = CreateSlowTestDownload(); 928 download_item = CreateSlowTestDownload();
929 args32 = base::StringPrintf("[%d, {\"size\": 32}]", download_item->GetId());
967 ASSERT_TRUE(download_item); 930 ASSERT_TRUE(download_item);
968 expected_path = download_item->GetTargetFilePath();
969 931
970 // Cancel the download. As long as the download has a target path, we should 932 // Cancel the download. As long as the download has a target path, we should
971 // be able to query the file icon. 933 // be able to query the file icon.
972 download_item->Cancel(true); 934 download_item->Cancel(true);
973 // Let cleanup complete on the FILE thread. 935 // Let cleanup complete on the FILE thread.
974 content::RunAllPendingInMessageLoop(BrowserThread::FILE); 936 content::RunAllPendingInMessageLoop(BrowserThread::FILE);
975 args = base::StringPrintf("[%d, {\"size\": 32}]", download_item->GetId());
976 EXPECT_TRUE(RunFunctionAndReturnString(new DownloadsGetFileIconFunction(),
977 args, &result_string));
978 ExpectDataURLIsPNGWithSize(result_string, 32);
979
980 // Check the path passed to the icon extractor post-cancellation. 937 // Check the path passed to the icon extractor post-cancellation.
981 function = new DownloadsGetFileIconFunction(); 938 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
982 function->SetIconExtractorForTesting(new MockIconExtractorImpl( 939 download_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"),
983 expected_path, IconLoader::NORMAL, "foo")); 940 args32,
984 EXPECT_TRUE(RunFunctionAndReturnString(function.release(), args, 941 &result_string));
985 &result_string));
986 942
987 // Simulate an error during icon load by invoking the mock with an empty 943 // Simulate an error during icon load by invoking the mock with an empty
988 // result string. 944 // result string.
989 function = new DownloadsGetFileIconFunction(); 945 std::string error = RunFunctionAndReturnError(MockedGetFileIconFunction(
990 function->SetIconExtractorForTesting(new MockIconExtractorImpl( 946 download_item->GetTargetFilePath(), IconLoader::NORMAL, ""),
991 expected_path, IconLoader::NORMAL, "")); 947 args32);
992 std::string error = RunFunctionAndReturnError(function.release(), args);
993 EXPECT_STREQ(download_extension_errors::kIconNotFoundError, 948 EXPECT_STREQ(download_extension_errors::kIconNotFoundError,
994 error.c_str()); 949 error.c_str());
995 950
996 // Once the download item is deleted, we should return kInvalidOperationError. 951 // Once the download item is deleted, we should return kInvalidOperationError.
997 download_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 952 download_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
998 error = RunFunctionAndReturnError(new DownloadsGetFileIconFunction(), args); 953 download_item = NULL;
954 error = RunFunctionAndReturnError(new DownloadsGetFileIconFunction(), args32);
999 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 955 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
1000 error.c_str()); 956 error.c_str());
1001 } 957 }
1002 958
1003 // Test that we can acquire file icons for history downloads regardless of 959 // Test that we can acquire file icons for history downloads regardless of
1004 // whether they exist or not. If the file doesn't exist we should receive a 960 // whether they exist or not. If the file doesn't exist we should receive a
1005 // generic icon from the OS/toolkit that may or may not be specific to the file 961 // generic icon from the OS/toolkit that may or may not be specific to the file
1006 // type. 962 // type.
1007 // The test fails under ASan, see http://crbug.com/138211
1008 #if defined(ADDRESS_SANITIZER)
1009 #define MAYBE_DownloadExtensionTest_FileIcon_History \
1010 DISABLED_DownloadExtensionTest_FileIcon_History
1011 #else
1012 #define MAYBE_DownloadExtensionTest_FileIcon_History \
1013 DownloadExtensionTest_FileIcon_History
1014 #endif
1015 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 963 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1016 MAYBE_DownloadExtensionTest_FileIcon_History) { 964 DownloadExtensionTest_FileIcon_History) {
1017 const HistoryDownloadInfo kHistoryInfo[] = { 965 const HistoryDownloadInfo kHistoryInfo[] = {
1018 { FILE_PATH_LITERAL("real.txt"), 966 { FILE_PATH_LITERAL("real.txt"),
1019 DownloadItem::COMPLETE, 967 DownloadItem::COMPLETE,
1020 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }, 968 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS },
1021 { FILE_PATH_LITERAL("fake.txt"), 969 { FILE_PATH_LITERAL("fake.txt"),
1022 DownloadItem::COMPLETE, 970 DownloadItem::COMPLETE,
1023 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS } 971 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS }
1024 }; 972 };
1025 DownloadManager::DownloadVector all_downloads; 973 DownloadManager::DownloadVector all_downloads;
1026 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo), 974 ASSERT_TRUE(CreateHistoryDownloads(kHistoryInfo, arraysize(kHistoryInfo),
1027 &all_downloads)); 975 &all_downloads));
1028 976
1029 FilePath real_path = all_downloads[0]->GetFullPath(); 977 FilePath real_path = all_downloads[0]->GetFullPath();
1030 FilePath fake_path = all_downloads[1]->GetFullPath(); 978 FilePath fake_path = all_downloads[1]->GetFullPath();
1031 979
1032 EXPECT_EQ(0, file_util::WriteFile(real_path, "", 0)); 980 EXPECT_EQ(0, file_util::WriteFile(real_path, "", 0));
1033 ASSERT_TRUE(file_util::PathExists(real_path)); 981 ASSERT_TRUE(file_util::PathExists(real_path));
1034 ASSERT_FALSE(file_util::PathExists(fake_path)); 982 ASSERT_FALSE(file_util::PathExists(fake_path));
1035 983
1036 for (DownloadManager::DownloadVector::iterator iter = all_downloads.begin(); 984 for (DownloadManager::DownloadVector::iterator iter = all_downloads.begin();
1037 iter != all_downloads.end(); 985 iter != all_downloads.end();
1038 ++iter) { 986 ++iter) {
1039 std::string args(base::StringPrintf("[%d, {\"size\": 32}]",
1040 (*iter)->GetId()));
1041 std::string result_string; 987 std::string result_string;
1042 EXPECT_TRUE(RunFunctionAndReturnString(
1043 new DownloadsGetFileIconFunction(), args, &result_string));
1044 // Note: We are checking if the result is a Data URL that has encoded
1045 // image/png data for an icon of a specific size. Of these, only the icon
1046 // size is specified in the API contract. The image type (image/png) and URL
1047 // type (Data) are implementation details.
1048 ExpectDataURLIsPNGWithSize(result_string, 32);
1049
1050 // Use a MockIconExtractorImpl to test if the correct path is being passed 988 // Use a MockIconExtractorImpl to test if the correct path is being passed
1051 // into the DownloadFileIconExtractor. 989 // into the DownloadFileIconExtractor.
1052 scoped_refptr<DownloadsGetFileIconFunction> function( 990 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
1053 new DownloadsGetFileIconFunction()); 991 (*iter)->GetFullPath(), IconLoader::NORMAL, "hello"),
1054 function->SetIconExtractorForTesting(new MockIconExtractorImpl( 992 base::StringPrintf("[%d, {\"size\": 32}]", (*iter)->GetId()),
1055 (*iter)->GetFullPath(), IconLoader::NORMAL, "hello")); 993 &result_string));
1056 EXPECT_TRUE(RunFunctionAndReturnString(function.release(), args,
1057 &result_string));
1058 EXPECT_STREQ("hello", result_string.c_str()); 994 EXPECT_STREQ("hello", result_string.c_str());
1059 } 995 }
1060 996
1061 // The temporary files should be cleaned up when the ScopedTempDir is removed. 997 // The temporary files should be cleaned up when the ScopedTempDir is removed.
1062 } 998 }
1063 999
1064 // Test passing the empty query to search(). 1000 // Test passing the empty query to search().
1065 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1001 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1066 DownloadExtensionTest_SearchEmptyQuery) { 1002 DownloadExtensionTest_SearchEmptyQuery) {
1067 ScopedCancellingItem item(CreateSlowTestDownload()); 1003 ScopedCancellingItem item(CreateSlowTestDownload());
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); 1250 ASSERT_TRUE(result_list->GetDictionary(0, &item_value));
1315 FilePath::StringType item_name; 1251 FilePath::StringType item_name;
1316 ASSERT_TRUE(item_value->GetString("filename", &item_name)); 1252 ASSERT_TRUE(item_value->GetString("filename", &item_name));
1317 ASSERT_EQ(items[2]->GetFullPath().value(), item_name); 1253 ASSERT_EQ(items[2]->GetFullPath().value(), item_name);
1318 } 1254 }
1319 1255
1320 // Test that incognito downloads are only visible in incognito contexts, and 1256 // Test that incognito downloads are only visible in incognito contexts, and
1321 // test that on-record downloads are visible in both incognito and on-record 1257 // test that on-record downloads are visible in both incognito and on-record
1322 // contexts, for DownloadsSearchFunction, DownloadsPauseFunction, 1258 // contexts, for DownloadsSearchFunction, DownloadsPauseFunction,
1323 // DownloadsResumeFunction, and DownloadsCancelFunction. 1259 // DownloadsResumeFunction, and DownloadsCancelFunction.
1324 // The test fails under ASan, see http://crbug.com/138211
1325 #if defined(ADDRESS_SANITIZER)
1326 #define \
1327 MAYBE_DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito \
1328 DISABLED_DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito
1329 #else
1330 #define \
1331 MAYBE_DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito \
1332 DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito
1333 #endif
1334 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1260 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1335 MAYBE_DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito) { 1261 DownloadExtensionTest_SearchPauseResumeCancelGetFileIconIncognito) {
1336 scoped_ptr<base::Value> result_value; 1262 scoped_ptr<base::Value> result_value;
1337 base::ListValue* result_list = NULL; 1263 base::ListValue* result_list = NULL;
1338 base::DictionaryValue* result_dict = NULL; 1264 base::DictionaryValue* result_dict = NULL;
1339 FilePath::StringType filename; 1265 FilePath::StringType filename;
1340 bool is_incognito = false; 1266 bool is_incognito = false;
1341 std::string error; 1267 std::string error;
1342 std::string on_item_arg; 1268 std::string on_item_arg;
1343 std::string off_item_arg; 1269 std::string off_item_arg;
1344 std::string result_string; 1270 std::string result_string;
1345 1271
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 new DownloadsGetFileIconFunction(), 1330 new DownloadsGetFileIconFunction(),
1405 base::StringPrintf("[%d, {}]", off_item->GetId())); 1331 base::StringPrintf("[%d, {}]", off_item->GetId()));
1406 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1332 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
1407 error.c_str()); 1333 error.c_str());
1408 1334
1409 GoOffTheRecord(); 1335 GoOffTheRecord();
1410 1336
1411 // Do the FileIcon test for both the on- and off-items while off the record. 1337 // Do the FileIcon test for both the on- and off-items while off the record.
1412 // NOTE(benjhayden): This does not include the FileIcon test from history, 1338 // NOTE(benjhayden): This does not include the FileIcon test from history,
1413 // just active downloads. This shouldn't be a problem. 1339 // just active downloads. This shouldn't be a problem.
1414 EXPECT_TRUE(RunFunctionAndReturnString( 1340 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
1415 new DownloadsGetFileIconFunction(), 1341 on_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"),
1416 base::StringPrintf("[%d, {}]", on_item->GetId()), &result_string)); 1342 base::StringPrintf("[%d, {}]", on_item->GetId()), &result_string));
1417 EXPECT_TRUE(RunFunctionAndReturnString( 1343 EXPECT_TRUE(RunFunctionAndReturnString(MockedGetFileIconFunction(
1418 new DownloadsGetFileIconFunction(), 1344 off_item->GetTargetFilePath(), IconLoader::NORMAL, "foo"),
1419 base::StringPrintf("[%d, {}]", off_item->GetId()), &result_string)); 1345 base::StringPrintf("[%d, {}]", off_item->GetId()), &result_string));
1420 1346
1421 // Do the pause/resume/cancel test for both the on- and off-items while off 1347 // Do the pause/resume/cancel test for both the on- and off-items while off
1422 // the record. 1348 // the record.
1423 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), on_item_arg)); 1349 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), on_item_arg));
1424 EXPECT_TRUE(on_item->IsPaused()); 1350 EXPECT_TRUE(on_item->IsPaused());
1425 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), on_item_arg)); 1351 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), on_item_arg));
1426 EXPECT_TRUE(on_item->IsPaused()); 1352 EXPECT_TRUE(on_item->IsPaused());
1427 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), on_item_arg)); 1353 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), on_item_arg));
1428 EXPECT_FALSE(on_item->IsPaused()); 1354 EXPECT_FALSE(on_item->IsPaused());
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 " \"state\": {" 2081 " \"state\": {"
2156 " \"previous\": \"in_progress\"," 2082 " \"previous\": \"in_progress\","
2157 " \"current\": \"complete\"}}]", 2083 " \"current\": \"complete\"}}]",
2158 result_id, 2084 result_id,
2159 GetFilename("on_record.txt.crdownload").c_str(), 2085 GetFilename("on_record.txt.crdownload").c_str(),
2160 GetFilename("on_record.txt").c_str()))); 2086 GetFilename("on_record.txt").c_str())));
2161 std::string disk_data; 2087 std::string disk_data;
2162 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2088 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2163 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2089 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2164 } 2090 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698