| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/quic/test_tools/quic_stream_factory_peer.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "net/cert/x509_certificate.h" | |
| 11 #include "net/quic/chromium/quic_chromium_client_session.h" | |
| 12 #include "net/quic/chromium/quic_http_stream.h" | |
| 13 #include "net/quic/chromium/quic_stream_factory.h" | |
| 14 #include "net/quic/core/crypto/quic_crypto_client_config.h" | |
| 15 #include "net/quic/platform/impl/quic_chromium_clock.h" | |
| 16 #include "net/test/cert_test_util.h" | |
| 17 #include "net/test/test_data_directory.h" | |
| 18 | |
| 19 using std::string; | |
| 20 | |
| 21 namespace net { | |
| 22 namespace test { | |
| 23 | |
| 24 const QuicConfig* QuicStreamFactoryPeer::GetConfig(QuicStreamFactory* factory) { | |
| 25 return &factory->config_; | |
| 26 } | |
| 27 | |
| 28 QuicCryptoClientConfig* QuicStreamFactoryPeer::GetCryptoConfig( | |
| 29 QuicStreamFactory* factory) { | |
| 30 return &factory->crypto_config_; | |
| 31 } | |
| 32 | |
| 33 bool QuicStreamFactoryPeer::HasActiveSession(QuicStreamFactory* factory, | |
| 34 const QuicServerId& server_id) { | |
| 35 return factory->HasActiveSession(server_id); | |
| 36 } | |
| 37 | |
| 38 bool QuicStreamFactoryPeer::HasActiveJob(QuicStreamFactory* factory, | |
| 39 const QuicServerId& server_id) { | |
| 40 return factory->HasActiveJob(server_id); | |
| 41 } | |
| 42 | |
| 43 bool QuicStreamFactoryPeer::HasActiveCertVerifierJob( | |
| 44 QuicStreamFactory* factory, | |
| 45 const QuicServerId& server_id) { | |
| 46 return factory->HasActiveCertVerifierJob(server_id); | |
| 47 } | |
| 48 | |
| 49 QuicChromiumClientSession* QuicStreamFactoryPeer::GetActiveSession( | |
| 50 QuicStreamFactory* factory, | |
| 51 const QuicServerId& server_id) { | |
| 52 DCHECK(factory->HasActiveSession(server_id)); | |
| 53 return factory->active_sessions_[server_id]; | |
| 54 } | |
| 55 | |
| 56 std::unique_ptr<QuicHttpStream> QuicStreamFactoryPeer::CreateFromSession( | |
| 57 QuicStreamFactory* factory, | |
| 58 QuicChromiumClientSession* session) { | |
| 59 return factory->CreateFromSession(session); | |
| 60 } | |
| 61 | |
| 62 bool QuicStreamFactoryPeer::IsLiveSession(QuicStreamFactory* factory, | |
| 63 QuicChromiumClientSession* session) { | |
| 64 for (QuicStreamFactory::SessionIdMap::iterator it = | |
| 65 factory->all_sessions_.begin(); | |
| 66 it != factory->all_sessions_.end(); ++it) { | |
| 67 if (it->first == session) | |
| 68 return true; | |
| 69 } | |
| 70 return false; | |
| 71 } | |
| 72 | |
| 73 void QuicStreamFactoryPeer::SetTaskRunner(QuicStreamFactory* factory, | |
| 74 base::TaskRunner* task_runner) { | |
| 75 factory->task_runner_ = task_runner; | |
| 76 } | |
| 77 | |
| 78 QuicTime::Delta QuicStreamFactoryPeer::GetPingTimeout( | |
| 79 QuicStreamFactory* factory) { | |
| 80 return factory->ping_timeout_; | |
| 81 } | |
| 82 | |
| 83 bool QuicStreamFactoryPeer::IsQuicDisabled(QuicStreamFactory* factory) { | |
| 84 return factory->IsQuicDisabled(); | |
| 85 } | |
| 86 | |
| 87 bool QuicStreamFactoryPeer::GetDelayTcpRace(QuicStreamFactory* factory) { | |
| 88 return factory->delay_tcp_race_; | |
| 89 } | |
| 90 | |
| 91 void QuicStreamFactoryPeer::SetDelayTcpRace(QuicStreamFactory* factory, | |
| 92 bool delay_tcp_race) { | |
| 93 factory->delay_tcp_race_ = delay_tcp_race; | |
| 94 } | |
| 95 | |
| 96 bool QuicStreamFactoryPeer::GetRaceCertVerification( | |
| 97 QuicStreamFactory* factory) { | |
| 98 return factory->race_cert_verification_; | |
| 99 } | |
| 100 | |
| 101 void QuicStreamFactoryPeer::SetRaceCertVerification( | |
| 102 QuicStreamFactory* factory, | |
| 103 bool race_cert_verification) { | |
| 104 factory->race_cert_verification_ = race_cert_verification; | |
| 105 } | |
| 106 | |
| 107 QuicAsyncStatus QuicStreamFactoryPeer::StartCertVerifyJob( | |
| 108 QuicStreamFactory* factory, | |
| 109 const QuicServerId& server_id, | |
| 110 int cert_verify_flags, | |
| 111 const NetLogWithSource& net_log) { | |
| 112 return factory->StartCertVerifyJob(server_id, cert_verify_flags, net_log); | |
| 113 } | |
| 114 | |
| 115 void QuicStreamFactoryPeer::SetYieldAfterPackets(QuicStreamFactory* factory, | |
| 116 int yield_after_packets) { | |
| 117 factory->yield_after_packets_ = yield_after_packets; | |
| 118 } | |
| 119 | |
| 120 void QuicStreamFactoryPeer::SetYieldAfterDuration( | |
| 121 QuicStreamFactory* factory, | |
| 122 QuicTime::Delta yield_after_duration) { | |
| 123 factory->yield_after_duration_ = yield_after_duration; | |
| 124 } | |
| 125 | |
| 126 size_t QuicStreamFactoryPeer::GetNumberOfActiveJobs( | |
| 127 QuicStreamFactory* factory, | |
| 128 const QuicServerId& server_id) { | |
| 129 auto it = factory->active_jobs_.find(server_id); | |
| 130 if (it == factory->active_jobs_.end()) | |
| 131 return 0; | |
| 132 return it->second.size(); | |
| 133 } | |
| 134 | |
| 135 void QuicStreamFactoryPeer::MaybeInitialize(QuicStreamFactory* factory) { | |
| 136 factory->MaybeInitialize(); | |
| 137 } | |
| 138 | |
| 139 bool QuicStreamFactoryPeer::HasInitializedData(QuicStreamFactory* factory) { | |
| 140 return factory->has_initialized_data_; | |
| 141 } | |
| 142 | |
| 143 bool QuicStreamFactoryPeer::SupportsQuicAtStartUp(QuicStreamFactory* factory, | |
| 144 HostPortPair host_port_pair) { | |
| 145 return base::ContainsKey(factory->quic_supported_servers_at_startup_, | |
| 146 host_port_pair); | |
| 147 } | |
| 148 | |
| 149 bool QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( | |
| 150 QuicStreamFactory* factory, | |
| 151 const QuicServerId& quic_server_id) { | |
| 152 return factory->CryptoConfigCacheIsEmpty(quic_server_id); | |
| 153 } | |
| 154 | |
| 155 void QuicStreamFactoryPeer::CacheDummyServerConfig( | |
| 156 QuicStreamFactory* factory, | |
| 157 const QuicServerId& quic_server_id) { | |
| 158 // Minimum SCFG that passes config validation checks. | |
| 159 const char scfg[] = {// SCFG | |
| 160 0x53, 0x43, 0x46, 0x47, | |
| 161 // num entries | |
| 162 0x01, 0x00, | |
| 163 // padding | |
| 164 0x00, 0x00, | |
| 165 // EXPY | |
| 166 0x45, 0x58, 0x50, 0x59, | |
| 167 // EXPY end offset | |
| 168 0x08, 0x00, 0x00, 0x00, | |
| 169 // Value | |
| 170 '1', '2', '3', '4', '5', '6', '7', '8'}; | |
| 171 | |
| 172 string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); | |
| 173 string source_address_token("test_source_address_token"); | |
| 174 string signature("test_signature"); | |
| 175 | |
| 176 std::vector<string> certs; | |
| 177 // Load a certificate that is valid for *.example.org | |
| 178 scoped_refptr<X509Certificate> cert( | |
| 179 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); | |
| 180 DCHECK(cert); | |
| 181 std::string der_bytes; | |
| 182 bool success = | |
| 183 X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_bytes); | |
| 184 DCHECK(success); | |
| 185 certs.push_back(der_bytes); | |
| 186 | |
| 187 QuicCryptoClientConfig* crypto_config = &factory->crypto_config_; | |
| 188 QuicCryptoClientConfig::CachedState* cached = | |
| 189 crypto_config->LookupOrCreate(quic_server_id); | |
| 190 QuicChromiumClock clock; | |
| 191 cached->Initialize(server_config, source_address_token, certs, "", "", | |
| 192 signature, clock.WallNow(), QuicWallTime::Zero()); | |
| 193 DCHECK(!cached->certs().empty()); | |
| 194 } | |
| 195 | |
| 196 QuicClientPushPromiseIndex* QuicStreamFactoryPeer::GetPushPromiseIndex( | |
| 197 QuicStreamFactory* factory) { | |
| 198 return &factory->push_promise_index_; | |
| 199 } | |
| 200 | |
| 201 int QuicStreamFactoryPeer::GetNumPushStreamsCreated( | |
| 202 QuicStreamFactory* factory) { | |
| 203 return factory->num_push_streams_created_; | |
| 204 } | |
| 205 | |
| 206 } // namespace test | |
| 207 } // namespace net | |
| OLD | NEW |