| 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 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 MATCHER(IsNullCallback, "") { return (arg.is_null()); } | 68 MATCHER(IsNullCallback, "") { return (arg.is_null()); } |
| 69 | 69 |
| 70 typedef void (DownloadFile::*DownloadFileRenameMethodType)( | 70 typedef void (DownloadFile::*DownloadFileRenameMethodType)( |
| 71 const base::FilePath&, | 71 const base::FilePath&, |
| 72 const DownloadFile::RenameCompletionCallback&); | 72 const DownloadFile::RenameCompletionCallback&); |
| 73 | 73 |
| 74 // This is a test DownloadFileImpl that has no retry delay and, on Posix, | 74 // This is a test DownloadFileImpl that has no retry delay and, on Posix, |
| 75 // retries renames failed due to ACCESS_DENIED. | 75 // retries renames failed due to ACCESS_DENIED. |
| 76 class TestDownloadFileImpl : public DownloadFileImpl { | 76 class TestDownloadFileImpl : public DownloadFileImpl { |
| 77 public: | 77 public: |
| 78 TestDownloadFileImpl(scoped_ptr<DownloadSaveInfo> save_info, | 78 TestDownloadFileImpl(const DownloadSaveInfo& save_info, |
| 79 const base::FilePath& default_downloads_directory, | 79 const base::FilePath& default_downloads_directory, |
| 80 const GURL& url, | 80 const GURL& url, |
| 81 const GURL& referrer_url, | 81 const GURL& referrer_url, |
| 82 bool calculate_hash, | 82 bool calculate_hash, |
| 83 base::File file, |
| 83 scoped_ptr<ByteStreamReader> stream, | 84 scoped_ptr<ByteStreamReader> stream, |
| 84 const net::BoundNetLog& bound_net_log, | 85 const net::BoundNetLog& bound_net_log, |
| 85 base::WeakPtr<DownloadDestinationObserver> observer) | 86 base::WeakPtr<DownloadDestinationObserver> observer) |
| 86 : DownloadFileImpl(std::move(save_info), | 87 : DownloadFileImpl(save_info, |
| 87 default_downloads_directory, | 88 default_downloads_directory, |
| 88 url, | 89 url, |
| 89 referrer_url, | 90 referrer_url, |
| 90 calculate_hash, | 91 calculate_hash, |
| 92 std::move(file), |
| 91 std::move(stream), | 93 std::move(stream), |
| 92 bound_net_log, | 94 bound_net_log, |
| 93 observer) {} | 95 observer) {} |
| 94 | 96 |
| 95 protected: | 97 protected: |
| 96 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { | 98 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { |
| 97 return base::TimeDelta::FromMilliseconds(0); | 99 return base::TimeDelta::FromMilliseconds(0); |
| 98 } | 100 } |
| 99 | 101 |
| 100 #if !defined(OS_WIN) | 102 #if !defined(OS_WIN) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 171 |
| 170 input_stream_ = new StrictMock<MockByteStreamReader>(); | 172 input_stream_ = new StrictMock<MockByteStreamReader>(); |
| 171 | 173 |
| 172 // TODO: Need to actually create a function that'll set the variables | 174 // TODO: Need to actually create a function that'll set the variables |
| 173 // based on the inputs from the callback. | 175 // based on the inputs from the callback. |
| 174 EXPECT_CALL(*input_stream_, RegisterCallback(_)) | 176 EXPECT_CALL(*input_stream_, RegisterCallback(_)) |
| 175 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) | 177 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) |
| 176 .RetiresOnSaturation(); | 178 .RetiresOnSaturation(); |
| 177 | 179 |
| 178 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 180 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
| 179 scoped_ptr<TestDownloadFileImpl> download_file_impl( | 181 download_file_.reset(new TestDownloadFileImpl( |
| 180 new TestDownloadFileImpl( | 182 *save_info, base::FilePath(), |
| 181 std::move(save_info), base::FilePath(), | 183 GURL(), // Source |
| 182 GURL(), // Source | 184 GURL(), // Referrer |
| 183 GURL(), // Referrer | 185 calculate_hash, std::move(save_info->file), |
| 184 calculate_hash, scoped_ptr<ByteStreamReader>(input_stream_), | 186 scoped_ptr<ByteStreamReader>(input_stream_), net::BoundNetLog(), |
| 185 net::BoundNetLog(), observer_factory_.GetWeakPtr())); | 187 observer_factory_.GetWeakPtr())); |
| 186 download_file_impl->SetClientGuid("12345678-ABCD-1234-DCBA-123456789ABC"); | 188 download_file_->SetClientGuid("12345678-ABCD-1234-DCBA-123456789ABC"); |
| 187 download_file_ = std::move(download_file_impl); | |
| 188 | 189 |
| 189 EXPECT_CALL(*input_stream_, Read(_, _)) | 190 EXPECT_CALL(*input_stream_, Read(_, _)) |
| 190 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) | 191 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) |
| 191 .RetiresOnSaturation(); | 192 .RetiresOnSaturation(); |
| 192 | 193 |
| 193 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); | 194 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); |
| 194 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; | 195 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 195 base::RunLoop loop_runner; | 196 base::RunLoop loop_runner; |
| 196 download_file_->Initialize(base::Bind( | 197 download_file_->Initialize(base::Bind( |
| 197 &DownloadFileTest::SetInterruptReasonCallback, | 198 &DownloadFileTest::SetInterruptReasonCallback, |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 | 788 |
| 788 EXPECT_EQ(static_cast<int64_t>(strlen(kTestData1) + strlen(kTestData2)), | 789 EXPECT_EQ(static_cast<int64_t>(strlen(kTestData1) + strlen(kTestData2)), |
| 789 bytes_); | 790 bytes_); |
| 790 EXPECT_EQ(download_file_->GetHashState(), hash_state_); | 791 EXPECT_EQ(download_file_->GetHashState(), hash_state_); |
| 791 | 792 |
| 792 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); | 793 FinishStream(DOWNLOAD_INTERRUPT_REASON_NONE, true); |
| 793 DestroyDownloadFile(0); | 794 DestroyDownloadFile(0); |
| 794 } | 795 } |
| 795 | 796 |
| 796 } // namespace content | 797 } // namespace content |
| OLD | NEW |