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

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

Powered by Google App Engine
This is Rietveld 408576698