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_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include "net/base/ip_endpoint.h" | 7 #include "net/base/ip_endpoint.h" |
8 #include "net/spdy/spdy_io_buffer.h" | 8 #include "net/spdy/spdy_io_buffer.h" |
9 #include "net/spdy/spdy_session_pool.h" | 9 #include "net/spdy/spdy_session_pool.h" |
10 #include "net/spdy/spdy_stream.h" | 10 #include "net/spdy/spdy_stream.h" |
11 #include "net/spdy/spdy_test_util.h" | 11 #include "net/spdy/spdy_test_util.h" |
12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 // TODO(cbentzel): Expose compression setter/getter in public SpdySession | 16 // TODO(cbentzel): Expose compression setter/getter in public SpdySession |
17 // interface rather than going through all these contortions. | 17 // interface rather than going through all these contortions. |
18 class SpdySessionTest : public PlatformTest { | 18 class SpdySessionTest : public PlatformTest { |
19 public: | 19 public: |
20 static void TurnOffCompression() { | 20 static void TurnOffCompression() { |
21 spdy::SpdyFramer::set_enable_compression_default(false); | 21 spdy::SpdyFramer::set_enable_compression_default(false); |
22 } | 22 } |
23 | |
24 protected: | |
25 virtual void SetUp() OVERRIDE { | |
26 // Disable sending PING. | |
27 SpdySession::set_enable_ping_based_connection_checking(false); | |
28 } | |
29 | |
30 virtual void TearDown() OVERRIDE { | |
31 // Enable sending PING. | |
32 SpdySession::set_enable_ping_based_connection_checking(true); | |
33 } | |
23 }; | 34 }; |
24 | 35 |
25 namespace { | 36 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate { |
37 public: | |
38 explicit TestSpdyStreamDelegate(OldCompletionCallback* callback) | |
39 : callback_(callback) {} | |
40 virtual ~TestSpdyStreamDelegate() {} | |
41 | |
42 virtual bool OnSendHeadersComplete(int status) { return true; } | |
43 | |
44 virtual int OnSendBody() { | |
45 return ERR_UNEXPECTED; | |
46 } | |
47 | |
48 virtual int OnSendBodyComplete(int /*status*/, bool* /*eof*/) { | |
49 return ERR_UNEXPECTED; | |
50 } | |
51 | |
52 virtual int OnResponseReceived(const spdy::SpdyHeaderBlock& response, | |
53 base::Time response_time, | |
54 int status) { | |
55 return status; | |
56 } | |
57 | |
58 virtual void OnDataReceived(const char* buffer, int bytes) { | |
59 } | |
60 | |
61 virtual void OnDataSent(int length) { | |
62 } | |
63 | |
64 virtual void OnClose(int status) { | |
65 OldCompletionCallback* callback = callback_; | |
66 callback_ = NULL; | |
67 callback->Run(OK); | |
68 } | |
69 | |
70 virtual void set_chunk_callback(net::ChunkCallback *) {} | |
71 | |
72 private: | |
73 OldCompletionCallback* callback_; | |
74 }; | |
75 | |
26 | 76 |
27 // Test the SpdyIOBuffer class. | 77 // Test the SpdyIOBuffer class. |
28 TEST_F(SpdySessionTest, SpdyIOBuffer) { | 78 TEST_F(SpdySessionTest, SpdyIOBuffer) { |
29 std::priority_queue<SpdyIOBuffer> queue_; | 79 std::priority_queue<SpdyIOBuffer> queue_; |
30 const size_t kQueueSize = 100; | 80 const size_t kQueueSize = 100; |
31 | 81 |
32 // Insert 100 items; pri 100 to 1. | 82 // Insert 100 items; pri 100 to 1. |
33 for (size_t index = 0; index < kQueueSize; ++index) { | 83 for (size_t index = 0; index < kQueueSize; ++index) { |
34 SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL); | 84 SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL); |
35 queue_.push(buffer); | 85 queue_.push(buffer); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 spdy_session_pool->Get(pair, BoundNetLog()); | 165 spdy_session_pool->Get(pair, BoundNetLog()); |
116 | 166 |
117 // Delete the first session. | 167 // Delete the first session. |
118 session = NULL; | 168 session = NULL; |
119 | 169 |
120 // Delete the second session. | 170 // Delete the second session. |
121 spdy_session_pool->Remove(session2); | 171 spdy_session_pool->Remove(session2); |
122 session2 = NULL; | 172 session2 = NULL; |
123 } | 173 } |
124 | 174 |
175 TEST_F(SpdySessionTest, Ping) { | |
176 SpdySessionDependencies session_deps; | |
177 session_deps.host_resolver->set_synchronous_mode(true); | |
178 | |
179 MockConnect connect_data(false, OK); | |
180 scoped_ptr<spdy::SpdyFrame> read_ping(ConstructSpdyPing()); | |
181 MockRead reads[] = { | |
182 CreateMockRead(*read_ping), | |
183 CreateMockRead(*read_ping), | |
184 MockRead(false, 0, 0) // EOF | |
185 }; | |
186 scoped_ptr<spdy::SpdyFrame> write_ping(ConstructSpdyPing()); | |
187 MockRead writes[] = { | |
188 CreateMockRead(*write_ping), | |
189 CreateMockRead(*write_ping), | |
190 }; | |
191 StaticSocketDataProvider data( | |
192 reads, arraysize(reads), writes, arraysize(writes)); | |
193 data.set_connect_data(connect_data); | |
194 session_deps.socket_factory->AddSocketDataProvider(&data); | |
195 | |
196 SSLSocketDataProvider ssl(false, OK); | |
197 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | |
198 | |
199 scoped_refptr<HttpNetworkSession> http_session( | |
200 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
201 | |
202 const char* kStreamUrl = "http://www.google.com/"; | |
willchan no longer on Chromium
2011/10/15 08:08:03
This is not a constant. It's a non-const pointer t
ramant (doing other things)
2011/10/15 23:33:11
Done.
| |
203 GURL url(kStreamUrl); | |
204 | |
205 const std::string kTestHost("www.google.com"); | |
206 const int kTestPort = 80; | |
207 HostPortPair test_host_port_pair(kTestHost, kTestPort); | |
208 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | |
209 | |
210 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | |
211 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | |
212 scoped_refptr<SpdySession> session = | |
213 spdy_session_pool->Get(pair, BoundNetLog()); | |
214 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | |
215 | |
216 | |
217 scoped_refptr<TransportSocketParams> transport_params( | |
218 new TransportSocketParams(test_host_port_pair, | |
219 MEDIUM, | |
220 GURL(), | |
221 false, | |
222 false)); | |
223 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
224 EXPECT_EQ(OK, | |
225 connection->Init(test_host_port_pair.ToString(), | |
226 transport_params, | |
227 MEDIUM, | |
228 NULL, | |
229 http_session->transport_socket_pool(), | |
230 BoundNetLog())); | |
231 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | |
232 | |
233 scoped_refptr<SpdyStream> spdy_stream1; | |
234 TestOldCompletionCallback callback1; | |
235 EXPECT_EQ(OK, session->CreateStream(url, | |
236 MEDIUM, | |
237 &spdy_stream1, | |
238 BoundNetLog(), | |
239 &callback1)); | |
240 scoped_ptr<TestSpdyStreamDelegate> delegate( | |
241 new TestSpdyStreamDelegate(&callback1)); | |
242 spdy_stream1->SetDelegate(delegate.get()); | |
243 | |
244 base::TimeTicks before_ping_time = base::TimeTicks::Now(); | |
245 | |
246 // Enable sending of PING. | |
247 SpdySession::set_enable_ping_based_connection_checking(true); | |
248 SpdySession::set_connection_at_risk_of_loss_ms(0); | |
249 SpdySession::set_trailing_ping_delay_time_ms(0); | |
250 SpdySession::set_hung_interval_ms(50); | |
251 | |
252 session->SendPrefacePingIfNoneInFlight(); | |
253 | |
254 EXPECT_EQ(OK, callback1.WaitForResult()); | |
255 | |
256 EXPECT_EQ(0, session->pings_in_flight()); | |
257 EXPECT_GT(session->next_ping_id(), static_cast<uint32>(1)); | |
258 EXPECT_FALSE(session->trailing_ping_pending()); | |
259 // TODO(rtenneti): check_ping_status_pending works in debug mode with | |
260 // breakpoints, but fails if run in stand alone mode. | |
261 // EXPECT_FALSE(session->check_ping_status_pending()); | |
262 EXPECT_GE(session->received_data_time(), before_ping_time); | |
263 | |
264 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | |
265 | |
266 // Delete the first session. | |
267 session = NULL; | |
268 } | |
269 | |
125 class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > { | 270 class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > { |
126 public: | 271 public: |
127 StreamReleaserCallback(SpdySession* session, | 272 StreamReleaserCallback(SpdySession* session, |
128 SpdyStream* first_stream) | 273 SpdyStream* first_stream) |
129 : session_(session), first_stream_(first_stream) {} | 274 : session_(session), first_stream_(first_stream) {} |
130 ~StreamReleaserCallback() {} | 275 ~StreamReleaserCallback() {} |
131 | 276 |
132 int WaitForResult() { return callback_.WaitForResult(); } | 277 int WaitForResult() { return callback_.WaitForResult(); } |
133 | 278 |
134 virtual void RunWithParams(const Tuple1<int>& params) { | 279 virtual void RunWithParams(const Tuple1<int>& params) { |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 const size_t max_concurrent_streams = 2; | 821 const size_t max_concurrent_streams = 2; |
677 spdy::SpdySettings test_settings; | 822 spdy::SpdySettings test_settings; |
678 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); | 823 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); |
679 | 824 |
680 test_settings_storage->Set(test_host_port_pair, test_settings); | 825 test_settings_storage->Set(test_host_port_pair, test_settings); |
681 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size()); | 826 EXPECT_NE(0u, test_settings_storage->Get(test_host_port_pair).size()); |
682 spdy_session_pool->OnIPAddressChanged(); | 827 spdy_session_pool->OnIPAddressChanged(); |
683 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size()); | 828 EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size()); |
684 } | 829 } |
685 | 830 |
686 } // namespace | |
687 | |
688 } // namespace net | 831 } // namespace net |
OLD | NEW |