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

Side by Side Diff: content/browser/background_fetch/background_fetch_batch_manager_unittest.cc

Issue 2708943002: Create the BackgroundFetchBatchManager and initiate a download. (Closed)
Patch Set: Integrated code review comments and added BackgroundFetchDataManager::BatchData which feeds FetchRe… 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/background_fetch/background_fetch_batch_manager.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/callback_helpers.h"
9 #include "base/run_loop.h"
10 #include "content/browser/background_fetch/background_fetch_data_manager.h"
11 #include "content/browser/background_fetch/batch_request.h"
12 #include "content/browser/background_fetch/fetch_request.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/test/mock_download_manager.h"
15 #include "content/public/test/test_browser_context.h"
16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace {
20
21 const char kOrigin[] = "https://example.com/";
22 const char kBatchGuid[] = "TestRequestGuid";
23 constexpr int64_t kServiceWorkerRegistrationId = 9001;
24 const char kTestUrl[] = "http://www.example.com/example.html";
25 const char kTag[] = "testTag";
26
27 } // namespace
28
29 namespace content {
30
31 class BackgroundFetchBatchManagerTest : public ::testing::Test {
32 public:
33 BackgroundFetchBatchManagerTest()
34 : batch_manager_(
35 &browser_context_,
36 BrowserContext::GetDefaultStoragePartition(&browser_context_)),
37 download_manager_(new MockDownloadManager()) {
38 BrowserContext::SetDownloadManagerForTesting(&browser_context_,
39 download_manager_);
Peter Beverloo 2017/02/24 02:05:15 Something to consider -- We usually set overrides
harkness 2017/02/24 11:47:10 Sounds like a good practice to keep to. I've moved
40 }
41 ~BackgroundFetchBatchManagerTest() override {}
Peter Beverloo 2017/02/24 02:05:15 nit: "= default" all the things
harkness 2017/02/24 11:47:10 Done.
42
43 void ProcessBatch(const std::string& batch_guid,
44 BackgroundFetchDataManager::BatchData* batch_data) {
45 base::RunLoop run_loop;
46 BrowserThread::PostTask(
47 BrowserThread::IO, FROM_HERE,
48 base::Bind(&BackgroundFetchBatchManagerTest::ProcessBatchOnIO,
49 base::Unretained(this), batch_guid, batch_data,
50 run_loop.QuitClosure()));
51 run_loop.Run();
52 }
53
54 void ProcessBatchOnIO(const std::string& batch_guid,
55 BackgroundFetchDataManager::BatchData* batch_data,
56 const base::Closure& closure) {
57 batch_manager_.ProcessBatch(batch_guid, batch_data);
58 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, closure);
59 }
60
61 BackgroundFetchBatchManager* batch_manager() { return &batch_manager_; }
62 MockDownloadManager* download_manager() { return download_manager_; }
63
64 private:
65 TestBrowserThreadBundle thread_bundle_;
66 TestBrowserContext browser_context_;
67 BackgroundFetchBatchManager batch_manager_;
68 MockDownloadManager* download_manager_;
Peter Beverloo 2017/02/24 02:05:15 This needs to be an std::unique_ptr<>. We leak the
harkness 2017/02/24 11:47:10 Actually, I believe that we want to pass the raw p
69 };
70
71 TEST_F(BackgroundFetchBatchManagerTest, StartDownload) {
72 BatchRequest batch_request(kTag, url::Origin(GURL(kOrigin)),
73 kServiceWorkerRegistrationId);
74 FetchRequest fetch_request(GURL(kTestUrl), kBatchGuid);
75 std::vector<FetchRequest> fetch_requests;
76 fetch_requests.push_back(fetch_request);
Peter Beverloo 2017/02/24 02:05:15 nit: std::vector<FetchRequest> fetch_requests { f
harkness 2017/02/24 11:47:10 Done.
77
78 // Get a BatchData to give to the BatchManager. The BatchManager then gets the
79 // FetchRequests from the BatchData.
80 BackgroundFetchDataManager::BatchData batch_data(batch_request,
81 fetch_requests);
82
83 EXPECT_CALL(*(download_manager()),
84 DownloadUrlMock(::testing::Pointee(::testing::Property(
85 &DownloadUrlParameters::url, GURL(kTestUrl)))))
86 .Times(1);
87
88 ProcessBatch(kBatchGuid, &batch_data);
89 }
90
91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698