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

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

Issue 2708943002: Create the BackgroundFetchBatchManager and initiate a download. (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_batch_manager_unittest.cc
diff --git a/content/browser/background_fetch/background_fetch_batch_manager_unittest.cc b/content/browser/background_fetch/background_fetch_batch_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f39c127b3dd9c55143036cd3202ab697054b3f51
--- /dev/null
+++ b/content/browser/background_fetch/background_fetch_batch_manager_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/background_fetch/background_fetch_batch_manager.h"
+
+#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
+#include "base/run_loop.h"
+#include "content/browser/background_fetch/fetch_request.h"
+#include "content/public/browser/browser_thread.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"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kOrigin[] = "https://example.com/";
+const char kBatchUid[] = "TestRequestUid";
+constexpr int64_t kServiceWorkerRegistrationId = 9001;
+const char kTestUrl[] = "http://www.example.com/example.html";
+
+} // namespace
+
+namespace content {
+
+class BackgroundFetchBatchManagerTest : public ::testing::Test {
+ public:
+ BackgroundFetchBatchManagerTest()
+ : batch_manager_(
+ &browser_context_,
+ BrowserContext::GetDefaultStoragePartition(&browser_context_)),
+ download_manager_(new content::MockDownloadManager()) {
Peter Beverloo 2017/02/23 12:14:56 nit: drop `content::`
harkness 2017/02/23 17:08:41 Done.
+ BrowserContext::SetDownloadManagerForTesting(&browser_context_,
+ download_manager_);
+ }
+ ~BackgroundFetchBatchManagerTest() override {}
+
+ void ProcessBatch(const std::string& batch_uid,
+ const std::vector<FetchRequest>& requests) {
+ base::RunLoop run_loop;
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&BackgroundFetchBatchManagerTest::ProcessBatchOnIO,
+ base::Unretained(this), batch_uid, requests,
+ run_loop.QuitClosure()));
+ run_loop.Run();
+ }
+
+ void ProcessBatchOnIO(const std::string& batch_uid,
+ const std::vector<FetchRequest>& requests,
+ const base::Closure& closure) {
+ batch_manager_.ProcessBatch(batch_uid, requests);
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, closure);
+ }
+
+ BackgroundFetchBatchManager* GetBatchManager() { return &batch_manager_; }
Peter Beverloo 2017/02/23 12:14:59 nit: batch_manager() const { .. }
harkness 2017/02/23 17:08:41 Done.
+ MockDownloadManager* GetDownloadManager() { return download_manager_; }
Peter Beverloo 2017/02/23 12:14:56 nit: download_manager() const { .. }
harkness 2017/02/23 17:08:41 Done.
+
+ private:
+ TestBrowserThreadBundle thread_bundle_;
+ TestBrowserContext browser_context_;
+ BackgroundFetchBatchManager batch_manager_;
+ MockDownloadManager* download_manager_;
+};
+
+TEST_F(BackgroundFetchBatchManagerTest, StartDownload) {
+ FetchRequest request(url::Origin(GURL(kOrigin)), GURL(kTestUrl),
+ kServiceWorkerRegistrationId, kBatchUid);
Peter Beverloo 2017/02/23 12:14:56 What is a "uid"?
harkness 2017/02/23 17:08:41 An imprecise statement of a guid. I've updated.
+ std::vector<FetchRequest> requests;
+ requests.push_back(request);
+
+ EXPECT_CALL(*(GetDownloadManager()),
+ DownloadUrlMock(::testing::Pointee(::testing::Property(
+ &DownloadUrlParameters::url, GURL(kTestUrl)))))
+ .Times(1);
+ ProcessBatch(kBatchUid, requests);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698