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

Unified Diff: content/browser/background_fetch/background_fetch_job_controller_unittest.cc

Issue 2724783002: Make the BackgroundFetchJobController a per-job object (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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..d8fa7c9cb5c9fa5276c6139d89790bc274f3b817 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_.reset(new BackgroundFetchJobController(
Peter Beverloo 2017/03/08 14:27:04 MakeUnique<>
harkness 2017/03/09 13:33:25 Done.
+ kJobGuid, &browser_context_,
+ BrowserContext::GetDefaultStoragePartition(&browser_context_),
+ 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/08 14:27:04 nit: std::unique_ptr<> here too.
harkness 2017/03/09 13:33:25 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

Powered by Google App Engine
This is Rietveld 408576698