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 "net/quic/quic_session.h" | 5 #include "net/quic/quic_session.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
| 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
12 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "net/quic/crypto/crypto_protocol.h" | 16 #include "net/quic/crypto/crypto_protocol.h" |
16 #include "net/quic/quic_crypto_stream.h" | 17 #include "net/quic/quic_crypto_stream.h" |
17 #include "net/quic/quic_flags.h" | 18 #include "net/quic/quic_flags.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 class TestCryptoStream : public QuicCryptoStream { | 52 class TestCryptoStream : public QuicCryptoStream { |
52 public: | 53 public: |
53 explicit TestCryptoStream(QuicSession* session) | 54 explicit TestCryptoStream(QuicSession* session) |
54 : QuicCryptoStream(session) { | 55 : QuicCryptoStream(session) { |
55 } | 56 } |
56 | 57 |
57 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override { | 58 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override { |
58 encryption_established_ = true; | 59 encryption_established_ = true; |
59 handshake_confirmed_ = true; | 60 handshake_confirmed_ = true; |
60 CryptoHandshakeMessage msg; | 61 CryptoHandshakeMessage msg; |
61 string error_details; | 62 std::string error_details; |
62 session()->config()->SetInitialFlowControlWindowToSend( | 63 session()->config()->SetInitialFlowControlWindowToSend( |
63 kInitialSessionFlowControlWindowForTest); | 64 kInitialSessionFlowControlWindowForTest); |
64 session()->config()->SetInitialStreamFlowControlWindowToSend( | 65 session()->config()->SetInitialStreamFlowControlWindowToSend( |
65 kInitialStreamFlowControlWindowForTest); | 66 kInitialStreamFlowControlWindowForTest); |
66 session()->config()->SetInitialSessionFlowControlWindowToSend( | 67 session()->config()->SetInitialSessionFlowControlWindowToSend( |
67 kInitialSessionFlowControlWindowForTest); | 68 kInitialSessionFlowControlWindowForTest); |
68 session()->config()->ToHandshakeMessage(&msg); | 69 session()->config()->ToHandshakeMessage(&msg); |
69 const QuicErrorCode error = session()->config()->ProcessPeerHello( | 70 const QuicErrorCode error = session()->config()->ProcessPeerHello( |
70 msg, CLIENT, &error_details); | 71 msg, CLIENT, &error_details); |
71 EXPECT_EQ(QUIC_NO_ERROR, error); | 72 EXPECT_EQ(QUIC_NO_ERROR, error); |
(...skipping 18 matching lines...) Expand all Loading... |
90 TestStream(QuicStreamId id, QuicSession* session) | 91 TestStream(QuicStreamId id, QuicSession* session) |
91 : QuicDataStream(id, session) { | 92 : QuicDataStream(id, session) { |
92 } | 93 } |
93 | 94 |
94 using ReliableQuicStream::CloseWriteSide; | 95 using ReliableQuicStream::CloseWriteSide; |
95 | 96 |
96 uint32 ProcessData(const char* data, uint32 data_len) override { | 97 uint32 ProcessData(const char* data, uint32 data_len) override { |
97 return data_len; | 98 return data_len; |
98 } | 99 } |
99 | 100 |
100 void SendBody(const string& data, bool fin) { | 101 void SendBody(const std::string& data, bool fin) { |
101 WriteOrBufferData(data, fin, nullptr); | 102 WriteOrBufferData(data, fin, nullptr); |
102 } | 103 } |
103 | 104 |
104 MOCK_METHOD0(OnCanWrite, void()); | 105 MOCK_METHOD0(OnCanWrite, void()); |
105 }; | 106 }; |
106 | 107 |
107 // Poor man's functor for use as callback in a mock. | 108 // Poor man's functor for use as callback in a mock. |
108 class StreamBlocker { | 109 class StreamBlocker { |
109 public: | 110 public: |
110 StreamBlocker(QuicSession* session, QuicStreamId stream_id) | 111 StreamBlocker(QuicSession* session, QuicStreamId stream_id) |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 TEST_P(QuicSessionTest, HandshakeUnblocksFlowControlBlockedStream) { | 630 TEST_P(QuicSessionTest, HandshakeUnblocksFlowControlBlockedStream) { |
630 // Test that if a stream is flow control blocked, then on receipt of the SHLO | 631 // Test that if a stream is flow control blocked, then on receipt of the SHLO |
631 // containing a suitable send window offset, the stream becomes unblocked. | 632 // containing a suitable send window offset, the stream becomes unblocked. |
632 | 633 |
633 // Ensure that Writev consumes all the data it is given (simulate no socket | 634 // Ensure that Writev consumes all the data it is given (simulate no socket |
634 // blocking). | 635 // blocking). |
635 session_.set_writev_consumes_all_data(true); | 636 session_.set_writev_consumes_all_data(true); |
636 | 637 |
637 // Create a stream, and send enough data to make it flow control blocked. | 638 // Create a stream, and send enough data to make it flow control blocked. |
638 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 639 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
639 string body(kDefaultFlowControlSendWindow, '.'); | 640 std::string body(kDefaultFlowControlSendWindow, '.'); |
640 EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); | 641 EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); |
641 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); | 642 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked()); |
642 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); | 643 EXPECT_FALSE(session_.IsStreamFlowControlBlocked()); |
643 stream2->SendBody(body, false); | 644 stream2->SendBody(body, false); |
644 EXPECT_TRUE(stream2->flow_controller()->IsBlocked()); | 645 EXPECT_TRUE(stream2->flow_controller()->IsBlocked()); |
645 EXPECT_TRUE(session_.IsConnectionFlowControlBlocked()); | 646 EXPECT_TRUE(session_.IsConnectionFlowControlBlocked()); |
646 EXPECT_TRUE(session_.IsStreamFlowControlBlocked()); | 647 EXPECT_TRUE(session_.IsStreamFlowControlBlocked()); |
647 | 648 |
648 // The handshake message will call OnCanWrite, so the stream can resume | 649 // The handshake message will call OnCanWrite, so the stream can resume |
649 // writing. | 650 // writing. |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 855 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); |
855 | 856 |
856 // Reset our stream: this results in the stream being closed locally. | 857 // Reset our stream: this results in the stream being closed locally. |
857 TestStream* stream = session_.CreateOutgoingDataStream(); | 858 TestStream* stream = session_.CreateOutgoingDataStream(); |
858 stream->Reset(QUIC_STREAM_CANCELLED); | 859 stream->Reset(QUIC_STREAM_CANCELLED); |
859 | 860 |
860 // Now receive a response from the peer with a FIN. We should handle this by | 861 // Now receive a response from the peer with a FIN. We should handle this by |
861 // adjusting the connection level flow control receive window to take into | 862 // adjusting the connection level flow control receive window to take into |
862 // account the total number of bytes sent by the peer. | 863 // account the total number of bytes sent by the peer. |
863 const QuicStreamOffset kByteOffset = 5678; | 864 const QuicStreamOffset kByteOffset = 5678; |
864 string body = "hello"; | 865 std::string body = "hello"; |
865 IOVector data = MakeIOVector(body); | 866 IOVector data = MakeIOVector(body); |
866 QuicStreamFrame frame(stream->id(), true, kByteOffset, data); | 867 QuicStreamFrame frame(stream->id(), true, kByteOffset, data); |
867 vector<QuicStreamFrame> frames; | 868 vector<QuicStreamFrame> frames; |
868 frames.push_back(frame); | 869 frames.push_back(frame); |
869 session_.OnStreamFrames(frames); | 870 session_.OnStreamFrames(frames); |
870 | 871 |
871 QuicStreamOffset total_stream_bytes_sent_by_peer = | 872 QuicStreamOffset total_stream_bytes_sent_by_peer = |
872 kByteOffset + body.length(); | 873 kByteOffset + body.length(); |
873 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer, | 874 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer, |
874 session_.flow_controller()->bytes_consumed()); | 875 session_.flow_controller()->bytes_consumed()); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 } | 1015 } |
1015 | 1016 |
1016 // Called after any new data is received by the session, and triggers the call | 1017 // Called after any new data is received by the session, and triggers the call |
1017 // to close the connection. | 1018 // to close the connection. |
1018 session_.PostProcessAfterData(); | 1019 session_.PostProcessAfterData(); |
1019 } | 1020 } |
1020 | 1021 |
1021 } // namespace | 1022 } // namespace |
1022 } // namespace test | 1023 } // namespace test |
1023 } // namespace net | 1024 } // namespace net |
OLD | NEW |