Chromium Code Reviews| Index: net/quic/test_tools/crypto_test_utils.cc |
| diff --git a/net/quic/test_tools/crypto_test_utils.cc b/net/quic/test_tools/crypto_test_utils.cc |
| index f67cdbab70791d7d01c4b2a3d61321243cb84040..ecfa1ee99f2542a66f15653367766901b6fe8871 100644 |
| --- a/net/quic/test_tools/crypto_test_utils.cc |
| +++ b/net/quic/test_tools/crypto_test_utils.cc |
| @@ -124,11 +124,54 @@ bool HexChar(char c, uint8* value) { |
| return false; |
| } |
| +// A ChannelIDSource that works in async mode unless the |callback| argument |
| +// to GetChannelIDKey is NULL. |
| +class AsyncTestChannelIDSource : public ChannelIDSource, |
| + public CryptoTestUtils::TaskSource { |
| + public: |
| + // Takes ownership of |sync_source|. |
| + explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source) |
| + : sync_source_(sync_source) {} |
| + virtual ~AsyncTestChannelIDSource() {} |
| + |
| + // ChannelIDSource implementation. |
| + virtual QuicAsyncStatus GetChannelIDKey( |
| + const string& hostname, |
| + scoped_ptr<ChannelIDKey>* channel_id_key, |
| + ChannelIDSourceCallback* callback) OVERRIDE { |
| + if (!callback) { |
| + return sync_source_->GetChannelIDKey(hostname, channel_id_key, NULL); |
| + } |
| + |
| + QuicAsyncStatus status = |
| + sync_source_->GetChannelIDKey(hostname, &channel_id_key_, NULL); |
| + if (status != QUIC_SUCCESS) { |
| + return QUIC_FAILURE; |
| + } |
| + callback_.reset(callback); |
| + return QUIC_PENDING; |
| + } |
| + |
| + // TaskSource implementation. |
| + virtual void RunPending() OVERRIDE { |
| + if (callback_.get()) { |
| + callback_->Run(&channel_id_key_); |
| + callback_.reset(); |
| + } |
| + } |
| + |
| + private: |
| + scoped_ptr<ChannelIDSource> sync_source_; |
| + scoped_ptr<ChannelIDSourceCallback> callback_; |
| + scoped_ptr<ChannelIDKey> channel_id_key_; |
| +}; |
| + |
| } // anonymous namespace |
| CryptoTestUtils::FakeClientOptions::FakeClientOptions() |
| : dont_verify_certs(false), |
| - channel_id_enabled(false) { |
| + channel_id_enabled(false), |
| + channel_id_source_async(false) { |
| } |
| // static |
| @@ -176,9 +219,16 @@ int CryptoTestUtils::HandshakeWithFakeClient( |
| crypto_config.SetProofVerifier(FakeProofVerifierForTesting()); |
| } |
| bool is_https = false; |
| + AsyncTestChannelIDSource* async_channel_id_source = NULL; |
| if (options.channel_id_enabled) { |
| is_https = true; |
| - crypto_config.SetChannelIDSource(ChannelIDSourceForTesting()); |
| + |
| + ChannelIDSource* source = ChannelIDSourceForTesting(); |
| + if (options.channel_id_source_async) { |
| + async_channel_id_source = new AsyncTestChannelIDSource(source); |
| + source = async_channel_id_source; |
| + } |
| + crypto_config.SetChannelIDSource(source); |
| } |
| QuicServerId server_id(kServerHostname, kServerPort, is_https, |
| PRIVACY_MODE_DISABLED); |
| @@ -190,7 +240,8 @@ int CryptoTestUtils::HandshakeWithFakeClient( |
| CHECK(client.CryptoConnect()); |
| CHECK_EQ(1u, client_conn->packets_.size()); |
| - CommunicateHandshakeMessages(client_conn, &client, server_conn, server); |
| + CommunicateHandshakeMessages( |
| + client_conn, &client, server_conn, server, async_channel_id_source); |
| CompareClientAndServerKeys(&client, server); |
| @@ -226,20 +277,24 @@ void CryptoTestUtils::CommunicateHandshakeMessages( |
| PacketSavingConnection* a_conn, |
| QuicCryptoStream* a, |
| PacketSavingConnection* b_conn, |
| - QuicCryptoStream* b) { |
| + QuicCryptoStream* b, |
| + TaskSource* task_source) { |
| size_t a_i = 0, b_i = 0; |
| while (!a->handshake_confirmed()) { |
| + if (task_source) { |
| + task_source->RunPending(); |
| + } |
| ASSERT_GT(a_conn->packets_.size(), a_i); |
| LOG(INFO) << "Processing " << a_conn->packets_.size() - a_i |
| << " packets a->b"; |
| MovePackets(a_conn, &a_i, b, b_conn); |
| + if (task_source) { |
| + task_source->RunPending(); |
| + } |
| ASSERT_GT(b_conn->packets_.size(), b_i); |
| LOG(INFO) << "Processing " << b_conn->packets_.size() - b_i |
| << " packets b->a"; |
| - if (b_conn->packets_.size() - b_i == 2) { |
| - LOG(INFO) << "here"; |
|
wtc
2014/07/09 01:03:52
This looks like a debugging message that Adam forg
|
| - } |
| MovePackets(b_conn, &b_i, a, a_conn); |
| } |
| } |