• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <map>
9 #include <memory>
10 #include <vector>
11 
12 #include "base/containers/queue.h"
13 #include "base/memory/raw_ptr.h"
14 #include "net/quic/crypto/proof_verifier_chromium.h"
15 #include "net/quic/mock_crypto_client_stream.h"
16 #include "net/quic/quic_crypto_client_stream_factory.h"
17 #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h"
18 
19 namespace quic {
20 class QuicCryptoClientStream;
21 }  // namespace quic
22 namespace net {
23 
24 class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory {
25  public:
26   MockCryptoClientStreamFactory();
27 
28   MockCryptoClientStreamFactory(const MockCryptoClientStreamFactory&) = delete;
29   MockCryptoClientStreamFactory& operator=(
30       const MockCryptoClientStreamFactory&) = delete;
31 
32   ~MockCryptoClientStreamFactory() override;
33 
34   std::unique_ptr<quic::QuicCryptoClientStream> CreateQuicCryptoClientStream(
35       const quic::QuicServerId& server_id,
36       QuicChromiumClientSession* session,
37       std::unique_ptr<quic::ProofVerifyContext> proof_verify_context,
38       quic::QuicCryptoClientConfig* crypto_config) override;
39 
set_handshake_mode(MockCryptoClientStream::HandshakeMode handshake_mode)40   void set_handshake_mode(
41       MockCryptoClientStream::HandshakeMode handshake_mode) {
42     handshake_mode_ = handshake_mode;
43   }
44 
set_use_mock_crypter(bool use_mock_crypter)45   void set_use_mock_crypter(bool use_mock_crypter) {
46     use_mock_crypter_ = use_mock_crypter;
47   }
48 
49   // The caller keeps ownership of |proof_verify_details|.
AddProofVerifyDetails(const ProofVerifyDetailsChromium * proof_verify_details)50   void AddProofVerifyDetails(
51       const ProofVerifyDetailsChromium* proof_verify_details) {
52     proof_verify_details_queue_.push(proof_verify_details);
53   }
54 
55   MockCryptoClientStream* last_stream() const;
streams()56   const std::vector<base::WeakPtr<MockCryptoClientStream>>& streams() const {
57     return streams_;
58   }
59 
60   // Sets initial config for new sessions with no matching server_id.
61   void SetConfig(const quic::QuicConfig& config);
62 
63   // Sets the initial config for a new session with the given server_id,
64   // overriding any existing setting.
65   void SetConfigForServerId(const quic::QuicServerId& server_id,
66                             const quic::QuicConfig& config);
67 
68  private:
69   MockCryptoClientStream::HandshakeMode handshake_mode_ =
70       MockCryptoClientStream::CONFIRM_HANDSHAKE;
71   std::vector<base::WeakPtr<MockCryptoClientStream>> streams_;
72   base::queue<raw_ptr<const ProofVerifyDetailsChromium, CtnExperimental>>
73       proof_verify_details_queue_;
74   std::unique_ptr<quic::QuicConfig> config_;
75   std::map<quic::QuicServerId, std::unique_ptr<quic::QuicConfig>>
76       config_for_server_;
77   bool use_mock_crypter_ = false;
78 };
79 
80 }  // namespace net
81 
82 #endif  // NET_QUIC_MOCK_CRYPTO_CLIENT_STREAM_FACTORY_H_
83