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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 enum DownloadFileRenameMethodType { RENAME_AND_UNIQUIFY, RENAME_AND_ANNOTATE }; | 95 enum DownloadFileRenameMethodType { RENAME_AND_UNIQUIFY, RENAME_AND_ANNOTATE }; |
96 | 96 |
97 // This is a test DownloadFileImpl that has no retry delay and, on Posix, | 97 // This is a test DownloadFileImpl that has no retry delay and, on Posix, |
98 // retries renames failed due to ACCESS_DENIED. | 98 // retries renames failed due to ACCESS_DENIED. |
99 class TestDownloadFileImpl : public DownloadFileImpl { | 99 class TestDownloadFileImpl : public DownloadFileImpl { |
100 public: | 100 public: |
101 TestDownloadFileImpl(std::unique_ptr<DownloadSaveInfo> save_info, | 101 TestDownloadFileImpl(std::unique_ptr<DownloadSaveInfo> save_info, |
102 const base::FilePath& default_downloads_directory, | 102 const base::FilePath& default_downloads_directory, |
103 std::unique_ptr<ByteStreamReader> stream, | 103 std::unique_ptr<ByteStreamReader> stream, |
104 const net::BoundNetLog& bound_net_log, | 104 const net::NetLogWithSource& net_log, |
105 base::WeakPtr<DownloadDestinationObserver> observer) | 105 base::WeakPtr<DownloadDestinationObserver> observer) |
106 : DownloadFileImpl(std::move(save_info), | 106 : DownloadFileImpl(std::move(save_info), |
107 default_downloads_directory, | 107 default_downloads_directory, |
108 std::move(stream), | 108 std::move(stream), |
109 bound_net_log, | 109 net_log, |
110 observer) {} | 110 observer) {} |
111 | 111 |
112 protected: | 112 protected: |
113 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { | 113 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { |
114 return base::TimeDelta::FromMilliseconds(0); | 114 return base::TimeDelta::FromMilliseconds(0); |
115 } | 115 } |
116 | 116 |
117 #if !defined(OS_WIN) | 117 #if !defined(OS_WIN) |
118 // On Posix, we don't encounter transient errors during renames, except | 118 // On Posix, we don't encounter transient errors during renames, except |
119 // possibly EAGAIN, which is difficult to replicate reliably. So we resort to | 119 // possibly EAGAIN, which is difficult to replicate reliably. So we resort to |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 184 |
185 // TODO: Need to actually create a function that'll set the variables | 185 // TODO: Need to actually create a function that'll set the variables |
186 // based on the inputs from the callback. | 186 // based on the inputs from the callback. |
187 EXPECT_CALL(*input_stream_, RegisterCallback(_)) | 187 EXPECT_CALL(*input_stream_, RegisterCallback(_)) |
188 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) | 188 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) |
189 .RetiresOnSaturation(); | 189 .RetiresOnSaturation(); |
190 | 190 |
191 std::unique_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 191 std::unique_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
192 download_file_.reset(new TestDownloadFileImpl( | 192 download_file_.reset(new TestDownloadFileImpl( |
193 std::move(save_info), base::FilePath(), | 193 std::move(save_info), base::FilePath(), |
194 std::unique_ptr<ByteStreamReader>(input_stream_), net::BoundNetLog(), | 194 std::unique_ptr<ByteStreamReader>(input_stream_), |
195 observer_factory_.GetWeakPtr())); | 195 net::NetLogWithSource(), observer_factory_.GetWeakPtr())); |
196 | 196 |
197 EXPECT_CALL(*input_stream_, Read(_, _)) | 197 EXPECT_CALL(*input_stream_, Read(_, _)) |
198 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) | 198 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) |
199 .RetiresOnSaturation(); | 199 .RetiresOnSaturation(); |
200 | 200 |
201 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); | 201 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); |
202 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; | 202 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; |
203 base::RunLoop loop_runner; | 203 base::RunLoop loop_runner; |
204 download_file_->Initialize(base::Bind( | 204 download_file_->Initialize(base::Bind( |
205 &DownloadFileTest::SetInterruptReasonCallback, | 205 &DownloadFileTest::SetInterruptReasonCallback, |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 EXPECT_CALL(*(observer_.get()), | 789 EXPECT_CALL(*(observer_.get()), |
790 CurrentUpdateStatus(strlen(kTestData1) + strlen(kTestData2), _)); | 790 CurrentUpdateStatus(strlen(kTestData1) + strlen(kTestData2), _)); |
791 | 791 |
792 sink_callback_.Run(); | 792 sink_callback_.Run(); |
793 base::RunLoop().RunUntilIdle(); | 793 base::RunLoop().RunUntilIdle(); |
794 VerifyStreamAndSize(); | 794 VerifyStreamAndSize(); |
795 DestroyDownloadFile(0); | 795 DestroyDownloadFile(0); |
796 } | 796 } |
797 | 797 |
798 } // namespace content | 798 } // namespace content |
OLD | NEW |