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 "content/browser/download/mock_download_file.h" | 5 #include "content/browser/download/mock_download_file.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "content/public/browser/browser_thread.h" |
6 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
7 | 10 |
8 using ::testing::_; | 11 using ::testing::_; |
9 using ::testing::Return; | 12 using ::testing::Return; |
10 | 13 |
11 namespace content { | 14 namespace content { |
12 namespace { | 15 namespace { |
13 | 16 |
14 void SuccessRun( | 17 void SuccessRun(const DownloadFile::InitializeCallback& initialize_callback) { |
| 18 initialize_callback.Run(DOWNLOAD_INTERRUPT_REASON_NONE); |
| 19 } |
| 20 |
| 21 void PostSuccessRun( |
15 const DownloadFile::InitializeCallback& initialize_callback, | 22 const DownloadFile::InitializeCallback& initialize_callback, |
16 const DownloadFile::CancelRequestCallback& cancel_request_callback, | 23 const DownloadFile::CancelRequestCallback& cancel_request_callback, |
17 const DownloadItem::ReceivedSlices& received_slices, | 24 const DownloadItem::ReceivedSlices& received_slices, |
18 bool is_parallelizable) { | 25 bool is_parallelizable) { |
19 initialize_callback.Run(DOWNLOAD_INTERRUPT_REASON_NONE); | 26 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 27 base::Bind(&SuccessRun, initialize_callback)); |
20 } | 28 } |
21 | 29 |
22 } // namespace | 30 } // namespace |
23 | 31 |
24 MockDownloadFile::MockDownloadFile() { | 32 MockDownloadFile::MockDownloadFile() { |
25 // This is here because |Initialize()| is normally called right after | 33 // This is here because |Initialize()| is normally called right after |
26 // construction. | 34 // construction. |
27 ON_CALL(*this, Initialize(_, _, _, _)) | 35 ON_CALL(*this, Initialize(_, _, _, _)) |
28 .WillByDefault(::testing::Invoke(SuccessRun)); | 36 .WillByDefault(::testing::Invoke(PostSuccessRun)); |
29 } | 37 } |
30 | 38 |
31 MockDownloadFile::~MockDownloadFile() { | 39 MockDownloadFile::~MockDownloadFile() { |
32 } | 40 } |
33 | 41 |
34 void MockDownloadFile::AddByteStream( | 42 void MockDownloadFile::AddByteStream( |
35 std::unique_ptr<ByteStreamReader> stream_reader, | 43 std::unique_ptr<ByteStreamReader> stream_reader, |
36 int64_t offset, | 44 int64_t offset, |
37 int64_t length) { | 45 int64_t length) { |
38 // Gmock currently can't mock method that takes move-only parameters, | 46 // Gmock currently can't mock method that takes move-only parameters, |
39 // delegate the EXPECT_CALL count to |DoAddByteStream|. | 47 // delegate the EXPECT_CALL count to |DoAddByteStream|. |
40 DoAddByteStream(stream_reader.get(), offset, length); | 48 DoAddByteStream(stream_reader.get(), offset, length); |
41 } | 49 } |
42 | 50 |
43 } // namespace content | 51 } // namespace content |
OLD | NEW |