| 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 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 enum DownloadFileRenameMethodType { RENAME_AND_UNIQUIFY, RENAME_AND_ANNOTATE }; | 115 enum DownloadFileRenameMethodType { RENAME_AND_UNIQUIFY, RENAME_AND_ANNOTATE }; |
| 116 | 116 |
| 117 // This is a test DownloadFileImpl that has no retry delay and, on Posix, | 117 // This is a test DownloadFileImpl that has no retry delay and, on Posix, |
| 118 // retries renames failed due to ACCESS_DENIED. | 118 // retries renames failed due to ACCESS_DENIED. |
| 119 class TestDownloadFileImpl : public DownloadFileImpl { | 119 class TestDownloadFileImpl : public DownloadFileImpl { |
| 120 public: | 120 public: |
| 121 TestDownloadFileImpl( | 121 TestDownloadFileImpl( |
| 122 std::unique_ptr<DownloadSaveInfo> save_info, | 122 std::unique_ptr<DownloadSaveInfo> save_info, |
| 123 const base::FilePath& default_downloads_directory, | 123 const base::FilePath& default_downloads_directory, |
| 124 std::unique_ptr<ByteStreamReader> stream, | 124 std::unique_ptr<ByteStreamReader> stream, |
| 125 const std::vector<DownloadItem::ReceivedSlice>& received_slices, | |
| 126 const net::NetLogWithSource& net_log, | 125 const net::NetLogWithSource& net_log, |
| 127 base::WeakPtr<DownloadDestinationObserver> observer) | 126 base::WeakPtr<DownloadDestinationObserver> observer) |
| 128 : DownloadFileImpl(std::move(save_info), | 127 : DownloadFileImpl(std::move(save_info), |
| 129 default_downloads_directory, | 128 default_downloads_directory, |
| 130 std::move(stream), | 129 std::move(stream), |
| 131 received_slices, | |
| 132 net_log, | 130 net_log, |
| 133 observer) {} | 131 observer) {} |
| 134 | 132 |
| 135 protected: | 133 protected: |
| 136 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { | 134 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { |
| 137 return base::TimeDelta::FromMilliseconds(0); | 135 return base::TimeDelta::FromMilliseconds(0); |
| 138 } | 136 } |
| 139 | 137 |
| 140 #if !defined(OS_WIN) | 138 #if !defined(OS_WIN) |
| 141 // On Posix, we don't encounter transient errors during renames, except | 139 // On Posix, we don't encounter transient errors during renames, except |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 EXPECT_CALL(*input_stream_, RegisterCallback(_)) | 222 EXPECT_CALL(*input_stream_, RegisterCallback(_)) |
| 225 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) | 223 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) |
| 226 .RetiresOnSaturation(); | 224 .RetiresOnSaturation(); |
| 227 | 225 |
| 228 std::unique_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 226 std::unique_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
| 229 save_info->offset = offset; | 227 save_info->offset = offset; |
| 230 save_info->length = length; | 228 save_info->length = length; |
| 231 | 229 |
| 232 download_file_.reset(new TestDownloadFileImpl( | 230 download_file_.reset(new TestDownloadFileImpl( |
| 233 std::move(save_info), base::FilePath(), | 231 std::move(save_info), base::FilePath(), |
| 234 std::unique_ptr<ByteStreamReader>(input_stream_), received_slices, | 232 std::unique_ptr<ByteStreamReader>(input_stream_), |
| 235 net::NetLogWithSource(), observer_factory_.GetWeakPtr())); | 233 net::NetLogWithSource(), observer_factory_.GetWeakPtr())); |
| 236 | 234 |
| 237 EXPECT_CALL(*input_stream_, Read(_, _)) | 235 EXPECT_CALL(*input_stream_, Read(_, _)) |
| 238 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) | 236 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) |
| 239 .RetiresOnSaturation(); | 237 .RetiresOnSaturation(); |
| 240 | 238 |
| 241 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); | 239 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); |
| 242 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; | 240 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 243 base::RunLoop loop_runner; | 241 base::RunLoop loop_runner; |
| 244 download_file_->Initialize(base::Bind( | 242 download_file_->Initialize( |
| 245 &DownloadFileTest::SetInterruptReasonCallback, | 243 base::Bind(&DownloadFileTest::SetInterruptReasonCallback, |
| 246 weak_ptr_factory.GetWeakPtr(), loop_runner.QuitClosure(), &result)); | 244 weak_ptr_factory.GetWeakPtr(), loop_runner.QuitClosure(), |
| 245 &result), |
| 246 received_slices); |
| 247 loop_runner.Run(); | 247 loop_runner.Run(); |
| 248 | 248 |
| 249 ::testing::Mock::VerifyAndClearExpectations(input_stream_); | 249 ::testing::Mock::VerifyAndClearExpectations(input_stream_); |
| 250 return result == DOWNLOAD_INTERRUPT_REASON_NONE; | 250 return result == DOWNLOAD_INTERRUPT_REASON_NONE; |
| 251 } | 251 } |
| 252 | 252 |
| 253 void DestroyDownloadFile(int offset, bool compare_disk_data = true) { | 253 void DestroyDownloadFile(int offset, bool compare_disk_data = true) { |
| 254 EXPECT_FALSE(download_file_->InProgress()); | 254 EXPECT_FALSE(download_file_->InProgress()); |
| 255 | 255 |
| 256 // Make sure the data has been properly written to disk. | 256 // Make sure the data has been properly written to disk. |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 SourceStreamTestData stream_data_0(0, stream_0_length, true); | 1016 SourceStreamTestData stream_data_0(0, stream_0_length, true); |
| 1017 SourceStreamTestData stream_data_1(stream_0_length - 1, 0, false); | 1017 SourceStreamTestData stream_data_1(stream_0_length - 1, 0, false); |
| 1018 VerifySourceStreamsStates(stream_data_0); | 1018 VerifySourceStreamsStates(stream_data_0); |
| 1019 VerifySourceStreamsStates(stream_data_1); | 1019 VerifySourceStreamsStates(stream_data_1); |
| 1020 EXPECT_EQ(stream_0_length, TotalBytesReceived()); | 1020 EXPECT_EQ(stream_0_length, TotalBytesReceived()); |
| 1021 | 1021 |
| 1022 DestroyDownloadFile(0); | 1022 DestroyDownloadFile(0); |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 } // namespace content | 1025 } // namespace content |
| OLD | NEW |