Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: content/browser/download/download_file_unittest.cc

Issue 2722503006: Add slice information to DownloadDestinationObserver::DestinationUpdate(). (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 // ByteStream functions 60 // ByteStream functions
61 MOCK_METHOD2(Read, ByteStreamReader::StreamState( 61 MOCK_METHOD2(Read, ByteStreamReader::StreamState(
62 scoped_refptr<net::IOBuffer>*, size_t*)); 62 scoped_refptr<net::IOBuffer>*, size_t*));
63 MOCK_CONST_METHOD0(GetStatus, int()); 63 MOCK_CONST_METHOD0(GetStatus, int());
64 MOCK_METHOD1(RegisterCallback, void(const base::Closure&)); 64 MOCK_METHOD1(RegisterCallback, void(const base::Closure&));
65 }; 65 };
66 66
67 class MockDownloadDestinationObserver : public DownloadDestinationObserver { 67 class MockDownloadDestinationObserver : public DownloadDestinationObserver {
68 public: 68 public:
69 MOCK_METHOD2(DestinationUpdate, void(int64_t, int64_t)); 69 MOCK_METHOD3(DestinationUpdate, void(
70 int64_t, int64_t, const std::vector<DownloadItem::ReceivedSlice>&));
70 void DestinationError( 71 void DestinationError(
71 DownloadInterruptReason reason, 72 DownloadInterruptReason reason,
72 int64_t bytes_so_far, 73 int64_t bytes_so_far,
73 std::unique_ptr<crypto::SecureHash> hash_state) override { 74 std::unique_ptr<crypto::SecureHash> hash_state) override {
74 MockDestinationError( 75 MockDestinationError(
75 reason, bytes_so_far, GetHexEncodedHashValue(hash_state.get())); 76 reason, bytes_so_far, GetHexEncodedHashValue(hash_state.get()));
76 } 77 }
77 void DestinationCompleted( 78 void DestinationCompleted(
78 int64_t total_bytes, 79 int64_t total_bytes,
79 std::unique_ptr<crypto::SecureHash> hash_state) override { 80 std::unique_ptr<crypto::SecureHash> hash_state) override {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 141
141 DownloadFileTest() 142 DownloadFileTest()
142 : observer_(new StrictMock<MockDownloadDestinationObserver>), 143 : observer_(new StrictMock<MockDownloadDestinationObserver>),
143 observer_factory_(observer_.get()), 144 observer_factory_(observer_.get()),
144 input_stream_(NULL), 145 input_stream_(NULL),
145 bytes_(-1), 146 bytes_(-1),
146 bytes_per_sec_(-1) {} 147 bytes_per_sec_(-1) {}
147 148
148 ~DownloadFileTest() override {} 149 ~DownloadFileTest() override {}
149 150
150 void SetUpdateDownloadInfo(int64_t bytes, int64_t bytes_per_sec) { 151 void SetUpdateDownloadInfo(
152 int64_t bytes, int64_t bytes_per_sec,
153 const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
151 bytes_ = bytes; 154 bytes_ = bytes;
152 bytes_per_sec_ = bytes_per_sec; 155 bytes_per_sec_ = bytes_per_sec;
153 } 156 }
154 157
155 void ConfirmUpdateDownloadInfo() { 158 void ConfirmUpdateDownloadInfo() {
156 observer_->CurrentUpdateStatus(bytes_, bytes_per_sec_); 159 observer_->CurrentUpdateStatus(bytes_, bytes_per_sec_);
157 } 160 }
158 161
159 void SetUp() override { 162 void SetUp() override {
160 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _)) 163 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _, _))
161 .Times(AnyNumber()) 164 .Times(AnyNumber())
162 .WillRepeatedly(Invoke(this, &DownloadFileTest::SetUpdateDownloadInfo)); 165 .WillRepeatedly(Invoke(this, &DownloadFileTest::SetUpdateDownloadInfo));
163 } 166 }
164 167
165 // Mock calls to this function are forwarded here. 168 // Mock calls to this function are forwarded here.
166 void RegisterCallback(const base::Closure& sink_callback) { 169 void RegisterCallback(const base::Closure& sink_callback) {
167 sink_callback_ = sink_callback; 170 sink_callback_ = sink_callback;
168 } 171 }
169 172
170 void SetInterruptReasonCallback(const base::Closure& closure, 173 void SetInterruptReasonCallback(const base::Closure& closure,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 const std::string& expected_hash) { 282 const std::string& expected_hash) {
280 ::testing::Sequence s1; 283 ::testing::Sequence s1;
281 SetupFinishStream(interrupt_reason, s1); 284 SetupFinishStream(interrupt_reason, s1);
282 sink_callback_.Run(); 285 sink_callback_.Run();
283 VerifyStreamAndSize(); 286 VerifyStreamAndSize();
284 if (check_observer) { 287 if (check_observer) {
285 EXPECT_CALL(*(observer_.get()), 288 EXPECT_CALL(*(observer_.get()),
286 MockDestinationCompleted(_, expected_hash)); 289 MockDestinationCompleted(_, expected_hash));
287 base::RunLoop().RunUntilIdle(); 290 base::RunLoop().RunUntilIdle();
288 ::testing::Mock::VerifyAndClearExpectations(observer_.get()); 291 ::testing::Mock::VerifyAndClearExpectations(observer_.get());
289 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _)) 292 EXPECT_CALL(*(observer_.get()), DestinationUpdate(_, _, _))
290 .Times(AnyNumber()) 293 .Times(AnyNumber())
291 .WillRepeatedly( 294 .WillRepeatedly(
292 Invoke(this, &DownloadFileTest::SetUpdateDownloadInfo)); 295 Invoke(this, &DownloadFileTest::SetUpdateDownloadInfo));
293 } 296 }
294 } 297 }
295 298
296 DownloadInterruptReason RenameAndUniquify( 299 DownloadInterruptReason RenameAndUniquify(
297 const base::FilePath& full_path, 300 const base::FilePath& full_path,
298 base::FilePath* result_path_p) { 301 base::FilePath* result_path_p) {
299 return InvokeRenameMethodAndWaitForCallback( 302 return InvokeRenameMethodAndWaitForCallback(
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 EXPECT_CALL(*(observer_.get()), 785 EXPECT_CALL(*(observer_.get()),
783 CurrentUpdateStatus(strlen(kTestData1) + strlen(kTestData2), _)); 786 CurrentUpdateStatus(strlen(kTestData1) + strlen(kTestData2), _));
784 787
785 sink_callback_.Run(); 788 sink_callback_.Run();
786 base::RunLoop().RunUntilIdle(); 789 base::RunLoop().RunUntilIdle();
787 VerifyStreamAndSize(); 790 VerifyStreamAndSize();
788 DestroyDownloadFile(0); 791 DestroyDownloadFile(0);
789 } 792 }
790 793
791 } // namespace content 794 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698