| OLD | NEW |
| 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_data_manager.h" | 5 #include "content/browser/background_fetch/background_fetch_data_manager.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "content/browser/background_fetch/background_fetch_context.h" | 8 #include "content/browser/background_fetch/background_fetch_context.h" |
| 9 #include "content/browser/background_fetch/background_fetch_job_info.h" | 9 #include "content/browser/background_fetch/background_fetch_job_info.h" |
| 10 #include "content/browser/background_fetch/background_fetch_request_info.h" | 10 #include "content/browser/background_fetch/background_fetch_request_info.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 TEST_F(BackgroundFetchDataManagerTest, AddRequest) { | 51 TEST_F(BackgroundFetchDataManagerTest, AddRequest) { |
| 52 // Create a BackgroundFetchJobInfo and a set of BackgroundFetchRequestInfos. | 52 // Create a BackgroundFetchJobInfo and a set of BackgroundFetchRequestInfos. |
| 53 std::vector<BackgroundFetchRequestInfo> request_infos; | 53 std::vector<BackgroundFetchRequestInfo> request_infos; |
| 54 std::vector<std::string> request_guids; | 54 std::vector<std::string> request_guids; |
| 55 for (int i = 0; i < 10; i++) { | 55 for (int i = 0; i < 10; i++) { |
| 56 BackgroundFetchRequestInfo request_info(GURL(kResource), kTag); | 56 BackgroundFetchRequestInfo request_info(GURL(kResource), kTag); |
| 57 request_guids.push_back(request_info.guid()); | 57 request_guids.push_back(request_info.guid()); |
| 58 request_infos.push_back(std::move(request_info)); | 58 request_infos.push_back(std::move(request_info)); |
| 59 } | 59 } |
| 60 BackgroundFetchJobInfo job_info(kTag, url::Origin(GURL(kOrigin)), | 60 std::unique_ptr<BackgroundFetchJobInfo> job_info = |
| 61 kServiceWorkerRegistrationId); | 61 base::MakeUnique<BackgroundFetchJobInfo>(kTag, url::Origin(GURL(kOrigin)), |
| 62 kServiceWorkerRegistrationId); |
| 62 | 63 |
| 63 // Initialize a BackgroundFetchJobData with the constructed requests. | 64 // Initialize a BackgroundFetchJobData with the constructed requests. |
| 64 BackgroundFetchDataManager* data_manager = GetDataManager(); | 65 BackgroundFetchDataManager* data_manager = GetDataManager(); |
| 65 std::unique_ptr<BackgroundFetchJobData> job_data = | 66 std::unique_ptr<BackgroundFetchJobData> job_data = |
| 66 data_manager->CreateRequest(job_info, request_infos); | 67 data_manager->CreateRequest(std::move(job_info), request_infos); |
| 67 | 68 |
| 68 // Get all of the fetch requests from the BackgroundFetchJobData. | 69 // Get all of the fetch requests from the BackgroundFetchJobData. |
| 69 for (int i = 0; i < 10; i++) { | 70 for (int i = 0; i < 10; i++) { |
| 70 EXPECT_FALSE(job_data->IsComplete()); | 71 EXPECT_FALSE(job_data->IsComplete()); |
| 71 ASSERT_TRUE(job_data->HasRequestsRemaining()); | 72 ASSERT_TRUE(job_data->HasRequestsRemaining()); |
| 72 const BackgroundFetchRequestInfo& request_info = | 73 const BackgroundFetchRequestInfo& request_info = |
| 73 job_data->GetNextBackgroundFetchRequestInfo(); | 74 job_data->GetNextBackgroundFetchRequestInfo(); |
| 74 EXPECT_EQ(request_info.tag(), kTag); | 75 EXPECT_EQ(request_info.tag(), kTag); |
| 75 EXPECT_EQ(request_info.state(), | 76 EXPECT_EQ(request_info.state(), |
| 76 DownloadItem::DownloadState::MAX_DOWNLOAD_STATE); | 77 DownloadItem::DownloadState::MAX_DOWNLOAD_STATE); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 98 EXPECT_FALSE(job_data->IsComplete()); | 99 EXPECT_FALSE(job_data->IsComplete()); |
| 99 | 100 |
| 100 // Complete the final fetch request. | 101 // Complete the final fetch request. |
| 101 EXPECT_FALSE(job_data->UpdateBackgroundFetchRequestState( | 102 EXPECT_FALSE(job_data->UpdateBackgroundFetchRequestState( |
| 102 request_guids[9], DownloadItem::DownloadState::COMPLETE, | 103 request_guids[9], DownloadItem::DownloadState::COMPLETE, |
| 103 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE)); | 104 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE)); |
| 104 EXPECT_TRUE(job_data->IsComplete()); | 105 EXPECT_TRUE(job_data->IsComplete()); |
| 105 } | 106 } |
| 106 | 107 |
| 107 } // namespace content | 108 } // namespace content |
| OLD | NEW |