1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_QUIC_MOCK_CRYPTO_CLIENT_STREAM_FACTORY_H_ 6 #define NET_QUIC_MOCK_CRYPTO_CLIENT_STREAM_FACTORY_H_ 7 8 #include <memory> 9 #include <vector> 10 11 #include "base/containers/queue.h" 12 #include "base/memory/raw_ptr.h" 13 #include "net/quic/crypto/proof_verifier_chromium.h" 14 #include "net/quic/mock_crypto_client_stream.h" 15 #include "net/quic/quic_crypto_client_stream_factory.h" 16 #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h" 17 18 namespace quic { 19 class QuicCryptoClientStream; 20 } // namespace quic 21 namespace net { 22 23 class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory { 24 public: 25 MockCryptoClientStreamFactory(); 26 27 MockCryptoClientStreamFactory(const MockCryptoClientStreamFactory&) = delete; 28 MockCryptoClientStreamFactory& operator=( 29 const MockCryptoClientStreamFactory&) = delete; 30 31 ~MockCryptoClientStreamFactory() override; 32 33 std::unique_ptr<quic::QuicCryptoClientStream> CreateQuicCryptoClientStream( 34 const quic::QuicServerId& server_id, 35 QuicChromiumClientSession* session, 36 std::unique_ptr<quic::ProofVerifyContext> proof_verify_context, 37 quic::QuicCryptoClientConfig* crypto_config) override; 38 set_handshake_mode(MockCryptoClientStream::HandshakeMode handshake_mode)39 void set_handshake_mode( 40 MockCryptoClientStream::HandshakeMode handshake_mode) { 41 handshake_mode_ = handshake_mode; 42 } 43 set_use_mock_crypter(bool use_mock_crypter)44 void set_use_mock_crypter(bool use_mock_crypter) { 45 use_mock_crypter_ = use_mock_crypter; 46 } 47 48 // The caller keeps ownership of |proof_verify_details|. AddProofVerifyDetails(const ProofVerifyDetailsChromium * proof_verify_details)49 void AddProofVerifyDetails( 50 const ProofVerifyDetailsChromium* proof_verify_details) { 51 proof_verify_details_queue_.push(proof_verify_details); 52 } 53 54 MockCryptoClientStream* last_stream() const; streams()55 const std::vector<base::WeakPtr<MockCryptoClientStream>>& streams() const { 56 return streams_; 57 } 58 59 // Sets initial config for new sessions. 60 void SetConfig(const quic::QuicConfig& config); 61 62 private: 63 MockCryptoClientStream::HandshakeMode handshake_mode_ = 64 MockCryptoClientStream::CONFIRM_HANDSHAKE; 65 std::vector<base::WeakPtr<MockCryptoClientStream>> streams_; 66 base::queue<const ProofVerifyDetailsChromium*> proof_verify_details_queue_; 67 std::unique_ptr<quic::QuicConfig> config_; 68 bool use_mock_crypter_ = false; 69 }; 70 71 } // namespace net 72 73 #endif // NET_QUIC_MOCK_CRYPTO_CLIENT_STREAM_FACTORY_H_ 74