| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <utility> |
| 7 | 8 |
| 8 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 9 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 11 #include "base/location.h" |
| 11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/test/test_file_util.h" | 15 #include "base/test/test_file_util.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 class TestDownloadFileImpl : public DownloadFileImpl { | 76 class TestDownloadFileImpl : public DownloadFileImpl { |
| 76 public: | 77 public: |
| 77 TestDownloadFileImpl(scoped_ptr<DownloadSaveInfo> save_info, | 78 TestDownloadFileImpl(scoped_ptr<DownloadSaveInfo> save_info, |
| 78 const base::FilePath& default_downloads_directory, | 79 const base::FilePath& default_downloads_directory, |
| 79 const GURL& url, | 80 const GURL& url, |
| 80 const GURL& referrer_url, | 81 const GURL& referrer_url, |
| 81 bool calculate_hash, | 82 bool calculate_hash, |
| 82 scoped_ptr<ByteStreamReader> stream, | 83 scoped_ptr<ByteStreamReader> stream, |
| 83 const net::BoundNetLog& bound_net_log, | 84 const net::BoundNetLog& bound_net_log, |
| 84 base::WeakPtr<DownloadDestinationObserver> observer) | 85 base::WeakPtr<DownloadDestinationObserver> observer) |
| 85 : DownloadFileImpl(save_info.Pass(), | 86 : DownloadFileImpl(std::move(save_info), |
| 86 default_downloads_directory, | 87 default_downloads_directory, |
| 87 url, | 88 url, |
| 88 referrer_url, | 89 referrer_url, |
| 89 calculate_hash, | 90 calculate_hash, |
| 90 stream.Pass(), | 91 std::move(stream), |
| 91 bound_net_log, | 92 bound_net_log, |
| 92 observer) {} | 93 observer) {} |
| 93 | 94 |
| 94 protected: | 95 protected: |
| 95 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { | 96 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { |
| 96 return base::TimeDelta::FromMilliseconds(0); | 97 return base::TimeDelta::FromMilliseconds(0); |
| 97 } | 98 } |
| 98 | 99 |
| 99 #if !defined(OS_WIN) | 100 #if !defined(OS_WIN) |
| 100 // On Posix, we don't encounter transient errors during renames, except | 101 // On Posix, we don't encounter transient errors during renames, except |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 input_stream_ = new StrictMock<MockByteStreamReader>(); | 170 input_stream_ = new StrictMock<MockByteStreamReader>(); |
| 170 | 171 |
| 171 // TODO: Need to actually create a function that'll set the variables | 172 // TODO: Need to actually create a function that'll set the variables |
| 172 // based on the inputs from the callback. | 173 // based on the inputs from the callback. |
| 173 EXPECT_CALL(*input_stream_, RegisterCallback(_)) | 174 EXPECT_CALL(*input_stream_, RegisterCallback(_)) |
| 174 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) | 175 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) |
| 175 .RetiresOnSaturation(); | 176 .RetiresOnSaturation(); |
| 176 | 177 |
| 177 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 178 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
| 178 scoped_ptr<TestDownloadFileImpl> download_file_impl( | 179 scoped_ptr<TestDownloadFileImpl> download_file_impl( |
| 179 new TestDownloadFileImpl(save_info.Pass(), | 180 new TestDownloadFileImpl( |
| 180 base::FilePath(), | 181 std::move(save_info), base::FilePath(), |
| 181 GURL(), // Source | 182 GURL(), // Source |
| 182 GURL(), // Referrer | 183 GURL(), // Referrer |
| 183 calculate_hash, | 184 calculate_hash, scoped_ptr<ByteStreamReader>(input_stream_), |
| 184 scoped_ptr<ByteStreamReader>(input_stream_), | 185 net::BoundNetLog(), observer_factory_.GetWeakPtr())); |
| 185 net::BoundNetLog(), | |
| 186 observer_factory_.GetWeakPtr())); | |
| 187 download_file_impl->SetClientGuid("12345678-ABCD-1234-DCBA-123456789ABC"); | 186 download_file_impl->SetClientGuid("12345678-ABCD-1234-DCBA-123456789ABC"); |
| 188 download_file_ = download_file_impl.Pass(); | 187 download_file_ = std::move(download_file_impl); |
| 189 | 188 |
| 190 EXPECT_CALL(*input_stream_, Read(_, _)) | 189 EXPECT_CALL(*input_stream_, Read(_, _)) |
| 191 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) | 190 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) |
| 192 .RetiresOnSaturation(); | 191 .RetiresOnSaturation(); |
| 193 | 192 |
| 194 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); | 193 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); |
| 195 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; | 194 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 196 base::RunLoop loop_runner; | 195 base::RunLoop loop_runner; |
| 197 download_file_->Initialize(base::Bind( | 196 download_file_->Initialize(base::Bind( |
| 198 &DownloadFileTest::SetInterruptReasonCallback, | 197 &DownloadFileTest::SetInterruptReasonCallback, |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 | 787 |
| 789 EXPECT_EQ(static_cast<int64_t>(strlen(kTestData1) + strlen(kTestData2)), | 788 EXPECT_EQ(static_cast<int64_t>(strlen(kTestData1) + strlen(kTestData2)), |
| 790 bytes_); | 789 bytes_); |
| 791 EXPECT_EQ(download_file_->GetHashState(), hash_state_); | 790 EXPECT_EQ(download_file_->GetHashState(), hash_state_); |
| 792 | 791 |
| 793 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); | 792 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 794 DestroyDownloadFile(0); | 793 DestroyDownloadFile(0); |
| 795 } | 794 } |
| 796 | 795 |
| 797 } // namespace content | 796 } // namespace content |
| OLD | NEW |