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 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1486 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[3][0].type()); | 1486 ASSERT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[3][0].type()); |
1487 CheckRequestCompleteErrorCode(msgs[3][1], net::ERR_ABORTED); | 1487 CheckRequestCompleteErrorCode(msgs[3][1], net::ERR_ABORTED); |
1488 | 1488 |
1489 // However, request 4 should have actually gone to completion. (Only request 2 | 1489 // However, request 4 should have actually gone to completion. (Only request 2 |
1490 // was canceled.) | 1490 // was canceled.) |
1491 EXPECT_EQ(4, network_delegate()->completed_requests()); | 1491 EXPECT_EQ(4, network_delegate()->completed_requests()); |
1492 EXPECT_EQ(1, network_delegate()->canceled_requests()); | 1492 EXPECT_EQ(1, network_delegate()->canceled_requests()); |
1493 EXPECT_EQ(0, network_delegate()->error_count()); | 1493 EXPECT_EQ(0, network_delegate()->error_count()); |
1494 } | 1494 } |
1495 | 1495 |
1496 TEST_P(ResourceDispatcherHostTest, DownloadToNetworkCache) { | |
1497 // Normal request. | |
1498 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_2()); | |
1499 | |
1500 // Cache-only request. | |
1501 ResourceRequest request_to_cache = CreateResourceRequest( | |
1502 "GET", RESOURCE_TYPE_IMAGE, net::URLRequestTestJob::test_url_3()); | |
1503 request_to_cache.download_to_network_cache_only = true; | |
1504 ResourceHostMsg_RequestResource msg_to_cache(0, 2, request_to_cache); | |
1505 host_.OnMessageReceived(msg_to_cache, filter_.get()); | |
1506 | |
1507 KickOffRequest(); | |
1508 | |
1509 // The handler for the cache-only request should have been detached now. | |
1510 GlobalRequestID global_request_id(filter_->child_id(), 2); | |
1511 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | |
1512 host_.GetURLRequest(global_request_id)); | |
1513 ASSERT_TRUE(info->detachable_handler()->is_detached()); | |
1514 | |
1515 // Flush all the pending requests. | |
1516 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | |
1517 base::RunLoop().RunUntilIdle(); | |
1518 | |
1519 // Everything should be out now. | |
1520 EXPECT_EQ(0, host_.pending_requests()); | |
1521 | |
1522 ResourceIPCAccumulator::ClassifiedMessages msgs; | |
1523 accum_.GetClassifiedMessages(&msgs); | |
1524 | |
1525 // there are two requests, so we should have gotten them classified as such. | |
mmenke
2016/08/25 19:36:43
nit: Capitalize "There"
| |
1526 ASSERT_EQ(2U, msgs.size()); | |
1527 | |
1528 // The normal request succeeded. | |
1529 CheckSuccessfulRequest(msgs[0], net::URLRequestTestJob::test_data_2()); | |
1530 | |
1531 // The cache-only request got canceled, as far as the renderer is concerned. | |
1532 ASSERT_EQ(1U, msgs[1].size()); | |
1533 CheckRequestCompleteErrorCode(msgs[1][0], net::ERR_ABORTED); | |
1534 | |
1535 // However, all requests should have actually gone to completion. | |
1536 EXPECT_EQ(2, network_delegate()->completed_requests()); | |
1537 EXPECT_EQ(0, network_delegate()->canceled_requests()); | |
1538 EXPECT_EQ(0, network_delegate()->error_count()); | |
1539 } | |
1540 | |
1496 // Shows that detachable requests will timeout if the request takes too long to | 1541 // Shows that detachable requests will timeout if the request takes too long to |
1497 // complete. | 1542 // complete. |
1498 TEST_P(ResourceDispatcherHostTest, DetachedResourceTimesOut) { | 1543 TEST_P(ResourceDispatcherHostTest, DetachedResourceTimesOut) { |
1499 MakeTestRequestWithResourceType(filter_.get(), 0, 1, | 1544 MakeTestRequestWithResourceType(filter_.get(), 0, 1, |
1500 net::URLRequestTestJob::test_url_2(), | 1545 net::URLRequestTestJob::test_url_2(), |
1501 RESOURCE_TYPE_PREFETCH); // detachable type | 1546 RESOURCE_TYPE_PREFETCH); // detachable type |
1502 GlobalRequestID global_request_id(filter_->child_id(), 1); | 1547 GlobalRequestID global_request_id(filter_->child_id(), 1); |
1503 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( | 1548 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest( |
1504 host_.GetURLRequest(global_request_id)); | 1549 host_.GetURLRequest(global_request_id)); |
1505 ASSERT_TRUE(info->detachable_handler()); | 1550 ASSERT_TRUE(info->detachable_handler()); |
(...skipping 2317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3823 return nullptr; | 3868 return nullptr; |
3824 } | 3869 } |
3825 | 3870 |
3826 INSTANTIATE_TEST_CASE_P( | 3871 INSTANTIATE_TEST_CASE_P( |
3827 ResourceDispatcherHostTests, | 3872 ResourceDispatcherHostTests, |
3828 ResourceDispatcherHostTest, | 3873 ResourceDispatcherHostTest, |
3829 testing::Values(TestConfig::kDefault, | 3874 testing::Values(TestConfig::kDefault, |
3830 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3875 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
3831 | 3876 |
3832 } // namespace content | 3877 } // namespace content |
OLD | NEW |