OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 // Tests that a basic request works. | 218 // Tests that a basic request works. |
219 TEST_F(NavigationURLLoaderTest, Basic) { | 219 TEST_F(NavigationURLLoaderTest, Basic) { |
220 TestNavigationURLLoaderDelegate delegate; | 220 TestNavigationURLLoaderDelegate delegate; |
221 scoped_ptr<NavigationURLLoader> loader = | 221 scoped_ptr<NavigationURLLoader> loader = |
222 MakeTestLoader(net::URLRequestTestJob::test_url_1(), &delegate); | 222 MakeTestLoader(net::URLRequestTestJob::test_url_1(), &delegate); |
223 | 223 |
224 // Wait for the response to come back. | 224 // Wait for the response to come back. |
225 delegate.WaitForResponseStarted(); | 225 delegate.WaitForResponseStarted(); |
226 | 226 |
| 227 // Proceed with the response. |
| 228 loader->ProceedWithResponse(); |
| 229 |
227 // Check the response is correct. | 230 // Check the response is correct. |
228 EXPECT_EQ("text/html", delegate.response()->head.mime_type); | 231 EXPECT_EQ("text/html", delegate.response()->head.mime_type); |
229 EXPECT_EQ(200, delegate.response()->head.headers->response_code()); | 232 EXPECT_EQ(200, delegate.response()->head.headers->response_code()); |
230 | 233 |
231 // Check the body is correct. | 234 // Check the body is correct. |
232 EXPECT_EQ(net::URLRequestTestJob::test_data_1(), | 235 EXPECT_EQ(net::URLRequestTestJob::test_data_1(), |
233 FetchURL(delegate.body()->GetURL())); | 236 FetchURL(delegate.body()->GetURL())); |
234 | 237 |
235 EXPECT_EQ(1, delegate.on_request_handled_counter()); | 238 EXPECT_EQ(1, delegate.on_request_handled_counter()); |
236 } | 239 } |
(...skipping 26 matching lines...) Expand all Loading... |
263 EXPECT_EQ("GET", delegate.redirect_info().new_method); | 266 EXPECT_EQ("GET", delegate.redirect_info().new_method); |
264 EXPECT_EQ(net::URLRequestTestJob::test_url_2(), | 267 EXPECT_EQ(net::URLRequestTestJob::test_url_2(), |
265 delegate.redirect_info().new_first_party_for_cookies); | 268 delegate.redirect_info().new_first_party_for_cookies); |
266 EXPECT_EQ(302, delegate.redirect_response()->head.headers->response_code()); | 269 EXPECT_EQ(302, delegate.redirect_response()->head.headers->response_code()); |
267 EXPECT_EQ(1, delegate.on_request_handled_counter()); | 270 EXPECT_EQ(1, delegate.on_request_handled_counter()); |
268 | 271 |
269 // Wait for the response to complete. | 272 // Wait for the response to complete. |
270 loader->FollowRedirect(); | 273 loader->FollowRedirect(); |
271 delegate.WaitForResponseStarted(); | 274 delegate.WaitForResponseStarted(); |
272 | 275 |
| 276 // Proceed with the response. |
| 277 loader->ProceedWithResponse(); |
| 278 |
273 // Check the response is correct. | 279 // Check the response is correct. |
274 EXPECT_EQ("text/html", delegate.response()->head.mime_type); | 280 EXPECT_EQ("text/html", delegate.response()->head.mime_type); |
275 EXPECT_EQ(200, delegate.response()->head.headers->response_code()); | 281 EXPECT_EQ(200, delegate.response()->head.headers->response_code()); |
276 | 282 |
277 // Release the body and check it is correct. | 283 // Release the body and check it is correct. |
278 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 284 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
279 EXPECT_EQ(net::URLRequestTestJob::test_data_2(), | 285 EXPECT_EQ(net::URLRequestTestJob::test_data_2(), |
280 FetchURL(delegate.body()->GetURL())); | 286 FetchURL(delegate.body()->GetURL())); |
281 | 287 |
282 EXPECT_EQ(1, delegate.on_request_handled_counter()); | 288 EXPECT_EQ(1, delegate.on_request_handled_counter()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // Tests that ownership leaves the loader once the response is received. | 370 // Tests that ownership leaves the loader once the response is received. |
365 TEST_F(NavigationURLLoaderTest, LoaderDetached) { | 371 TEST_F(NavigationURLLoaderTest, LoaderDetached) { |
366 // Fake a top-level request to a URL whose body does not load immediately. | 372 // Fake a top-level request to a URL whose body does not load immediately. |
367 TestNavigationURLLoaderDelegate delegate; | 373 TestNavigationURLLoaderDelegate delegate; |
368 scoped_ptr<NavigationURLLoader> loader = | 374 scoped_ptr<NavigationURLLoader> loader = |
369 MakeTestLoader(net::URLRequestTestJob::test_url_2(), &delegate); | 375 MakeTestLoader(net::URLRequestTestJob::test_url_2(), &delegate); |
370 | 376 |
371 // Wait for the response to come back. | 377 // Wait for the response to come back. |
372 delegate.WaitForResponseStarted(); | 378 delegate.WaitForResponseStarted(); |
373 | 379 |
| 380 // Proceed with the response. |
| 381 loader->ProceedWithResponse(); |
| 382 |
374 // Check the response is correct. | 383 // Check the response is correct. |
375 EXPECT_EQ("text/html", delegate.response()->head.mime_type); | 384 EXPECT_EQ("text/html", delegate.response()->head.mime_type); |
376 EXPECT_EQ(200, delegate.response()->head.headers->response_code()); | 385 EXPECT_EQ(200, delegate.response()->head.headers->response_code()); |
377 | 386 |
378 // Destroy the loader. | 387 // Destroy the loader. |
379 loader.reset(); | 388 loader.reset(); |
380 base::RunLoop().RunUntilIdle(); | 389 base::RunLoop().RunUntilIdle(); |
381 | 390 |
382 // Check the body can still be fetched through the StreamHandle. | 391 // Check the body can still be fetched through the StreamHandle. |
383 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 392 EXPECT_TRUE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
384 EXPECT_EQ(net::URLRequestTestJob::test_data_2(), | 393 EXPECT_EQ(net::URLRequestTestJob::test_data_2(), |
385 FetchURL(delegate.body()->GetURL())); | 394 FetchURL(delegate.body()->GetURL())); |
386 } | 395 } |
387 | 396 |
388 // Tests that the request is owned by the body StreamHandle. | 397 // Tests that the request is owned by the body StreamHandle. |
389 TEST_F(NavigationURLLoaderTest, OwnedByHandle) { | 398 TEST_F(NavigationURLLoaderTest, OwnedByHandle) { |
390 // Fake a top-level request to a URL whose body does not load immediately. | 399 // Fake a top-level request to a URL whose body does not load immediately. |
391 TestNavigationURLLoaderDelegate delegate; | 400 TestNavigationURLLoaderDelegate delegate; |
392 scoped_ptr<NavigationURLLoader> loader = | 401 scoped_ptr<NavigationURLLoader> loader = |
393 MakeTestLoader(net::URLRequestTestJob::test_url_2(), &delegate); | 402 MakeTestLoader(net::URLRequestTestJob::test_url_2(), &delegate); |
394 | 403 |
395 // Wait for the response to come back. | 404 // Wait for the response to come back. |
396 delegate.WaitForResponseStarted(); | 405 delegate.WaitForResponseStarted(); |
397 | 406 |
| 407 // Proceed with the response. |
| 408 loader->ProceedWithResponse(); |
| 409 |
398 // Release the body. | 410 // Release the body. |
399 delegate.ReleaseBody(); | 411 delegate.ReleaseBody(); |
400 base::RunLoop().RunUntilIdle(); | 412 base::RunLoop().RunUntilIdle(); |
401 | 413 |
402 // Verify that URLRequestTestJob no longer has anything paused. | 414 // Verify that URLRequestTestJob no longer has anything paused. |
403 EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage()); | 415 EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage()); |
404 } | 416 } |
405 | 417 |
406 } // namespace content | 418 } // namespace content |
OLD | NEW |