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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "net/base/completion_callback.h" | 6 #include "net/base/completion_callback.h" |
7 #include "net/base/net_log_unittest.h" | 7 #include "net/base/net_log_unittest.h" |
8 #include "net/spdy/spdy_stream.h" | 8 #include "net/spdy/spdy_stream.h" |
9 #include "net/spdy/spdy_http_utils.h" | 9 #include "net/spdy/spdy_http_utils.h" |
10 #include "net/spdy/spdy_session.h" | 10 #include "net/spdy/spdy_session.h" |
11 #include "net/spdy/spdy_test_util.h" | 11 #include "net/spdy/spdy_test_util_spdy3.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
| 14 using namespace net::test_spdy3; |
| 15 |
14 // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc | 16 // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc |
15 // | 17 // |
16 namespace net { | 18 namespace net { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 class TestSpdyStreamDelegate : public SpdyStream::Delegate { | 22 class TestSpdyStreamDelegate : public SpdyStream::Delegate { |
21 public: | 23 public: |
22 TestSpdyStreamDelegate(SpdyStream* stream, | 24 TestSpdyStreamDelegate(SpdyStream* stream, |
23 IOBufferWithSize* buf, | 25 IOBufferWithSize* buf, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 bool closed_; | 91 bool closed_; |
90 }; | 92 }; |
91 | 93 |
92 spdy::SpdyFrame* ConstructSpdyBodyFrame(const char* data, int length) { | 94 spdy::SpdyFrame* ConstructSpdyBodyFrame(const char* data, int length) { |
93 spdy::SpdyFramer framer; | 95 spdy::SpdyFramer framer; |
94 return framer.CreateDataFrame(1, data, length, spdy::DATA_FLAG_NONE); | 96 return framer.CreateDataFrame(1, data, length, spdy::DATA_FLAG_NONE); |
95 } | 97 } |
96 | 98 |
97 } // anonymous namespace | 99 } // anonymous namespace |
98 | 100 |
99 class SpdyStreamTest : public testing::Test { | 101 class SpdyStreamSpdy3Test : public testing::Test { |
100 protected: | 102 protected: |
101 SpdyStreamTest() { | 103 SpdyStreamSpdy3Test() { |
102 } | 104 } |
103 | 105 |
104 scoped_refptr<SpdySession> CreateSpdySession() { | 106 scoped_refptr<SpdySession> CreateSpdySession() { |
105 spdy::SpdyFramer::set_enable_compression_default(false); | 107 spdy::SpdyFramer::set_enable_compression_default(false); |
106 HostPortPair host_port_pair("www.google.com", 80); | 108 HostPortPair host_port_pair("www.google.com", 80); |
107 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); | 109 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); |
108 scoped_refptr<SpdySession> session( | 110 scoped_refptr<SpdySession> session( |
109 session_->spdy_session_pool()->Get(pair, BoundNetLog())); | 111 session_->spdy_session_pool()->Get(pair, BoundNetLog())); |
110 return session; | 112 return session; |
111 } | 113 } |
112 | 114 |
113 virtual void TearDown() { | 115 virtual void TearDown() { |
114 MessageLoop::current()->RunAllPending(); | 116 MessageLoop::current()->RunAllPending(); |
115 } | 117 } |
116 | 118 |
117 scoped_refptr<HttpNetworkSession> session_; | 119 scoped_refptr<HttpNetworkSession> session_; |
118 }; | 120 }; |
119 | 121 |
120 TEST_F(SpdyStreamTest, SendDataAfterOpen) { | 122 TEST_F(SpdyStreamSpdy3Test, SendDataAfterOpen) { |
121 SpdySessionDependencies session_deps; | 123 SpdySessionDependencies session_deps; |
122 | 124 |
123 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); | 125 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); |
124 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); | 126 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); |
125 | 127 |
126 const SpdyHeaderInfo kSynStartHeader = { | 128 const SpdyHeaderInfo kSynStartHeader = { |
127 spdy::SYN_STREAM, | 129 spdy::SYN_STREAM, |
128 1, | 130 1, |
129 0, | 131 0, |
130 net::ConvertRequestPriorityToSpdyPriority(LOWEST), | 132 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 EXPECT_EQ(OK, callback.WaitForResult()); | 227 EXPECT_EQ(OK, callback.WaitForResult()); |
226 | 228 |
227 EXPECT_TRUE(delegate->send_headers_completed()); | 229 EXPECT_TRUE(delegate->send_headers_completed()); |
228 EXPECT_EQ("200", (*delegate->response())["status"]); | 230 EXPECT_EQ("200", (*delegate->response())["status"]); |
229 EXPECT_EQ("HTTP/1.1", (*delegate->response())["version"]); | 231 EXPECT_EQ("HTTP/1.1", (*delegate->response())["version"]); |
230 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data()); | 232 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data()); |
231 EXPECT_EQ(8, delegate->data_sent()); | 233 EXPECT_EQ(8, delegate->data_sent()); |
232 EXPECT_TRUE(delegate->closed()); | 234 EXPECT_TRUE(delegate->closed()); |
233 } | 235 } |
234 | 236 |
235 TEST_F(SpdyStreamTest, PushedStream) { | 237 TEST_F(SpdyStreamSpdy3Test, PushedStream) { |
236 const char kStreamUrl[] = "http://www.google.com/"; | 238 const char kStreamUrl[] = "http://www.google.com/"; |
237 | 239 |
238 SpdySessionDependencies session_deps; | 240 SpdySessionDependencies session_deps; |
239 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); | 241 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); |
240 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); | 242 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); |
241 scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); | 243 scoped_refptr<SpdySession> spdy_session(CreateSpdySession()); |
242 BoundNetLog net_log; | 244 BoundNetLog net_log; |
243 | 245 |
244 // Conjure up a stream. | 246 // Conjure up a stream. |
245 scoped_refptr<SpdyStream> stream = new SpdyStream(spdy_session, | 247 scoped_refptr<SpdyStream> stream = new SpdyStream(spdy_session, |
(...skipping 13 matching lines...) Expand all Loading... |
259 response["status"] = "200"; | 261 response["status"] = "200"; |
260 response["version"] = "OK"; | 262 response["version"] = "OK"; |
261 stream->OnHeaders(headers); | 263 stream->OnHeaders(headers); |
262 | 264 |
263 stream->set_response_received(); | 265 stream->set_response_received(); |
264 EXPECT_TRUE(stream->response_received()); | 266 EXPECT_TRUE(stream->response_received()); |
265 EXPECT_TRUE(stream->HasUrl()); | 267 EXPECT_TRUE(stream->HasUrl()); |
266 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); | 268 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
267 } | 269 } |
268 | 270 |
269 TEST_F(SpdyStreamTest, StreamError) { | 271 TEST_F(SpdyStreamSpdy3Test, StreamError) { |
270 SpdySessionDependencies session_deps; | 272 SpdySessionDependencies session_deps; |
271 | 273 |
272 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); | 274 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); |
273 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); | 275 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); |
274 | 276 |
275 const SpdyHeaderInfo kSynStartHeader = { | 277 const SpdyHeaderInfo kSynStartHeader = { |
276 spdy::SYN_STREAM, | 278 spdy::SYN_STREAM, |
277 1, | 279 1, |
278 0, | 280 0, |
279 net::ConvertRequestPriorityToSpdyPriority(LOWEST), | 281 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 net::NetLog::PHASE_NONE); | 398 net::NetLog::PHASE_NONE); |
397 | 399 |
398 CapturingNetLog::Entry entry = entries[pos]; | 400 CapturingNetLog::Entry entry = entries[pos]; |
399 NetLogSpdyStreamErrorParameter* request_params = | 401 NetLogSpdyStreamErrorParameter* request_params = |
400 static_cast<NetLogSpdyStreamErrorParameter*>( | 402 static_cast<NetLogSpdyStreamErrorParameter*>( |
401 entry.extra_parameters.get()); | 403 entry.extra_parameters.get()); |
402 EXPECT_EQ(stream_id, request_params->stream_id()); | 404 EXPECT_EQ(stream_id, request_params->stream_id()); |
403 } | 405 } |
404 | 406 |
405 } // namespace net | 407 } // namespace net |
OLD | NEW |