Chromium Code Reviews| Index: content/browser/background_fetch/background_fetch_job_controller_unittest.cc |
| diff --git a/content/browser/background_fetch/background_fetch_job_controller_unittest.cc b/content/browser/background_fetch/background_fetch_job_controller_unittest.cc |
| index ea602d2e24b98d1ebafc977480e84df29865ba65..ac3f05827962f30702709b2dd4e3d1219e5876d0 100644 |
| --- a/content/browser/background_fetch/background_fetch_job_controller_unittest.cc |
| +++ b/content/browser/background_fetch/background_fetch_job_controller_unittest.cc |
| @@ -32,10 +32,7 @@ namespace content { |
| class BackgroundFetchJobControllerTest : public ::testing::Test { |
| public: |
| BackgroundFetchJobControllerTest() |
| - : job_controller_( |
| - &browser_context_, |
| - BrowserContext::GetDefaultStoragePartition(&browser_context_)), |
| - download_manager_(new MockDownloadManager()) {} |
| + : download_manager_(new MockDownloadManager()) {} |
| ~BackgroundFetchJobControllerTest() override = default; |
| void SetUp() override { |
| @@ -45,31 +42,36 @@ class BackgroundFetchJobControllerTest : public ::testing::Test { |
| download_manager_); |
| } |
| - void ProcessJob(const std::string& job_guid, |
| - BackgroundFetchJobData* job_data) { |
| + void InitializeJobController(BackgroundFetchJobData* job_data) { |
| + job_controller_ = base::MakeUnique<BackgroundFetchJobController>( |
| + kJobGuid, &browser_context_, |
| + BrowserContext::GetDefaultStoragePartition(&browser_context_), |
| + base::WrapUnique(job_data)); |
| + } |
| + |
| + void StartProcessing() { |
| base::RunLoop run_loop; |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| - base::Bind(&BackgroundFetchJobControllerTest::ProcessJobOnIO, |
| - base::Unretained(this), job_guid, job_data, |
| - run_loop.QuitClosure())); |
| + base::Bind(&BackgroundFetchJobControllerTest::StartProcessingOnIO, |
| + base::Unretained(this), run_loop.QuitClosure())); |
| run_loop.Run(); |
| } |
| - void ProcessJobOnIO(const std::string& job_guid, |
| - BackgroundFetchJobData* job_data, |
| - const base::Closure& closure) { |
| - job_controller_.ProcessJob(job_guid, job_data); |
| + void StartProcessingOnIO(const base::Closure& closure) { |
| + job_controller_->StartProcessing(); |
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, closure); |
| } |
| - BackgroundFetchJobController* job_controller() { return &job_controller_; } |
| + BackgroundFetchJobController* job_controller() { |
| + return job_controller_.get(); |
| + } |
| MockDownloadManager* download_manager() { return download_manager_; } |
| private: |
| TestBrowserThreadBundle thread_bundle_; |
| TestBrowserContext browser_context_; |
| - BackgroundFetchJobController job_controller_; |
| + std::unique_ptr<BackgroundFetchJobController> job_controller_; |
| MockDownloadManager* download_manager_; |
| }; |
| @@ -80,15 +82,17 @@ TEST_F(BackgroundFetchJobControllerTest, StartDownload) { |
| std::vector<BackgroundFetchRequestInfo> request_infos{request_info}; |
| // Get a JobData to give to the JobController. The JobController then gets |
| - // the BackgroundFetchRequestInfos from the JobData. |
| - BackgroundFetchJobData job_data(request_infos); |
| + // the BackgroundFetchRequestInfos from the JobData. The JobController will |
| + // take ownership of the JobData. |
| + BackgroundFetchJobData* job_data = new BackgroundFetchJobData(request_infos); |
|
Peter Beverloo
2017/03/09 15:18:57
Store this in a std::unique_ptr<> and std::move()
harkness
2017/03/09 18:35:31
Done.
|
| + InitializeJobController(job_data); |
| EXPECT_CALL(*(download_manager()), |
| DownloadUrlMock(::testing::Pointee(::testing::Property( |
| &DownloadUrlParameters::url, GURL(kTestUrl))))) |
| .Times(1); |
| - ProcessJob(kJobGuid, &job_data); |
| + StartProcessing(); |
| } |
| } // namespace content |