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/download_item_impl.h" | 5 #include "content/browser/download/download_item_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "content/browser/download/download_item_impl_delegate.h" | 28 #include "content/browser/download/download_item_impl_delegate.h" |
29 #include "content/browser/download/download_request_handle.h" | 29 #include "content/browser/download/download_request_handle.h" |
30 #include "content/browser/download/mock_download_file.h" | 30 #include "content/browser/download/mock_download_file.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/download_interrupt_reasons.h" | 32 #include "content/public/browser/download_interrupt_reasons.h" |
33 #include "content/public/browser/download_url_parameters.h" | 33 #include "content/public/browser/download_url_parameters.h" |
34 #include "content/public/common/content_features.h" | 34 #include "content/public/common/content_features.h" |
35 #include "content/public/test/mock_download_item.h" | 35 #include "content/public/test/mock_download_item.h" |
36 #include "content/public/test/test_browser_context.h" | 36 #include "content/public/test/test_browser_context.h" |
37 #include "content/public/test/test_browser_thread_bundle.h" | 37 #include "content/public/test/test_browser_thread_bundle.h" |
38 #include "content/public/test/test_utils.h" | |
38 #include "content/public/test/web_contents_tester.h" | 39 #include "content/public/test/web_contents_tester.h" |
39 #include "crypto/secure_hash.h" | 40 #include "crypto/secure_hash.h" |
40 #include "net/http/http_response_headers.h" | 41 #include "net/http/http_response_headers.h" |
41 #include "testing/gmock/include/gmock/gmock.h" | 42 #include "testing/gmock/include/gmock/gmock.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
43 | 44 |
44 using ::testing::DoAll; | 45 using ::testing::DoAll; |
45 using ::testing::Invoke; | 46 using ::testing::Invoke; |
46 using ::testing::InvokeWithoutArgs; | 47 using ::testing::InvokeWithoutArgs; |
47 using ::testing::NiceMock; | 48 using ::testing::NiceMock; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 item->Cancel(true); | 387 item->Cancel(true); |
387 RunAllPendingInMessageLoops(); | 388 RunAllPendingInMessageLoops(); |
388 } | 389 } |
389 } | 390 } |
390 | 391 |
391 // Destroy a previously created download item. | 392 // Destroy a previously created download item. |
392 void DestroyDownloadItem(DownloadItem* item) { | 393 void DestroyDownloadItem(DownloadItem* item) { |
393 allocated_downloads_.erase(item); | 394 allocated_downloads_.erase(item); |
394 } | 395 } |
395 | 396 |
396 void RunAllPendingInMessageLoops() { base::RunLoop().RunUntilIdle(); } | 397 void RunAllPendingInMessageLoops() { RunAllBlockingPoolTasksUntilIdle(); } |
gab
2017/06/21 19:42:24
inline below instead of having this indirection?
Sigurður Ásgeirsson
2017/06/22 14:50:09
Done.
| |
397 | 398 |
398 MockDelegate* mock_delegate() { | 399 MockDelegate* mock_delegate() { |
399 return &delegate_; | 400 return &delegate_; |
400 } | 401 } |
401 | 402 |
402 void OnDownloadFileAcquired(base::FilePath* return_path, | 403 void OnDownloadFileAcquired(base::FilePath* return_path, |
403 const base::FilePath& path) { | 404 const base::FilePath& path) { |
404 *return_path = path; | 405 *return_path = path; |
405 } | 406 } |
406 | 407 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
808 Property(&DownloadUrlParameters::offset, 1)), | 809 Property(&DownloadUrlParameters::offset, 1)), |
809 _)) | 810 _)) |
810 .Times(DownloadItemImpl::kMaxAutoResumeAttempts); | 811 .Times(DownloadItemImpl::kMaxAutoResumeAttempts); |
811 for (int i = 0; i < (DownloadItemImpl::kMaxAutoResumeAttempts + 1); ++i) { | 812 for (int i = 0; i < (DownloadItemImpl::kMaxAutoResumeAttempts + 1); ++i) { |
812 SCOPED_TRACE(::testing::Message() << "Iteration " << i); | 813 SCOPED_TRACE(::testing::Message() << "Iteration " << i); |
813 | 814 |
814 mock_download_file = base::MakeUnique<NiceMock<MockDownloadFile>>(); | 815 mock_download_file = base::MakeUnique<NiceMock<MockDownloadFile>>(); |
815 mock_download_file_ref = mock_download_file.get(); | 816 mock_download_file_ref = mock_download_file.get(); |
816 mock_request_handle = base::MakeUnique<NiceMock<MockRequestHandle>>(); | 817 mock_request_handle = base::MakeUnique<NiceMock<MockRequestHandle>>(); |
817 | 818 |
819 EXPECT_CALL(*mock_download_file, Initialize(_, _, _, _)) | |
820 .WillOnce(ScheduleCallbackWithParam(DOWNLOAD_INTERRUPT_REASON_NONE)); | |
gab
2017/06/21 19:42:24
Why is this changing?
Sigurður Ásgeirsson
2017/06/22 14:50:08
As-is, the default mock setup fires the callback o
| |
818 ON_CALL(*mock_download_file_ref, FullPath()) | 821 ON_CALL(*mock_download_file_ref, FullPath()) |
819 .WillByDefault(ReturnRefOfCopy(base::FilePath())); | 822 .WillByDefault(ReturnRefOfCopy(base::FilePath())); |
820 | 823 |
821 // Copied key parts of DoIntermediateRename & CallDownloadItemStart | 824 // Copied key parts of DoIntermediateRename & CallDownloadItemStart |
822 // to allow for holding onto the request handle. | 825 // to allow for holding onto the request handle. |
823 item->Start(std::move(mock_download_file), std::move(mock_request_handle), | 826 item->Start(std::move(mock_download_file), std::move(mock_request_handle), |
824 *create_info()); | 827 *create_info()); |
825 RunAllPendingInMessageLoops(); | 828 RunAllPendingInMessageLoops(); |
826 | 829 |
827 base::FilePath target_path(kDummyTargetPath); | 830 base::FilePath target_path(kDummyTargetPath); |
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2347 | 2350 |
2348 item_->Cancel(true); | 2351 item_->Cancel(true); |
2349 RunAllPendingInMessageLoops(); | 2352 RunAllPendingInMessageLoops(); |
2350 } | 2353 } |
2351 | 2354 |
2352 TEST(MockDownloadItem, Compiles) { | 2355 TEST(MockDownloadItem, Compiles) { |
2353 MockDownloadItem mock_item; | 2356 MockDownloadItem mock_item; |
2354 } | 2357 } |
2355 | 2358 |
2356 } // namespace content | 2359 } // namespace content |
OLD | NEW |