| OLD | NEW |
| 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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/mock_host_resolver.h" | 9 #include "net/base/mock_host_resolver.h" |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| 11 #include "net/http/http_response_info.h" | 11 #include "net/http/http_response_info.h" |
| 12 #include "net/http/http_util.h" | 12 #include "net/http/http_util.h" |
| 13 #include "net/quic/quic_http_stream.h" | 13 #include "net/quic/quic_http_stream.h" |
| 14 #include "net/quic/test_tools/mock_clock.h" | 14 #include "net/quic/test_tools/mock_clock.h" |
| 15 #include "net/quic/test_tools/mock_random.h" | 15 #include "net/quic/test_tools/mock_random.h" |
| 16 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
| 17 #include "net/socket/socket_test_util.h" | 17 #include "net/socket/socket_test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 namespace test { | 21 namespace test { |
| 22 | 22 |
| 23 class QuicStreamFactoryTest : public ::testing::Test { | 23 class QuicStreamFactoryTest : public ::testing::Test { |
| 24 protected: | 24 protected: |
| 25 QuicStreamFactoryTest() | 25 QuicStreamFactoryTest() |
| 26 : factory_(&host_resolver_, &socket_factory_, | 26 : clock_(new MockClock()), |
| 27 &random_generator_, | 27 factory_(&host_resolver_, &socket_factory_, |
| 28 new MockClock()), | 28 &random_generator_, clock_), |
| 29 host_port_proxy_pair_(HostPortPair("www.google.com", 443), | 29 host_port_proxy_pair_(HostPortPair("www.google.com", 443), |
| 30 ProxyServer::Direct()) { | 30 ProxyServer::Direct()) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 scoped_ptr<QuicEncryptedPacket> ConstructChlo() { | 33 scoped_ptr<QuicEncryptedPacket> ConstructChlo() { |
| 34 scoped_ptr<QuicPacket> chlo(ConstructHandshakePacket(0xDEADBEEF, kCHLO)); | 34 scoped_ptr<QuicPacket> chlo(ConstructClientHelloPacket(0xDEADBEEF, |
| 35 clock_, |
| 36 &random_generator_)); |
| 35 QuicFramer framer(QuicDecrypter::Create(kNULL), | 37 QuicFramer framer(QuicDecrypter::Create(kNULL), |
| 36 QuicEncrypter::Create(kNULL)); | 38 QuicEncrypter::Create(kNULL)); |
| 37 return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket(*chlo)); | 39 return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket(*chlo)); |
| 38 } | 40 } |
| 39 | 41 |
| 40 scoped_ptr<QuicEncryptedPacket> ConstructShlo() { | 42 scoped_ptr<QuicEncryptedPacket> ConstructShlo() { |
| 41 scoped_ptr<QuicPacket> shlo(ConstructHandshakePacket(0xDEADBEEF, kSHLO)); | 43 scoped_ptr<QuicPacket> shlo(ConstructHandshakePacket(0xDEADBEEF, kSHLO)); |
| 42 QuicFramer framer(QuicDecrypter::Create(kNULL), | 44 QuicFramer framer(QuicDecrypter::Create(kNULL), |
| 43 QuicEncrypter::Create(kNULL)); | 45 QuicEncrypter::Create(kNULL)); |
| 44 return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket(*shlo)); | 46 return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket(*shlo)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 QuicFrames frames; | 101 QuicFrames frames; |
| 100 frames.push_back(frame); | 102 frames.push_back(frame); |
| 101 scoped_ptr<QuicPacket> packet( | 103 scoped_ptr<QuicPacket> packet( |
| 102 framer.ConstructFrameDataPacket(header, frames)); | 104 framer.ConstructFrameDataPacket(header, frames)); |
| 103 return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket(*packet)); | 105 return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket(*packet)); |
| 104 } | 106 } |
| 105 | 107 |
| 106 MockHostResolver host_resolver_; | 108 MockHostResolver host_resolver_; |
| 107 MockClientSocketFactory socket_factory_; | 109 MockClientSocketFactory socket_factory_; |
| 108 MockRandom random_generator_; | 110 MockRandom random_generator_; |
| 111 MockClock* clock_; // Owned by factory_. |
| 109 QuicStreamFactory factory_; | 112 QuicStreamFactory factory_; |
| 110 HostPortProxyPair host_port_proxy_pair_; | 113 HostPortProxyPair host_port_proxy_pair_; |
| 111 BoundNetLog net_log_; | 114 BoundNetLog net_log_; |
| 112 TestCompletionCallback callback_; | 115 TestCompletionCallback callback_; |
| 113 }; | 116 }; |
| 114 | 117 |
| 115 TEST_F(QuicStreamFactoryTest, CreateIfSessionExists) { | 118 TEST_F(QuicStreamFactoryTest, CreateIfSessionExists) { |
| 116 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, | 119 EXPECT_EQ(NULL, factory_.CreateIfSessionExists(host_port_proxy_pair_, |
| 117 net_log_).get()); | 120 net_log_).get()); |
| 118 } | 121 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_)); | 218 factory_.CreateIfSessionExists(host_port_proxy_pair_, net_log_)); |
| 216 EXPECT_TRUE(stream.get()); | 219 EXPECT_TRUE(stream.get()); |
| 217 stream.reset(); | 220 stream.reset(); |
| 218 | 221 |
| 219 EXPECT_TRUE(socket_data.at_read_eof()); | 222 EXPECT_TRUE(socket_data.at_read_eof()); |
| 220 EXPECT_TRUE(socket_data.at_write_eof()); | 223 EXPECT_TRUE(socket_data.at_write_eof()); |
| 221 } | 224 } |
| 222 | 225 |
| 223 } // namespace test | 226 } // namespace test |
| 224 } // namespace net | 227 } // namespace net |
| OLD | NEW |