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

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

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Address Avi's comments. Created 3 years, 5 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
« no previous file with comments | « content/browser/download/mock_download_file.cc ('k') | content/browser/download/save_file.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/parallel_download_job.h" 5 #include "content/browser/download/parallel_download_job.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/test/scoped_task_environment.h"
12 #include "content/browser/download/download_destination_observer.h" 13 #include "content/browser/download/download_destination_observer.h"
13 #include "content/browser/download/download_file_impl.h" 14 #include "content/browser/download/download_file_impl.h"
14 #include "content/browser/download/download_item_impl_delegate.h" 15 #include "content/browser/download/download_item_impl_delegate.h"
16 #include "content/browser/download/download_task_runner.h"
15 #include "content/browser/download/mock_download_item_impl.h" 17 #include "content/browser/download/mock_download_item_impl.h"
16 #include "content/browser/download/parallel_download_utils.h" 18 #include "content/browser/download/parallel_download_utils.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 using ::testing::_; 23 using ::testing::_;
22 using ::testing::NiceMock; 24 using ::testing::NiceMock;
23 using ::testing::StrictMock; 25 using ::testing::StrictMock;
24 26
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 107
106 private: 108 private:
107 int request_count_; 109 int request_count_;
108 int min_slice_size_; 110 int min_slice_size_;
109 int min_remaining_time_; 111 int min_remaining_time_;
110 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJobForTest); 112 DISALLOW_COPY_AND_ASSIGN(ParallelDownloadJobForTest);
111 }; 113 };
112 114
113 class ParallelDownloadJobTest : public testing::Test { 115 class ParallelDownloadJobTest : public testing::Test {
114 public: 116 public:
117 ParallelDownloadJobTest()
118 : task_environment_(
119 base::test::ScopedTaskEnvironment::MainThreadType::UI,
120 base::test::ScopedTaskEnvironment::ExecutionMode::QUEUED) {}
121
115 void CreateParallelJob(int64_t initial_request_offset, 122 void CreateParallelJob(int64_t initial_request_offset,
116 int64_t content_length, 123 int64_t content_length,
117 const DownloadItem::ReceivedSlices& slices, 124 const DownloadItem::ReceivedSlices& slices,
118 int request_count, 125 int request_count,
119 int64_t min_slice_size, 126 int64_t min_slice_size,
120 int min_remaining_time) { 127 int min_remaining_time) {
121 item_delegate_ = base::MakeUnique<DownloadItemImplDelegate>(); 128 item_delegate_ = base::MakeUnique<DownloadItemImplDelegate>();
122 download_item_ = base::MakeUnique<NiceMock<MockDownloadItemImpl>>( 129 download_item_ = base::MakeUnique<NiceMock<MockDownloadItemImpl>>(
123 item_delegate_.get(), slices); 130 item_delegate_.get(), slices);
124 EXPECT_CALL(*download_item_, GetTotalBytes()) 131 EXPECT_CALL(*download_item_, GetTotalBytes())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void VerifyWorker(int64_t offset, int64_t length) const { 173 void VerifyWorker(int64_t offset, int64_t length) const {
167 EXPECT_TRUE(job_->workers_.find(offset) != job_->workers_.end()); 174 EXPECT_TRUE(job_->workers_.find(offset) != job_->workers_.end());
168 EXPECT_EQ(offset, job_->workers_[offset]->offset()); 175 EXPECT_EQ(offset, job_->workers_[offset]->offset());
169 EXPECT_EQ(length, job_->workers_[offset]->length()); 176 EXPECT_EQ(length, job_->workers_[offset]->length());
170 } 177 }
171 178
172 void OnFileInitialized(DownloadInterruptReason result) { 179 void OnFileInitialized(DownloadInterruptReason result) {
173 file_initialized_ = true; 180 file_initialized_ = true;
174 } 181 }
175 182
183 base::test::ScopedTaskEnvironment task_environment_;
176 content::TestBrowserThreadBundle browser_threads_; 184 content::TestBrowserThreadBundle browser_threads_;
177 std::unique_ptr<DownloadItemImplDelegate> item_delegate_; 185 std::unique_ptr<DownloadItemImplDelegate> item_delegate_;
178 std::unique_ptr<MockDownloadItemImpl> download_item_; 186 std::unique_ptr<MockDownloadItemImpl> download_item_;
179 std::unique_ptr<ParallelDownloadJobForTest> job_; 187 std::unique_ptr<ParallelDownloadJobForTest> job_;
180 bool file_initialized_; 188 bool file_initialized_;
181 // Request handle for the original request. 189 // Request handle for the original request.
182 MockDownloadRequestHandle* mock_request_handle_; 190 MockDownloadRequestHandle* mock_request_handle_;
183 }; 191 };
184 192
185 // Test if parallel requests can be built correctly for a new download without 193 // Test if parallel requests can be built correctly for a new download without
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 CreateParallelJob(0, 100, DownloadItem::ReceivedSlices(), 2, 0, 0); 380 CreateParallelJob(0, 100, DownloadItem::ReceivedSlices(), 2, 0, 0);
373 job_->Start(download_file.get(), 381 job_->Start(download_file.get(),
374 base::Bind(&ParallelDownloadJobTest::OnFileInitialized, 382 base::Bind(&ParallelDownloadJobTest::OnFileInitialized,
375 base::Unretained(this)), 383 base::Unretained(this)),
376 DownloadItem::ReceivedSlices()); 384 DownloadItem::ReceivedSlices());
377 EXPECT_FALSE(file_initialized_); 385 EXPECT_FALSE(file_initialized_);
378 EXPECT_EQ(0u, job_->workers().size()); 386 EXPECT_EQ(0u, job_->workers().size());
379 EXPECT_CALL(*input_stream, RegisterCallback(_)); 387 EXPECT_CALL(*input_stream, RegisterCallback(_));
380 EXPECT_CALL(*input_stream, Read(_, _)); 388 EXPECT_CALL(*input_stream, Read(_, _));
381 EXPECT_CALL(*(observer.get()), DestinationUpdate(_, _, _)); 389 EXPECT_CALL(*(observer.get()), DestinationUpdate(_, _, _));
382 base::RunLoop().RunUntilIdle(); 390 task_environment_.RunUntilIdle();
383 EXPECT_TRUE(file_initialized_); 391 EXPECT_TRUE(file_initialized_);
384 EXPECT_EQ(1u, job_->workers().size()); 392 EXPECT_EQ(1u, job_->workers().size());
385 DestroyParallelJob(); 393 DestroyParallelJob();
394
395 // The download file lives on the download sequence, and must
396 // be deleted there.
397 GetDownloadTaskRunner()->DeleteSoon(FROM_HERE, std::move(download_file));
398 task_environment_.RunUntilIdle();
386 } 399 }
387 400
388 } // namespace content 401 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/mock_download_file.cc ('k') | content/browser/download/save_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698