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

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

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup, and added fields to DownloadPersistentStoreInfo. Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/download/download_create_info.h" 9 #include "content/browser/download/download_create_info.h"
10 #include "content/browser/download/download_file.h" 10 #include "content/browser/download/download_file.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 ui_thread_.message_loop()->RunAllPending(); 66 ui_thread_.message_loop()->RunAllPending();
67 } 67 }
68 68
69 virtual void CreateDownloadFile(scoped_ptr<DownloadFile>* file, int offset) { 69 virtual void CreateDownloadFile(scoped_ptr<DownloadFile>* file, int offset) {
70 DownloadCreateInfo info; 70 DownloadCreateInfo info;
71 info.download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset); 71 info.download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset);
72 // info.request_handle default constructed to null. 72 // info.request_handle default constructed to null.
73 info.save_info.file_stream = file_stream_; 73 info.save_info.file_stream = file_stream_;
74 file->reset( 74 file->reset(
75 new DownloadFile(&info, new DownloadRequestHandle(), 75 new DownloadFile(&info, new DownloadRequestHandle(),
76 download_manager_)); 76 download_manager_, ""));
77 } 77 }
78 78
79 virtual void DestroyDownloadFile(scoped_ptr<DownloadFile>* file, int offset) { 79 virtual void DestroyDownloadFile(scoped_ptr<DownloadFile>* file, int offset) {
80 EXPECT_EQ(kDummyDownloadId + offset, (*file)->id()); 80 EXPECT_EQ(kDummyDownloadId + offset, (*file)->id());
81 EXPECT_EQ(download_manager_, (*file)->GetDownloadManager()); 81 EXPECT_EQ(download_manager_, (*file)->GetDownloadManager());
82 EXPECT_FALSE((*file)->in_progress()); 82 EXPECT_FALSE((*file)->in_progress());
83 EXPECT_EQ(static_cast<int64>(expected_data_.size()), 83 EXPECT_EQ(static_cast<int64>(expected_data_.size()),
84 (*file)->bytes_so_far()); 84 (*file)->bytes_so_far());
85 85
86 // Make sure the data has been properly written to disk. 86 // Make sure the data has been properly written to disk.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 // Rename the file after downloading all the data. 175 // Rename the file after downloading all the data.
176 EXPECT_EQ(net::OK, download_file_->Rename(path_3)); 176 EXPECT_EQ(net::OK, download_file_->Rename(path_3));
177 renamed_path = download_file_->full_path(); 177 renamed_path = download_file_->full_path();
178 EXPECT_EQ(path_3, renamed_path); 178 EXPECT_EQ(path_3, renamed_path);
179 179
180 // Check the files. 180 // Check the files.
181 EXPECT_FALSE(file_util::PathExists(path_2)); 181 EXPECT_FALSE(file_util::PathExists(path_2));
182 EXPECT_TRUE(file_util::PathExists(path_3)); 182 EXPECT_TRUE(file_util::PathExists(path_3));
183 183
184 // Should not be able to get the hash until the file is closed.
185 std::string hash;
186 EXPECT_FALSE(download_file_->GetSha256Hash(&hash));
187
188 download_file_->Finish(); 184 download_file_->Finish();
189 185
190 // Rename the file after downloading all the data and closing the file. 186 // Rename the file after downloading all the data and closing the file.
191 EXPECT_EQ(net::OK, download_file_->Rename(path_4)); 187 EXPECT_EQ(net::OK, download_file_->Rename(path_4));
192 renamed_path = download_file_->full_path(); 188 renamed_path = download_file_->full_path();
193 EXPECT_EQ(path_4, renamed_path); 189 EXPECT_EQ(path_4, renamed_path);
194 190
195 // Check the files. 191 // Check the files.
196 EXPECT_FALSE(file_util::PathExists(path_3)); 192 EXPECT_FALSE(file_util::PathExists(path_3));
197 EXPECT_TRUE(file_util::PathExists(path_4)); 193 EXPECT_TRUE(file_util::PathExists(path_4));
198 194
199 // Check the hash. 195 // Check the hash.
196 std::string hash;
200 EXPECT_TRUE(download_file_->GetSha256Hash(&hash)); 197 EXPECT_TRUE(download_file_->GetSha256Hash(&hash));
201 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size())); 198 EXPECT_EQ(kDataHash, base::HexEncode(hash.data(), hash.size()));
202 199
203 DestroyDownloadFile(&download_file_, 0); 200 DestroyDownloadFile(&download_file_, 0);
204 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698