| OLD | NEW |
| 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_impl.h" | 10 #include "content/browser/download/download_file_impl.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 DownloadFileImpl(&info, new DownloadRequestHandle(), | 75 new DownloadFileImpl(&info, new DownloadRequestHandle(), |
| 76 download_manager_)); | 76 download_manager_, Pickle())); |
| 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)->InProgress()); | 82 EXPECT_FALSE((*file)->InProgress()); |
| 83 EXPECT_EQ(static_cast<int64>(expected_data_.size()), | 83 EXPECT_EQ(static_cast<int64>(expected_data_.size()), |
| 84 (*file)->BytesSoFar()); | 84 (*file)->BytesSoFar()); |
| 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 Loading... |
| 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_->FullPath(); | 177 renamed_path = download_file_->FullPath(); |
| 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_->FullPath(); | 188 renamed_path = download_file_->FullPath(); |
| 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 } |
| OLD | NEW |