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

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

Issue 2708943002: Create the BackgroundFetchBatchManager and initiate a download. (Closed)
Patch Set: fixed nits 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 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_job_controller.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/callback_helpers.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h"
11 #include "content/browser/background_fetch/background_fetch_data_manager.h"
12 #include "content/browser/background_fetch/background_fetch_job_info.h"
13 #include "content/browser/background_fetch/background_fetch_request_info.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/test/mock_download_manager.h"
16 #include "content/public/test/test_browser_context.h"
17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace {
21
22 const char kOrigin[] = "https://example.com/";
23 const char kJobGuid[] = "TestRequestGuid";
24 constexpr int64_t kServiceWorkerRegistrationId = 9001;
25 const char kTestUrl[] = "http://www.example.com/example.html";
26 const char kTag[] = "testTag";
27
28 } // namespace
29
30 namespace content {
31
32 class BackgroundFetchJobControllerTest : public ::testing::Test {
33 public:
34 BackgroundFetchJobControllerTest()
35 : job_controller_(
36 &browser_context_,
37 BrowserContext::GetDefaultStoragePartition(&browser_context_)),
38 download_manager_(new MockDownloadManager()) {}
39 ~BackgroundFetchJobControllerTest() override = default;
40
41 void SetUp() override {
42 // The download_manager_ ownership is given to the BrowserContext, and the
43 // BrowserContext will take care of deallocating it.
44 BrowserContext::SetDownloadManagerForTesting(&browser_context_,
45 download_manager_);
46 }
47
48 void ProcessJob(const std::string& job_guid,
49 BackgroundFetchJobData* job_data) {
50 base::RunLoop run_loop;
51 BrowserThread::PostTask(
52 BrowserThread::IO, FROM_HERE,
53 base::Bind(&BackgroundFetchJobControllerTest::ProcessJobOnIO,
54 base::Unretained(this), job_guid, job_data,
55 run_loop.QuitClosure()));
56 run_loop.Run();
57 }
58
59 void ProcessJobOnIO(const std::string& job_guid,
60 BackgroundFetchJobData* job_data,
61 const base::Closure& closure) {
62 job_controller_.ProcessJob(job_guid, job_data);
63 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, closure);
64 }
65
66 BackgroundFetchJobController* job_controller() { return &job_controller_; }
67 MockDownloadManager* download_manager() { return download_manager_; }
68
69 private:
70 TestBrowserThreadBundle thread_bundle_;
71 TestBrowserContext browser_context_;
72 BackgroundFetchJobController job_controller_;
73 MockDownloadManager* download_manager_;
74 };
75
76 TEST_F(BackgroundFetchJobControllerTest, StartDownload) {
77 BackgroundFetchJobInfo job_info(kTag, url::Origin(GURL(kOrigin)),
78 kServiceWorkerRegistrationId);
79 BackgroundFetchRequestInfo request_info(GURL(kTestUrl), kJobGuid);
80 std::vector<BackgroundFetchRequestInfo> request_infos{request_info};
81
82 // Get a JobData to give to the JobController. The JobController then gets
83 // the BackgroundFetchRequestInfos from the JobData.
84 BackgroundFetchJobData job_data(request_infos);
85
86 EXPECT_CALL(*(download_manager()),
87 DownloadUrlMock(::testing::Pointee(::testing::Property(
88 &DownloadUrlParameters::url, GURL(kTestUrl)))))
89 .Times(1);
90
91 ProcessJob(kJobGuid, &job_data);
92 }
93
94 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698