| 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/tools/quic/quic_client_session.h" | 5 #include "net/tools/quic/quic_client_session.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
| 10 #include "net/quic/core/spdy_utils.h" | 10 #include "net/quic/core/spdy_utils.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 connection, | 47 connection, |
| 48 server_id, | 48 server_id, |
| 49 crypto_config, | 49 crypto_config, |
| 50 push_promise_index) {} | 50 push_promise_index) {} |
| 51 | 51 |
| 52 std::unique_ptr<QuicSpdyClientStream> CreateClientStream() override { | 52 std::unique_ptr<QuicSpdyClientStream> CreateClientStream() override { |
| 53 return QuicMakeUnique<MockQuicSpdyClientStream>(GetNextOutgoingStreamId(), | 53 return QuicMakeUnique<MockQuicSpdyClientStream>(GetNextOutgoingStreamId(), |
| 54 this); | 54 this); |
| 55 } | 55 } |
| 56 | 56 |
| 57 std::unique_ptr<QuicStream> CreateStream(QuicStreamId id) override { |
| 58 return QuicMakeUnique<MockQuicSpdyClientStream>(id, this); |
| 59 } |
| 60 |
| 57 MockQuicSpdyClientStream* CreateIncomingDynamicStream( | 61 MockQuicSpdyClientStream* CreateIncomingDynamicStream( |
| 58 QuicStreamId id) override { | 62 QuicStreamId id) override { |
| 59 MockQuicSpdyClientStream* stream = new MockQuicSpdyClientStream(id, this); | 63 MockQuicSpdyClientStream* stream = new MockQuicSpdyClientStream(id, this); |
| 60 ActivateStream(QuicWrapUnique(stream)); | 64 ActivateStream(QuicWrapUnique(stream)); |
| 61 return stream; | 65 return stream; |
| 62 } | 66 } |
| 67 |
| 68 QuicSpdyClientStream* CreateOutgoingDynamicStream( |
| 69 SpdyPriority priority) override { |
| 70 return FLAGS_quic_reloadable_flag_quic_refactor_stream_creation |
| 71 ? MaybeCreateOutgoingDynamicStream(priority) |
| 72 : QuicClientSession::CreateOutgoingDynamicStream(priority); |
| 73 } |
| 63 }; | 74 }; |
| 64 | 75 |
| 65 class QuicClientSessionTest : public QuicTestWithParam<QuicVersion> { | 76 class QuicClientSessionTest : public QuicTestWithParam<QuicVersion> { |
| 66 protected: | 77 protected: |
| 67 QuicClientSessionTest() | 78 QuicClientSessionTest() |
| 68 : crypto_config_(crypto_test_utils::ProofVerifierForTesting()), | 79 : crypto_config_(crypto_test_utils::ProofVerifierForTesting()), |
| 69 promised_stream_id_(kServerDataStreamId1), | 80 promised_stream_id_(kInvalidStreamId), |
| 70 associated_stream_id_(kClientDataStreamId1) { | 81 associated_stream_id_(kInvalidStreamId) { |
| 71 Initialize(); | 82 Initialize(); |
| 72 // Advance the time, because timers do not like uninitialized times. | 83 // Advance the time, because timers do not like uninitialized times. |
| 73 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 84 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 74 } | 85 } |
| 75 | 86 |
| 76 ~QuicClientSessionTest() override { | 87 ~QuicClientSessionTest() override { |
| 77 // Session must be destroyed before promised_by_url_ | 88 // Session must be destroyed before promised_by_url_ |
| 78 session_.reset(nullptr); | 89 session_.reset(nullptr); |
| 79 } | 90 } |
| 80 | 91 |
| 81 void Initialize() { | 92 void Initialize() { |
| 82 session_.reset(); | 93 session_.reset(); |
| 83 connection_ = new PacketSavingConnection(&helper_, &alarm_factory_, | 94 connection_ = new PacketSavingConnection(&helper_, &alarm_factory_, |
| 84 Perspective::IS_CLIENT, | 95 Perspective::IS_CLIENT, |
| 85 SupportedVersions(GetParam())); | 96 SupportedVersions(GetParam())); |
| 86 session_.reset(new TestQuicClientSession( | 97 session_.reset(new TestQuicClientSession( |
| 87 DefaultQuicConfig(), connection_, | 98 DefaultQuicConfig(), connection_, |
| 88 QuicServerId(kServerHostname, kPort, PRIVACY_MODE_DISABLED), | 99 QuicServerId(kServerHostname, kPort, PRIVACY_MODE_DISABLED), |
| 89 &crypto_config_, &push_promise_index_)); | 100 &crypto_config_, &push_promise_index_)); |
| 90 session_->Initialize(); | 101 session_->Initialize(); |
| 91 push_promise_[":path"] = "/bar"; | 102 push_promise_[":path"] = "/bar"; |
| 92 push_promise_[":authority"] = "www.google.com"; | 103 push_promise_[":authority"] = "www.google.com"; |
| 93 push_promise_[":version"] = "HTTP/1.1"; | 104 push_promise_[":version"] = "HTTP/1.1"; |
| 94 push_promise_[":method"] = "GET"; | 105 push_promise_[":method"] = "GET"; |
| 95 push_promise_[":scheme"] = "https"; | 106 push_promise_[":scheme"] = "https"; |
| 96 promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); | 107 promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); |
| 108 promised_stream_id_ = |
| 109 QuicSpdySessionPeer::GetNthServerInitiatedStreamId(*session_, 0); |
| 110 associated_stream_id_ = |
| 111 QuicSpdySessionPeer::GetNthClientInitiatedStreamId(*session_, 0); |
| 97 } | 112 } |
| 98 | 113 |
| 99 void CompleteCryptoHandshake() { | 114 void CompleteCryptoHandshake() { |
| 100 CompleteCryptoHandshake(kDefaultMaxStreamsPerConnection); | 115 CompleteCryptoHandshake(kDefaultMaxStreamsPerConnection); |
| 101 } | 116 } |
| 102 | 117 |
| 103 void CompleteCryptoHandshake(uint32_t server_max_incoming_streams) { | 118 void CompleteCryptoHandshake(uint32_t server_max_incoming_streams) { |
| 104 session_->CryptoConnect(); | 119 session_->CryptoConnect(); |
| 105 QuicCryptoClientStream* stream = static_cast<QuicCryptoClientStream*>( | 120 QuicCryptoClientStream* stream = static_cast<QuicCryptoClientStream*>( |
| 106 session_->GetMutableCryptoStream()); | 121 session_->GetMutableCryptoStream()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // at NONE. | 167 // at NONE. |
| 153 CryptoHandshakeMessage rej; | 168 CryptoHandshakeMessage rej; |
| 154 crypto_test_utils::FillInDummyReject(&rej, /* stateless */ false); | 169 crypto_test_utils::FillInDummyReject(&rej, /* stateless */ false); |
| 155 EXPECT_TRUE(session_->IsEncryptionEstablished()); | 170 EXPECT_TRUE(session_->IsEncryptionEstablished()); |
| 156 session_->GetMutableCryptoStream()->OnHandshakeMessage(rej); | 171 session_->GetMutableCryptoStream()->OnHandshakeMessage(rej); |
| 157 EXPECT_FALSE(session_->IsEncryptionEstablished()); | 172 EXPECT_FALSE(session_->IsEncryptionEstablished()); |
| 158 EXPECT_EQ(ENCRYPTION_NONE, | 173 EXPECT_EQ(ENCRYPTION_NONE, |
| 159 QuicPacketCreatorPeer::GetEncryptionLevel( | 174 QuicPacketCreatorPeer::GetEncryptionLevel( |
| 160 QuicConnectionPeer::GetPacketCreator(connection_))); | 175 QuicConnectionPeer::GetPacketCreator(connection_))); |
| 161 // Verify that no new streams may be created. | 176 // Verify that no new streams may be created. |
| 162 EXPECT_TRUE(session_->CreateOutgoingDynamicStream(kDefaultPriority) == | 177 if (FLAGS_quic_reloadable_flag_quic_refactor_stream_creation) { |
| 163 nullptr); | 178 EXPECT_EQ(nullptr, session_->CreateOutgoingDynamicStream(kDefaultPriority)); |
| 179 } else { |
| 180 EXPECT_TRUE(session_->CreateOutgoingDynamicStream(kDefaultPriority) == |
| 181 nullptr); |
| 182 } |
| 164 // Verify that no data may be send on existing streams. | 183 // Verify that no data may be send on existing streams. |
| 165 char data[] = "hello world"; | 184 char data[] = "hello world"; |
| 166 struct iovec iov = {data, arraysize(data)}; | 185 struct iovec iov = {data, arraysize(data)}; |
| 167 QuicIOVector iovector(&iov, 1, iov.iov_len); | 186 QuicIOVector iovector(&iov, 1, iov.iov_len); |
| 168 QuicConsumedData consumed = | 187 QuicConsumedData consumed = |
| 169 session_->WritevData(stream, stream->id(), iovector, 0, NO_FIN, nullptr); | 188 session_->WritevData(stream, stream->id(), iovector, 0, NO_FIN, nullptr); |
| 170 EXPECT_FALSE(consumed.fin_consumed); | 189 EXPECT_FALSE(consumed.fin_consumed); |
| 171 EXPECT_EQ(0u, consumed.bytes_consumed); | 190 EXPECT_EQ(0u, consumed.bytes_consumed); |
| 172 } | 191 } |
| 173 | 192 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 QuicClientPromisedInfo* promised = | 577 QuicClientPromisedInfo* promised = |
| 559 session_->GetPromisedById(promised_stream_id_); | 578 session_->GetPromisedById(promised_stream_id_); |
| 560 EXPECT_NE(promised, nullptr); | 579 EXPECT_NE(promised, nullptr); |
| 561 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); | 580 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 562 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); | 581 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); |
| 563 } | 582 } |
| 564 | 583 |
| 565 } // namespace | 584 } // namespace |
| 566 } // namespace test | 585 } // namespace test |
| 567 } // namespace net | 586 } // namespace net |
| OLD | NEW |