| 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 #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 "base/test/test_file_util.h" | 8 #include "base/test/test_file_util.h" |
| 9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/browser/download/byte_stream.h" | 10 #include "content/browser/download/byte_stream.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 DCHECK(!download_file_.get()); | 132 DCHECK(!download_file_.get()); |
| 133 | 133 |
| 134 input_stream_ = new StrictMock<MockByteStreamReader>(); | 134 input_stream_ = new StrictMock<MockByteStreamReader>(); |
| 135 | 135 |
| 136 // TODO: Need to actually create a function that'll set the variables | 136 // TODO: Need to actually create a function that'll set the variables |
| 137 // based on the inputs from the callback. | 137 // based on the inputs from the callback. |
| 138 EXPECT_CALL(*input_stream_, RegisterCallback(_)) | 138 EXPECT_CALL(*input_stream_, RegisterCallback(_)) |
| 139 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) | 139 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) |
| 140 .RetiresOnSaturation(); | 140 .RetiresOnSaturation(); |
| 141 | 141 |
| 142 DownloadCreateInfo info; | 142 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo()); |
| 143 // info.request_handle default constructed to null. | 143 // info.request_handle default constructed to null. |
| 144 info.download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset); | 144 info->download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset); |
| 145 info.save_info.file_stream = file_stream_; | |
| 146 download_file_.reset( | 145 download_file_.reset( |
| 147 new DownloadFileImpl( | 146 new DownloadFileImpl( |
| 148 &info, | 147 info.Pass(), |
| 149 scoped_ptr<content::ByteStreamReader>(input_stream_).Pass(), | 148 scoped_ptr<content::ByteStreamReader>(input_stream_).Pass(), |
| 150 new DownloadRequestHandle(), | 149 new DownloadRequestHandle(), |
| 151 download_manager_, calculate_hash, | 150 download_manager_, calculate_hash, |
| 152 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), | 151 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), |
| 153 net::BoundNetLog())); | 152 net::BoundNetLog())); |
| 154 | 153 |
| 155 EXPECT_CALL(*input_stream_, Read(_, _)) | 154 EXPECT_CALL(*input_stream_, Read(_, _)) |
| 156 .WillOnce(Return(content::ByteStreamReader::STREAM_EMPTY)) | 155 .WillOnce(Return(content::ByteStreamReader::STREAM_EMPTY)) |
| 157 .RetiresOnSaturation(); | 156 .RetiresOnSaturation(); |
| 158 content::DownloadInterruptReason result = download_file_->Initialize(); | 157 content::DownloadInterruptReason result = download_file_->Initialize(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 &result_reason, result_path_p)); | 266 &result_reason, result_path_p)); |
| 268 loop_.RunAllPending(); | 267 loop_.RunAllPending(); |
| 269 | 268 |
| 270 EXPECT_TRUE(callback_was_called); | 269 EXPECT_TRUE(callback_was_called); |
| 271 return result_reason; | 270 return result_reason; |
| 272 } | 271 } |
| 273 | 272 |
| 274 protected: | 273 protected: |
| 275 scoped_refptr<StrictMock<LocalMockDownloadManager> > download_manager_; | 274 scoped_refptr<StrictMock<LocalMockDownloadManager> > download_manager_; |
| 276 | 275 |
| 277 linked_ptr<net::FileStream> file_stream_; | |
| 278 | |
| 279 // DownloadFile instance we are testing. | 276 // DownloadFile instance we are testing. |
| 280 scoped_ptr<DownloadFile> download_file_; | 277 scoped_ptr<DownloadFile> download_file_; |
| 281 | 278 |
| 282 // Stream for sending data into the download file. | 279 // Stream for sending data into the download file. |
| 283 // Owned by download_file_; will be alive for lifetime of download_file_. | 280 // Owned by download_file_; will be alive for lifetime of download_file_. |
| 284 StrictMock<MockByteStreamReader>* input_stream_; | 281 StrictMock<MockByteStreamReader>* input_stream_; |
| 285 | 282 |
| 286 // Sink callback data for stream. | 283 // Sink callback data for stream. |
| 287 base::Closure sink_callback_; | 284 base::Closure sink_callback_; |
| 288 | 285 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 base::TimeDelta::FromMilliseconds(750)); | 599 base::TimeDelta::FromMilliseconds(750)); |
| 603 loop_.Run(); | 600 loop_.Run(); |
| 604 | 601 |
| 605 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), | 602 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), |
| 606 bytes_); | 603 bytes_); |
| 607 EXPECT_EQ(download_file_->GetHashState(), hash_state_); | 604 EXPECT_EQ(download_file_->GetHashState(), hash_state_); |
| 608 | 605 |
| 609 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true); | 606 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 610 DestroyDownloadFile(0); | 607 DestroyDownloadFile(0); |
| 611 } | 608 } |
| OLD | NEW |