| 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 <sys/epoll.h> | 6 #include <sys/epoll.h> |
| 7 | 7 |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 QuicFlowControllerPeer::ReceiveWindowSize(server)); | 596 QuicFlowControllerPeer::ReceiveWindowSize(server)); |
| 597 EXPECT_EQ(QuicFlowControllerPeer::ReceiveWindowSize(client), | 597 EXPECT_EQ(QuicFlowControllerPeer::ReceiveWindowSize(client), |
| 598 QuicFlowControllerPeer::SendWindowSize(server)); | 598 QuicFlowControllerPeer::SendWindowSize(server)); |
| 599 } | 599 } |
| 600 | 600 |
| 601 // Must be called before Initialize to have effect. | 601 // Must be called before Initialize to have effect. |
| 602 void SetSpdyStreamFactory(QuicTestServer::StreamFactory* factory) { | 602 void SetSpdyStreamFactory(QuicTestServer::StreamFactory* factory) { |
| 603 stream_factory_ = factory; | 603 stream_factory_ = factory; |
| 604 } | 604 } |
| 605 | 605 |
| 606 QuicStreamId GetNthClientInitiatedId(int n) { | |
| 607 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId( | |
| 608 *client_->client()->session(), n); | |
| 609 } | |
| 610 | |
| 611 QuicStreamId GetNthServerInitiatedId(int n) { | |
| 612 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId( | |
| 613 *client_->client()->session(), n); | |
| 614 } | |
| 615 | |
| 616 bool initialized_; | 606 bool initialized_; |
| 617 QuicSocketAddress server_address_; | 607 QuicSocketAddress server_address_; |
| 618 string server_hostname_; | 608 string server_hostname_; |
| 619 QuicHttpResponseCache response_cache_; | 609 QuicHttpResponseCache response_cache_; |
| 620 std::unique_ptr<ServerThread> server_thread_; | 610 std::unique_ptr<ServerThread> server_thread_; |
| 621 std::unique_ptr<QuicTestClient> client_; | 611 std::unique_ptr<QuicTestClient> client_; |
| 622 PacketDroppingTestWriter* client_writer_; | 612 PacketDroppingTestWriter* client_writer_; |
| 623 PacketDroppingTestWriter* server_writer_; | 613 PacketDroppingTestWriter* server_writer_; |
| 624 bool server_started_; | 614 bool server_started_; |
| 625 QuicConfig client_config_; | 615 QuicConfig client_config_; |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 | 1190 |
| 1201 string body(kMaxPacketSize, 'a'); | 1191 string body(kMaxPacketSize, 'a'); |
| 1202 SpdyHeaderBlock headers; | 1192 SpdyHeaderBlock headers; |
| 1203 headers[":method"] = "POST"; | 1193 headers[":method"] = "POST"; |
| 1204 headers[":path"] = "/foo"; | 1194 headers[":path"] = "/foo"; |
| 1205 headers[":scheme"] = "https"; | 1195 headers[":scheme"] = "https"; |
| 1206 headers[":authority"] = server_hostname_; | 1196 headers[":authority"] = server_hostname_; |
| 1207 | 1197 |
| 1208 // Force the client to write with a stream ID belonging to a nonexistent | 1198 // Force the client to write with a stream ID belonging to a nonexistent |
| 1209 // server-side stream. | 1199 // server-side stream. |
| 1210 QuicSpdySession* session = client_->client()->session(); | 1200 QuicSessionPeer::SetNextOutgoingStreamId(client_->client()->session(), 2); |
| 1211 QuicSessionPeer::SetNextOutgoingStreamId(session, GetNthServerInitiatedId(0)); | |
| 1212 | 1201 |
| 1213 client_->SendCustomSynchronousRequest(headers, body); | 1202 client_->SendCustomSynchronousRequest(headers, body); |
| 1214 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 1203 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
| 1215 EXPECT_EQ(QUIC_INVALID_STREAM_ID, client_->connection_error()); | 1204 EXPECT_EQ(QUIC_INVALID_STREAM_ID, client_->connection_error()); |
| 1216 } | 1205 } |
| 1217 | 1206 |
| 1218 // Test that if the the server will close the connection if the client attempts | 1207 // Test that if the the server will close the connection if the client attempts |
| 1219 // to send a request with overly large headers. | 1208 // to send a request with overly large headers. |
| 1220 TEST_P(EndToEndTest, LargeHeaders) { | 1209 TEST_P(EndToEndTest, LargeHeaders) { |
| 1221 ASSERT_TRUE(Initialize()); | 1210 ASSERT_TRUE(Initialize()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { | 1281 TEST_P(EndToEndTest, MaxIncomingDynamicStreamsLimitRespected) { |
| 1293 // Set a limit on maximum number of incoming dynamic streams. | 1282 // Set a limit on maximum number of incoming dynamic streams. |
| 1294 // Make sure the limit is respected. | 1283 // Make sure the limit is respected. |
| 1295 const uint32_t kServerMaxIncomingDynamicStreams = 1; | 1284 const uint32_t kServerMaxIncomingDynamicStreams = 1; |
| 1296 server_config_.SetMaxIncomingDynamicStreamsToSend( | 1285 server_config_.SetMaxIncomingDynamicStreamsToSend( |
| 1297 kServerMaxIncomingDynamicStreams); | 1286 kServerMaxIncomingDynamicStreams); |
| 1298 ASSERT_TRUE(Initialize()); | 1287 ASSERT_TRUE(Initialize()); |
| 1299 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | 1288 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
| 1300 | 1289 |
| 1301 // Make the client misbehave after negotiation. | 1290 // Make the client misbehave after negotiation. |
| 1302 const int kServerMaxStreams = kMaxStreamsMinimumIncrement + 1; | 1291 const int kServerMaxStreams = |
| 1292 kMaxStreamsMinimumIncrement + kServerMaxIncomingDynamicStreams; |
| 1303 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), | 1293 QuicSessionPeer::SetMaxOpenOutgoingStreams(client_->client()->session(), |
| 1304 kServerMaxStreams + 1); | 1294 kServerMaxStreams + 1); |
| 1305 | 1295 |
| 1306 SpdyHeaderBlock headers; | 1296 SpdyHeaderBlock headers; |
| 1307 headers[":method"] = "POST"; | 1297 headers[":method"] = "POST"; |
| 1308 headers[":path"] = "/foo"; | 1298 headers[":path"] = "/foo"; |
| 1309 headers[":scheme"] = "https"; | 1299 headers[":scheme"] = "https"; |
| 1310 headers[":authority"] = server_hostname_; | 1300 headers[":authority"] = server_hostname_; |
| 1311 headers["content-length"] = "3"; | 1301 headers["content-length"] = "3"; |
| 1312 | 1302 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1546 | 1536 |
| 1547 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | 1537 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
| 1548 | 1538 |
| 1549 QuicSession* session = client_->client()->session(); | 1539 QuicSession* session = client_->client()->session(); |
| 1550 // Lose the request. | 1540 // Lose the request. |
| 1551 SetPacketLossPercentage(100); | 1541 SetPacketLossPercentage(100); |
| 1552 EXPECT_LT(0, client_->SendRequest("/small_response")); | 1542 EXPECT_LT(0, client_->SendRequest("/small_response")); |
| 1553 client_->client()->WaitForEvents(); | 1543 client_->client()->WaitForEvents(); |
| 1554 // Transmit the cancel, and ensure the connection is torn down properly. | 1544 // Transmit the cancel, and ensure the connection is torn down properly. |
| 1555 SetPacketLossPercentage(0); | 1545 SetPacketLossPercentage(0); |
| 1556 QuicStreamId stream_id = GetNthClientInitiatedId(0); | 1546 QuicStreamId stream_id = kClientDataStreamId1; |
| 1557 session->SendRstStream(stream_id, QUIC_STREAM_CANCELLED, 0); | 1547 session->SendRstStream(stream_id, QUIC_STREAM_CANCELLED, 0); |
| 1558 | 1548 |
| 1559 // WaitForEvents waits 50ms and returns true if there are outstanding | 1549 // WaitForEvents waits 50ms and returns true if there are outstanding |
| 1560 // requests. | 1550 // requests. |
| 1561 while (client_->client()->WaitForEvents() == true) { | 1551 while (client_->client()->WaitForEvents() == true) { |
| 1562 } | 1552 } |
| 1563 // It should be completely fine to RST a stream before any data has been | 1553 // It should be completely fine to RST a stream before any data has been |
| 1564 // received for that stream. | 1554 // received for that stream. |
| 1565 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1555 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 1566 } | 1556 } |
| (...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 server_id, | 2410 server_id, |
| 2421 crypto_config, | 2411 crypto_config, |
| 2422 push_promise_index) {} | 2412 push_promise_index) {} |
| 2423 | 2413 |
| 2424 ~ClientSessionThatDropsBody() override {} | 2414 ~ClientSessionThatDropsBody() override {} |
| 2425 | 2415 |
| 2426 std::unique_ptr<QuicSpdyClientStream> CreateClientStream() override { | 2416 std::unique_ptr<QuicSpdyClientStream> CreateClientStream() override { |
| 2427 return QuicMakeUnique<ClientStreamThatDropsBody>(GetNextOutgoingStreamId(), | 2417 return QuicMakeUnique<ClientStreamThatDropsBody>(GetNextOutgoingStreamId(), |
| 2428 this); | 2418 this); |
| 2429 } | 2419 } |
| 2430 std::unique_ptr<QuicStream> CreateStream(QuicStreamId id) override { | |
| 2431 return QuicMakeUnique<ClientStreamThatDropsBody>(id, this); | |
| 2432 } | |
| 2433 }; | 2420 }; |
| 2434 | 2421 |
| 2435 class MockableQuicClientThatDropsBody : public MockableQuicClient { | 2422 class MockableQuicClientThatDropsBody : public MockableQuicClient { |
| 2436 public: | 2423 public: |
| 2437 MockableQuicClientThatDropsBody(QuicSocketAddress server_address, | 2424 MockableQuicClientThatDropsBody(QuicSocketAddress server_address, |
| 2438 const QuicServerId& server_id, | 2425 const QuicServerId& server_id, |
| 2439 const QuicConfig& config, | 2426 const QuicConfig& config, |
| 2440 const QuicVersionVector& supported_versions, | 2427 const QuicVersionVector& supported_versions, |
| 2441 EpollServer* epoll_server) | 2428 EpollServer* epoll_server) |
| 2442 : MockableQuicClient(server_address, | 2429 : MockableQuicClient(server_address, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2460 public: | 2447 public: |
| 2461 QuicTestClientThatDropsBody(QuicSocketAddress server_address, | 2448 QuicTestClientThatDropsBody(QuicSocketAddress server_address, |
| 2462 const string& server_hostname, | 2449 const string& server_hostname, |
| 2463 const QuicConfig& config, | 2450 const QuicConfig& config, |
| 2464 const QuicVersionVector& supported_versions) | 2451 const QuicVersionVector& supported_versions) |
| 2465 : QuicTestClient(server_address, | 2452 : QuicTestClient(server_address, |
| 2466 server_hostname, | 2453 server_hostname, |
| 2467 config, | 2454 config, |
| 2468 supported_versions) { | 2455 supported_versions) { |
| 2469 set_client(new MockableQuicClientThatDropsBody( | 2456 set_client(new MockableQuicClientThatDropsBody( |
| 2470 server_address, | 2457 server_address, QuicServerId(server_hostname, server_address.port(), |
| 2471 QuicServerId(server_hostname, server_address.port(), | 2458 PRIVACY_MODE_DISABLED), |
| 2472 PRIVACY_MODE_DISABLED), | |
| 2473 config, supported_versions, epoll_server())); | 2459 config, supported_versions, epoll_server())); |
| 2474 } | 2460 } |
| 2475 ~QuicTestClientThatDropsBody() override {} | 2461 ~QuicTestClientThatDropsBody() override {} |
| 2476 }; | 2462 }; |
| 2477 | 2463 |
| 2478 TEST_P(EndToEndTest, EarlyResponseFinRecording) { | 2464 TEST_P(EndToEndTest, EarlyResponseFinRecording) { |
| 2479 set_smaller_flow_control_receive_window(); | 2465 set_smaller_flow_control_receive_window(); |
| 2480 | 2466 |
| 2481 // Verify that an incoming FIN is recorded in a stream object even if the read | 2467 // Verify that an incoming FIN is recorded in a stream object even if the read |
| 2482 // side has been closed. This prevents an entry from being made in | 2468 // side has been closed. This prevents an entry from being made in |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2573 // Tell the client to not close the stream if it receives an early response. | 2559 // Tell the client to not close the stream if it receives an early response. |
| 2574 client_->set_allow_bidirectional_data(true); | 2560 client_->set_allow_bidirectional_data(true); |
| 2575 // Send the headers. | 2561 // Send the headers. |
| 2576 client_->SendMessage(headers, "", /*fin=*/false); | 2562 client_->SendMessage(headers, "", /*fin=*/false); |
| 2577 | 2563 |
| 2578 // Receive the response and let the server close writing. | 2564 // Receive the response and let the server close writing. |
| 2579 client_->WaitForInitialResponse(); | 2565 client_->WaitForInitialResponse(); |
| 2580 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); | 2566 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 2581 | 2567 |
| 2582 // Receive the reset stream from server on early response. | 2568 // Receive the reset stream from server on early response. |
| 2583 QuicStream* stream = client_->client()->session()->GetOrCreateStream( | 2569 QuicStream* stream = |
| 2584 GetNthClientInitiatedId(0)); | 2570 client_->client()->session()->GetOrCreateStream(kClientDataStreamId1); |
| 2585 // The stream is reset by server's reset stream. | 2571 // The stream is reset by server's reset stream. |
| 2586 EXPECT_EQ(stream, nullptr); | 2572 EXPECT_EQ(stream, nullptr); |
| 2587 } | 2573 } |
| 2588 | 2574 |
| 2589 TEST_P(EndToEndTest, Trailers) { | 2575 TEST_P(EndToEndTest, Trailers) { |
| 2590 // Test sending and receiving HTTP/2 Trailers (trailing HEADERS frames). | 2576 // Test sending and receiving HTTP/2 Trailers (trailing HEADERS frames). |
| 2591 ASSERT_TRUE(Initialize()); | 2577 ASSERT_TRUE(Initialize()); |
| 2592 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | 2578 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
| 2593 | 2579 |
| 2594 // Set reordering to ensure that Trailers arriving before body is ok. | 2580 // Set reordering to ensure that Trailers arriving before body is ok. |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3123 client_->WaitForResponse(); | 3109 client_->WaitForResponse(); |
| 3124 EXPECT_EQ(kBarResponseBody, client_->response_body()); | 3110 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
| 3125 QuicConnectionStats client_stats = | 3111 QuicConnectionStats client_stats = |
| 3126 client_->client()->session()->connection()->GetStats(); | 3112 client_->client()->session()->connection()->GetStats(); |
| 3127 EXPECT_EQ(0u, client_stats.packets_lost); | 3113 EXPECT_EQ(0u, client_stats.packets_lost); |
| 3128 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 3114 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 3129 } | 3115 } |
| 3130 } // namespace | 3116 } // namespace |
| 3131 } // namespace test | 3117 } // namespace test |
| 3132 } // namespace net | 3118 } // namespace net |
| OLD | NEW |