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

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

Issue 2727253002: Added DownloadItem::Observer to JobController. (Closed)
Patch Set: Cleanup 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 d8fa7c9cb5c9fa5276c6139d89790bc274f3b817..537e61041d6294b4f000857d03e627fb95274e7a 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,39 @@ const char kTag[] = "testTag";
namespace content {
+// Use the basic MockDownloadItem, but override it to provide a valid GUID.
+class MockDownloadItemWithValues : public MockDownloadItem {
Peter Beverloo 2017/03/08 14:58:19 WithValues -> WithGuid?
harkness 2017/03/10 13:33:54 We'll be adding more state to this item, so I'd ra
+ 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());
+ params->callback().Run(&download_item_, DOWNLOAD_INTERRUPT_REASON_NONE);
Peter Beverloo 2017/03/08 14:58:19 Should this perhaps be a PostTask() to make sure w
harkness 2017/03/10 13:33:54 Good idea.
+ }
+
+ DownloadItem* GetDownloadByGuid(const std::string& guid) override {
+ return &download_item_;
Peter Beverloo 2017/03/08 14:58:19 DCHECK on the `guid`?
harkness 2017/03/10 13:33:54 Done.
+ }
+
+ 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 +72,8 @@ class BackgroundFetchJobControllerTest : public ::testing::Test {
download_manager_);
}
+ void TearDown() override { job_controller_->Shutdown(); }
+
void InitializeJobController(BackgroundFetchJobData* job_data) {
job_controller_.reset(new BackgroundFetchJobController(
kJobGuid, &browser_context_,
@@ -66,13 +98,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) {
@@ -81,6 +117,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. The JobController will
// take ownership of the JobData.

Powered by Google App Engine
This is Rietveld 408576698