| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 } | 828 } |
| 829 | 829 |
| 830 private: | 830 private: |
| 831 int resource_request_redirect_count_; | 831 int resource_request_redirect_count_; |
| 832 int resource_response_start_count_; | 832 int resource_response_start_count_; |
| 833 }; | 833 }; |
| 834 | 834 |
| 835 // Information used to create resource requests that use URLRequestLoadInfoJobs. | 835 // Information used to create resource requests that use URLRequestLoadInfoJobs. |
| 836 // The child_id is just that of ResourceDispatcherHostTest::filter_. | 836 // The child_id is just that of ResourceDispatcherHostTest::filter_. |
| 837 struct LoadInfoTestRequestInfo { | 837 struct LoadInfoTestRequestInfo { |
| 838 int route_id; | 838 GlobalFrameRoutingId route_id; |
| 839 GURL url; | 839 GURL url; |
| 840 net::LoadState load_state; | 840 net::LoadState load_state; |
| 841 net::UploadProgress upload_progress; | 841 net::UploadProgress upload_progress; |
| 842 }; | 842 }; |
| 843 | 843 |
| 844 enum class TestConfig { | 844 enum class TestConfig { |
| 845 kDefault, | 845 kDefault, |
| 846 kOptimizeIPCForSmallResourceEnabled, | 846 kOptimizeIPCForSmallResourceEnabled, |
| 847 }; | 847 }; |
| 848 | 848 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 return true; | 929 return true; |
| 930 } | 930 } |
| 931 | 931 |
| 932 std::unique_ptr<LoadInfoMap> RunLoadInfoTest( | 932 std::unique_ptr<LoadInfoMap> RunLoadInfoTest( |
| 933 LoadInfoTestRequestInfo* request_info, | 933 LoadInfoTestRequestInfo* request_info, |
| 934 size_t num_requests) { | 934 size_t num_requests) { |
| 935 for (size_t i = 0; i < num_requests; ++i) { | 935 for (size_t i = 0; i < num_requests; ++i) { |
| 936 loader_test_request_info_.reset( | 936 loader_test_request_info_.reset( |
| 937 new LoadInfoTestRequestInfo(request_info[i])); | 937 new LoadInfoTestRequestInfo(request_info[i])); |
| 938 wait_for_request_create_loop_.reset(new base::RunLoop()); | 938 wait_for_request_create_loop_.reset(new base::RunLoop()); |
| 939 MakeTestRequest(request_info[i].route_id, i + 1, request_info[i].url); | 939 MakeTestRequestWithRenderFrame( |
| 940 0, request_info[i].route_id.frame_routing_id, i + 1, |
| 941 request_info[i].url, RESOURCE_TYPE_SUB_RESOURCE); |
| 940 wait_for_request_create_loop_->Run(); | 942 wait_for_request_create_loop_->Run(); |
| 941 wait_for_request_create_loop_.reset(); | 943 wait_for_request_create_loop_.reset(); |
| 942 } | 944 } |
| 943 return ResourceDispatcherHostImpl::Get()->GetLoadInfoForAllRoutes(); | 945 return ResourceDispatcherHostImpl::Get()->GetLoadInfoForAllRoutes(); |
| 944 } | 946 } |
| 945 | 947 |
| 946 protected: | 948 protected: |
| 947 friend class TestURLRequestJobFactory; | 949 friend class TestURLRequestJobFactory; |
| 948 | 950 |
| 949 // testing::Test | 951 // testing::Test |
| (...skipping 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3593 | 3595 |
| 3594 // Tests GetLoadInfoForAllRoutes when there are no pending requests. | 3596 // Tests GetLoadInfoForAllRoutes when there are no pending requests. |
| 3595 TEST_P(ResourceDispatcherHostTest, LoadInfoNoRequests) { | 3597 TEST_P(ResourceDispatcherHostTest, LoadInfoNoRequests) { |
| 3596 std::unique_ptr<LoadInfoMap> load_info_map = RunLoadInfoTest(nullptr, 0); | 3598 std::unique_ptr<LoadInfoMap> load_info_map = RunLoadInfoTest(nullptr, 0); |
| 3597 EXPECT_EQ(0u, load_info_map->size()); | 3599 EXPECT_EQ(0u, load_info_map->size()); |
| 3598 } | 3600 } |
| 3599 | 3601 |
| 3600 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same | 3602 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same |
| 3601 // RenderView. The second one is farthest along. | 3603 // RenderView. The second one is farthest along. |
| 3602 TEST_P(ResourceDispatcherHostTest, LoadInfo) { | 3604 TEST_P(ResourceDispatcherHostTest, LoadInfo) { |
| 3603 const GlobalRoutingID kId(filter_->child_id(), 0); | 3605 const GlobalFrameRoutingId kId(filter_->child_id(), 0); |
| 3604 LoadInfoTestRequestInfo request_info[] = { | 3606 LoadInfoTestRequestInfo request_info[] = { |
| 3605 {kId.route_id, | 3607 {kId, GURL("test://1/"), net::LOAD_STATE_SENDING_REQUEST, |
| 3606 GURL("test://1/"), | |
| 3607 net::LOAD_STATE_SENDING_REQUEST, | |
| 3608 net::UploadProgress(0, 0)}, | 3608 net::UploadProgress(0, 0)}, |
| 3609 {kId.route_id, | 3609 {kId, GURL("test://2/"), net::LOAD_STATE_READING_RESPONSE, |
| 3610 GURL("test://2/"), | |
| 3611 net::LOAD_STATE_READING_RESPONSE, | |
| 3612 net::UploadProgress(0, 0)}, | 3610 net::UploadProgress(0, 0)}, |
| 3613 {kId.route_id, | 3611 {kId, GURL("test://3/"), net::LOAD_STATE_SENDING_REQUEST, |
| 3614 GURL("test://3/"), | |
| 3615 net::LOAD_STATE_SENDING_REQUEST, | |
| 3616 net::UploadProgress(0, 0)}, | 3612 net::UploadProgress(0, 0)}, |
| 3617 }; | 3613 }; |
| 3618 std::unique_ptr<LoadInfoMap> load_info_map = | 3614 std::unique_ptr<LoadInfoMap> load_info_map = |
| 3619 RunLoadInfoTest(request_info, arraysize(request_info)); | 3615 RunLoadInfoTest(request_info, arraysize(request_info)); |
| 3620 ASSERT_EQ(1u, load_info_map->size()); | 3616 ASSERT_EQ(1u, load_info_map->size()); |
| 3621 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); | 3617 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); |
| 3622 EXPECT_EQ(GURL("test://2/"), (*load_info_map)[kId].url); | 3618 EXPECT_EQ(GURL("test://2/"), (*load_info_map)[kId].url); |
| 3623 EXPECT_EQ(net::LOAD_STATE_READING_RESPONSE, | 3619 EXPECT_EQ(net::LOAD_STATE_READING_RESPONSE, |
| 3624 (*load_info_map)[kId].load_state.state); | 3620 (*load_info_map)[kId].load_state.state); |
| 3625 EXPECT_EQ(0u, (*load_info_map)[kId].upload_position); | 3621 EXPECT_EQ(0u, (*load_info_map)[kId].upload_position); |
| 3626 EXPECT_EQ(0u, (*load_info_map)[kId].upload_size); | 3622 EXPECT_EQ(0u, (*load_info_map)[kId].upload_size); |
| 3627 } | 3623 } |
| 3628 | 3624 |
| 3629 // Tests GetLoadInfoForAllRoutes when there are 2 requests with the same | 3625 // Tests GetLoadInfoForAllRoutes when there are 2 requests with the same |
| 3630 // priority. The first one (Which will have the lowest ID) should be returned. | 3626 // priority. The first one (Which will have the lowest ID) should be returned. |
| 3631 TEST_P(ResourceDispatcherHostTest, LoadInfoSamePriority) { | 3627 TEST_P(ResourceDispatcherHostTest, LoadInfoSamePriority) { |
| 3632 const GlobalRoutingID kId(filter_->child_id(), 0); | 3628 const GlobalFrameRoutingId kId(filter_->child_id(), 0); |
| 3633 LoadInfoTestRequestInfo request_info[] = { | 3629 LoadInfoTestRequestInfo request_info[] = { |
| 3634 {kId.route_id, | 3630 {kId, GURL("test://1/"), net::LOAD_STATE_IDLE, net::UploadProgress(0, 0)}, |
| 3635 GURL("test://1/"), | 3631 {kId, GURL("test://2/"), net::LOAD_STATE_IDLE, net::UploadProgress(0, 0)}, |
| 3636 net::LOAD_STATE_IDLE, | |
| 3637 net::UploadProgress(0, 0)}, | |
| 3638 {kId.route_id, | |
| 3639 GURL("test://2/"), | |
| 3640 net::LOAD_STATE_IDLE, | |
| 3641 net::UploadProgress(0, 0)}, | |
| 3642 }; | 3632 }; |
| 3643 std::unique_ptr<LoadInfoMap> load_info_map = | 3633 std::unique_ptr<LoadInfoMap> load_info_map = |
| 3644 RunLoadInfoTest(request_info, arraysize(request_info)); | 3634 RunLoadInfoTest(request_info, arraysize(request_info)); |
| 3645 ASSERT_EQ(1u, load_info_map->size()); | 3635 ASSERT_EQ(1u, load_info_map->size()); |
| 3646 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); | 3636 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); |
| 3647 EXPECT_EQ(GURL("test://1/"), (*load_info_map)[kId].url); | 3637 EXPECT_EQ(GURL("test://1/"), (*load_info_map)[kId].url); |
| 3648 EXPECT_EQ(net::LOAD_STATE_IDLE, (*load_info_map)[kId].load_state.state); | 3638 EXPECT_EQ(net::LOAD_STATE_IDLE, (*load_info_map)[kId].load_state.state); |
| 3649 EXPECT_EQ(0u, (*load_info_map)[kId].upload_position); | 3639 EXPECT_EQ(0u, (*load_info_map)[kId].upload_position); |
| 3650 EXPECT_EQ(0u, (*load_info_map)[kId].upload_size); | 3640 EXPECT_EQ(0u, (*load_info_map)[kId].upload_size); |
| 3651 } | 3641 } |
| 3652 | 3642 |
| 3653 // Tests GetLoadInfoForAllRoutes when a request is uploading a body. | 3643 // Tests GetLoadInfoForAllRoutes when a request is uploading a body. |
| 3654 TEST_P(ResourceDispatcherHostTest, LoadInfoUploadProgress) { | 3644 TEST_P(ResourceDispatcherHostTest, LoadInfoUploadProgress) { |
| 3655 const GlobalRoutingID kId(filter_->child_id(), 0); | 3645 const GlobalFrameRoutingId kId(filter_->child_id(), 0); |
| 3656 LoadInfoTestRequestInfo request_info[] = { | 3646 LoadInfoTestRequestInfo request_info[] = { |
| 3657 {kId.route_id, | 3647 {kId, GURL("test://1/"), net::LOAD_STATE_READING_RESPONSE, |
| 3658 GURL("test://1/"), | |
| 3659 net::LOAD_STATE_READING_RESPONSE, | |
| 3660 net::UploadProgress(0, 0)}, | 3648 net::UploadProgress(0, 0)}, |
| 3661 {kId.route_id, | 3649 {kId, GURL("test://1/"), net::LOAD_STATE_READING_RESPONSE, |
| 3662 GURL("test://1/"), | |
| 3663 net::LOAD_STATE_READING_RESPONSE, | |
| 3664 net::UploadProgress(1000, 1000)}, | 3650 net::UploadProgress(1000, 1000)}, |
| 3665 {kId.route_id, | 3651 {kId, GURL("test://2/"), net::LOAD_STATE_SENDING_REQUEST, |
| 3666 GURL("test://2/"), | |
| 3667 net::LOAD_STATE_SENDING_REQUEST, | |
| 3668 net::UploadProgress(50, 100)}, | 3652 net::UploadProgress(50, 100)}, |
| 3669 {kId.route_id, | 3653 {kId, GURL("test://1/"), net::LOAD_STATE_READING_RESPONSE, |
| 3670 GURL("test://1/"), | |
| 3671 net::LOAD_STATE_READING_RESPONSE, | |
| 3672 net::UploadProgress(1000, 1000)}, | 3654 net::UploadProgress(1000, 1000)}, |
| 3673 {kId.route_id, | 3655 {kId, GURL("test://3/"), net::LOAD_STATE_READING_RESPONSE, |
| 3674 GURL("test://3/"), | |
| 3675 net::LOAD_STATE_READING_RESPONSE, | |
| 3676 net::UploadProgress(0, 0)}, | 3656 net::UploadProgress(0, 0)}, |
| 3677 }; | 3657 }; |
| 3678 std::unique_ptr<LoadInfoMap> load_info_map = | 3658 std::unique_ptr<LoadInfoMap> load_info_map = |
| 3679 RunLoadInfoTest(request_info, arraysize(request_info)); | 3659 RunLoadInfoTest(request_info, arraysize(request_info)); |
| 3680 ASSERT_EQ(1u, load_info_map->size()); | 3660 ASSERT_EQ(1u, load_info_map->size()); |
| 3681 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); | 3661 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); |
| 3682 EXPECT_EQ(GURL("test://2/"), (*load_info_map)[kId].url); | 3662 EXPECT_EQ(GURL("test://2/"), (*load_info_map)[kId].url); |
| 3683 EXPECT_EQ(net::LOAD_STATE_SENDING_REQUEST, | 3663 EXPECT_EQ(net::LOAD_STATE_SENDING_REQUEST, |
| 3684 (*load_info_map)[kId].load_state.state); | 3664 (*load_info_map)[kId].load_state.state); |
| 3685 EXPECT_EQ(50u, (*load_info_map)[kId].upload_position); | 3665 EXPECT_EQ(50u, (*load_info_map)[kId].upload_position); |
| 3686 EXPECT_EQ(100u, (*load_info_map)[kId].upload_size); | 3666 EXPECT_EQ(100u, (*load_info_map)[kId].upload_size); |
| 3687 } | 3667 } |
| 3688 | 3668 |
| 3689 // Tests GetLoadInfoForAllRoutes when there are 4 requests from 2 different | 3669 // Tests GetLoadInfoForAllRoutes when there are 4 requests from 2 different |
| 3690 // RenderViews. Also tests the case where the first / last requests are the | 3670 // RenderViews. Also tests the case where the first / last requests are the |
| 3691 // most interesting ones. | 3671 // most interesting ones. |
| 3692 TEST_P(ResourceDispatcherHostTest, LoadInfoTwoRenderViews) { | 3672 TEST_P(ResourceDispatcherHostTest, LoadInfoTwoRenderViews) { |
| 3693 const GlobalRoutingID kId1(filter_->child_id(), 0); | 3673 const GlobalFrameRoutingId kId1(filter_->child_id(), 0); |
| 3694 const GlobalRoutingID kId2(filter_->child_id(), 1); | 3674 const GlobalFrameRoutingId kId2(filter_->child_id(), 1); |
| 3695 LoadInfoTestRequestInfo request_info[] = { | 3675 LoadInfoTestRequestInfo request_info[] = { |
| 3696 {kId1.route_id, | 3676 {kId1, GURL("test://1/"), net::LOAD_STATE_CONNECTING, |
| 3697 GURL("test://1/"), | |
| 3698 net::LOAD_STATE_CONNECTING, | |
| 3699 net::UploadProgress(0, 0)}, | 3677 net::UploadProgress(0, 0)}, |
| 3700 {kId2.route_id, | 3678 {kId2, GURL("test://2/"), net::LOAD_STATE_IDLE, |
| 3701 GURL("test://2/"), | |
| 3702 net::LOAD_STATE_IDLE, | |
| 3703 net::UploadProgress(0, 0)}, | 3679 net::UploadProgress(0, 0)}, |
| 3704 {kId1.route_id, | 3680 {kId1, GURL("test://3/"), net::LOAD_STATE_IDLE, |
| 3705 GURL("test://3/"), | |
| 3706 net::LOAD_STATE_IDLE, | |
| 3707 net::UploadProgress(0, 0)}, | 3681 net::UploadProgress(0, 0)}, |
| 3708 {kId2.route_id, | 3682 {kId2, GURL("test://4/"), net::LOAD_STATE_CONNECTING, |
| 3709 GURL("test://4/"), | |
| 3710 net::LOAD_STATE_CONNECTING, | |
| 3711 net::UploadProgress(0, 0)}, | 3683 net::UploadProgress(0, 0)}, |
| 3712 }; | 3684 }; |
| 3713 std::unique_ptr<LoadInfoMap> load_info_map = | 3685 std::unique_ptr<LoadInfoMap> load_info_map = |
| 3714 RunLoadInfoTest(request_info, arraysize(request_info)); | 3686 RunLoadInfoTest(request_info, arraysize(request_info)); |
| 3715 ASSERT_EQ(2u, load_info_map->size()); | 3687 ASSERT_EQ(2u, load_info_map->size()); |
| 3716 | 3688 |
| 3717 ASSERT_TRUE(load_info_map->find(kId1) != load_info_map->end()); | 3689 ASSERT_TRUE(load_info_map->find(kId1) != load_info_map->end()); |
| 3718 EXPECT_EQ(GURL("test://1/"), (*load_info_map)[kId1].url); | 3690 EXPECT_EQ(GURL("test://1/"), (*load_info_map)[kId1].url); |
| 3719 EXPECT_EQ(net::LOAD_STATE_CONNECTING, | 3691 EXPECT_EQ(net::LOAD_STATE_CONNECTING, |
| 3720 (*load_info_map)[kId1].load_state.state); | 3692 (*load_info_map)[kId1].load_state.state); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3904 return nullptr; | 3876 return nullptr; |
| 3905 } | 3877 } |
| 3906 | 3878 |
| 3907 INSTANTIATE_TEST_CASE_P( | 3879 INSTANTIATE_TEST_CASE_P( |
| 3908 ResourceDispatcherHostTests, | 3880 ResourceDispatcherHostTests, |
| 3909 ResourceDispatcherHostTest, | 3881 ResourceDispatcherHostTest, |
| 3910 testing::Values(TestConfig::kDefault, | 3882 testing::Values(TestConfig::kDefault, |
| 3911 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3883 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
| 3912 | 3884 |
| 3913 } // namespace content | 3885 } // namespace content |
| OLD | NEW |