| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 // ByteStream functions | 78 // ByteStream functions |
| 79 MOCK_METHOD2(Read, ByteStreamReader::StreamState( | 79 MOCK_METHOD2(Read, ByteStreamReader::StreamState( |
| 80 scoped_refptr<net::IOBuffer>*, size_t*)); | 80 scoped_refptr<net::IOBuffer>*, size_t*)); |
| 81 MOCK_CONST_METHOD0(GetStatus, int()); | 81 MOCK_CONST_METHOD0(GetStatus, int()); |
| 82 MOCK_METHOD1(RegisterCallback, void(const base::Closure&)); | 82 MOCK_METHOD1(RegisterCallback, void(const base::Closure&)); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 class MockDownloadDestinationObserver : public DownloadDestinationObserver { | 85 class MockDownloadDestinationObserver : public DownloadDestinationObserver { |
| 86 public: | 86 public: |
| 87 MOCK_METHOD3(DestinationUpdate, void( | 87 MOCK_METHOD4(DestinationUpdate, |
| 88 int64_t, int64_t, const std::vector<DownloadItem::ReceivedSlice>&)); | 88 void(int64_t, |
| 89 int64_t, |
| 90 const std::vector<DownloadItem::ReceivedSlice>&, |
| 91 const std::unordered_set<int64_t>&)); |
| 89 void DestinationError( | 92 void DestinationError( |
| 90 DownloadInterruptReason reason, | 93 DownloadInterruptReason reason, |
| 91 int64_t bytes_so_far, | 94 int64_t bytes_so_far, |
| 92 std::unique_ptr<crypto::SecureHash> hash_state) override { | 95 std::unique_ptr<crypto::SecureHash> hash_state) override { |
| 93 MockDestinationError( | 96 MockDestinationError( |
| 94 reason, bytes_so_far, GetHexEncodedHashValue(hash_state.get())); | 97 reason, bytes_so_far, GetHexEncodedHashValue(hash_state.get())); |
| 95 } | 98 } |
| 96 void DestinationCompleted( | 99 void DestinationCompleted( |
| 97 int64_t total_bytes, | 100 int64_t total_bytes, |
| 98 std::unique_ptr<crypto::SecureHash> hash_state) override { | 101 std::unique_ptr<crypto::SecureHash> hash_state) override { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 observer_factory_(observer_.get()), | 171 observer_factory_(observer_.get()), |
| 169 input_stream_(NULL), | 172 input_stream_(NULL), |
| 170 additional_streams_( | 173 additional_streams_( |
| 171 std::vector<StrictMock<MockByteStreamReader>*>{nullptr, nullptr}), | 174 std::vector<StrictMock<MockByteStreamReader>*>{nullptr, nullptr}), |
| 172 bytes_(-1), | 175 bytes_(-1), |
| 173 bytes_per_sec_(-1) {} | 176 bytes_per_sec_(-1) {} |
| 174 | 177 |
| 175 ~DownloadFileTest() override {} | 178 ~DownloadFileTest() override {} |
| 176 | 179 |
| 177 void SetUpdateDownloadInfo( | 180 void SetUpdateDownloadInfo( |
| 178 int64_t bytes, int64_t bytes_per_sec, | 181 int64_t bytes, |
| 179 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { | 182 int64_t bytes_per_sec, |
| 183 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 184 const std::unordered_set<int64_t>& streams_to_close) { |
| 180 bytes_ = bytes; | 185 bytes_ = bytes; |
| 181 bytes_per_sec_ = bytes_per_sec; | 186 bytes_per_sec_ = bytes_per_sec; |
| 182 } | 187 } |
| 183 | 188 |
| 184 void ConfirmUpdateDownloadInfo() { | 189 void ConfirmUpdateDownloadInfo() { |
| 185 observer_->CurrentUpdateStatus(bytes_, bytes_per_sec_); | 190 observer_->CurrentUpdateStatus(bytes_, bytes_per_sec_); |
| 186 } | 191 } |
| 187 | 192 |
| 188 void SetUp() override { | 193 void SetUp() override { |
| 189 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _, _)) | 194 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _, _, _)) |
| 190 .Times(AnyNumber()) | 195 .Times(AnyNumber()) |
| 191 .WillRepeatedly(Invoke(this, &DownloadFileTest::SetUpdateDownloadInfo)); | 196 .WillRepeatedly(Invoke(this, &DownloadFileTest::SetUpdateDownloadInfo)); |
| 192 } | 197 } |
| 193 | 198 |
| 194 // Mock calls to this function are forwarded here. | 199 // Mock calls to this function are forwarded here. |
| 195 void RegisterCallback(const base::Closure& sink_callback) { | 200 void RegisterCallback(const base::Closure& sink_callback) { |
| 196 sink_callback_ = sink_callback; | 201 sink_callback_ = sink_callback; |
| 197 } | 202 } |
| 198 | 203 |
| 199 void SetInterruptReasonCallback(const base::Closure& closure, | 204 void SetInterruptReasonCallback(const base::Closure& closure, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 const std::string& expected_hash) { | 344 const std::string& expected_hash) { |
| 340 ::testing::Sequence s1; | 345 ::testing::Sequence s1; |
| 341 SetupFinishStream(interrupt_reason, input_stream_, s1); | 346 SetupFinishStream(interrupt_reason, input_stream_, s1); |
| 342 sink_callback_.Run(); | 347 sink_callback_.Run(); |
| 343 VerifyStreamAndSize(); | 348 VerifyStreamAndSize(); |
| 344 if (check_observer) { | 349 if (check_observer) { |
| 345 EXPECT_CALL(*(observer_.get()), | 350 EXPECT_CALL(*(observer_.get()), |
| 346 MockDestinationCompleted(_, expected_hash)); | 351 MockDestinationCompleted(_, expected_hash)); |
| 347 base::RunLoop().RunUntilIdle(); | 352 base::RunLoop().RunUntilIdle(); |
| 348 ::testing::Mock::VerifyAndClearExpectations(observer_.get()); | 353 ::testing::Mock::VerifyAndClearExpectations(observer_.get()); |
| 349 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _, _)) | 354 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _, _, _)) |
| 350 .Times(AnyNumber()) | 355 .Times(AnyNumber()) |
| 351 .WillRepeatedly( | 356 .WillRepeatedly( |
| 352 Invoke(this, &DownloadFileTest::SetUpdateDownloadInfo)); | 357 Invoke(this, &DownloadFileTest::SetUpdateDownloadInfo)); |
| 353 } | 358 } |
| 354 } | 359 } |
| 355 | 360 |
| 356 DownloadInterruptReason RenameAndUniquify( | 361 DownloadInterruptReason RenameAndUniquify( |
| 357 const base::FilePath& full_path, | 362 const base::FilePath& full_path, |
| 358 base::FilePath* result_path_p) { | 363 base::FilePath* result_path_p) { |
| 359 return InvokeRenameMethodAndWaitForCallback( | 364 return InvokeRenameMethodAndWaitForCallback( |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 SourceStreamTestData stream_data_0(0, stream_0_length, true); | 1021 SourceStreamTestData stream_data_0(0, stream_0_length, true); |
| 1017 SourceStreamTestData stream_data_1(stream_0_length - 1, 0, false); | 1022 SourceStreamTestData stream_data_1(stream_0_length - 1, 0, false); |
| 1018 VerifySourceStreamsStates(stream_data_0); | 1023 VerifySourceStreamsStates(stream_data_0); |
| 1019 VerifySourceStreamsStates(stream_data_1); | 1024 VerifySourceStreamsStates(stream_data_1); |
| 1020 EXPECT_EQ(stream_0_length, TotalBytesReceived()); | 1025 EXPECT_EQ(stream_0_length, TotalBytesReceived()); |
| 1021 | 1026 |
| 1022 DestroyDownloadFile(0); | 1027 DestroyDownloadFile(0); |
| 1023 } | 1028 } |
| 1024 | 1029 |
| 1025 } // namespace content | 1030 } // namespace content |
| OLD | NEW |