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

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

Issue 1887873002: [Downloads] BaseFile shouldn't read past the expected EOF for a stub file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 // N.b. we can't make any assumptions about how many bytes are transferred by 2218 // N.b. we can't make any assumptions about how many bytes are transferred by
2219 // the first request since response data will be bufferred until DownloadFile 2219 // the first request since response data will be bufferred until DownloadFile
2220 // is done initializing. 2220 // is done initializing.
2221 // 2221 //
2222 // TODO(asanka): Ideally we'll check that the intermediate file matches 2222 // TODO(asanka): Ideally we'll check that the intermediate file matches
2223 // expectations prior to issuing the first resumption request. 2223 // expectations prior to issuing the first resumption request.
2224 ASSERT_EQ(2u, completed_requests.size()); 2224 ASSERT_EQ(2u, completed_requests.size());
2225 EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count); 2225 EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count);
2226 } 2226 }
2227 2227
2228 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_LongFile) {
2229 // These numbers are sufficiently large that the intermediate file won't be
2230 // read in a single Read().
2231 const int kFileSize = 1024 * 1024;
2232 const int kIntermediateSize = kFileSize / 2 + 111;
2233
2234 TestDownloadRequestHandler request_handler;
2235 TestDownloadRequestHandler::Parameters parameters;
2236 parameters.size = kFileSize;
2237 request_handler.StartServing(parameters);
2238
2239 base::FilePath intermediate_file_path =
2240 GetDownloadDirectory().AppendASCII("intermediate");
2241 std::vector<GURL> url_chain;
2242
2243 // Size of file is slightly longer than the size known to DownloadItem.
2244 std::vector<char> buffer(kIntermediateSize + 100);
2245 request_handler.GetPatternBytes(
2246 parameters.pattern_generator_seed, 0, buffer.size(), buffer.data());
2247 ASSERT_EQ(
2248 kIntermediateSize + 100,
2249 base::WriteFile(intermediate_file_path, buffer.data(), buffer.size()));
2250 url_chain.push_back(request_handler.url());
2251
2252 DownloadItem* download = DownloadManagerForShell(shell())->CreateDownloadItem(
2253 "F7FB1F59-7DE1-4845-AFDB-8A688F70F583",
2254 1,
2255 intermediate_file_path,
2256 base::FilePath(),
2257 url_chain,
2258 GURL(),
2259 GURL(),
2260 GURL(),
2261 "application/octet-stream",
2262 "application/octet-stream",
2263 base::Time::Now(),
2264 base::Time(),
2265 parameters.etag,
2266 std::string(),
2267 kIntermediateSize,
2268 parameters.size,
2269 std::string(),
2270 DownloadItem::INTERRUPTED,
2271 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
2272 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED,
2273 false);
2274
2275 download->Resume();
2276 WaitForCompletion(download);
2277
2278 EXPECT_FALSE(base::PathExists(intermediate_file_path));
2279 ReadAndVerifyFileContents(parameters.pattern_generator_seed,
2280 parameters.size,
2281 download->GetTargetFilePath());
2282
2283 TestDownloadRequestHandler::CompletedRequests completed_requests;
2284 request_handler.GetCompletedRequestInfo(&completed_requests);
2285
2286 // There should be only one request. The intermediate file should be truncated
2287 // to the expected size, and the request should be issued for the remainder.
2288 //
2289 // TODO(asanka): Ideally we'll check that the intermediate file matches
2290 // expectations prior to issuing the first resumption request.
2291 ASSERT_EQ(1u, completed_requests.size());
2292 EXPECT_EQ(parameters.size - kIntermediateSize,
2293 completed_requests[0].transferred_byte_count);
2294 }
2295
2228 // Check that the cookie policy is correctly updated when downloading a file 2296 // Check that the cookie policy is correctly updated when downloading a file
2229 // that redirects cross origin. 2297 // that redirects cross origin.
2230 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { 2298 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) {
2231 net::EmbeddedTestServer origin_one; 2299 net::EmbeddedTestServer origin_one;
2232 net::EmbeddedTestServer origin_two; 2300 net::EmbeddedTestServer origin_two;
2233 ASSERT_TRUE(origin_one.Start()); 2301 ASSERT_TRUE(origin_one.Start());
2234 ASSERT_TRUE(origin_two.Start()); 2302 ASSERT_TRUE(origin_two.Start());
2235 2303
2236 // Block third-party cookies. 2304 // Block third-party cookies.
2237 ShellNetworkDelegate::SetAcceptAllCookies(false); 2305 ShellNetworkDelegate::SetAcceptAllCookies(false);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2469 2537
2470 std::vector<DownloadItem*> downloads; 2538 std::vector<DownloadItem*> downloads;
2471 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 2539 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
2472 ASSERT_EQ(1u, downloads.size()); 2540 ASSERT_EQ(1u, downloads.size());
2473 2541
2474 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 2542 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
2475 downloads[0]->GetTargetFilePath().BaseName().value()); 2543 downloads[0]->GetTargetFilePath().BaseName().value());
2476 } 2544 }
2477 2545
2478 } // namespace content 2546 } // 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