OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 #include "net/spdy/spdy_session.h" | 6 #include "net/spdy/spdy_session.h" |
7 #include "net/spdy/spdy_test_util.h" | 7 #include "net/spdy/spdy_test_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
11 | 11 |
12 class SpdyHttpStreamTest : public testing::Test { | 12 class SpdyHttpStreamTest : public testing::Test { |
13 public: | 13 public: |
14 OrderedSocketData* data() { return data_; } | 14 OrderedSocketData* data() { return data_.get(); } |
15 protected: | 15 protected: |
16 SpdyHttpStreamTest() {} | 16 SpdyHttpStreamTest() {} |
17 | 17 |
18 void EnableCompression(bool enabled) { | 18 void EnableCompression(bool enabled) { |
19 spdy::SpdyFramer::set_enable_compression_default(enabled); | 19 spdy::SpdyFramer::set_enable_compression_default(enabled); |
20 } | 20 } |
21 | 21 |
22 virtual void TearDown() { | 22 virtual void TearDown() { |
23 MessageLoop::current()->RunAllPending(); | 23 MessageLoop::current()->RunAllPending(); |
24 } | 24 } |
25 int InitSession(MockRead* reads, size_t reads_count, | 25 int InitSession(MockRead* reads, size_t reads_count, |
26 MockWrite* writes, size_t writes_count, | 26 MockWrite* writes, size_t writes_count, |
27 HostPortPair& host_port_pair) { | 27 HostPortPair& host_port_pair) { |
28 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); | 28 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); |
29 data_ = new OrderedSocketData(reads, reads_count, writes, writes_count); | 29 data_.reset(new OrderedSocketData(reads, reads_count, |
| 30 writes, writes_count)); |
30 session_deps_.socket_factory->AddSocketDataProvider(data_.get()); | 31 session_deps_.socket_factory->AddSocketDataProvider(data_.get()); |
31 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 32 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
32 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); | 33 session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); |
33 transport_params_ = new TransportSocketParams(host_port_pair, | 34 transport_params_ = new TransportSocketParams(host_port_pair, |
34 MEDIUM, false, false); | 35 MEDIUM, false, false); |
35 TestCompletionCallback callback; | 36 TestCompletionCallback callback; |
36 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 37 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
37 EXPECT_EQ(ERR_IO_PENDING, | 38 EXPECT_EQ(ERR_IO_PENDING, |
38 connection->Init(host_port_pair.ToString(), | 39 connection->Init(host_port_pair.ToString(), |
39 transport_params_, | 40 transport_params_, |
40 MEDIUM, | 41 MEDIUM, |
41 callback.callback(), | 42 callback.callback(), |
42 http_session_->GetTransportSocketPool(), | 43 http_session_->GetTransportSocketPool(), |
43 BoundNetLog())); | 44 BoundNetLog())); |
44 EXPECT_EQ(OK, callback.WaitForResult()); | 45 EXPECT_EQ(OK, callback.WaitForResult()); |
45 return session_->InitializeWithSocket(connection.release(), false, OK); | 46 return session_->InitializeWithSocket(connection.release(), false, OK); |
46 } | 47 } |
47 SpdySessionDependencies session_deps_; | 48 SpdySessionDependencies session_deps_; |
48 scoped_refptr<OrderedSocketData> data_; | 49 scoped_ptr<OrderedSocketData> data_; |
49 scoped_refptr<HttpNetworkSession> http_session_; | 50 scoped_refptr<HttpNetworkSession> http_session_; |
50 scoped_refptr<SpdySession> session_; | 51 scoped_refptr<SpdySession> session_; |
51 scoped_refptr<TransportSocketParams> transport_params_; | 52 scoped_refptr<TransportSocketParams> transport_params_; |
52 }; | 53 }; |
53 | 54 |
54 TEST_F(SpdyHttpStreamTest, SendRequest) { | 55 TEST_F(SpdyHttpStreamTest, SendRequest) { |
55 EnableCompression(false); | 56 EnableCompression(false); |
56 SpdySession::SetSSLMode(false); | 57 SpdySession::SetSSLMode(false); |
57 | 58 |
58 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 59 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // pool anymore. | 218 // pool anymore. |
218 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); | 219 EXPECT_FALSE(http_session_->spdy_session_pool()->HasSession(pair)); |
219 EXPECT_TRUE(data()->at_read_eof()); | 220 EXPECT_TRUE(data()->at_read_eof()); |
220 EXPECT_TRUE(data()->at_write_eof()); | 221 EXPECT_TRUE(data()->at_write_eof()); |
221 } | 222 } |
222 | 223 |
223 // TODO(willchan): Write a longer test for SpdyStream that exercises all | 224 // TODO(willchan): Write a longer test for SpdyStream that exercises all |
224 // methods. | 225 // methods. |
225 | 226 |
226 } // namespace net | 227 } // namespace net |
OLD | NEW |