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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 : background_fetch_data_manager_( | 39 : background_fetch_data_manager_( |
40 base::MakeUnique<BackgroundFetchDataManager>(&browser_context_)) {} | 40 base::MakeUnique<BackgroundFetchDataManager>(&browser_context_)) {} |
41 ~BackgroundFetchDataManagerTest() override = default; | 41 ~BackgroundFetchDataManagerTest() override = default; |
42 | 42 |
43 protected: | 43 protected: |
44 void CreateRequests(int num_requests) { | 44 void CreateRequests(int num_requests) { |
45 DCHECK(num_requests > 0); | 45 DCHECK(num_requests > 0); |
46 // Create |num_requests| BackgroundFetchRequestInfo's. | 46 // Create |num_requests| BackgroundFetchRequestInfo's. |
47 std::vector<std::unique_ptr<BackgroundFetchRequestInfo>> request_infos; | 47 std::vector<std::unique_ptr<BackgroundFetchRequestInfo>> request_infos; |
48 for (int i = 0; i < num_requests; i++) { | 48 for (int i = 0; i < num_requests; i++) { |
| 49 ServiceWorkerHeaderMap headers; |
| 50 ServiceWorkerFetchRequest request(GURL(kResource), "GET", headers, |
| 51 Referrer(), false /* is_reload */); |
49 request_infos.push_back( | 52 request_infos.push_back( |
50 base::MakeUnique<BackgroundFetchRequestInfo>(GURL(kResource), kTag)); | 53 base::MakeUnique<BackgroundFetchRequestInfo>(request)); |
51 } | 54 } |
52 std::unique_ptr<BackgroundFetchJobInfo> job_info = | 55 std::unique_ptr<BackgroundFetchJobInfo> job_info = |
53 base::MakeUnique<BackgroundFetchJobInfo>( | 56 base::MakeUnique<BackgroundFetchJobInfo>( |
54 "tag", url::Origin(GURL(kJobOrigin)), kServiceWorkerRegistrationId); | 57 kTag, url::Origin(GURL(kJobOrigin)), kServiceWorkerRegistrationId); |
55 job_guid_ = job_info->guid(); | 58 job_guid_ = job_info->guid(); |
56 background_fetch_data_manager_->CreateRequest(std::move(job_info), | 59 background_fetch_data_manager_->CreateRequest(std::move(job_info), |
57 std::move(request_infos)); | 60 std::move(request_infos)); |
58 } | 61 } |
59 | 62 |
60 void GetResponse() { | 63 void GetResponse() { |
61 base::RunLoop run_loop; | 64 base::RunLoop run_loop; |
62 BackgroundFetchResponseCompleteCallback callback = | 65 BackgroundFetchResponseCompleteCallback callback = |
63 base::Bind(&BackgroundFetchDataManagerTest::DidGetResponse, | 66 base::Bind(&BackgroundFetchDataManagerTest::DidGetResponse, |
64 base::Unretained(this), run_loop.QuitClosure()); | 67 base::Unretained(this), run_loop.QuitClosure()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 BackgroundFetchDataManager* data_manager = background_fetch_data_manager(); | 108 BackgroundFetchDataManager* data_manager = background_fetch_data_manager(); |
106 std::vector<std::string> request_guids; | 109 std::vector<std::string> request_guids; |
107 | 110 |
108 // Get all of the fetch requests from the BackgroundFetchDataManager. | 111 // Get all of the fetch requests from the BackgroundFetchDataManager. |
109 for (int i = 0; i < 10; i++) { | 112 for (int i = 0; i < 10; i++) { |
110 EXPECT_FALSE(data_manager->IsComplete(job_guid())); | 113 EXPECT_FALSE(data_manager->IsComplete(job_guid())); |
111 ASSERT_TRUE(data_manager->HasRequestsRemaining(job_guid())); | 114 ASSERT_TRUE(data_manager->HasRequestsRemaining(job_guid())); |
112 const BackgroundFetchRequestInfo& request_info = | 115 const BackgroundFetchRequestInfo& request_info = |
113 data_manager->GetNextBackgroundFetchRequestInfo(job_guid()); | 116 data_manager->GetNextBackgroundFetchRequestInfo(job_guid()); |
114 request_guids.push_back(request_info.guid()); | 117 request_guids.push_back(request_info.guid()); |
115 EXPECT_EQ(request_info.tag(), kTag); | |
116 EXPECT_EQ(request_info.state(), | 118 EXPECT_EQ(request_info.state(), |
117 DownloadItem::DownloadState::MAX_DOWNLOAD_STATE); | 119 DownloadItem::DownloadState::MAX_DOWNLOAD_STATE); |
118 EXPECT_EQ(request_info.interrupt_reason(), | 120 EXPECT_EQ(request_info.interrupt_reason(), |
119 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE); | 121 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE); |
120 } | 122 } |
121 | 123 |
122 // At this point, all the fetches have been started, but none finished. | 124 // At this point, all the fetches have been started, but none finished. |
123 EXPECT_FALSE(data_manager->HasRequestsRemaining(job_guid())); | 125 EXPECT_FALSE(data_manager->HasRequestsRemaining(job_guid())); |
124 | 126 |
125 // Complete all of the fetch requests. | 127 // Complete all of the fetch requests. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 247 |
246 const BackgroundFetchRequestInfo& request_info = | 248 const BackgroundFetchRequestInfo& request_info = |
247 data_manager->GetNextBackgroundFetchRequestInfo(job_guid); | 249 data_manager->GetNextBackgroundFetchRequestInfo(job_guid); |
248 EXPECT_FALSE(data_manager->UpdateRequestState( | 250 EXPECT_FALSE(data_manager->UpdateRequestState( |
249 job_guid, request_info.guid(), DownloadItem::DownloadState::COMPLETE, | 251 job_guid, request_info.guid(), DownloadItem::DownloadState::COMPLETE, |
250 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE)); | 252 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE)); |
251 EXPECT_TRUE(data_manager->IsComplete(job_guid)); | 253 EXPECT_TRUE(data_manager->IsComplete(job_guid)); |
252 } | 254 } |
253 | 255 |
254 } // namespace content | 256 } // namespace content |
OLD | NEW |