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

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

Issue 2727253002: Added DownloadItem::Observer to JobController. (Closed)
Patch Set: Added TODO Created 3 years, 9 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 753ed548dbb1801765f00a2f1a2830969a49b64c..18513b2b8f8477d47b396a9070cdbf202b870163 100644
--- a/content/browser/background_fetch/background_fetch_job_controller_unittest.cc
+++ b/content/browser/background_fetch/background_fetch_job_controller_unittest.cc
@@ -12,6 +12,7 @@
#include "content/browser/background_fetch/background_fetch_job_info.h"
#include "content/browser/background_fetch/background_fetch_request_info.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/test/mock_download_item.h"
#include "content/public/test/mock_download_manager.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h"
@@ -29,10 +30,42 @@ const char kTag[] = "testTag";
namespace content {
+// Use the basic MockDownloadItem, but override it to provide a valid GUID.
+class MockDownloadItemWithValues : public MockDownloadItem {
+ public:
+ const std::string& GetGuid() const override { return guid_; }
+ void SetGuid(const std::string& guid) { guid_ = guid; }
+
+ private:
+ std::string guid_;
+};
+
+// Use the basic MockDownloadManager, but override it so that it implements the
+// functionality that the JobController requires.
+class MockDownloadManagerWithCallback : public MockDownloadManager {
+ public:
+ void DownloadUrl(std::unique_ptr<DownloadUrlParameters> params) override {
+ DownloadUrlMock(params.get());
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(params->callback(), &download_item_,
+ DOWNLOAD_INTERRUPT_REASON_NONE));
+ }
+
+ DownloadItem* GetDownloadByGuid(const std::string& guid) override {
+ DCHECK_EQ(download_item_.GetGuid(), guid);
+ return &download_item_;
+ }
+
+ MockDownloadItemWithValues* download_item() { return &download_item_; }
+
+ private:
+ MockDownloadItemWithValues download_item_;
+};
+
class BackgroundFetchJobControllerTest : public ::testing::Test {
public:
BackgroundFetchJobControllerTest()
- : download_manager_(new MockDownloadManager()) {}
+ : download_manager_(new MockDownloadManagerWithCallback()) {}
~BackgroundFetchJobControllerTest() override = default;
void SetUp() override {
@@ -42,6 +75,8 @@ class BackgroundFetchJobControllerTest : public ::testing::Test {
download_manager_);
}
+ void TearDown() override { job_controller_->Shutdown(); }
+
void InitializeJobController(
std::unique_ptr<BackgroundFetchJobData> job_data) {
job_controller_ = base::MakeUnique<BackgroundFetchJobController>(
@@ -67,13 +102,17 @@ class BackgroundFetchJobControllerTest : public ::testing::Test {
BackgroundFetchJobController* job_controller() {
return job_controller_.get();
}
- MockDownloadManager* download_manager() { return download_manager_; }
+ MockDownloadManagerWithCallback* download_manager() {
+ return download_manager_;
+ }
+
+ DownloadItem::Observer* ItemObserver() const { return job_controller_.get(); }
private:
TestBrowserThreadBundle thread_bundle_;
TestBrowserContext browser_context_;
std::unique_ptr<BackgroundFetchJobController> job_controller_;
- MockDownloadManager* download_manager_;
+ MockDownloadManagerWithCallback* download_manager_;
};
TEST_F(BackgroundFetchJobControllerTest, StartDownload) {
@@ -82,6 +121,10 @@ TEST_F(BackgroundFetchJobControllerTest, StartDownload) {
BackgroundFetchRequestInfo request_info(GURL(kTestUrl), kJobGuid);
std::vector<BackgroundFetchRequestInfo> request_infos{request_info};
+ // Create a MockDownloadItem that the test can manipulate.
+ MockDownloadItemWithValues* item = download_manager()->download_item();
+ item->SetGuid("foo");
+
// Get a JobData to give to the JobController. The JobController then gets
// the BackgroundFetchRequestInfos from the JobData.
std::unique_ptr<BackgroundFetchJobData> job_data =

Powered by Google App Engine
This is Rietveld 408576698