Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: net/quic/quic_crypto_client_stream_test.cc

Issue 114933003: Minor cleanup of QUIC MockConnection and PacketSavingConnection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_client_session_test.cc ('k') | net/quic/quic_crypto_server_stream_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/quic/quic_crypto_client_stream.h" 5 #include "net/quic/quic_crypto_client_stream.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
9 #include "net/quic/crypto/quic_decrypter.h" 9 #include "net/quic/crypto/quic_decrypter.h"
10 #include "net/quic/crypto/quic_encrypter.h" 10 #include "net/quic/crypto/quic_encrypter.h"
11 #include "net/quic/quic_protocol.h" 11 #include "net/quic/quic_protocol.h"
12 #include "net/quic/test_tools/crypto_test_utils.h" 12 #include "net/quic/test_tools/crypto_test_utils.h"
13 #include "net/quic/test_tools/quic_test_utils.h" 13 #include "net/quic/test_tools/quic_test_utils.h"
14 #include "net/quic/test_tools/simple_quic_framer.h" 14 #include "net/quic/test_tools/simple_quic_framer.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace net { 18 namespace net {
19 namespace test { 19 namespace test {
20 namespace { 20 namespace {
21 21
22 const char kServerHostname[] = "example.com"; 22 const char kServerHostname[] = "example.com";
23 23
24 class QuicCryptoClientStreamTest : public ::testing::Test { 24 class QuicCryptoClientStreamTest : public ::testing::Test {
25 public: 25 public:
26 QuicCryptoClientStreamTest() 26 QuicCryptoClientStreamTest()
27 : addr_(), 27 : connection_(new PacketSavingConnection(false)),
28 connection_(new PacketSavingConnection(1, addr_, false)),
29 session_(new TestSession(connection_, DefaultQuicConfig(), false)), 28 session_(new TestSession(connection_, DefaultQuicConfig(), false)),
30 stream_(new QuicCryptoClientStream(kServerHostname, session_.get(), 29 stream_(new QuicCryptoClientStream(kServerHostname, session_.get(),
31 &crypto_config_)) { 30 &crypto_config_)) {
32 session_->SetCryptoStream(stream_.get()); 31 session_->SetCryptoStream(stream_.get());
33 crypto_config_.SetDefaults(); 32 crypto_config_.SetDefaults();
34 } 33 }
35 34
36 void CompleteCryptoHandshake() { 35 void CompleteCryptoHandshake() {
37 EXPECT_TRUE(stream_->CryptoConnect()); 36 EXPECT_TRUE(stream_->CryptoConnect());
38 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); 37 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get());
39 } 38 }
40 39
41 void ConstructHandshakeMessage() { 40 void ConstructHandshakeMessage() {
42 CryptoFramer framer; 41 CryptoFramer framer;
43 message_data_.reset(framer.ConstructHandshakeMessage(message_)); 42 message_data_.reset(framer.ConstructHandshakeMessage(message_));
44 } 43 }
45 44
46 IPEndPoint addr_;
47 PacketSavingConnection* connection_; 45 PacketSavingConnection* connection_;
48 scoped_ptr<TestSession> session_; 46 scoped_ptr<TestSession> session_;
49 scoped_ptr<QuicCryptoClientStream> stream_; 47 scoped_ptr<QuicCryptoClientStream> stream_;
50 CryptoHandshakeMessage message_; 48 CryptoHandshakeMessage message_;
51 scoped_ptr<QuicData> message_data_; 49 scoped_ptr<QuicData> message_data_;
52 QuicCryptoClientConfig crypto_config_; 50 QuicCryptoClientConfig crypto_config_;
53 }; 51 };
54 52
55 TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) { 53 TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) {
56 EXPECT_FALSE(stream_->encryption_established()); 54 EXPECT_FALSE(stream_->encryption_established());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 106
109 CompleteCryptoHandshake(); 107 CompleteCryptoHandshake();
110 EXPECT_TRUE(stream_->encryption_established()); 108 EXPECT_TRUE(stream_->encryption_established());
111 EXPECT_TRUE(stream_->handshake_confirmed()); 109 EXPECT_TRUE(stream_->handshake_confirmed());
112 } 110 }
113 111
114 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { 112 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) {
115 // Seed the config with a cached server config. 113 // Seed the config with a cached server config.
116 CompleteCryptoHandshake(); 114 CompleteCryptoHandshake();
117 115
118 connection_ = new PacketSavingConnection(1, addr_, true); 116 connection_ = new PacketSavingConnection(true);
119 session_.reset(new TestSession(connection_, DefaultQuicConfig(), true)); 117 session_.reset(new TestSession(connection_, DefaultQuicConfig(), true));
120 stream_.reset(new QuicCryptoClientStream(kServerHostname, session_.get(), 118 stream_.reset(new QuicCryptoClientStream(kServerHostname, session_.get(),
121 &crypto_config_)); 119 &crypto_config_));
122 120
123 session_->SetCryptoStream(stream_.get()); 121 session_->SetCryptoStream(stream_.get());
124 session_->config()->SetDefaults(); 122 session_->config()->SetDefaults();
125 123
126 // Advance time 5 years to ensure that we pass the expiry time of the cached 124 // Advance time 5 years to ensure that we pass the expiry time of the cached
127 // server config. 125 // server config.
128 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) 126 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock()))
129 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); 127 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5));
130 128
131 // Check that a client hello was sent and that CryptoConnect doesn't fail 129 // Check that a client hello was sent and that CryptoConnect doesn't fail
132 // with an error. 130 // with an error.
133 EXPECT_TRUE(stream_->CryptoConnect()); 131 EXPECT_TRUE(stream_->CryptoConnect());
134 ASSERT_EQ(1u, connection_->packets_.size()); 132 ASSERT_EQ(1u, connection_->packets_.size());
135 } 133 }
136 134
137 } // namespace 135 } // namespace
138 } // namespace test 136 } // namespace test
139 } // namespace net 137 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_client_session_test.cc ('k') | net/quic/quic_crypto_server_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698