Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_unittest.cc

Issue 1903133004: Report invalid URLs as ERR_INVALID_URL rather than ERR_ABORTED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility> 6 #include <utility>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 const std::string& reference_data) { 1420 const std::string& reference_data) {
1421 ASSERT_EQ(5U, messages.size()); 1421 ASSERT_EQ(5U, messages.size());
1422 ASSERT_EQ(ResourceMsg_ReceivedRedirect::ID, messages[0].type()); 1422 ASSERT_EQ(ResourceMsg_ReceivedRedirect::ID, messages[0].type());
1423 1423
1424 const std::vector<IPC::Message> second_req_msgs = 1424 const std::vector<IPC::Message> second_req_msgs =
1425 std::vector<IPC::Message>(messages.begin() + 1, messages.end()); 1425 std::vector<IPC::Message>(messages.begin() + 1, messages.end());
1426 CheckSuccessfulRequest(second_req_msgs, reference_data); 1426 CheckSuccessfulRequest(second_req_msgs, reference_data);
1427 } 1427 }
1428 1428
1429 void CheckFailedRequest(const std::vector<IPC::Message>& messages, 1429 void CheckFailedRequest(const std::vector<IPC::Message>& messages,
1430 const std::string& reference_data,
1431 int expected_error) { 1430 int expected_error) {
1432 ASSERT_LT(0U, messages.size()); 1431 ASSERT_LT(0U, messages.size());
1433 ASSERT_GE(2U, messages.size()); 1432 ASSERT_GE(2U, messages.size());
1434 size_t failure_index = messages.size() - 1; 1433 size_t failure_index = messages.size() - 1;
1435 1434
1436 if (messages.size() == 2) { 1435 if (messages.size() == 2) {
1437 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type()); 1436 EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, messages[0].type());
1438 } 1437 }
1439 1438
1440 CheckRequestCompleteErrorCode(messages[failure_index], expected_error); 1439 CheckRequestCompleteErrorCode(messages[failure_index], expected_error);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[3][0].type()); 1519 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[3][0].type());
1521 CheckRequestCompleteErrorCode(msgs[3][1], net::ERR_ABORTED); 1520 CheckRequestCompleteErrorCode(msgs[3][1], net::ERR_ABORTED);
1522 1521
1523 // However, request 4 should have actually gone to completion. (Only request 2 1522 // However, request 4 should have actually gone to completion. (Only request 2
1524 // was canceled.) 1523 // was canceled.)
1525 EXPECT_EQ(4, network_delegate()->completed_requests()); 1524 EXPECT_EQ(4, network_delegate()->completed_requests());
1526 EXPECT_EQ(1, network_delegate()->canceled_requests()); 1525 EXPECT_EQ(1, network_delegate()->canceled_requests());
1527 EXPECT_EQ(0, network_delegate()->error_count()); 1526 EXPECT_EQ(0, network_delegate()->error_count());
1528 } 1527 }
1529 1528
1529 // Tests that invalid URLs fail with net::ERR_INVALID_URL.
1530 TEST_P(ResourceDispatcherHostTest, InvalidURL) {
1531 MakeTestRequest(0, 1, GURL("https:///"));
1532
1533 // Sort out all the messages we saw by request.
1534 ResourceIPCAccumulator::ClassifiedMessages msgs;
1535 accum_.GetClassifiedMessages(&msgs);
1536
1537 ASSERT_EQ(1U, msgs.size());
1538 CheckFailedRequest(msgs[0], net::ERR_INVALID_URL);
1539 }
1540
1541 // Tests that redirects to invalid URLs fail with net::ERR_INVALID_URL.
1542 TEST_P(ResourceDispatcherHostTest, InvalidURLRedirect) {
1543 static const char kHeaders[] =
1544 "HTTP/1.1 302 Moved\n"
1545 "Location: http:///\n"
1546 "\n";
1547 SetResponse(kHeaders);
1548 HandleScheme("http");
1549
1550 MakeTestRequest(0, 1, GURL("http://example.com"));
1551
1552 // Finish the redirect.
1553 ResourceHostMsg_FollowRedirect redirect_msg(1);
1554 host_.OnMessageReceived(redirect_msg, filter_.get());
1555 base::MessageLoop::current()->RunUntilIdle();
1556
1557 // Sort out all the messages we saw by request.
1558 ResourceIPCAccumulator::ClassifiedMessages msgs;
1559 accum_.GetClassifiedMessages(&msgs);
1560
1561 ASSERT_EQ(1U, msgs.size());
1562 CheckFailedRequest(msgs[0], net::ERR_INVALID_URL);
1563 }
1564
1530 // Shows that detachable requests will timeout if the request takes too long to 1565 // Shows that detachable requests will timeout if the request takes too long to
1531 // complete. 1566 // complete.
1532 TEST_P(ResourceDispatcherHostTest, DetachedResourceTimesOut) { 1567 TEST_P(ResourceDispatcherHostTest, DetachedResourceTimesOut) {
1533 MakeTestRequestWithResourceType(filter_.get(), 0, 1, 1568 MakeTestRequestWithResourceType(filter_.get(), 0, 1,
1534 net::URLRequestTestJob::test_url_2(), 1569 net::URLRequestTestJob::test_url_2(),
1535 RESOURCE_TYPE_PREFETCH); // detachable type 1570 RESOURCE_TYPE_PREFETCH); // detachable type
1536 GlobalRequestID global_request_id(filter_->child_id(), 1); 1571 GlobalRequestID global_request_id(filter_->child_id(), 1);
1537 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( 1572 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(
1538 host_.GetURLRequest(global_request_id)); 1573 host_.GetURLRequest(global_request_id));
1539 ASSERT_TRUE(info->detachable_handler()); 1574 ASSERT_TRUE(info->detachable_handler());
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 2358
2324 // Check that the first kMaxRequests succeeded. 2359 // Check that the first kMaxRequests succeeded.
2325 for (size_t i = 0; i < kMaxRequests; ++i) 2360 for (size_t i = 0; i < kMaxRequests; ++i)
2326 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2()); 2361 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2());
2327 2362
2328 // Check that the subsequent two requests (kMaxRequests + 1) and 2363 // Check that the subsequent two requests (kMaxRequests + 1) and
2329 // (kMaxRequests + 2) were failed, since the per-process bound was reached. 2364 // (kMaxRequests + 2) were failed, since the per-process bound was reached.
2330 for (int i = 0; i < 2; ++i) { 2365 for (int i = 0; i < 2; ++i) {
2331 // Should have sent a single RequestComplete message. 2366 // Should have sent a single RequestComplete message.
2332 int index = kMaxRequests + i; 2367 int index = kMaxRequests + i;
2333 CheckFailedRequest(msgs[index], net::URLRequestTestJob::test_data_2(), 2368 CheckFailedRequest(msgs[index], net::ERR_INSUFFICIENT_RESOURCES);
2334 net::ERR_INSUFFICIENT_RESOURCES);
2335 } 2369 }
2336 2370
2337 // The final 2 requests should have succeeded. 2371 // The final 2 requests should have succeeded.
2338 CheckSuccessfulRequest(msgs[kMaxRequests + 2], 2372 CheckSuccessfulRequest(msgs[kMaxRequests + 2],
2339 net::URLRequestTestJob::test_data_2()); 2373 net::URLRequestTestJob::test_data_2());
2340 CheckSuccessfulRequest(msgs[kMaxRequests + 3], 2374 CheckSuccessfulRequest(msgs[kMaxRequests + 3],
2341 net::URLRequestTestJob::test_data_2()); 2375 net::URLRequestTestJob::test_data_2());
2342 } 2376 }
2343 2377
2344 // Test that when too many requests are outstanding for a particular 2378 // Test that when too many requests are outstanding for a particular
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 // The processes issued the following requests: 2424 // The processes issued the following requests:
2391 // #1 issued kMaxRequestsPerProcess that passed + 1 that failed 2425 // #1 issued kMaxRequestsPerProcess that passed + 1 that failed
2392 // #2 issued 1 request that passed 2426 // #2 issued 1 request that passed
2393 // #3 issued 1 request that failed 2427 // #3 issued 1 request that failed
2394 ASSERT_EQ((kMaxRequestsPerProcess + 1) + 1 + 1, msgs.size()); 2428 ASSERT_EQ((kMaxRequestsPerProcess + 1) + 1 + 1, msgs.size());
2395 2429
2396 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i) 2430 for (size_t i = 0; i < kMaxRequestsPerProcess; ++i)
2397 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2()); 2431 CheckSuccessfulRequest(msgs[i], net::URLRequestTestJob::test_data_2());
2398 2432
2399 CheckFailedRequest(msgs[kMaxRequestsPerProcess + 0], 2433 CheckFailedRequest(msgs[kMaxRequestsPerProcess + 0],
2400 net::URLRequestTestJob::test_data_2(),
2401 net::ERR_INSUFFICIENT_RESOURCES); 2434 net::ERR_INSUFFICIENT_RESOURCES);
2402 CheckSuccessfulRequest(msgs[kMaxRequestsPerProcess + 1], 2435 CheckSuccessfulRequest(msgs[kMaxRequestsPerProcess + 1],
2403 net::URLRequestTestJob::test_data_2()); 2436 net::URLRequestTestJob::test_data_2());
2404 CheckFailedRequest(msgs[kMaxRequestsPerProcess + 2], 2437 CheckFailedRequest(msgs[kMaxRequestsPerProcess + 2],
2405 net::URLRequestTestJob::test_data_2(),
2406 net::ERR_INSUFFICIENT_RESOURCES); 2438 net::ERR_INSUFFICIENT_RESOURCES);
2407 } 2439 }
2408 2440
2409 // Tests that we sniff the mime type for a simple request. 2441 // Tests that we sniff the mime type for a simple request.
2410 TEST_P(ResourceDispatcherHostTest, MimeSniffed) { 2442 TEST_P(ResourceDispatcherHostTest, MimeSniffed) {
2411 std::string raw_headers("HTTP/1.1 200 OK\n\n"); 2443 std::string raw_headers("HTTP/1.1 200 OK\n\n");
2412 std::string response_data("<html><title>Test One</title></html>"); 2444 std::string response_data("<html><title>Test One</title></html>");
2413 SetResponse(raw_headers, response_data); 2445 SetResponse(raw_headers, response_data);
2414 2446
2415 HandleScheme("http"); 2447 HandleScheme("http");
(...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after
3898 return nullptr; 3930 return nullptr;
3899 } 3931 }
3900 3932
3901 INSTANTIATE_TEST_CASE_P( 3933 INSTANTIATE_TEST_CASE_P(
3902 ResourceDispatcherHostTests, 3934 ResourceDispatcherHostTests,
3903 ResourceDispatcherHostTest, 3935 ResourceDispatcherHostTest,
3904 testing::Values(TestConfig::kDefault, 3936 testing::Values(TestConfig::kDefault,
3905 TestConfig::kOptimizeIPCForSmallResourceEnabled)); 3937 TestConfig::kOptimizeIPCForSmallResourceEnabled));
3906 3938
3907 } // namespace content 3939 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698