| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_stream.h" | 5 #include "net/spdy/spdy_stream.h" |
| 6 #include "base/ref_counted.h" | 6 #include "base/ref_counted.h" |
| 7 #include "base/time.h" | |
| 8 #include "net/base/mock_host_resolver.h" | |
| 9 #include "net/base/net_errors.h" | |
| 10 #include "net/base/net_log.h" | |
| 11 #include "net/base/ssl_config_service.h" | |
| 12 #include "net/base/ssl_config_service_defaults.h" | |
| 13 #include "net/base/test_completion_callback.h" | |
| 14 #include "net/http/http_auth_handler_factory.h" | |
| 15 #include "net/http/http_network_session.h" | |
| 16 #include "net/http/http_request_info.h" | |
| 17 #include "net/http/http_response_info.h" | |
| 18 #include "net/proxy/proxy_service.h" | |
| 19 #include "net/socket/socket_test_util.h" | |
| 20 #include "net/spdy/spdy_framer.h" | |
| 21 #include "net/spdy/spdy_session.h" | 7 #include "net/spdy/spdy_session.h" |
| 22 #include "net/spdy/spdy_session_pool.h" | |
| 23 #include "net/spdy/spdy_test_util.h" | 8 #include "net/spdy/spdy_test_util.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 10 |
| 26 namespace net { | 11 namespace net { |
| 27 | 12 |
| 28 // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc | 13 // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc |
| 29 class SpdySessionPoolPeer { | 14 class SpdySessionPoolPeer { |
| 30 public: | 15 public: |
| 31 explicit SpdySessionPoolPeer(const scoped_refptr<SpdySessionPool>& pool) | 16 explicit SpdySessionPoolPeer(const scoped_refptr<SpdySessionPool>& pool) |
| 32 : pool_(pool) {} | 17 : pool_(pool) {} |
| 33 | 18 |
| 34 void RemoveSpdySession(const scoped_refptr<SpdySession>& session) { | 19 void RemoveSpdySession(const scoped_refptr<SpdySession>& session) { |
| 35 pool_->Remove(session); | 20 pool_->Remove(session); |
| 36 } | 21 } |
| 37 | 22 |
| 38 private: | 23 private: |
| 39 const scoped_refptr<SpdySessionPool> pool_; | 24 const scoped_refptr<SpdySessionPool> pool_; |
| 40 | 25 |
| 41 DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); | 26 DISALLOW_COPY_AND_ASSIGN(SpdySessionPoolPeer); |
| 42 }; | 27 }; |
| 43 | 28 |
| 44 namespace { | 29 namespace { |
| 45 | 30 |
| 46 // Create a proxy service which fails on all requests (falls back to direct). | 31 // Create a proxy service which fails on all requests (falls back to direct). |
| 47 ProxyService* CreateNullProxyService() { | 32 ProxyService* CreateNullProxyService() { |
| 48 return ProxyService::CreateNull(); | 33 return ProxyService::CreateNull(); |
| 49 } | 34 } |
| 50 | 35 |
| 51 // Helper to manage the lifetimes of the dependencies for a | |
| 52 // SpdyNetworkTransaction. | |
| 53 class SessionDependencies { | |
| 54 public: | |
| 55 // Default set of dependencies -- "null" proxy service. | |
| 56 SessionDependencies() | |
| 57 : host_resolver(new MockHostResolver), | |
| 58 proxy_service(CreateNullProxyService()), | |
| 59 ssl_config_service(new SSLConfigServiceDefaults), | |
| 60 http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), | |
| 61 spdy_session_pool(new SpdySessionPool()) {} | |
| 62 | |
| 63 // Custom proxy service dependency. | |
| 64 explicit SessionDependencies(ProxyService* proxy_service) | |
| 65 : host_resolver(new MockHostResolver), | |
| 66 proxy_service(proxy_service), | |
| 67 ssl_config_service(new SSLConfigServiceDefaults), | |
| 68 http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), | |
| 69 spdy_session_pool(new SpdySessionPool()) {} | |
| 70 | |
| 71 scoped_refptr<MockHostResolverBase> host_resolver; | |
| 72 scoped_refptr<ProxyService> proxy_service; | |
| 73 scoped_refptr<SSLConfigService> ssl_config_service; | |
| 74 MockClientSocketFactory socket_factory; | |
| 75 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; | |
| 76 scoped_refptr<SpdySessionPool> spdy_session_pool; | |
| 77 }; | |
| 78 | |
| 79 HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { | |
| 80 return new HttpNetworkSession(session_deps->host_resolver, | |
| 81 session_deps->proxy_service, | |
| 82 &session_deps->socket_factory, | |
| 83 session_deps->ssl_config_service, | |
| 84 session_deps->spdy_session_pool, | |
| 85 session_deps->http_auth_handler_factory.get(), | |
| 86 NULL, | |
| 87 NULL); | |
| 88 } | |
| 89 | |
| 90 class TestSpdyStreamDelegate : public SpdyStream::Delegate { | 36 class TestSpdyStreamDelegate : public SpdyStream::Delegate { |
| 91 public: | 37 public: |
| 92 TestSpdyStreamDelegate(SpdyStream* stream, | 38 TestSpdyStreamDelegate(SpdyStream* stream, |
| 93 IOBufferWithSize* buf, | 39 IOBufferWithSize* buf, |
| 94 CompletionCallback* callback) | 40 CompletionCallback* callback) |
| 95 : stream_(stream), | 41 : stream_(stream), |
| 96 buf_(buf), | 42 buf_(buf), |
| 97 callback_(callback), | 43 callback_(callback), |
| 98 send_headers_completed_(false), | 44 send_headers_completed_(false), |
| 99 response_(new spdy::SpdyHeaderBlock), | 45 response_(new spdy::SpdyHeaderBlock), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 125 } |
| 180 | 126 |
| 181 virtual void TearDown() { | 127 virtual void TearDown() { |
| 182 MessageLoop::current()->RunAllPending(); | 128 MessageLoop::current()->RunAllPending(); |
| 183 } | 129 } |
| 184 | 130 |
| 185 scoped_refptr<HttpNetworkSession> session_; | 131 scoped_refptr<HttpNetworkSession> session_; |
| 186 }; | 132 }; |
| 187 | 133 |
| 188 TEST_F(SpdyStreamTest, SendDataAfterOpen) { | 134 TEST_F(SpdyStreamTest, SendDataAfterOpen) { |
| 189 SessionDependencies session_deps; | 135 SpdySessionDependencies session_deps; |
| 190 | 136 |
| 191 session_ = CreateSession(&session_deps); | 137 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps); |
| 192 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); | 138 SpdySessionPoolPeer pool_peer_(session_->spdy_session_pool()); |
| 193 | 139 |
| 194 const SpdyHeaderInfo kSynStartHeader = { | 140 const SpdyHeaderInfo kSynStartHeader = { |
| 195 spdy::SYN_STREAM, | 141 spdy::SYN_STREAM, |
| 196 1, | 142 1, |
| 197 0, | 143 0, |
| 198 SPDY_PRIORITY_LOWEST, | 144 SPDY_PRIORITY_LOWEST, |
| 199 spdy::CONTROL_FLAG_NONE, | 145 spdy::CONTROL_FLAG_NONE, |
| 200 false, | 146 false, |
| 201 spdy::INVALID, | 147 spdy::INVALID, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 223 |
| 278 EXPECT_TRUE(delegate->send_headers_completed()); | 224 EXPECT_TRUE(delegate->send_headers_completed()); |
| 279 EXPECT_EQ("200", (*delegate->response())["status"]); | 225 EXPECT_EQ("200", (*delegate->response())["status"]); |
| 280 EXPECT_EQ("HTTP/1.1", (*delegate->response())["version"]); | 226 EXPECT_EQ("HTTP/1.1", (*delegate->response())["version"]); |
| 281 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data()); | 227 EXPECT_EQ(std::string("\0hello!\xff", 8), delegate->received_data()); |
| 282 EXPECT_EQ(8, delegate->data_sent()); | 228 EXPECT_EQ(8, delegate->data_sent()); |
| 283 EXPECT_TRUE(delegate->closed()); | 229 EXPECT_TRUE(delegate->closed()); |
| 284 } | 230 } |
| 285 | 231 |
| 286 } // namespace net | 232 } // namespace net |
| OLD | NEW |