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

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

Issue 2778793002: Start aligning BackgroundFetchRequestInfo with the passed in request object. (Closed)
Patch Set: Rebase Created 3 years, 8 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/background_fetch/background_fetch_job_controller.h" 5 #include "content/browser/background_fetch/background_fetch_job_controller.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "content/browser/background_fetch/background_fetch_data_manager.h" 17 #include "content/browser/background_fetch/background_fetch_data_manager.h"
18 #include "content/browser/background_fetch/background_fetch_job_info.h" 18 #include "content/browser/background_fetch/background_fetch_job_info.h"
19 #include "content/browser/background_fetch/background_fetch_request_info.h" 19 #include "content/browser/background_fetch/background_fetch_request_info.h"
20 #include "content/common/service_worker/service_worker_types.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/test/fake_download_item.h" 22 #include "content/public/test/fake_download_item.h"
22 #include "content/public/test/mock_download_manager.h" 23 #include "content/public/test/mock_download_manager.h"
23 #include "content/public/test/test_browser_context.h" 24 #include "content/public/test/test_browser_context.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 25 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 namespace content { 28 namespace content {
28 29
29 namespace { 30 namespace {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 TestBrowserContext browser_context_; 205 TestBrowserContext browser_context_;
205 std::unique_ptr<FakeBackgroundFetchDataManager> data_manager_; 206 std::unique_ptr<FakeBackgroundFetchDataManager> data_manager_;
206 std::unique_ptr<BackgroundFetchJobController> job_controller_; 207 std::unique_ptr<BackgroundFetchJobController> job_controller_;
207 MockDownloadManagerWithCallback* download_manager_; 208 MockDownloadManagerWithCallback* download_manager_;
208 }; 209 };
209 210
210 TEST_F(BackgroundFetchJobControllerTest, SingleRequestJob) { 211 TEST_F(BackgroundFetchJobControllerTest, SingleRequestJob) {
211 BackgroundFetchRegistrationId registration_id( 212 BackgroundFetchRegistrationId registration_id(
212 kServiceWorkerRegistrationId, url::Origin(GURL(kOrigin)), kTag); 213 kServiceWorkerRegistrationId, url::Origin(GURL(kOrigin)), kTag);
213 214
214 BackgroundFetchRequestInfo request_info(GURL(kTestUrl), kJobGuid); 215 ServiceWorkerHeaderMap headers;
216 ServiceWorkerFetchRequest request(GURL(kTestUrl), "GET", headers, Referrer(),
217 false /* is_reload */);
218 BackgroundFetchRequestInfo request_info(request);
215 request_info.set_state(DownloadItem::DownloadState::IN_PROGRESS); 219 request_info.set_state(DownloadItem::DownloadState::IN_PROGRESS);
216 data_manager()->set_next_request(&request_info); 220 data_manager()->set_next_request(&request_info);
217 InitializeJobController(registration_id); 221 InitializeJobController(registration_id);
218 222
219 EXPECT_CALL(*(download_manager()), 223 EXPECT_CALL(*(download_manager()),
220 DownloadUrlMock(::testing::Pointee(::testing::Property( 224 DownloadUrlMock(::testing::Pointee(::testing::Property(
221 &DownloadUrlParameters::url, GURL(kTestUrl))))) 225 &DownloadUrlParameters::url, GURL(kTestUrl)))))
222 .Times(1); 226 .Times(1);
223 227
224 StartProcessing(); 228 StartProcessing();
(...skipping 16 matching lines...) Expand all
241 EXPECT_EQ(DownloadItem::DownloadState::COMPLETE, request_info.state()); 245 EXPECT_EQ(DownloadItem::DownloadState::COMPLETE, request_info.state());
242 EXPECT_TRUE(did_complete_job()); 246 EXPECT_TRUE(did_complete_job());
243 } 247 }
244 248
245 TEST_F(BackgroundFetchJobControllerTest, MultipleRequestJob) { 249 TEST_F(BackgroundFetchJobControllerTest, MultipleRequestJob) {
246 BackgroundFetchRegistrationId registration_id( 250 BackgroundFetchRegistrationId registration_id(
247 kServiceWorkerRegistrationId, url::Origin(GURL(kOrigin)), kTag); 251 kServiceWorkerRegistrationId, url::Origin(GURL(kOrigin)), kTag);
248 252
249 std::vector<BackgroundFetchRequestInfo> request_infos; 253 std::vector<BackgroundFetchRequestInfo> request_infos;
250 for (int i = 0; i < 10; i++) { 254 for (int i = 0; i < 10; i++) {
251 request_infos.emplace_back(GURL(kTestUrl), base::IntToString(i)); 255 ServiceWorkerHeaderMap headers;
256 ServiceWorkerFetchRequest request(GURL(kTestUrl), "GET", headers,
257 Referrer(), false /* is_reload */);
258 request_infos.emplace_back(request);
252 } 259 }
253 data_manager()->set_next_request(&request_infos[0]); 260 data_manager()->set_next_request(&request_infos[0]);
254 InitializeJobController(registration_id); 261 InitializeJobController(registration_id);
255 262
256 EXPECT_CALL(*(download_manager()), 263 EXPECT_CALL(*(download_manager()),
257 DownloadUrlMock(::testing::Pointee(::testing::Property( 264 DownloadUrlMock(::testing::Pointee(::testing::Property(
258 &DownloadUrlParameters::url, GURL(kTestUrl))))) 265 &DownloadUrlParameters::url, GURL(kTestUrl)))))
259 .Times(10); 266 .Times(10);
260 267
261 StartProcessing(); 268 StartProcessing();
(...skipping 29 matching lines...) Expand all
291 item->SetState(DownloadItem::DownloadState::COMPLETE); 298 item->SetState(DownloadItem::DownloadState::COMPLETE);
292 ItemObserver()->OnDownloadUpdated(item); 299 ItemObserver()->OnDownloadUpdated(item);
293 300
294 EXPECT_TRUE(did_complete_job()); 301 EXPECT_TRUE(did_complete_job());
295 } 302 }
296 303
297 TEST_F(BackgroundFetchJobControllerTest, UpdateStorageState) { 304 TEST_F(BackgroundFetchJobControllerTest, UpdateStorageState) {
298 BackgroundFetchRegistrationId registration_id( 305 BackgroundFetchRegistrationId registration_id(
299 kServiceWorkerRegistrationId, url::Origin(GURL(kOrigin)), kTag); 306 kServiceWorkerRegistrationId, url::Origin(GURL(kOrigin)), kTag);
300 307
301 BackgroundFetchRequestInfo request_info(GURL(kTestUrl), kJobGuid); 308 ServiceWorkerHeaderMap headers;
309 ServiceWorkerFetchRequest request(GURL(kTestUrl), "GET", headers, Referrer(),
310 false /* is_reload */);
311 BackgroundFetchRequestInfo request_info(request);
302 request_info.set_state(DownloadItem::DownloadState::IN_PROGRESS); 312 request_info.set_state(DownloadItem::DownloadState::IN_PROGRESS);
303 data_manager()->set_next_request(&request_info); 313 data_manager()->set_next_request(&request_info);
304 InitializeJobController(registration_id); 314 InitializeJobController(registration_id);
305 315
306 EXPECT_CALL(*(download_manager()), 316 EXPECT_CALL(*(download_manager()),
307 DownloadUrlMock(::testing::Pointee(::testing::Property( 317 DownloadUrlMock(::testing::Pointee(::testing::Property(
308 &DownloadUrlParameters::url, GURL(kTestUrl))))) 318 &DownloadUrlParameters::url, GURL(kTestUrl)))))
309 .Times(1); 319 .Times(1);
310 320
311 StartProcessing(); 321 StartProcessing();
(...skipping 10 matching lines...) Expand all
322 // Trigger the observer. The JobController should update the JobData that the 332 // Trigger the observer. The JobController should update the JobData that the
323 // request is complete and should fill in storage state. 333 // request is complete and should fill in storage state.
324 ItemObserver()->OnDownloadUpdated(item); 334 ItemObserver()->OnDownloadUpdated(item);
325 335
326 EXPECT_EQ(123, request_info.received_bytes()); 336 EXPECT_EQ(123, request_info.received_bytes());
327 EXPECT_TRUE(data_manager()->IsComplete(kJobGuid)); 337 EXPECT_TRUE(data_manager()->IsComplete(kJobGuid));
328 EXPECT_TRUE(did_complete_job()); 338 EXPECT_TRUE(did_complete_job());
329 } 339 }
330 340
331 } // namespace content 341 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698