| 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 "content/child/web_url_loader_impl.h" | 5 #include "content/child/web_url_loader_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 19 #include "base/time/default_tick_clock.h" | 20 #include "base/time/default_tick_clock.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "components/scheduler/child/scheduler_tqm_delegate_impl.h" | 22 #include "components/scheduler/child/scheduler_tqm_delegate_impl.h" |
| 22 #include "components/scheduler/child/web_task_runner_impl.h" | 23 #include "components/scheduler/child/web_task_runner_impl.h" |
| 23 #include "components/scheduler/child/worker_scheduler.h" | 24 #include "components/scheduler/child/worker_scheduler.h" |
| 24 #include "content/child/request_extra_data.h" | 25 #include "content/child/request_extra_data.h" |
| 25 #include "content/child/request_info.h" | 26 #include "content/child/request_info.h" |
| 26 #include "content/child/resource_dispatcher.h" | 27 #include "content/child/resource_dispatcher.h" |
| 27 #include "content/public/child/fixed_received_data.h" | 28 #include "content/public/child/fixed_received_data.h" |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 DoReceiveData(); | 443 DoReceiveData(); |
| 443 DoFailRequest(); | 444 DoFailRequest(); |
| 444 } | 445 } |
| 445 | 446 |
| 446 TEST_F(WebURLLoaderImplTest, DeleteBeforeResponseDataURL) { | 447 TEST_F(WebURLLoaderImplTest, DeleteBeforeResponseDataURL) { |
| 447 blink::WebURLRequest request; | 448 blink::WebURLRequest request; |
| 448 request.initialize(); | 449 request.initialize(); |
| 449 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); | 450 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); |
| 450 client()->loader()->loadAsynchronously(request, client()); | 451 client()->loader()->loadAsynchronously(request, client()); |
| 451 client()->DeleteLoader(); | 452 client()->DeleteLoader(); |
| 452 message_loop()->RunUntilIdle(); | 453 base::RunLoop().RunUntilIdle(); |
| 453 EXPECT_FALSE(client()->did_receive_response()); | 454 EXPECT_FALSE(client()->did_receive_response()); |
| 454 } | 455 } |
| 455 | 456 |
| 456 // Data URL tests. | 457 // Data URL tests. |
| 457 | 458 |
| 458 TEST_F(WebURLLoaderImplTest, DataURL) { | 459 TEST_F(WebURLLoaderImplTest, DataURL) { |
| 459 blink::WebURLRequest request; | 460 blink::WebURLRequest request; |
| 460 request.initialize(); | 461 request.initialize(); |
| 461 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); | 462 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); |
| 462 client()->loader()->loadAsynchronously(request, client()); | 463 client()->loader()->loadAsynchronously(request, client()); |
| 463 message_loop()->RunUntilIdle(); | 464 base::RunLoop().RunUntilIdle(); |
| 464 EXPECT_EQ("blah!", client()->received_data()); | 465 EXPECT_EQ("blah!", client()->received_data()); |
| 465 EXPECT_TRUE(client()->did_finish()); | 466 EXPECT_TRUE(client()->did_finish()); |
| 466 EXPECT_EQ(net::OK, client()->error().reason); | 467 EXPECT_EQ(net::OK, client()->error().reason); |
| 467 EXPECT_EQ("", client()->error().domain.utf8()); | 468 EXPECT_EQ("", client()->error().domain.utf8()); |
| 468 } | 469 } |
| 469 | 470 |
| 470 TEST_F(WebURLLoaderImplTest, DataURLDeleteOnReceiveResponse) { | 471 TEST_F(WebURLLoaderImplTest, DataURLDeleteOnReceiveResponse) { |
| 471 blink::WebURLRequest request; | 472 blink::WebURLRequest request; |
| 472 request.initialize(); | 473 request.initialize(); |
| 473 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); | 474 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); |
| 474 client()->set_delete_on_receive_response(); | 475 client()->set_delete_on_receive_response(); |
| 475 client()->loader()->loadAsynchronously(request, client()); | 476 client()->loader()->loadAsynchronously(request, client()); |
| 476 message_loop()->RunUntilIdle(); | 477 base::RunLoop().RunUntilIdle(); |
| 477 EXPECT_TRUE(client()->did_receive_response()); | 478 EXPECT_TRUE(client()->did_receive_response()); |
| 478 EXPECT_EQ("", client()->received_data()); | 479 EXPECT_EQ("", client()->received_data()); |
| 479 EXPECT_FALSE(client()->did_finish()); | 480 EXPECT_FALSE(client()->did_finish()); |
| 480 } | 481 } |
| 481 | 482 |
| 482 TEST_F(WebURLLoaderImplTest, DataURLDeleteOnReceiveData) { | 483 TEST_F(WebURLLoaderImplTest, DataURLDeleteOnReceiveData) { |
| 483 blink::WebURLRequest request; | 484 blink::WebURLRequest request; |
| 484 request.initialize(); | 485 request.initialize(); |
| 485 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); | 486 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); |
| 486 client()->set_delete_on_receive_data(); | 487 client()->set_delete_on_receive_data(); |
| 487 client()->loader()->loadAsynchronously(request, client()); | 488 client()->loader()->loadAsynchronously(request, client()); |
| 488 message_loop()->RunUntilIdle(); | 489 base::RunLoop().RunUntilIdle(); |
| 489 EXPECT_TRUE(client()->did_receive_response()); | 490 EXPECT_TRUE(client()->did_receive_response()); |
| 490 EXPECT_EQ("blah!", client()->received_data()); | 491 EXPECT_EQ("blah!", client()->received_data()); |
| 491 EXPECT_FALSE(client()->did_finish()); | 492 EXPECT_FALSE(client()->did_finish()); |
| 492 } | 493 } |
| 493 | 494 |
| 494 TEST_F(WebURLLoaderImplTest, DataURLDeleteOnFinish) { | 495 TEST_F(WebURLLoaderImplTest, DataURLDeleteOnFinish) { |
| 495 blink::WebURLRequest request; | 496 blink::WebURLRequest request; |
| 496 request.initialize(); | 497 request.initialize(); |
| 497 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); | 498 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); |
| 498 client()->set_delete_on_finish(); | 499 client()->set_delete_on_finish(); |
| 499 client()->loader()->loadAsynchronously(request, client()); | 500 client()->loader()->loadAsynchronously(request, client()); |
| 500 message_loop()->RunUntilIdle(); | 501 base::RunLoop().RunUntilIdle(); |
| 501 EXPECT_TRUE(client()->did_receive_response()); | 502 EXPECT_TRUE(client()->did_receive_response()); |
| 502 EXPECT_EQ("blah!", client()->received_data()); | 503 EXPECT_EQ("blah!", client()->received_data()); |
| 503 EXPECT_TRUE(client()->did_finish()); | 504 EXPECT_TRUE(client()->did_finish()); |
| 504 } | 505 } |
| 505 | 506 |
| 506 TEST_F(WebURLLoaderImplTest, DataURLDefersLoading) { | 507 TEST_F(WebURLLoaderImplTest, DataURLDefersLoading) { |
| 507 blink::WebURLRequest request; | 508 blink::WebURLRequest request; |
| 508 request.initialize(); | 509 request.initialize(); |
| 509 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); | 510 request.setURL(GURL("data:text/html;charset=utf-8,blah!")); |
| 510 client()->loader()->loadAsynchronously(request, client()); | 511 client()->loader()->loadAsynchronously(request, client()); |
| 511 | 512 |
| 512 // setDefersLoading() might be called with either false or true in no | 513 // setDefersLoading() might be called with either false or true in no |
| 513 // specific order. The user of the API will not have sufficient information | 514 // specific order. The user of the API will not have sufficient information |
| 514 // about the WebURLLoader's internal state, so the latter gracefully needs to | 515 // about the WebURLLoader's internal state, so the latter gracefully needs to |
| 515 // handle calling setDefersLoading any number of times with any values from | 516 // handle calling setDefersLoading any number of times with any values from |
| 516 // any point in time. | 517 // any point in time. |
| 517 | 518 |
| 518 client()->loader()->setDefersLoading(false); | 519 client()->loader()->setDefersLoading(false); |
| 519 client()->loader()->setDefersLoading(true); | 520 client()->loader()->setDefersLoading(true); |
| 520 client()->loader()->setDefersLoading(true); | 521 client()->loader()->setDefersLoading(true); |
| 521 message_loop()->RunUntilIdle(); | 522 base::RunLoop().RunUntilIdle(); |
| 522 EXPECT_FALSE(client()->did_finish()); | 523 EXPECT_FALSE(client()->did_finish()); |
| 523 | 524 |
| 524 client()->loader()->setDefersLoading(false); | 525 client()->loader()->setDefersLoading(false); |
| 525 client()->loader()->setDefersLoading(true); | 526 client()->loader()->setDefersLoading(true); |
| 526 message_loop()->RunUntilIdle(); | 527 base::RunLoop().RunUntilIdle(); |
| 527 EXPECT_FALSE(client()->did_finish()); | 528 EXPECT_FALSE(client()->did_finish()); |
| 528 | 529 |
| 529 client()->loader()->setDefersLoading(false); | 530 client()->loader()->setDefersLoading(false); |
| 530 message_loop()->RunUntilIdle(); | 531 base::RunLoop().RunUntilIdle(); |
| 531 EXPECT_TRUE(client()->did_finish()); | 532 EXPECT_TRUE(client()->did_finish()); |
| 532 | 533 |
| 533 client()->loader()->setDefersLoading(true); | 534 client()->loader()->setDefersLoading(true); |
| 534 client()->loader()->setDefersLoading(false); | 535 client()->loader()->setDefersLoading(false); |
| 535 client()->loader()->setDefersLoading(false); | 536 client()->loader()->setDefersLoading(false); |
| 536 message_loop()->RunUntilIdle(); | 537 base::RunLoop().RunUntilIdle(); |
| 537 EXPECT_TRUE(client()->did_finish()); | 538 EXPECT_TRUE(client()->did_finish()); |
| 538 | 539 |
| 539 EXPECT_EQ("blah!", client()->received_data()); | 540 EXPECT_EQ("blah!", client()->received_data()); |
| 540 EXPECT_EQ(net::OK, client()->error().reason); | 541 EXPECT_EQ(net::OK, client()->error().reason); |
| 541 EXPECT_EQ("", client()->error().domain.utf8()); | 542 EXPECT_EQ("", client()->error().domain.utf8()); |
| 542 } | 543 } |
| 543 | 544 |
| 544 TEST_F(WebURLLoaderImplTest, DefersLoadingBeforeStart) { | 545 TEST_F(WebURLLoaderImplTest, DefersLoadingBeforeStart) { |
| 545 client()->loader()->setDefersLoading(true); | 546 client()->loader()->setDefersLoading(true); |
| 546 EXPECT_FALSE(dispatcher()->defers_loading()); | 547 EXPECT_FALSE(dispatcher()->defers_loading()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 info.socket_address = net::HostPortPair(test.ip, 443); | 671 info.socket_address = net::HostPortPair(test.ip, 443); |
| 671 blink::WebURLResponse response; | 672 blink::WebURLResponse response; |
| 672 response.initialize(); | 673 response.initialize(); |
| 673 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); | 674 WebURLLoaderImpl::PopulateURLResponse(url, info, &response, true); |
| 674 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); | 675 EXPECT_EQ(test.expected, response.remoteIPAddress().utf8()); |
| 675 }; | 676 }; |
| 676 } | 677 } |
| 677 | 678 |
| 678 } // namespace | 679 } // namespace |
| 679 } // namespace content | 680 } // namespace content |
| OLD | NEW |