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 "chrome/browser/download/download_item_model.h" | 5 #include "chrome/browser/download/download_item_model.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 TEST_F(DownloadItemModelTest, InterruptedStatus) { | 117 TEST_F(DownloadItemModelTest, InterruptedStatus) { |
118 // Test that we have the correct interrupt status message for downloads that | 118 // Test that we have the correct interrupt status message for downloads that |
119 // are in the INTERRUPTED state. | 119 // are in the INTERRUPTED state. |
120 const struct TestCase { | 120 const struct TestCase { |
121 // The reason. | 121 // The reason. |
122 content::DownloadInterruptReason reason; | 122 content::DownloadInterruptReason reason; |
123 | 123 |
124 // Expected status string. This will include the progress as well. | 124 // Expected status string. This will include the progress as well. |
125 const char* expected_status; | 125 const char* expected_status; |
126 } kTestCases[] = { | 126 } kTestCases[] = { |
127 { content::DOWNLOAD_INTERRUPT_REASON_NONE, | 127 {content::DOWNLOAD_INTERRUPT_REASON_NONE, "1/2 B"}, |
128 "1/2 B" }, | 128 {content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
129 { content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | 129 "Failed - Download error"}, |
130 "Failed - Download error" }, | 130 {content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, |
131 { content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, | 131 "Failed - Insufficient permissions"}, |
132 "Failed - Insufficient permissions" }, | 132 {content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, "Failed - Disk full"}, |
133 { content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 133 {content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, |
134 "Failed - Disk full" }, | 134 "Failed - Path too long"}, |
135 { content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, | 135 {content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE, |
136 "Failed - Path too long" }, | 136 "Failed - File too large"}, |
137 { content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE, | 137 {content::DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED, |
138 "Failed - File too large" }, | 138 "Failed - Virus detected"}, |
139 { content::DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED, | 139 {content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, "Failed - Blocked"}, |
140 "Failed - Virus detected" }, | 140 {content::DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED, |
141 { content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, | 141 "Failed - Virus scan failed"}, |
142 "Failed - Blocked" }, | 142 {content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT, |
143 { content::DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED, | 143 "Failed - File truncated"}, |
144 "Failed - Virus scan failed" }, | 144 {content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, |
145 { content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT, | 145 "Failed - System busy"}, |
146 "Failed - File truncated" }, | 146 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, |
147 { content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, | 147 "Failed - Network error"}, |
148 "Failed - System busy" }, | 148 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, |
149 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, | 149 "Failed - Network timeout"}, |
150 "Failed - Network error" }, | 150 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, |
151 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, | 151 "Failed - Network disconnected"}, |
152 "Failed - Network timeout" }, | 152 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN, |
153 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, | 153 "Failed - Server unavailable"}, |
154 "Failed - Network disconnected" }, | 154 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST, |
155 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN, | 155 "Failed - Network error"}, |
156 "Failed - Server unavailable" }, | 156 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
157 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST, | 157 "Failed - Server problem"}, |
158 "Failed - Network error" }, | 158 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE, |
159 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 159 "Failed - Download error"}, |
160 "Failed - Server problem" }, | 160 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, |
161 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE, | 161 "Failed - No file"}, |
162 "Failed - Download error" }, | 162 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED, |
163 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 163 "Failed - Needs authorization"}, |
164 "Failed - No file" }, | 164 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, |
165 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED, | 165 "Failed - Bad certificate"}, |
166 "Failed - Needs authorization" }, | 166 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN, |
167 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, | 167 "Failed - Forbidden"}, |
168 "Failed - Bad certificate" }, | 168 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE, |
169 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN, | 169 "Failed - Server unreachable"}, |
170 "Failed - Forbidden" }, | 170 {content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, "Canceled"}, |
171 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, | 171 {content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, "Failed - Shutdown"}, |
172 "Canceled" }, | 172 {content::DOWNLOAD_INTERRUPT_REASON_CRASH, "Failed - Crash"}, |
173 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, | |
174 "Failed - Shutdown" }, | |
175 { content::DOWNLOAD_INTERRUPT_REASON_CRASH, | |
176 "Failed - Crash" }, | |
177 }; | 173 }; |
178 static_assert(kInterruptReasonCount == arraysize(kTestCases), | 174 static_assert(kInterruptReasonCount == arraysize(kTestCases), |
179 "interrupt reason mismatch"); | 175 "interrupt reason mismatch"); |
180 | 176 |
181 SetupDownloadItemDefaults(); | 177 SetupDownloadItemDefaults(); |
182 for (unsigned i = 0; i < arraysize(kTestCases); ++i) { | 178 for (unsigned i = 0; i < arraysize(kTestCases); ++i) { |
183 const TestCase& test_case = kTestCases[i]; | 179 const TestCase& test_case = kTestCases[i]; |
184 SetupInterruptedDownloadItem(test_case.reason); | 180 SetupInterruptedDownloadItem(test_case.reason); |
185 EXPECT_STREQ(test_case.expected_status, | 181 EXPECT_STREQ(test_case.expected_status, |
186 base::UTF16ToUTF8(model().GetStatusText()).c_str()); | 182 base::UTF16ToUTF8(model().GetStatusText()).c_str()); |
187 } | 183 } |
188 } | 184 } |
189 | 185 |
190 // Note: This test is currently skipped on Android. See http://crbug.com/139398 | 186 // Note: This test is currently skipped on Android. See http://crbug.com/139398 |
191 TEST_F(DownloadItemModelTest, InterruptTooltip) { | 187 TEST_F(DownloadItemModelTest, InterruptTooltip) { |
192 // Test that we have the correct interrupt tooltip for downloads that are in | 188 // Test that we have the correct interrupt tooltip for downloads that are in |
193 // the INTERRUPTED state. | 189 // the INTERRUPTED state. |
194 const struct TestCase { | 190 const struct TestCase { |
195 // The reason. | 191 // The reason. |
196 content::DownloadInterruptReason reason; | 192 content::DownloadInterruptReason reason; |
197 | 193 |
198 // Expected tooltip text. The tooltip text for interrupted downloads | 194 // Expected tooltip text. The tooltip text for interrupted downloads |
199 // typically consist of two lines. One for the filename and one for the | 195 // typically consist of two lines. One for the filename and one for the |
200 // interrupt reason. The returned string contains a newline. | 196 // interrupt reason. The returned string contains a newline. |
201 const char* expected_tooltip; | 197 const char* expected_tooltip; |
202 } kTestCases[] = { | 198 } kTestCases[] = { |
203 { content::DOWNLOAD_INTERRUPT_REASON_NONE, | 199 {content::DOWNLOAD_INTERRUPT_REASON_NONE, "foo.bar"}, |
204 "foo.bar" }, | 200 {content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
205 { content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | 201 "foo.bar\nDownload error"}, |
206 "foo.bar\nDownload error" }, | 202 {content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, |
207 { content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, | 203 "foo.bar\nInsufficient permissions"}, |
208 "foo.bar\nInsufficient permissions" }, | 204 {content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, "foo.bar\nDisk full"}, |
209 { content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 205 {content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, |
210 "foo.bar\nDisk full" }, | 206 "foo.bar\nPath too long"}, |
211 { content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, | 207 {content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE, |
212 "foo.bar\nPath too long" }, | 208 "foo.bar\nFile too large"}, |
213 { content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE, | 209 {content::DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED, |
214 "foo.bar\nFile too large" }, | 210 "foo.bar\nVirus detected"}, |
215 { content::DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED, | 211 {content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, "foo.bar\nBlocked"}, |
216 "foo.bar\nVirus detected" }, | 212 {content::DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED, |
217 { content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, | 213 "foo.bar\nVirus scan failed"}, |
218 "foo.bar\nBlocked" }, | 214 {content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT, |
219 { content::DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED, | 215 "foo.bar\nFile truncated"}, |
220 "foo.bar\nVirus scan failed" }, | 216 {content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, |
221 { content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT, | 217 "foo.bar\nSystem busy"}, |
222 "foo.bar\nFile truncated" }, | 218 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, |
223 { content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, | 219 "foo.bar\nNetwork error"}, |
224 "foo.bar\nSystem busy" }, | 220 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, |
225 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, | 221 "foo.bar\nNetwork timeout"}, |
226 "foo.bar\nNetwork error" }, | 222 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, |
227 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, | 223 "foo.bar\nNetwork disconnected"}, |
228 "foo.bar\nNetwork timeout" }, | 224 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN, |
229 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, | 225 "foo.bar\nServer unavailable"}, |
230 "foo.bar\nNetwork disconnected" }, | 226 {content::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST, |
231 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN, | 227 "foo.bar\nNetwork error"}, |
232 "foo.bar\nServer unavailable" }, | 228 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
233 { content::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST, | 229 "foo.bar\nServer problem"}, |
234 "foo.bar\nNetwork error" }, | 230 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE, |
235 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 231 "foo.bar\nDownload error"}, |
236 "foo.bar\nServer problem" }, | 232 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, |
237 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE, | 233 "foo.bar\nNo file"}, |
238 "foo.bar\nDownload error" }, | 234 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED, |
239 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 235 "foo.bar\nNeeds authorization"}, |
240 "foo.bar\nNo file" }, | 236 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, |
241 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED, | 237 "foo.bar\nBad certificate"}, |
242 "foo.bar\nNeeds authorization" }, | 238 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN, |
243 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, | 239 "foo.bar\nForbidden"}, |
244 "foo.bar\nBad certificate" }, | 240 {content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE, |
245 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN, | 241 "foo.bar\nServer unreachable"}, |
246 "foo.bar\nForbidden" }, | 242 {content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, "foo.bar"}, |
247 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, | 243 {content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, "foo.bar\nShutdown"}, |
248 "foo.bar" }, | 244 {content::DOWNLOAD_INTERRUPT_REASON_CRASH, "foo.bar\nCrash"}, |
249 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, | |
250 "foo.bar\nShutdown" }, | |
251 { content::DOWNLOAD_INTERRUPT_REASON_CRASH, | |
252 "foo.bar\nCrash" }, | |
253 }; | 245 }; |
254 static_assert(kInterruptReasonCount == arraysize(kTestCases), | 246 static_assert(kInterruptReasonCount == arraysize(kTestCases), |
255 "interrupt reason mismatch"); | 247 "interrupt reason mismatch"); |
256 | 248 |
257 // Large tooltip width. Should be large enough to accommodate the entire | 249 // Large tooltip width. Should be large enough to accommodate the entire |
258 // tooltip without truncation. | 250 // tooltip without truncation. |
259 const int kLargeTooltipWidth = 1000; | 251 const int kLargeTooltipWidth = 1000; |
260 | 252 |
261 // Small tooltip width. Small enough to require truncation of most | 253 // Small tooltip width. Small enough to require truncation of most |
262 // tooltips. Used to test eliding logic. | 254 // tooltips. Used to test eliding logic. |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 EXPECT_CALL(item(), GetAutoOpened()) | 424 EXPECT_CALL(item(), GetAutoOpened()) |
433 .WillRepeatedly(Return(test_case.auto_opened)); | 425 .WillRepeatedly(Return(test_case.auto_opened)); |
434 | 426 |
435 EXPECT_EQ(test_case.expected_result, | 427 EXPECT_EQ(test_case.expected_result, |
436 model().ShouldRemoveFromShelfWhenComplete()) | 428 model().ShouldRemoveFromShelfWhenComplete()) |
437 << "Test case: " << i; | 429 << "Test case: " << i; |
438 Mock::VerifyAndClearExpectations(&item()); | 430 Mock::VerifyAndClearExpectations(&item()); |
439 Mock::VerifyAndClearExpectations(&model()); | 431 Mock::VerifyAndClearExpectations(&model()); |
440 } | 432 } |
441 } | 433 } |
OLD | NEW |