Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 history::HistoryService* history_service = | 1023 history::HistoryService* history_service = |
| 1024 HistoryServiceFactory::GetForProfile(profile(), | 1024 HistoryServiceFactory::GetForProfile(profile(), |
| 1025 ServiceAccessType::EXPLICIT_ACCESS); | 1025 ServiceAccessType::EXPLICIT_ACCESS); |
| 1026 ASSERT_TRUE(history_service); | 1026 ASSERT_TRUE(history_service); |
| 1027 history_service->AddPage(url, time_of_visit, history::SOURCE_BROWSED); | 1027 history_service->AddPage(url, time_of_visit, history::SOURCE_BROWSED); |
| 1028 | 1028 |
| 1029 RunTestCasesWithActiveItem(kVisitedReferrerCases, | 1029 RunTestCasesWithActiveItem(kVisitedReferrerCases, |
| 1030 arraysize(kVisitedReferrerCases)); | 1030 arraysize(kVisitedReferrerCases)); |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 TEST_F(DownloadTargetDeterminerTest, TransitionType) { | |
| 1034 const struct { | |
| 1035 ui::PageTransition page_transition; | |
| 1036 DownloadTestCase test_case; | |
| 1037 } kTestCases[] = { | |
| 1038 { | |
| 1039 // Benign file type. Results in a danger type of NOT_DANGEROUS. Page | |
| 1040 // transition type is irrelevant. | |
| 1041 ui::PAGE_TRANSITION_LINK, | |
|
Peter Kasting
2016/06/29 23:35:01
So many of these enums probably should be converte
asanka
2016/06/30 15:48:52
Acknowledged.
| |
| 1042 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1043 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | |
| 1044 "text/plain", FILE_PATH_LITERAL(""), | |
| 1045 | |
| 1046 FILE_PATH_LITERAL("foo.txt"), | |
| 1047 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1048 | |
| 1049 EXPECT_CRDOWNLOAD}, | |
| 1050 }, | |
|
Peter Kasting
2016/06/29 23:35:01
Nit: Maybe you should write a helper that construc
asanka
2016/06/30 15:48:52
Yeah. I rewrote the test cases so that the definit
| |
| 1051 | |
| 1052 { | |
| 1053 // File type is ALLOW_ON_USER_GESTURE. PAGE_TRANSITION_LINK doesn't | |
| 1054 // cause file to be marked as safe. | |
| 1055 ui::PAGE_TRANSITION_LINK, | |
| 1056 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | |
|
Peter Kasting
2016/06/29 23:35:01
Shouldn't this case and the next one be using DOWN
asanka
2016/06/30 15:48:52
Danger type of the download == F( |danger level of
| |
| 1057 DownloadFileType::ALLOW_ON_USER_GESTURE, | |
| 1058 "http://example.com/foo.crx", "application/octet-stream", | |
| 1059 FILE_PATH_LITERAL(""), | |
| 1060 | |
| 1061 FILE_PATH_LITERAL("foo.crx"), | |
| 1062 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1063 | |
| 1064 EXPECT_UNCONFIRMED}, | |
| 1065 }, | |
| 1066 | |
| 1067 { | |
| 1068 // File type is ALLOW_ON_USER_GESTURE. PAGE_TRANSITION_TYPED doesn't | |
| 1069 // cause file to be marked as safe. TYPED can be used for certain | |
| 1070 // types of explicit page transitions that aren't necessarily | |
| 1071 // initiated by a user. Hence a resulting download may not be | |
| 1072 // intentional. | |
| 1073 ui::PAGE_TRANSITION_TYPED, | |
| 1074 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | |
| 1075 DownloadFileType::ALLOW_ON_USER_GESTURE, | |
| 1076 "http://example.com/foo.crx", "application/octet-stream", | |
| 1077 FILE_PATH_LITERAL(""), | |
| 1078 | |
| 1079 FILE_PATH_LITERAL("foo.crx"), | |
| 1080 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1081 | |
| 1082 EXPECT_UNCONFIRMED}, | |
| 1083 }, | |
| 1084 | |
| 1085 { | |
| 1086 // File type is ALLOW_ON_USER_GESTURE. | |
| 1087 // PAGE_TRANSITION_FROM_ADDRESS_BAR causes file to be marked as safe. | |
| 1088 static_cast<ui::PageTransition>(ui::PAGE_TRANSITION_TYPED | | |
| 1089 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR), | |
| 1090 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1091 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.crx", | |
| 1092 "application/octet-stream", FILE_PATH_LITERAL(""), | |
| 1093 | |
| 1094 FILE_PATH_LITERAL("foo.crx"), | |
| 1095 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1096 | |
| 1097 EXPECT_CRDOWNLOAD}, | |
| 1098 }, | |
| 1099 | |
| 1100 { | |
| 1101 // File type is ALLOW_ON_USER_GESTURE. | |
| 1102 // PAGE_TRANSITION_FROM_ADDRESS_BAR causes file to be marked as safe. | |
| 1103 static_cast<ui::PageTransition>(ui::PAGE_TRANSITION_GENERATED | | |
| 1104 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR), | |
| 1105 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1106 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.crx", | |
| 1107 "application/octet-stream", FILE_PATH_LITERAL(""), | |
| 1108 | |
| 1109 FILE_PATH_LITERAL("foo.crx"), | |
| 1110 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1111 | |
| 1112 EXPECT_CRDOWNLOAD}, | |
| 1113 }, | |
| 1114 | |
| 1115 { | |
| 1116 // File type is ALLOW_ON_USER_GESTURE. | |
| 1117 // PAGE_TRANSITION_FROM_ADDRESS_BAR causes file to be marked as safe. | |
| 1118 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR, | |
| 1119 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1120 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.crx", | |
| 1121 "application/octet-stream", FILE_PATH_LITERAL(""), | |
| 1122 | |
| 1123 FILE_PATH_LITERAL("foo.crx"), | |
| 1124 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1125 | |
| 1126 EXPECT_CRDOWNLOAD}, | |
| 1127 }, | |
| 1128 | |
| 1129 { | |
| 1130 // File type is DANGEROUS. PageTransition is irrelevant. | |
| 1131 static_cast<ui::PageTransition>(ui::PAGE_TRANSITION_TYPED | | |
| 1132 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR), | |
| 1133 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | |
| 1134 DownloadFileType::DANGEROUS, "http://example.com/foo.swf", | |
| 1135 "application/octet-stream", FILE_PATH_LITERAL(""), | |
| 1136 | |
| 1137 FILE_PATH_LITERAL("foo.swf"), | |
| 1138 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1139 | |
| 1140 EXPECT_UNCONFIRMED}, | |
| 1141 }, | |
| 1142 }; | |
| 1143 | |
| 1144 // Test assumptions: | |
| 1145 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, | |
| 1146 Policies()->GetFileDangerLevel( | |
| 1147 base::FilePath(FILE_PATH_LITERAL("foo.crx")))); | |
| 1148 ASSERT_EQ(DownloadFileType::DANGEROUS, | |
| 1149 Policies()->GetFileDangerLevel( | |
| 1150 base::FilePath(FILE_PATH_LITERAL("foo.swf")))); | |
| 1151 ASSERT_EQ(DownloadFileType::NOT_DANGEROUS, | |
| 1152 Policies()->GetFileDangerLevel( | |
| 1153 base::FilePath(FILE_PATH_LITERAL("foo.txt")))); | |
| 1154 | |
| 1155 for (const auto& test_case : kTestCases) { | |
| 1156 std::unique_ptr<content::MockDownloadItem> item( | |
| 1157 CreateActiveDownloadItem(1, test_case.test_case)); | |
| 1158 EXPECT_CALL(*item, GetTransitionType()) | |
| 1159 .WillRepeatedly(Return(test_case.page_transition)); | |
| 1160 RunTestCase(test_case.test_case, base::FilePath(), item.get()); | |
| 1161 } | |
| 1162 } | |
| 1163 | |
| 1033 // These test cases are run with "Prompt for download" user preference set to | 1164 // These test cases are run with "Prompt for download" user preference set to |
| 1034 // true. | 1165 // true. |
| 1035 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways) { | 1166 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways) { |
| 1036 const DownloadTestCase kPromptingTestCases[] = { | 1167 const DownloadTestCase kPromptingTestCases[] = { |
| 1037 {// 0: Safe Automatic - Should prompt because of "Prompt for download" | 1168 {// 0: Safe Automatic - Should prompt because of "Prompt for download" |
| 1038 // preference setting. | 1169 // preference setting. |
| 1039 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1170 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1040 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1171 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1041 "text/plain", FILE_PATH_LITERAL(""), | 1172 "text/plain", FILE_PATH_LITERAL(""), |
| 1042 | 1173 |
| (...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2019 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) | 2150 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) |
| 2020 .WillRepeatedly(Return(false)); | 2151 .WillRepeatedly(Return(false)); |
| 2021 target_info = RunDownloadTargetDeterminer( | 2152 target_info = RunDownloadTargetDeterminer( |
| 2022 GetPathInDownloadDir(kInitialPath), item.get()); | 2153 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2023 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2154 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2024 } | 2155 } |
| 2025 | 2156 |
| 2026 #endif // defined(ENABLE_PLUGINS) | 2157 #endif // defined(ENABLE_PLUGINS) |
| 2027 | 2158 |
| 2028 } // namespace | 2159 } // namespace |
| OLD | NEW |