| 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 // This file contains download browser tests that are known to be runnable | 5 // This file contains download browser tests that are known to be runnable |
| 6 // in a pure content context. Over time tests should be migrated here. | 6 // in a pure content context. Over time tests should be migrated here. |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2215 // N.b. we can't make any assumptions about how many bytes are transferred by | 2215 // N.b. we can't make any assumptions about how many bytes are transferred by |
| 2216 // the first request since response data will be bufferred until DownloadFile | 2216 // the first request since response data will be bufferred until DownloadFile |
| 2217 // is done initializing. | 2217 // is done initializing. |
| 2218 // | 2218 // |
| 2219 // TODO(asanka): Ideally we'll check that the intermediate file matches | 2219 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 2220 // expectations prior to issuing the first resumption request. | 2220 // expectations prior to issuing the first resumption request. |
| 2221 ASSERT_EQ(2u, completed_requests.size()); | 2221 ASSERT_EQ(2u, completed_requests.size()); |
| 2222 EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count); | 2222 EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count); |
| 2223 } | 2223 } |
| 2224 | 2224 |
| 2225 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_LongFile) { | |
| 2226 // These numbers are sufficiently large that the intermediate file won't be | |
| 2227 // read in a single Read(). | |
| 2228 const int kFileSize = 1024 * 1024; | |
| 2229 const int kIntermediateSize = kFileSize / 2 + 111; | |
| 2230 | |
| 2231 TestDownloadRequestHandler request_handler; | |
| 2232 TestDownloadRequestHandler::Parameters parameters; | |
| 2233 parameters.size = kFileSize; | |
| 2234 request_handler.StartServing(parameters); | |
| 2235 | |
| 2236 base::FilePath intermediate_file_path = | |
| 2237 GetDownloadDirectory().AppendASCII("intermediate"); | |
| 2238 std::vector<GURL> url_chain; | |
| 2239 | |
| 2240 // Size of file is slightly longer than the size known to DownloadItem. | |
| 2241 std::vector<char> buffer(kIntermediateSize + 100); | |
| 2242 request_handler.GetPatternBytes( | |
| 2243 parameters.pattern_generator_seed, 0, buffer.size(), buffer.data()); | |
| 2244 ASSERT_EQ( | |
| 2245 kIntermediateSize + 100, | |
| 2246 base::WriteFile(intermediate_file_path, buffer.data(), buffer.size())); | |
| 2247 url_chain.push_back(request_handler.url()); | |
| 2248 | |
| 2249 DownloadItem* download = DownloadManagerForShell(shell())->CreateDownloadItem( | |
| 2250 "F7FB1F59-7DE1-4845-AFDB-8A688F70F583", | |
| 2251 1, | |
| 2252 intermediate_file_path, | |
| 2253 base::FilePath(), | |
| 2254 url_chain, | |
| 2255 GURL(), | |
| 2256 GURL(), | |
| 2257 GURL(), | |
| 2258 "application/octet-stream", | |
| 2259 "application/octet-stream", | |
| 2260 base::Time::Now(), | |
| 2261 base::Time(), | |
| 2262 parameters.etag, | |
| 2263 std::string(), | |
| 2264 kIntermediateSize, | |
| 2265 parameters.size, | |
| 2266 std::string(), | |
| 2267 DownloadItem::INTERRUPTED, | |
| 2268 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 2269 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, | |
| 2270 false); | |
| 2271 | |
| 2272 download->Resume(); | |
| 2273 WaitForCompletion(download); | |
| 2274 | |
| 2275 EXPECT_FALSE(base::PathExists(intermediate_file_path)); | |
| 2276 ReadAndVerifyFileContents(parameters.pattern_generator_seed, | |
| 2277 parameters.size, | |
| 2278 download->GetTargetFilePath()); | |
| 2279 | |
| 2280 TestDownloadRequestHandler::CompletedRequests completed_requests; | |
| 2281 request_handler.GetCompletedRequestInfo(&completed_requests); | |
| 2282 | |
| 2283 // There should be only one request. The intermediate file should be truncated | |
| 2284 // to the expected size, and the request should be issued for the remainder. | |
| 2285 // | |
| 2286 // TODO(asanka): Ideally we'll check that the intermediate file matches | |
| 2287 // expectations prior to issuing the first resumption request. | |
| 2288 ASSERT_EQ(1u, completed_requests.size()); | |
| 2289 EXPECT_EQ(parameters.size - kIntermediateSize, | |
| 2290 completed_requests[0]->transferred_byte_count); | |
| 2291 } | |
| 2292 | |
| 2293 // Test that the referrer header is set correctly for a download that's resumed | 2225 // Test that the referrer header is set correctly for a download that's resumed |
| 2294 // partially. | 2226 // partially. |
| 2295 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ReferrerForPartialResumption) { | 2227 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ReferrerForPartialResumption) { |
| 2296 TestDownloadRequestHandler request_handler; | 2228 TestDownloadRequestHandler request_handler; |
| 2297 TestDownloadRequestHandler::Parameters parameters = | 2229 TestDownloadRequestHandler::Parameters parameters = |
| 2298 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 2230 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 2299 request_handler.StartServing(parameters); | 2231 request_handler.StartServing(parameters); |
| 2300 | 2232 |
| 2301 ASSERT_TRUE(embedded_test_server()->Start()); | 2233 ASSERT_TRUE(embedded_test_server()->Start()); |
| 2302 GURL document_url = embedded_test_server()->GetURL( | 2234 GURL document_url = embedded_test_server()->GetURL( |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 | 2498 |
| 2567 std::vector<DownloadItem*> downloads; | 2499 std::vector<DownloadItem*> downloads; |
| 2568 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2500 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 2569 ASSERT_EQ(1u, downloads.size()); | 2501 ASSERT_EQ(1u, downloads.size()); |
| 2570 | 2502 |
| 2571 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 2503 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
| 2572 downloads[0]->GetTargetFilePath().BaseName().value()); | 2504 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 2573 } | 2505 } |
| 2574 | 2506 |
| 2575 } // namespace content | 2507 } // namespace content |
| OLD | NEW |