| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 for (int i = 0; i < 10; i++) { | 53 for (int i = 0; i < 10; i++) { |
| 54 BackgroundFetchRequestInfo request_info(GURL(kResource), kTag); | 54 BackgroundFetchRequestInfo request_info(GURL(kResource), kTag); |
| 55 request_guids.push_back(request_info.guid()); | 55 request_guids.push_back(request_info.guid()); |
| 56 request_infos.push_back(std::move(request_info)); | 56 request_infos.push_back(std::move(request_info)); |
| 57 } | 57 } |
| 58 BackgroundFetchJobInfo job_info(kTag, url::Origin(GURL(kOrigin)), | 58 BackgroundFetchJobInfo job_info(kTag, url::Origin(GURL(kOrigin)), |
| 59 kServiceWorkerRegistrationId); | 59 kServiceWorkerRegistrationId); |
| 60 | 60 |
| 61 // Initialize a BackgroundFetchJobData with the constructed requests. | 61 // Initialize a BackgroundFetchJobData with the constructed requests. |
| 62 BackgroundFetchDataManager* data_manager = GetDataManager(); | 62 BackgroundFetchDataManager* data_manager = GetDataManager(); |
| 63 BackgroundFetchJobData* job_data = | 63 std::unique_ptr<BackgroundFetchJobData> job_data = |
| 64 data_manager->CreateRequest(job_info, request_infos); | 64 data_manager->CreateRequest(job_info, request_infos); |
| 65 | 65 |
| 66 // Get all of the fetch requests from the BackgroundFetchJobData. | 66 // Get all of the fetch requests from the BackgroundFetchJobData. |
| 67 for (int i = 0; i < 10; i++) { | 67 for (int i = 0; i < 10; i++) { |
| 68 EXPECT_FALSE(job_data->IsComplete()); | 68 EXPECT_FALSE(job_data->IsComplete()); |
| 69 ASSERT_TRUE(job_data->HasRequestsRemaining()); | 69 ASSERT_TRUE(job_data->HasRequestsRemaining()); |
| 70 const BackgroundFetchRequestInfo& request_info = | 70 const BackgroundFetchRequestInfo& request_info = |
| 71 job_data->GetNextBackgroundFetchRequestInfo(); | 71 job_data->GetNextBackgroundFetchRequestInfo(); |
| 72 EXPECT_EQ(request_info.tag(), kTag); | 72 EXPECT_EQ(request_info.tag(), kTag); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // At this point, all the fetches have been started, but none finished. | 75 // At this point, all the fetches have been started, but none finished. |
| 76 EXPECT_FALSE(job_data->HasRequestsRemaining()); | 76 EXPECT_FALSE(job_data->HasRequestsRemaining()); |
| 77 EXPECT_FALSE(job_data->IsComplete()); | 77 EXPECT_FALSE(job_data->IsComplete()); |
| 78 | 78 |
| 79 // Complete all buy one of the fetch requests. | 79 // Complete all buy one of the fetch requests. |
| 80 for (int i = 0; i < 9; i++) { | 80 for (int i = 0; i < 9; i++) { |
| 81 EXPECT_FALSE( | 81 EXPECT_FALSE( |
| 82 job_data->BackgroundFetchRequestInfoComplete(request_guids[i])); | 82 job_data->BackgroundFetchRequestInfoComplete(request_guids[i])); |
| 83 EXPECT_FALSE(job_data->IsComplete()); | 83 EXPECT_FALSE(job_data->IsComplete()); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Complete the final fetch request. | 86 // Complete the final fetch request. |
| 87 EXPECT_FALSE(job_data->BackgroundFetchRequestInfoComplete(request_guids[9])); | 87 EXPECT_FALSE(job_data->BackgroundFetchRequestInfoComplete(request_guids[9])); |
| 88 EXPECT_TRUE(job_data->IsComplete()); | 88 EXPECT_TRUE(job_data->IsComplete()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace content | 91 } // namespace content |
| OLD | NEW |