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

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 1956403005: [Merge M51][Downloads] BaseFile shouldn't read past the expected EOF for a stub file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 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
« no previous file with comments | « content/browser/download/base_file_unittest.cc ('k') | 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 // 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 2236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 parameters.pattern_generator_seed, parameters.size, 2247 parameters.pattern_generator_seed, parameters.size,
2248 download->GetTargetFilePath())); 2248 download->GetTargetFilePath()));
2249 2249
2250 TestDownloadRequestHandler::CompletedRequests requests; 2250 TestDownloadRequestHandler::CompletedRequests requests;
2251 request_handler.GetCompletedRequestInfo(&requests); 2251 request_handler.GetCompletedRequestInfo(&requests);
2252 2252
2253 ASSERT_GE(2u, requests.size()); 2253 ASSERT_GE(2u, requests.size());
2254 EXPECT_EQ(document_url.spec(), requests.back()->referrer); 2254 EXPECT_EQ(document_url.spec(), requests.back()->referrer);
2255 } 2255 }
2256 2256
2257 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_LongFile) {
2258 // These numbers are sufficiently large that the intermediate file won't be
2259 // read in a single Read().
2260 const int kFileSize = 1024 * 1024;
2261 const int kIntermediateSize = kFileSize / 2 + 111;
2262
2263 TestDownloadRequestHandler request_handler;
2264 TestDownloadRequestHandler::Parameters parameters;
2265 parameters.size = kFileSize;
2266 request_handler.StartServing(parameters);
2267
2268 base::FilePath intermediate_file_path =
2269 GetDownloadDirectory().AppendASCII("intermediate");
2270 std::vector<GURL> url_chain;
2271
2272 // Size of file is slightly longer than the size known to DownloadItem.
2273 std::vector<char> buffer(kIntermediateSize + 100);
2274 request_handler.GetPatternBytes(
2275 parameters.pattern_generator_seed, 0, buffer.size(), buffer.data());
2276 ASSERT_EQ(
2277 kIntermediateSize + 100,
2278 base::WriteFile(intermediate_file_path, buffer.data(), buffer.size()));
2279 url_chain.push_back(request_handler.url());
2280
2281 DownloadItem* download = DownloadManagerForShell(shell())->CreateDownloadItem(
2282 "F7FB1F59-7DE1-4845-AFDB-8A688F70F583",
2283 1,
2284 intermediate_file_path,
2285 base::FilePath(),
2286 url_chain,
2287 GURL(),
2288 GURL(),
2289 GURL(),
2290 "application/octet-stream",
2291 "application/octet-stream",
2292 base::Time::Now(),
2293 base::Time(),
2294 parameters.etag,
2295 std::string(),
2296 kIntermediateSize,
2297 parameters.size,
2298 std::string(),
2299 DownloadItem::INTERRUPTED,
2300 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
2301 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED,
2302 false);
2303
2304 download->Resume();
2305 WaitForCompletion(download);
2306
2307 EXPECT_FALSE(base::PathExists(intermediate_file_path));
2308 ReadAndVerifyFileContents(parameters.pattern_generator_seed,
2309 parameters.size,
2310 download->GetTargetFilePath());
2311
2312 TestDownloadRequestHandler::CompletedRequests completed_requests;
2313 request_handler.GetCompletedRequestInfo(&completed_requests);
2314
2315 // There should be only one request. The intermediate file should be truncated
2316 // to the expected size, and the request should be issued for the remainder.
2317 //
2318 // TODO(asanka): Ideally we'll check that the intermediate file matches
2319 // expectations prior to issuing the first resumption request.
2320 ASSERT_EQ(1u, completed_requests.size());
2321 EXPECT_EQ(parameters.size - kIntermediateSize,
2322 completed_requests[0].transferred_byte_count);
2323 }
2324
2257 // Check that the cookie policy is correctly updated when downloading a file 2325 // Check that the cookie policy is correctly updated when downloading a file
2258 // that redirects cross origin. 2326 // that redirects cross origin.
2259 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { 2327 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) {
2260 net::EmbeddedTestServer origin_one; 2328 net::EmbeddedTestServer origin_one;
2261 net::EmbeddedTestServer origin_two; 2329 net::EmbeddedTestServer origin_two;
2262 ASSERT_TRUE(origin_one.Start()); 2330 ASSERT_TRUE(origin_one.Start());
2263 ASSERT_TRUE(origin_two.Start()); 2331 ASSERT_TRUE(origin_two.Start());
2264 2332
2265 // Block third-party cookies. 2333 // Block third-party cookies.
2266 ShellNetworkDelegate::SetAcceptAllCookies(false); 2334 ShellNetworkDelegate::SetAcceptAllCookies(false);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2498 2566
2499 std::vector<DownloadItem*> downloads; 2567 std::vector<DownloadItem*> downloads;
2500 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 2568 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
2501 ASSERT_EQ(1u, downloads.size()); 2569 ASSERT_EQ(1u, downloads.size());
2502 2570
2503 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 2571 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
2504 downloads[0]->GetTargetFilePath().BaseName().value()); 2572 downloads[0]->GetTargetFilePath().BaseName().value());
2505 } 2573 }
2506 2574
2507 } // namespace content 2575 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/base_file_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698