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 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 } | 829 } |
830 | 830 |
831 private: | 831 private: |
832 int resource_request_redirect_count_; | 832 int resource_request_redirect_count_; |
833 int resource_response_start_count_; | 833 int resource_response_start_count_; |
834 }; | 834 }; |
835 | 835 |
836 // Information used to create resource requests that use URLRequestLoadInfoJobs. | 836 // Information used to create resource requests that use URLRequestLoadInfoJobs. |
837 // The child_id is just that of ResourceDispatcherHostTest::filter_. | 837 // The child_id is just that of ResourceDispatcherHostTest::filter_. |
838 struct LoadInfoTestRequestInfo { | 838 struct LoadInfoTestRequestInfo { |
839 int route_id; | 839 GlobalFrameRoutingId route_id; |
840 GURL url; | 840 GURL url; |
841 net::LoadState load_state; | 841 net::LoadState load_state; |
842 net::UploadProgress upload_progress; | 842 net::UploadProgress upload_progress; |
843 }; | 843 }; |
844 | 844 |
845 enum class TestConfig { | 845 enum class TestConfig { |
846 kDefault, | 846 kDefault, |
847 kOptimizeIPCForSmallResourceEnabled, | 847 kOptimizeIPCForSmallResourceEnabled, |
848 }; | 848 }; |
849 | 849 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
930 return true; | 930 return true; |
931 } | 931 } |
932 | 932 |
933 std::unique_ptr<LoadInfoMap> RunLoadInfoTest( | 933 std::unique_ptr<LoadInfoMap> RunLoadInfoTest( |
934 LoadInfoTestRequestInfo* request_info, | 934 LoadInfoTestRequestInfo* request_info, |
935 size_t num_requests) { | 935 size_t num_requests) { |
936 for (size_t i = 0; i < num_requests; ++i) { | 936 for (size_t i = 0; i < num_requests; ++i) { |
937 loader_test_request_info_.reset( | 937 loader_test_request_info_.reset( |
938 new LoadInfoTestRequestInfo(request_info[i])); | 938 new LoadInfoTestRequestInfo(request_info[i])); |
939 wait_for_request_create_loop_.reset(new base::RunLoop()); | 939 wait_for_request_create_loop_.reset(new base::RunLoop()); |
940 MakeTestRequest(request_info[i].route_id, i + 1, request_info[i].url); | 940 MakeTestRequestWithRenderFrame( |
941 0, request_info[i].route_id.frame_routing_id, i + 1, | |
nasko
2016/06/01 16:54:00
Don't use 0, use MSG_ROUTING_NONE, as there is no
Charlie Harrison
2016/06/02 14:22:28
Done.
| |
942 request_info[i].url, RESOURCE_TYPE_SUB_RESOURCE); | |
941 wait_for_request_create_loop_->Run(); | 943 wait_for_request_create_loop_->Run(); |
942 wait_for_request_create_loop_.reset(); | 944 wait_for_request_create_loop_.reset(); |
943 } | 945 } |
944 return ResourceDispatcherHostImpl::Get()->GetLoadInfoForAllRoutes(); | 946 return ResourceDispatcherHostImpl::Get()->GetLoadInfoForAllRoutes(); |
945 } | 947 } |
946 | 948 |
947 protected: | 949 protected: |
948 friend class TestURLRequestJobFactory; | 950 friend class TestURLRequestJobFactory; |
949 | 951 |
950 // testing::Test | 952 // testing::Test |
(...skipping 2634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3585 | 3587 |
3586 // Tests GetLoadInfoForAllRoutes when there are no pending requests. | 3588 // Tests GetLoadInfoForAllRoutes when there are no pending requests. |
3587 TEST_P(ResourceDispatcherHostTest, LoadInfoNoRequests) { | 3589 TEST_P(ResourceDispatcherHostTest, LoadInfoNoRequests) { |
3588 std::unique_ptr<LoadInfoMap> load_info_map = RunLoadInfoTest(nullptr, 0); | 3590 std::unique_ptr<LoadInfoMap> load_info_map = RunLoadInfoTest(nullptr, 0); |
3589 EXPECT_EQ(0u, load_info_map->size()); | 3591 EXPECT_EQ(0u, load_info_map->size()); |
3590 } | 3592 } |
3591 | 3593 |
3592 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same | 3594 // Tests GetLoadInfoForAllRoutes when there are 3 requests from the same |
3593 // RenderView. The second one is farthest along. | 3595 // RenderView. The second one is farthest along. |
3594 TEST_P(ResourceDispatcherHostTest, LoadInfo) { | 3596 TEST_P(ResourceDispatcherHostTest, LoadInfo) { |
3595 const GlobalRoutingID kId(filter_->child_id(), 0); | 3597 const GlobalFrameRoutingId kId(filter_->child_id(), 0); |
nasko
2016/06/01 16:54:00
nit: I'd use a non-zero integer as zero is not a v
Charlie Harrison
2016/06/02 14:22:28
Done.
| |
3596 LoadInfoTestRequestInfo request_info[] = { | 3598 LoadInfoTestRequestInfo request_info[] = { |
3597 {kId.route_id, | 3599 {kId, GURL("test://1/"), net::LOAD_STATE_SENDING_REQUEST, |
3598 GURL("test://1/"), | |
3599 net::LOAD_STATE_SENDING_REQUEST, | |
3600 net::UploadProgress(0, 0)}, | 3600 net::UploadProgress(0, 0)}, |
3601 {kId.route_id, | 3601 {kId, GURL("test://2/"), net::LOAD_STATE_READING_RESPONSE, |
3602 GURL("test://2/"), | |
3603 net::LOAD_STATE_READING_RESPONSE, | |
3604 net::UploadProgress(0, 0)}, | 3602 net::UploadProgress(0, 0)}, |
3605 {kId.route_id, | 3603 {kId, GURL("test://3/"), net::LOAD_STATE_SENDING_REQUEST, |
3606 GURL("test://3/"), | |
3607 net::LOAD_STATE_SENDING_REQUEST, | |
3608 net::UploadProgress(0, 0)}, | 3604 net::UploadProgress(0, 0)}, |
3609 }; | 3605 }; |
3610 std::unique_ptr<LoadInfoMap> load_info_map = | 3606 std::unique_ptr<LoadInfoMap> load_info_map = |
3611 RunLoadInfoTest(request_info, arraysize(request_info)); | 3607 RunLoadInfoTest(request_info, arraysize(request_info)); |
3612 ASSERT_EQ(1u, load_info_map->size()); | 3608 ASSERT_EQ(1u, load_info_map->size()); |
3613 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); | 3609 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); |
3614 EXPECT_EQ(GURL("test://2/"), (*load_info_map)[kId].url); | 3610 EXPECT_EQ(GURL("test://2/"), (*load_info_map)[kId].url); |
3615 EXPECT_EQ(net::LOAD_STATE_READING_RESPONSE, | 3611 EXPECT_EQ(net::LOAD_STATE_READING_RESPONSE, |
3616 (*load_info_map)[kId].load_state.state); | 3612 (*load_info_map)[kId].load_state.state); |
3617 EXPECT_EQ(0u, (*load_info_map)[kId].upload_position); | 3613 EXPECT_EQ(0u, (*load_info_map)[kId].upload_position); |
3618 EXPECT_EQ(0u, (*load_info_map)[kId].upload_size); | 3614 EXPECT_EQ(0u, (*load_info_map)[kId].upload_size); |
3619 } | 3615 } |
3620 | 3616 |
3621 // Tests GetLoadInfoForAllRoutes when there are 2 requests with the same | 3617 // Tests GetLoadInfoForAllRoutes when there are 2 requests with the same |
3622 // priority. The first one (Which will have the lowest ID) should be returned. | 3618 // priority. The first one (Which will have the lowest ID) should be returned. |
3623 TEST_P(ResourceDispatcherHostTest, LoadInfoSamePriority) { | 3619 TEST_P(ResourceDispatcherHostTest, LoadInfoSamePriority) { |
3624 const GlobalRoutingID kId(filter_->child_id(), 0); | 3620 const GlobalFrameRoutingId kId(filter_->child_id(), 0); |
3625 LoadInfoTestRequestInfo request_info[] = { | 3621 LoadInfoTestRequestInfo request_info[] = { |
3626 {kId.route_id, | 3622 {kId, GURL("test://1/"), net::LOAD_STATE_IDLE, net::UploadProgress(0, 0)}, |
3627 GURL("test://1/"), | 3623 {kId, GURL("test://2/"), net::LOAD_STATE_IDLE, net::UploadProgress(0, 0)}, |
3628 net::LOAD_STATE_IDLE, | |
3629 net::UploadProgress(0, 0)}, | |
3630 {kId.route_id, | |
3631 GURL("test://2/"), | |
3632 net::LOAD_STATE_IDLE, | |
3633 net::UploadProgress(0, 0)}, | |
3634 }; | 3624 }; |
3635 std::unique_ptr<LoadInfoMap> load_info_map = | 3625 std::unique_ptr<LoadInfoMap> load_info_map = |
3636 RunLoadInfoTest(request_info, arraysize(request_info)); | 3626 RunLoadInfoTest(request_info, arraysize(request_info)); |
3637 ASSERT_EQ(1u, load_info_map->size()); | 3627 ASSERT_EQ(1u, load_info_map->size()); |
3638 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); | 3628 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); |
3639 EXPECT_EQ(GURL("test://1/"), (*load_info_map)[kId].url); | 3629 EXPECT_EQ(GURL("test://1/"), (*load_info_map)[kId].url); |
3640 EXPECT_EQ(net::LOAD_STATE_IDLE, (*load_info_map)[kId].load_state.state); | 3630 EXPECT_EQ(net::LOAD_STATE_IDLE, (*load_info_map)[kId].load_state.state); |
3641 EXPECT_EQ(0u, (*load_info_map)[kId].upload_position); | 3631 EXPECT_EQ(0u, (*load_info_map)[kId].upload_position); |
3642 EXPECT_EQ(0u, (*load_info_map)[kId].upload_size); | 3632 EXPECT_EQ(0u, (*load_info_map)[kId].upload_size); |
3643 } | 3633 } |
3644 | 3634 |
3645 // Tests GetLoadInfoForAllRoutes when a request is uploading a body. | 3635 // Tests GetLoadInfoForAllRoutes when a request is uploading a body. |
3646 TEST_P(ResourceDispatcherHostTest, LoadInfoUploadProgress) { | 3636 TEST_P(ResourceDispatcherHostTest, LoadInfoUploadProgress) { |
3647 const GlobalRoutingID kId(filter_->child_id(), 0); | 3637 const GlobalFrameRoutingId kId(filter_->child_id(), 0); |
3648 LoadInfoTestRequestInfo request_info[] = { | 3638 LoadInfoTestRequestInfo request_info[] = { |
3649 {kId.route_id, | 3639 {kId, GURL("test://1/"), net::LOAD_STATE_READING_RESPONSE, |
3650 GURL("test://1/"), | |
3651 net::LOAD_STATE_READING_RESPONSE, | |
3652 net::UploadProgress(0, 0)}, | 3640 net::UploadProgress(0, 0)}, |
3653 {kId.route_id, | 3641 {kId, GURL("test://1/"), net::LOAD_STATE_READING_RESPONSE, |
3654 GURL("test://1/"), | |
3655 net::LOAD_STATE_READING_RESPONSE, | |
3656 net::UploadProgress(1000, 1000)}, | 3642 net::UploadProgress(1000, 1000)}, |
3657 {kId.route_id, | 3643 {kId, GURL("test://2/"), net::LOAD_STATE_SENDING_REQUEST, |
3658 GURL("test://2/"), | |
3659 net::LOAD_STATE_SENDING_REQUEST, | |
3660 net::UploadProgress(50, 100)}, | 3644 net::UploadProgress(50, 100)}, |
3661 {kId.route_id, | 3645 {kId, GURL("test://1/"), net::LOAD_STATE_READING_RESPONSE, |
3662 GURL("test://1/"), | |
3663 net::LOAD_STATE_READING_RESPONSE, | |
3664 net::UploadProgress(1000, 1000)}, | 3646 net::UploadProgress(1000, 1000)}, |
3665 {kId.route_id, | 3647 {kId, GURL("test://3/"), net::LOAD_STATE_READING_RESPONSE, |
3666 GURL("test://3/"), | |
3667 net::LOAD_STATE_READING_RESPONSE, | |
3668 net::UploadProgress(0, 0)}, | 3648 net::UploadProgress(0, 0)}, |
3669 }; | 3649 }; |
3670 std::unique_ptr<LoadInfoMap> load_info_map = | 3650 std::unique_ptr<LoadInfoMap> load_info_map = |
3671 RunLoadInfoTest(request_info, arraysize(request_info)); | 3651 RunLoadInfoTest(request_info, arraysize(request_info)); |
3672 ASSERT_EQ(1u, load_info_map->size()); | 3652 ASSERT_EQ(1u, load_info_map->size()); |
3673 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); | 3653 ASSERT_TRUE(load_info_map->find(kId) != load_info_map->end()); |
3674 EXPECT_EQ(GURL("test://2/"), (*load_info_map)[kId].url); | 3654 EXPECT_EQ(GURL("test://2/"), (*load_info_map)[kId].url); |
3675 EXPECT_EQ(net::LOAD_STATE_SENDING_REQUEST, | 3655 EXPECT_EQ(net::LOAD_STATE_SENDING_REQUEST, |
3676 (*load_info_map)[kId].load_state.state); | 3656 (*load_info_map)[kId].load_state.state); |
3677 EXPECT_EQ(50u, (*load_info_map)[kId].upload_position); | 3657 EXPECT_EQ(50u, (*load_info_map)[kId].upload_position); |
3678 EXPECT_EQ(100u, (*load_info_map)[kId].upload_size); | 3658 EXPECT_EQ(100u, (*load_info_map)[kId].upload_size); |
3679 } | 3659 } |
3680 | 3660 |
3681 // Tests GetLoadInfoForAllRoutes when there are 4 requests from 2 different | 3661 // Tests GetLoadInfoForAllRoutes when there are 4 requests from 2 different |
3682 // RenderViews. Also tests the case where the first / last requests are the | 3662 // RenderViews. Also tests the case where the first / last requests are the |
3683 // most interesting ones. | 3663 // most interesting ones. |
3684 TEST_P(ResourceDispatcherHostTest, LoadInfoTwoRenderViews) { | 3664 TEST_P(ResourceDispatcherHostTest, LoadInfoTwoRenderViews) { |
3685 const GlobalRoutingID kId1(filter_->child_id(), 0); | 3665 const GlobalFrameRoutingId kId1(filter_->child_id(), 0); |
3686 const GlobalRoutingID kId2(filter_->child_id(), 1); | 3666 const GlobalFrameRoutingId kId2(filter_->child_id(), 1); |
3687 LoadInfoTestRequestInfo request_info[] = { | 3667 LoadInfoTestRequestInfo request_info[] = { |
3688 {kId1.route_id, | 3668 {kId1, GURL("test://1/"), net::LOAD_STATE_CONNECTING, |
3689 GURL("test://1/"), | |
3690 net::LOAD_STATE_CONNECTING, | |
3691 net::UploadProgress(0, 0)}, | 3669 net::UploadProgress(0, 0)}, |
3692 {kId2.route_id, | 3670 {kId2, GURL("test://2/"), net::LOAD_STATE_IDLE, |
3693 GURL("test://2/"), | |
3694 net::LOAD_STATE_IDLE, | |
3695 net::UploadProgress(0, 0)}, | 3671 net::UploadProgress(0, 0)}, |
3696 {kId1.route_id, | 3672 {kId1, GURL("test://3/"), net::LOAD_STATE_IDLE, |
3697 GURL("test://3/"), | |
3698 net::LOAD_STATE_IDLE, | |
3699 net::UploadProgress(0, 0)}, | 3673 net::UploadProgress(0, 0)}, |
3700 {kId2.route_id, | 3674 {kId2, GURL("test://4/"), net::LOAD_STATE_CONNECTING, |
3701 GURL("test://4/"), | |
3702 net::LOAD_STATE_CONNECTING, | |
3703 net::UploadProgress(0, 0)}, | 3675 net::UploadProgress(0, 0)}, |
3704 }; | 3676 }; |
3705 std::unique_ptr<LoadInfoMap> load_info_map = | 3677 std::unique_ptr<LoadInfoMap> load_info_map = |
3706 RunLoadInfoTest(request_info, arraysize(request_info)); | 3678 RunLoadInfoTest(request_info, arraysize(request_info)); |
3707 ASSERT_EQ(2u, load_info_map->size()); | 3679 ASSERT_EQ(2u, load_info_map->size()); |
3708 | 3680 |
3709 ASSERT_TRUE(load_info_map->find(kId1) != load_info_map->end()); | 3681 ASSERT_TRUE(load_info_map->find(kId1) != load_info_map->end()); |
3710 EXPECT_EQ(GURL("test://1/"), (*load_info_map)[kId1].url); | 3682 EXPECT_EQ(GURL("test://1/"), (*load_info_map)[kId1].url); |
3711 EXPECT_EQ(net::LOAD_STATE_CONNECTING, | 3683 EXPECT_EQ(net::LOAD_STATE_CONNECTING, |
3712 (*load_info_map)[kId1].load_state.state); | 3684 (*load_info_map)[kId1].load_state.state); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3896 return nullptr; | 3868 return nullptr; |
3897 } | 3869 } |
3898 | 3870 |
3899 INSTANTIATE_TEST_CASE_P( | 3871 INSTANTIATE_TEST_CASE_P( |
3900 ResourceDispatcherHostTests, | 3872 ResourceDispatcherHostTests, |
3901 ResourceDispatcherHostTest, | 3873 ResourceDispatcherHostTest, |
3902 testing::Values(TestConfig::kDefault, | 3874 testing::Values(TestConfig::kDefault, |
3903 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3875 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
3904 | 3876 |
3905 } // namespace content | 3877 } // namespace content |
OLD | NEW |