| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 MATCHER(IsNullCallback, "") { return (arg.is_null()); } | 105 MATCHER(IsNullCallback, "") { return (arg.is_null()); } |
| 106 | 106 |
| 107 enum DownloadFileRenameMethodType { RENAME_AND_UNIQUIFY, RENAME_AND_ANNOTATE }; | 107 enum DownloadFileRenameMethodType { RENAME_AND_UNIQUIFY, RENAME_AND_ANNOTATE }; |
| 108 | 108 |
| 109 // This is a test DownloadFileImpl that has no retry delay and, on Posix, | 109 // This is a test DownloadFileImpl that has no retry delay and, on Posix, |
| 110 // retries renames failed due to ACCESS_DENIED. | 110 // retries renames failed due to ACCESS_DENIED. |
| 111 class TestDownloadFileImpl : public DownloadFileImpl { | 111 class TestDownloadFileImpl : public DownloadFileImpl { |
| 112 public: | 112 public: |
| 113 TestDownloadFileImpl(std::unique_ptr<DownloadSaveInfo> save_info, | 113 TestDownloadFileImpl( |
| 114 const base::FilePath& default_downloads_directory, | 114 std::unique_ptr<DownloadSaveInfo> save_info, |
| 115 std::unique_ptr<ByteStreamReader> stream, | 115 const base::FilePath& default_downloads_directory, |
| 116 const net::NetLogWithSource& net_log, | 116 std::unique_ptr<ByteStreamReader> stream, |
| 117 bool is_sparse_file, | 117 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 118 base::WeakPtr<DownloadDestinationObserver> observer) | 118 const net::NetLogWithSource& net_log, |
| 119 bool is_sparse_file, |
| 120 base::WeakPtr<DownloadDestinationObserver> observer) |
| 119 : DownloadFileImpl(std::move(save_info), | 121 : DownloadFileImpl(std::move(save_info), |
| 120 default_downloads_directory, | 122 default_downloads_directory, |
| 121 std::move(stream), | 123 std::move(stream), |
| 124 received_slices, |
| 122 net_log, | 125 net_log, |
| 123 is_sparse_file, | 126 is_sparse_file, |
| 124 observer) {} | 127 observer) {} |
| 125 | 128 |
| 126 protected: | 129 protected: |
| 127 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { | 130 base::TimeDelta GetRetryDelayForFailedRename(int attempt_count) override { |
| 128 return base::TimeDelta::FromMilliseconds(0); | 131 return base::TimeDelta::FromMilliseconds(0); |
| 129 } | 132 } |
| 130 | 133 |
| 131 #if !defined(OS_WIN) | 134 #if !defined(OS_WIN) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // TODO: Need to actually create a function that'll set the variables | 206 // TODO: Need to actually create a function that'll set the variables |
| 204 // based on the inputs from the callback. | 207 // based on the inputs from the callback. |
| 205 EXPECT_CALL(*input_stream_, RegisterCallback(_)) | 208 EXPECT_CALL(*input_stream_, RegisterCallback(_)) |
| 206 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) | 209 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) |
| 207 .RetiresOnSaturation(); | 210 .RetiresOnSaturation(); |
| 208 | 211 |
| 209 std::unique_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 212 std::unique_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
| 210 download_file_.reset(new TestDownloadFileImpl( | 213 download_file_.reset(new TestDownloadFileImpl( |
| 211 std::move(save_info), base::FilePath(), | 214 std::move(save_info), base::FilePath(), |
| 212 std::unique_ptr<ByteStreamReader>(input_stream_), | 215 std::unique_ptr<ByteStreamReader>(input_stream_), |
| 216 std::vector<DownloadItem::ReceivedSlice>(), |
| 213 net::NetLogWithSource(), is_sparse_file, | 217 net::NetLogWithSource(), is_sparse_file, |
| 214 observer_factory_.GetWeakPtr())); | 218 observer_factory_.GetWeakPtr())); |
| 215 | 219 |
| 216 EXPECT_CALL(*input_stream_, Read(_, _)) | 220 EXPECT_CALL(*input_stream_, Read(_, _)) |
| 217 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) | 221 .WillOnce(Return(ByteStreamReader::STREAM_EMPTY)) |
| 218 .RetiresOnSaturation(); | 222 .RetiresOnSaturation(); |
| 219 | 223 |
| 220 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); | 224 base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); |
| 221 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; | 225 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 222 base::RunLoop loop_runner; | 226 base::RunLoop loop_runner; |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 // Finish the second stream. | 994 // Finish the second stream. |
| 991 // TODO(xingliu): Refactor test code to deal with unfinished streams. | 995 // TODO(xingliu): Refactor test code to deal with unfinished streams. |
| 992 scoped_refptr<net::IOBuffer> data = new net::IOBuffer(strlen(kTestData5)); | 996 scoped_refptr<net::IOBuffer> data = new net::IOBuffer(strlen(kTestData5)); |
| 993 size_t size; | 997 size_t size; |
| 994 input_stream_1_->Read(&data, &size); | 998 input_stream_1_->Read(&data, &size); |
| 995 | 999 |
| 996 DestroyDownloadFile(0, false); | 1000 DestroyDownloadFile(0, false); |
| 997 } | 1001 } |
| 998 | 1002 |
| 999 } // namespace content | 1003 } // namespace content |
| OLD | NEW |