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

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

Issue 2860593003: Refactoring DownloadManager::DownloadURL to add proper annotation. (Closed)
Patch Set: Comment addressed. Created 3 years, 6 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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <unordered_map> 9 #include <unordered_map>
10 10
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "content/browser/background_fetch/background_fetch_constants.h" 14 #include "content/browser/background_fetch/background_fetch_constants.h"
15 #include "content/browser/background_fetch/background_fetch_data_manager.h" 15 #include "content/browser/background_fetch/background_fetch_data_manager.h"
16 #include "content/browser/background_fetch/background_fetch_registration_id.h" 16 #include "content/browser/background_fetch/background_fetch_registration_id.h"
17 #include "content/browser/background_fetch/background_fetch_test_base.h" 17 #include "content/browser/background_fetch/background_fetch_test_base.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/download_item.h" 19 #include "content/public/browser/download_item.h"
20 #include "content/public/browser/storage_partition.h" 20 #include "content/public/browser/storage_partition.h"
21 #include "content/public/test/fake_download_item.h" 21 #include "content/public/test/fake_download_item.h"
22 #include "content/public/test/mock_download_manager.h" 22 #include "content/public/test/mock_download_manager.h"
23 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
23 #include "net/url_request/url_request_context_getter.h" 24 #include "net/url_request/url_request_context_getter.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 26
26 using testing::_; 27 using testing::_;
27 28
28 namespace content { 29 namespace content {
29 namespace { 30 namespace {
30 31
31 const char kExampleTag[] = "my-example-tag"; 32 const char kExampleTag[] = "my-example-tag";
32 33
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ASSERT_NO_FATAL_FAILURE(CreateRegistrationForRequests( 142 ASSERT_NO_FATAL_FAILURE(CreateRegistrationForRequests(
142 &registration_id, &initial_requests, 143 &registration_id, &initial_requests,
143 {{"https://example.com/funny_cat.png", "GET"}})); 144 {{"https://example.com/funny_cat.png", "GET"}}));
144 145
145 std::unique_ptr<BackgroundFetchJobController> controller = 146 std::unique_ptr<BackgroundFetchJobController> controller =
146 CreateJobController(registration_id); 147 CreateJobController(registration_id);
147 148
148 EXPECT_EQ(controller->state(), 149 EXPECT_EQ(controller->state(),
149 BackgroundFetchJobController::State::INITIALIZED); 150 BackgroundFetchJobController::State::INITIALIZED);
150 151
151 controller->Start(initial_requests /* deliberate copy */); 152 controller->Start(initial_requests /* deliberate copy */,
153 TRAFFIC_ANNOTATION_FOR_TESTS);
152 EXPECT_EQ(controller->state(), BackgroundFetchJobController::State::FETCHING); 154 EXPECT_EQ(controller->state(), BackgroundFetchJobController::State::FETCHING);
153 155
154 // Mark the single download item as finished, completing the job. 156 // Mark the single download item as finished, completing the job.
155 { 157 {
156 base::RunLoop run_loop; 158 base::RunLoop run_loop;
157 job_completed_closure_ = run_loop.QuitClosure(); 159 job_completed_closure_ = run_loop.QuitClosure();
158 160
159 run_loop.Run(); 161 run_loop.Run();
160 } 162 }
161 163
(...skipping 23 matching lines...) Expand all
185 187
186 EXPECT_EQ(controller->state(), 188 EXPECT_EQ(controller->state(),
187 BackgroundFetchJobController::State::INITIALIZED); 189 BackgroundFetchJobController::State::INITIALIZED);
188 190
189 // Continue spinning until the Job Controller has completed all the requests. 191 // Continue spinning until the Job Controller has completed all the requests.
190 // The Download Manager has been told to automatically mark them as finished. 192 // The Download Manager has been told to automatically mark them as finished.
191 { 193 {
192 base::RunLoop run_loop; 194 base::RunLoop run_loop;
193 job_completed_closure_ = run_loop.QuitClosure(); 195 job_completed_closure_ = run_loop.QuitClosure();
194 196
195 controller->Start(initial_requests /* deliberate copy */); 197 controller->Start(initial_requests /* deliberate copy */,
198 TRAFFIC_ANNOTATION_FOR_TESTS);
196 EXPECT_EQ(controller->state(), 199 EXPECT_EQ(controller->state(),
197 BackgroundFetchJobController::State::FETCHING); 200 BackgroundFetchJobController::State::FETCHING);
198 201
199 run_loop.Run(); 202 run_loop.Run();
200 } 203 }
201 204
202 EXPECT_EQ(controller->state(), 205 EXPECT_EQ(controller->state(),
203 BackgroundFetchJobController::State::COMPLETED); 206 BackgroundFetchJobController::State::COMPLETED);
204 EXPECT_TRUE(did_complete_job_); 207 EXPECT_TRUE(did_complete_job_);
205 } 208 }
(...skipping 10 matching lines...) Expand all
216 CreateJobController(registration_id); 219 CreateJobController(registration_id);
217 220
218 EXPECT_EQ(controller->state(), 221 EXPECT_EQ(controller->state(),
219 BackgroundFetchJobController::State::INITIALIZED); 222 BackgroundFetchJobController::State::INITIALIZED);
220 223
221 // Start the set of |initial_requests|, and abort them immediately after. 224 // Start the set of |initial_requests|, and abort them immediately after.
222 { 225 {
223 base::RunLoop run_loop; 226 base::RunLoop run_loop;
224 job_completed_closure_ = run_loop.QuitClosure(); 227 job_completed_closure_ = run_loop.QuitClosure();
225 228
226 controller->Start(initial_requests /* deliberate copy */); 229 controller->Start(initial_requests /* deliberate copy */,
230 TRAFFIC_ANNOTATION_FOR_TESTS);
227 EXPECT_EQ(controller->state(), 231 EXPECT_EQ(controller->state(),
228 BackgroundFetchJobController::State::FETCHING); 232 BackgroundFetchJobController::State::FETCHING);
229 233
230 controller->Abort(); 234 controller->Abort();
231 235
232 run_loop.Run(); 236 run_loop.Run();
233 } 237 }
234 238
235 // TODO(peter): Verify that the issued download items have had their state 239 // TODO(peter): Verify that the issued download items have had their state
236 // updated to be cancelled as well. 240 // updated to be cancelled as well.
237 241
238 EXPECT_EQ(controller->state(), BackgroundFetchJobController::State::ABORTED); 242 EXPECT_EQ(controller->state(), BackgroundFetchJobController::State::ABORTED);
239 EXPECT_TRUE(did_complete_job_); 243 EXPECT_TRUE(did_complete_job_);
240 } 244 }
241 245
242 } // namespace 246 } // namespace
243 } // namespace content 247 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698