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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 | 939 |
940 // Generates a request using the given filter and resource type. | 940 // Generates a request using the given filter and resource type. |
941 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, | 941 void MakeTestRequestWithResourceType(ResourceMessageFilter* filter, |
942 int render_view_id, | 942 int render_view_id, |
943 int request_id, | 943 int request_id, |
944 const GURL& url, | 944 const GURL& url, |
945 ResourceType type); | 945 ResourceType type); |
946 | 946 |
947 void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url); | 947 void MakeWebContentsAssociatedTestRequest(int request_id, const GURL& url); |
948 | 948 |
| 949 void MakeTestFetchRequestWithRedirectMode( |
| 950 int render_view_id, |
| 951 int request_id, |
| 952 const GURL& url, |
| 953 FetchRedirectMode fetch_redirect_mode); |
| 954 |
949 void CancelRequest(int request_id); | 955 void CancelRequest(int request_id); |
950 void RendererCancelRequest(int request_id) { | 956 void RendererCancelRequest(int request_id) { |
951 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); | 957 ResourceMessageFilter* old_filter = SetFilter(filter_.get()); |
952 host_.OnCancelRequest(request_id); | 958 host_.OnCancelRequest(request_id); |
953 SetFilter(old_filter); | 959 SetFilter(old_filter); |
954 } | 960 } |
955 | 961 |
956 void CompleteStartRequest(int request_id); | 962 void CompleteStartRequest(int request_id); |
957 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); | 963 void CompleteStartRequest(ResourceMessageFilter* filter, int request_id); |
958 | 964 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 ResourceHostMsg_Request request = | 1071 ResourceHostMsg_Request request = |
1066 CreateResourceRequest("GET", RESOURCE_TYPE_SUB_RESOURCE, url); | 1072 CreateResourceRequest("GET", RESOURCE_TYPE_SUB_RESOURCE, url); |
1067 request.origin_pid = web_contents_->GetRenderProcessHost()->GetID(); | 1073 request.origin_pid = web_contents_->GetRenderProcessHost()->GetID(); |
1068 request.render_frame_id = web_contents_->GetMainFrame()->GetRoutingID(); | 1074 request.render_frame_id = web_contents_->GetMainFrame()->GetRoutingID(); |
1069 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id, | 1075 ResourceHostMsg_RequestResource msg(web_contents_->GetRoutingID(), request_id, |
1070 request); | 1076 request); |
1071 host_.OnMessageReceived(msg, web_contents_filter_.get()); | 1077 host_.OnMessageReceived(msg, web_contents_filter_.get()); |
1072 KickOffRequest(); | 1078 KickOffRequest(); |
1073 } | 1079 } |
1074 | 1080 |
| 1081 void ResourceDispatcherHostTest::MakeTestFetchRequestWithRedirectMode( |
| 1082 int render_view_id, |
| 1083 int request_id, |
| 1084 const GURL& url, |
| 1085 FetchRedirectMode fetch_redirect_mode) { |
| 1086 ResourceHostMsg_Request request = |
| 1087 CreateResourceRequest("GET", RESOURCE_TYPE_SUB_RESOURCE, url); |
| 1088 request.fetch_redirect_mode = fetch_redirect_mode; |
| 1089 ResourceHostMsg_RequestResource msg(render_view_id, request_id, request); |
| 1090 host_.OnMessageReceived(msg, filter_.get()); |
| 1091 KickOffRequest(); |
| 1092 } |
| 1093 |
1075 void ResourceDispatcherHostTest::CancelRequest(int request_id) { | 1094 void ResourceDispatcherHostTest::CancelRequest(int request_id) { |
1076 host_.CancelRequest(filter_->child_id(), request_id); | 1095 host_.CancelRequest(filter_->child_id(), request_id); |
1077 } | 1096 } |
1078 | 1097 |
1079 void ResourceDispatcherHostTest::CompleteStartRequest(int request_id) { | 1098 void ResourceDispatcherHostTest::CompleteStartRequest(int request_id) { |
1080 CompleteStartRequest(filter_.get(), request_id); | 1099 CompleteStartRequest(filter_.get(), request_id); |
1081 } | 1100 } |
1082 | 1101 |
1083 void ResourceDispatcherHostTest::CompleteStartRequest( | 1102 void ResourceDispatcherHostTest::CompleteStartRequest( |
1084 ResourceMessageFilter* filter, | 1103 ResourceMessageFilter* filter, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 const std::string& reference_data) { | 1195 const std::string& reference_data) { |
1177 ASSERT_EQ(5U, messages.size()); | 1196 ASSERT_EQ(5U, messages.size()); |
1178 ASSERT_EQ(ResourceMsg_ReceivedRedirect::ID, messages[0].type()); | 1197 ASSERT_EQ(ResourceMsg_ReceivedRedirect::ID, messages[0].type()); |
1179 | 1198 |
1180 const std::vector<IPC::Message> second_req_msgs = | 1199 const std::vector<IPC::Message> second_req_msgs = |
1181 std::vector<IPC::Message>(messages.begin() + 1, messages.end()); | 1200 std::vector<IPC::Message>(messages.begin() + 1, messages.end()); |
1182 CheckSuccessfulRequest(second_req_msgs, reference_data); | 1201 CheckSuccessfulRequest(second_req_msgs, reference_data); |
1183 } | 1202 } |
1184 | 1203 |
1185 void CheckFailedRequest(const std::vector<IPC::Message>& messages, | 1204 void CheckFailedRequest(const std::vector<IPC::Message>& messages, |
1186 const std::string& reference_data, | |
1187 int expected_error) { | 1205 int expected_error) { |
1188 ASSERT_LT(0U, messages.size()); | 1206 ASSERT_LT(0U, messages.size()); |
1189 ASSERT_GE(2U, messages.size()); | 1207 ASSERT_GE(2U, messages.size()); |
1190 size_t failure_index = messages.size() - 1; | 1208 size_t failure_index = messages.size() - 1; |
1191 | 1209 |
1192 if (messages.size() == 2) { | 1210 if (messages.size() == 2) { |
1193 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); | 1211 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); |
1194 } | 1212 } |
1195 | 1213 |
1196 CheckRequestCompleteErrorCode(messages[failure_index], expected_error); | 1214 CheckRequestCompleteErrorCode(messages[failure_index], expected_error); |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 | 2030 |
2013 // Check that the first kMaxRequests succeeded. | 2031 // Check that the first kMaxRequests succeeded. |
2014 for (size_t i = 0; i < kMaxRequests; ++i) | 2032 for (size_t i = 0; i < kMaxRequests; ++i) |
2015 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2()); | 2033 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2()); |
2016 | 2034 |
2017 // Check that the subsequent two requests (kMaxRequests + 1) and | 2035 // Check that the subsequent two requests (kMaxRequests + 1) and |
2018 // (kMaxRequests + 2) were failed, since the per-process bound was reached. | 2036 // (kMaxRequests + 2) were failed, since the per-process bound was reached. |
2019 for (int i = 0; i < 2; ++i) { | 2037 for (int i = 0; i < 2; ++i) { |
2020 // Should have sent a single RequestComplete message. | 2038 // Should have sent a single RequestComplete message. |
2021 int index = kMaxRequests + i; | 2039 int index = kMaxRequests + i; |
2022 CheckFailedRequest(msgs[index], net::URLRequestTestJob::test_data_2(), | 2040 CheckFailedRequest(msgs[index], net::ERR_INSUFFICIENT_RESOURCES); |
2023 net::ERR_INSUFFICIENT_RESOURCES); | |
2024 } | 2041 } |
2025 | 2042 |
2026 // The final 2 requests should have succeeded. | 2043 // The final 2 requests should have succeeded. |
2027 CheckSuccessfulRequest(msgs[kMaxRequests + 2], | 2044 CheckSuccessfulRequest(msgs[kMaxRequests + 2], |
2028 net::URLRequestTestJob::test_data_2()); | 2045 net::URLRequestTestJob::test_data_2()); |
2029 CheckSuccessfulRequest(msgs[kMaxRequests + 3], | 2046 CheckSuccessfulRequest(msgs[kMaxRequests + 3], |
2030 net::URLRequestTestJob::test_data_2()); | 2047 net::URLRequestTestJob::test_data_2()); |
2031 } | 2048 } |
2032 | 2049 |
2033 // Test that when too many requests are outstanding for a particular | 2050 // Test that when too many requests are outstanding for a particular |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2079 // The processes issued the following requests: | 2096 // The processes issued the following requests: |
2080 // #1 issued kMaxRequestsPerProcess that passed + 1 that failed | 2097 // #1 issued kMaxRequestsPerProcess that passed + 1 that failed |
2081 // #2 issued 1 request that passed | 2098 // #2 issued 1 request that passed |
2082 // #3 issued 1 request that failed | 2099 // #3 issued 1 request that failed |
2083 ASSERT_EQ((kMaxRequestsPerProcess + 1) + 1 + 1, msgs.size()); | 2100 ASSERT_EQ((kMaxRequestsPerProcess + 1) + 1 + 1, msgs.size()); |
2084 | 2101 |
2085 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) | 2102 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) |
2086 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2()); | 2103 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2()); |
2087 | 2104 |
2088 CheckFailedRequest(msgs[kMaxRequestsPerProcess + 0], | 2105 CheckFailedRequest(msgs[kMaxRequestsPerProcess + 0], |
2089 net::URLRequestTestJob::test_data_2(), | |
2090 net::ERR_INSUFFICIENT_RESOURCES); | 2106 net::ERR_INSUFFICIENT_RESOURCES); |
2091 CheckSuccessfulRequest(msgs[kMaxRequestsPerProcess + 1], | 2107 CheckSuccessfulRequest(msgs[kMaxRequestsPerProcess + 1], |
2092 net::URLRequestTestJob::test_data_2()); | 2108 net::URLRequestTestJob::test_data_2()); |
2093 CheckFailedRequest(msgs[kMaxRequestsPerProcess + 2], | 2109 CheckFailedRequest(msgs[kMaxRequestsPerProcess + 2], |
2094 net::URLRequestTestJob::test_data_2(), | |
2095 net::ERR_INSUFFICIENT_RESOURCES); | 2110 net::ERR_INSUFFICIENT_RESOURCES); |
2096 } | 2111 } |
2097 | 2112 |
2098 // Tests that we sniff the mime type for a simple request. | 2113 // Tests that we sniff the mime type for a simple request. |
2099 TEST_F(ResourceDispatcherHostTest, MimeSniffed) { | 2114 TEST_F(ResourceDispatcherHostTest, MimeSniffed) { |
2100 std::string raw_headers("HTTP/1.1 200 OK\n\n"); | 2115 std::string raw_headers("HTTP/1.1 200 OK\n\n"); |
2101 std::string response_data("<html><title>Test One</title></html>"); | 2116 std::string response_data("<html><title>Test One</title></html>"); |
2102 SetResponse(raw_headers, response_data); | 2117 SetResponse(raw_headers, response_data); |
2103 | 2118 |
2104 HandleScheme("http"); | 2119 HandleScheme("http"); |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3322 int initial_count = web_contents_observer_->resource_request_redirect_count(); | 3337 int initial_count = web_contents_observer_->resource_request_redirect_count(); |
3323 | 3338 |
3324 MakeWebContentsAssociatedTestRequest( | 3339 MakeWebContentsAssociatedTestRequest( |
3325 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); | 3340 1, net::URLRequestTestJob::test_url_redirect_to_url_2()); |
3326 base::MessageLoop::current()->RunUntilIdle(); | 3341 base::MessageLoop::current()->RunUntilIdle(); |
3327 | 3342 |
3328 EXPECT_EQ(initial_count + 1, | 3343 EXPECT_EQ(initial_count + 1, |
3329 web_contents_observer_->resource_request_redirect_count()); | 3344 web_contents_observer_->resource_request_redirect_count()); |
3330 } | 3345 } |
3331 | 3346 |
| 3347 // Confirm that the redirect response is handled as an error when the request's |
| 3348 // redirect mode is "error". |
| 3349 TEST_F(ResourceDispatcherHostTest, FetchRedirectModeError) { |
| 3350 MakeTestFetchRequestWithRedirectMode( |
| 3351 0, 1, net::URLRequestTestJob::test_url_redirect_to_url_2(), |
| 3352 FETCH_REDIRECT_MODE_ERROR); |
| 3353 |
| 3354 // flush all the pending requests |
| 3355 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 3356 base::MessageLoop::current()->RunUntilIdle(); |
| 3357 |
| 3358 // sorts out all the messages we saw by request |
| 3359 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 3360 accum_.GetClassifiedMessages(&msgs); |
| 3361 |
| 3362 ASSERT_EQ(1U, msgs.size()); |
| 3363 CheckFailedRequest(msgs[0], net::ERR_ABORTED); |
| 3364 } |
| 3365 |
| 3366 // Confirm that the redirect response is not followed when the request's |
| 3367 // redirect mode is "manual". |
| 3368 TEST_F(ResourceDispatcherHostTest, FetchRedirectModeManual) { |
| 3369 MakeTestFetchRequestWithRedirectMode( |
| 3370 0, 1, net::URLRequestTestJob::test_url_redirect_to_url_2(), |
| 3371 FETCH_REDIRECT_MODE_MANUAL); |
| 3372 |
| 3373 // flush all the pending requests |
| 3374 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 3375 base::MessageLoop::current()->RunUntilIdle(); |
| 3376 |
| 3377 // sorts out all the messages we saw by request |
| 3378 ResourceIPCAccumulator::ClassifiedMessages msgs; |
| 3379 accum_.GetClassifiedMessages(&msgs); |
| 3380 |
| 3381 ASSERT_EQ(1U, msgs.size()); |
| 3382 ASSERT_EQ(2U, msgs[0].size()); |
| 3383 ResourceResponseHead response_head; |
| 3384 GetResponseHead(msgs[0], &response_head); |
| 3385 ASSERT_TRUE(response_head.headers); |
| 3386 ASSERT_EQ(302, response_head.headers->response_code()); |
| 3387 CheckRequestCompleteErrorCode(msgs[0][1], net::OK); |
| 3388 } |
| 3389 |
3332 net::URLRequestJob* TestURLRequestJobFactory::MaybeCreateJobWithProtocolHandler( | 3390 net::URLRequestJob* TestURLRequestJobFactory::MaybeCreateJobWithProtocolHandler( |
3333 const std::string& scheme, | 3391 const std::string& scheme, |
3334 net::URLRequest* request, | 3392 net::URLRequest* request, |
3335 net::NetworkDelegate* network_delegate) const { | 3393 net::NetworkDelegate* network_delegate) const { |
3336 url_request_jobs_created_count_++; | 3394 url_request_jobs_created_count_++; |
3337 if (test_fixture_->wait_for_request_create_loop_) | 3395 if (test_fixture_->wait_for_request_create_loop_) |
3338 test_fixture_->wait_for_request_create_loop_->Quit(); | 3396 test_fixture_->wait_for_request_create_loop_->Quit(); |
3339 if (test_fixture_->loader_test_request_info_) { | 3397 if (test_fixture_->loader_test_request_info_) { |
3340 DCHECK_EQ(test_fixture_->loader_test_request_info_->url, request->url()); | 3398 DCHECK_EQ(test_fixture_->loader_test_request_info_->url, request->url()); |
3341 scoped_ptr<LoadInfoTestRequestInfo> info = | 3399 scoped_ptr<LoadInfoTestRequestInfo> info = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3383 return nullptr; | 3441 return nullptr; |
3384 } | 3442 } |
3385 | 3443 |
3386 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( | 3444 net::URLRequestJob* TestURLRequestJobFactory::MaybeInterceptResponse( |
3387 net::URLRequest* request, | 3445 net::URLRequest* request, |
3388 net::NetworkDelegate* network_delegate) const { | 3446 net::NetworkDelegate* network_delegate) const { |
3389 return nullptr; | 3447 return nullptr; |
3390 } | 3448 } |
3391 | 3449 |
3392 } // namespace content | 3450 } // namespace content |
OLD | NEW |