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 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | 43 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
44 #include "net/tools/quic/test_tools/quic_server_peer.h" | 44 #include "net/tools/quic/test_tools/quic_server_peer.h" |
45 #include "net/tools/quic/test_tools/quic_test_client.h" | 45 #include "net/tools/quic/test_tools/quic_test_client.h" |
46 #include "net/tools/quic/test_tools/server_thread.h" | 46 #include "net/tools/quic/test_tools/server_thread.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
48 | 48 |
49 using base::StringPiece; | 49 using base::StringPiece; |
50 using base::WaitableEvent; | 50 using base::WaitableEvent; |
51 using net::EpollServer; | 51 using net::EpollServer; |
52 using net::test::GenerateBody; | 52 using net::test::GenerateBody; |
| 53 using net::test::MockQuicConnectionDebugVisitor; |
53 using net::test::QuicConnectionPeer; | 54 using net::test::QuicConnectionPeer; |
54 using net::test::QuicFlowControllerPeer; | 55 using net::test::QuicFlowControllerPeer; |
55 using net::test::QuicSentPacketManagerPeer; | 56 using net::test::QuicSentPacketManagerPeer; |
56 using net::test::QuicSessionPeer; | 57 using net::test::QuicSessionPeer; |
57 using net::test::ReliableQuicStreamPeer; | 58 using net::test::ReliableQuicStreamPeer; |
58 using net::test::ValueRestore; | 59 using net::test::ValueRestore; |
59 using net::test::kClientDataStreamId1; | 60 using net::test::kClientDataStreamId1; |
60 using net::tools::test::PacketDroppingTestWriter; | 61 using net::tools::test::PacketDroppingTestWriter; |
61 using net::tools::test::QuicDispatcherPeer; | 62 using net::tools::test::QuicDispatcherPeer; |
62 using net::tools::test::QuicServerPeer; | 63 using net::tools::test::QuicServerPeer; |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 // Regression test for b/14677858. | 734 // Regression test for b/14677858. |
734 // Test that the resume write alarm is not set in QuicConnection::OnCanWrite | 735 // Test that the resume write alarm is not set in QuicConnection::OnCanWrite |
735 // if currently connection level flow control blocked. If set, this results in | 736 // if currently connection level flow control blocked. If set, this results in |
736 // an infinite loop in the EpollServer, as the alarm fires and is immediately | 737 // an infinite loop in the EpollServer, as the alarm fires and is immediately |
737 // rescheduled. | 738 // rescheduled. |
738 ASSERT_TRUE(Initialize()); | 739 ASSERT_TRUE(Initialize()); |
739 client_->client()->WaitForCryptoHandshakeConfirmed(); | 740 client_->client()->WaitForCryptoHandshakeConfirmed(); |
740 | 741 |
741 // Ensure both stream and connection level are flow control blocked by setting | 742 // Ensure both stream and connection level are flow control blocked by setting |
742 // the send window offset to 0. | 743 // the send window offset to 0. |
743 const uint64 kFlowControlWindow = | 744 const uint64 flow_control_window = |
744 server_config_.GetInitialStreamFlowControlWindowToSend(); | 745 server_config_.GetInitialStreamFlowControlWindowToSend(); |
745 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); | 746 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); |
746 QuicSession* session = client_->client()->session(); | 747 QuicSession* session = client_->client()->session(); |
747 QuicFlowControllerPeer::SetSendWindowOffset(stream->flow_controller(), 0); | 748 QuicFlowControllerPeer::SetSendWindowOffset(stream->flow_controller(), 0); |
748 QuicFlowControllerPeer::SetSendWindowOffset(session->flow_controller(), 0); | 749 QuicFlowControllerPeer::SetSendWindowOffset(session->flow_controller(), 0); |
749 EXPECT_TRUE(stream->flow_controller()->IsBlocked()); | 750 EXPECT_TRUE(stream->flow_controller()->IsBlocked()); |
750 EXPECT_TRUE(session->flow_controller()->IsBlocked()); | 751 EXPECT_TRUE(session->flow_controller()->IsBlocked()); |
751 | 752 |
752 // Make sure that the stream has data pending so that it will be marked as | 753 // Make sure that the stream has data pending so that it will be marked as |
753 // write blocked when it receives a stream level WINDOW_UPDATE. | 754 // write blocked when it receives a stream level WINDOW_UPDATE. |
754 stream->SendBody("hello", false); | 755 stream->SendBody("hello", false); |
755 | 756 |
756 // The stream now attempts to write, fails because it is still connection | 757 // The stream now attempts to write, fails because it is still connection |
757 // level flow control blocked, and is added to the write blocked list. | 758 // level flow control blocked, and is added to the write blocked list. |
758 QuicWindowUpdateFrame window_update(stream->id(), 2 * kFlowControlWindow); | 759 QuicWindowUpdateFrame window_update(stream->id(), 2 * flow_control_window); |
759 stream->OnWindowUpdateFrame(window_update); | 760 stream->OnWindowUpdateFrame(window_update); |
760 | 761 |
761 // Prior to fixing b/14677858 this call would result in an infinite loop in | 762 // Prior to fixing b/14677858 this call would result in an infinite loop in |
762 // Chromium. As a proxy for detecting this, we now check whether the | 763 // Chromium. As a proxy for detecting this, we now check whether the |
763 // resume_writes_alarm is set after OnCanWrite. It should not be, as the | 764 // resume_writes_alarm is set after OnCanWrite. It should not be, as the |
764 // connection is still flow control blocked. | 765 // connection is still flow control blocked. |
765 session->connection()->OnCanWrite(); | 766 session->connection()->OnCanWrite(); |
766 | 767 |
767 QuicAlarm* resume_writes_alarm = | 768 QuicAlarm* resume_writes_alarm = |
768 QuicConnectionPeer::GetResumeWritesAlarm(session->connection()); | 769 QuicConnectionPeer::GetResumeWritesAlarm(session->connection()); |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 // Pause the server to avoid races. | 1390 // Pause the server to avoid races. |
1390 server_thread_->Pause(); | 1391 server_thread_->Pause(); |
1391 // Make sure the delegate does get the notification it expects. | 1392 // Make sure the delegate does get the notification it expects. |
1392 while (!delegate->has_been_notified()) { | 1393 while (!delegate->has_been_notified()) { |
1393 // Waits for up to 50 ms. | 1394 // Waits for up to 50 ms. |
1394 client_->client()->WaitForEvents(); | 1395 client_->client()->WaitForEvents(); |
1395 } | 1396 } |
1396 server_thread_->Resume(); | 1397 server_thread_->Resume(); |
1397 } | 1398 } |
1398 | 1399 |
| 1400 // Send a public reset from the server for a different connection ID. |
| 1401 // It should be ignored. |
| 1402 TEST_P(EndToEndTest, ServerSendPublicResetWithDifferentConnectionId) { |
| 1403 ASSERT_TRUE(Initialize()); |
| 1404 |
| 1405 // Send the public reset. |
| 1406 QuicConnectionId incorrect_connection_id = |
| 1407 client_->client()->session()->connection()->connection_id() + 1; |
| 1408 QuicPublicResetPacket header; |
| 1409 header.public_header.connection_id = incorrect_connection_id; |
| 1410 header.public_header.reset_flag = true; |
| 1411 header.public_header.version_flag = false; |
| 1412 header.rejected_sequence_number = 10101; |
| 1413 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), |
| 1414 Perspective::IS_SERVER); |
| 1415 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); |
| 1416 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; |
| 1417 client_->client()->session()->connection()->set_debug_visitor(&visitor); |
| 1418 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) |
| 1419 .Times(1); |
| 1420 server_writer_->WritePacket(packet->data(), packet->length(), |
| 1421 server_address_.address(), |
| 1422 client_->client()->client_address()); |
| 1423 |
| 1424 // The connection should be unaffected. |
| 1425 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1426 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1427 |
| 1428 client_->client()->session()->connection()->set_debug_visitor(nullptr); |
| 1429 } |
| 1430 |
| 1431 // Send a public reset from the client for a different connection ID. |
| 1432 // It should be ignored. |
| 1433 TEST_P(EndToEndTest, ClientSendPublicResetWithDifferentConnectionId) { |
| 1434 ASSERT_TRUE(Initialize()); |
| 1435 |
| 1436 // Send the public reset. |
| 1437 QuicConnectionId incorrect_connection_id = |
| 1438 client_->client()->session()->connection()->connection_id() + 1; |
| 1439 QuicPublicResetPacket header; |
| 1440 header.public_header.connection_id = incorrect_connection_id; |
| 1441 header.public_header.reset_flag = true; |
| 1442 header.public_header.version_flag = false; |
| 1443 header.rejected_sequence_number = 10101; |
| 1444 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), |
| 1445 Perspective::IS_CLIENT); |
| 1446 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); |
| 1447 client_writer_->WritePacket(packet->data(), packet->length(), |
| 1448 client_->client()->client_address().address(), |
| 1449 server_address_); |
| 1450 |
| 1451 // The connection should be unaffected. |
| 1452 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1453 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1454 } |
| 1455 |
| 1456 // Send a version negotiation packet from the server for a different |
| 1457 // connection ID. It should be ignored. |
| 1458 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { |
| 1459 ASSERT_TRUE(Initialize()); |
| 1460 |
| 1461 // Send the version negotiation packet. |
| 1462 QuicConnectionId incorrect_connection_id = |
| 1463 client_->client()->session()->connection()->connection_id() + 1; |
| 1464 QuicVersionNegotiationPacket header; |
| 1465 header.connection_id = incorrect_connection_id; |
| 1466 header.reset_flag = true; |
| 1467 header.version_flag = true; |
| 1468 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), |
| 1469 Perspective::IS_SERVER); |
| 1470 scoped_ptr<QuicEncryptedPacket> packet( |
| 1471 framer.BuildVersionNegotiationPacket(header, server_supported_versions_)); |
| 1472 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; |
| 1473 client_->client()->session()->connection()->set_debug_visitor(&visitor); |
| 1474 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) |
| 1475 .Times(1); |
| 1476 server_writer_->WritePacket(packet->data(), packet->length(), |
| 1477 server_address_.address(), |
| 1478 client_->client()->client_address()); |
| 1479 |
| 1480 // The connection should be unaffected. |
| 1481 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1482 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1483 |
| 1484 client_->client()->session()->connection()->set_debug_visitor(nullptr); |
| 1485 } |
| 1486 |
1399 } // namespace | 1487 } // namespace |
1400 } // namespace test | 1488 } // namespace test |
1401 } // namespace tools | 1489 } // namespace tools |
1402 } // namespace net | 1490 } // namespace net |
OLD | NEW |