| 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/websockets/websocket_job.h" | 5 #include "net/websockets/websocket_job.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "net/spdy/spdy_websocket_test_util_spdy3.h" | 31 #include "net/spdy/spdy_websocket_test_util_spdy3.h" |
| 32 #include "net/ssl/ssl_config_service.h" | 32 #include "net/ssl/ssl_config_service.h" |
| 33 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
| 34 #include "net/websockets/websocket_throttle.h" | 34 #include "net/websockets/websocket_throttle.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "testing/platform_test.h" | 37 #include "testing/platform_test.h" |
| 38 | 38 |
| 39 using namespace net::test_spdy3; | 39 using namespace net::test_spdy3; |
| 40 | 40 |
| 41 namespace net { |
| 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 class MockSocketStream : public net::SocketStream { | 45 class MockSocketStream : public SocketStream { |
| 44 public: | 46 public: |
| 45 MockSocketStream(const GURL& url, net::SocketStream::Delegate* delegate) | 47 MockSocketStream(const GURL& url, SocketStream::Delegate* delegate) |
| 46 : SocketStream(url, delegate) { | 48 : SocketStream(url, delegate) { |
| 47 } | 49 } |
| 48 | 50 |
| 49 virtual void Connect() OVERRIDE {} | 51 virtual void Connect() OVERRIDE {} |
| 50 virtual bool SendData(const char* data, int len) OVERRIDE { | 52 virtual bool SendData(const char* data, int len) OVERRIDE { |
| 51 sent_data_ += std::string(data, len); | 53 sent_data_ += std::string(data, len); |
| 52 return true; | 54 return true; |
| 53 } | 55 } |
| 54 | 56 |
| 55 virtual void Close() OVERRIDE {} | 57 virtual void Close() OVERRIDE {} |
| 56 virtual void RestartWithAuth( | 58 virtual void RestartWithAuth( |
| 57 const net::AuthCredentials& credentials) OVERRIDE { | 59 const AuthCredentials& credentials) OVERRIDE { |
| 58 } | 60 } |
| 59 | 61 |
| 60 virtual void DetachDelegate() OVERRIDE { | 62 virtual void DetachDelegate() OVERRIDE { |
| 61 delegate_ = NULL; | 63 delegate_ = NULL; |
| 62 } | 64 } |
| 63 | 65 |
| 64 const std::string& sent_data() const { | 66 const std::string& sent_data() const { |
| 65 return sent_data_; | 67 return sent_data_; |
| 66 } | 68 } |
| 67 | 69 |
| 68 protected: | 70 protected: |
| 69 virtual ~MockSocketStream() {} | 71 virtual ~MockSocketStream() {} |
| 70 | 72 |
| 71 private: | 73 private: |
| 72 std::string sent_data_; | 74 std::string sent_data_; |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 class MockSocketStreamDelegate : public net::SocketStream::Delegate { | 77 class MockSocketStreamDelegate : public SocketStream::Delegate { |
| 76 public: | 78 public: |
| 77 MockSocketStreamDelegate() | 79 MockSocketStreamDelegate() |
| 78 : amount_sent_(0), | 80 : amount_sent_(0), |
| 79 allow_all_cookies_(true) { | 81 allow_all_cookies_(true) { |
| 80 } | 82 } |
| 81 | 83 |
| 82 void set_allow_all_cookies(bool allow_all_cookies) { | 84 void set_allow_all_cookies(bool allow_all_cookies) { |
| 83 allow_all_cookies_ = allow_all_cookies; | 85 allow_all_cookies_ = allow_all_cookies; |
| 84 } | 86 } |
| 85 virtual ~MockSocketStreamDelegate() {} | 87 virtual ~MockSocketStreamDelegate() {} |
| 86 | 88 |
| 87 void SetOnStartOpenConnection(const base::Closure& callback) { | 89 void SetOnStartOpenConnection(const base::Closure& callback) { |
| 88 on_start_open_connection_ = callback; | 90 on_start_open_connection_ = callback; |
| 89 } | 91 } |
| 90 void SetOnConnected(const base::Closure& callback) { | 92 void SetOnConnected(const base::Closure& callback) { |
| 91 on_connected_ = callback; | 93 on_connected_ = callback; |
| 92 } | 94 } |
| 93 void SetOnSentData(const base::Closure& callback) { | 95 void SetOnSentData(const base::Closure& callback) { |
| 94 on_sent_data_ = callback; | 96 on_sent_data_ = callback; |
| 95 } | 97 } |
| 96 void SetOnReceivedData(const base::Closure& callback) { | 98 void SetOnReceivedData(const base::Closure& callback) { |
| 97 on_received_data_ = callback; | 99 on_received_data_ = callback; |
| 98 } | 100 } |
| 99 void SetOnClose(const base::Closure& callback) { | 101 void SetOnClose(const base::Closure& callback) { |
| 100 on_close_ = callback; | 102 on_close_ = callback; |
| 101 } | 103 } |
| 102 | 104 |
| 103 virtual int OnStartOpenConnection( | 105 virtual int OnStartOpenConnection( |
| 104 net::SocketStream* socket, | 106 SocketStream* socket, |
| 105 const net::CompletionCallback& callback) OVERRIDE { | 107 const CompletionCallback& callback) OVERRIDE { |
| 106 if (!on_start_open_connection_.is_null()) | 108 if (!on_start_open_connection_.is_null()) |
| 107 on_start_open_connection_.Run(); | 109 on_start_open_connection_.Run(); |
| 108 return net::OK; | 110 return OK; |
| 109 } | 111 } |
| 110 virtual void OnConnected(net::SocketStream* socket, | 112 virtual void OnConnected(SocketStream* socket, |
| 111 int max_pending_send_allowed) OVERRIDE { | 113 int max_pending_send_allowed) OVERRIDE { |
| 112 if (!on_connected_.is_null()) | 114 if (!on_connected_.is_null()) |
| 113 on_connected_.Run(); | 115 on_connected_.Run(); |
| 114 } | 116 } |
| 115 virtual void OnSentData(net::SocketStream* socket, | 117 virtual void OnSentData(SocketStream* socket, |
| 116 int amount_sent) OVERRIDE { | 118 int amount_sent) OVERRIDE { |
| 117 amount_sent_ += amount_sent; | 119 amount_sent_ += amount_sent; |
| 118 if (!on_sent_data_.is_null()) | 120 if (!on_sent_data_.is_null()) |
| 119 on_sent_data_.Run(); | 121 on_sent_data_.Run(); |
| 120 } | 122 } |
| 121 virtual void OnReceivedData(net::SocketStream* socket, | 123 virtual void OnReceivedData(SocketStream* socket, |
| 122 const char* data, int len) OVERRIDE { | 124 const char* data, int len) OVERRIDE { |
| 123 received_data_ += std::string(data, len); | 125 received_data_ += std::string(data, len); |
| 124 if (!on_received_data_.is_null()) | 126 if (!on_received_data_.is_null()) |
| 125 on_received_data_.Run(); | 127 on_received_data_.Run(); |
| 126 } | 128 } |
| 127 virtual void OnClose(net::SocketStream* socket) OVERRIDE { | 129 virtual void OnClose(SocketStream* socket) OVERRIDE { |
| 128 if (!on_close_.is_null()) | 130 if (!on_close_.is_null()) |
| 129 on_close_.Run(); | 131 on_close_.Run(); |
| 130 } | 132 } |
| 131 virtual bool CanGetCookies(net::SocketStream* socket, | 133 virtual bool CanGetCookies(SocketStream* socket, |
| 132 const GURL& url) OVERRIDE { | 134 const GURL& url) OVERRIDE { |
| 133 return allow_all_cookies_; | 135 return allow_all_cookies_; |
| 134 } | 136 } |
| 135 virtual bool CanSetCookie(net::SocketStream* request, | 137 virtual bool CanSetCookie(SocketStream* request, |
| 136 const GURL& url, | 138 const GURL& url, |
| 137 const std::string& cookie_line, | 139 const std::string& cookie_line, |
| 138 net::CookieOptions* options) OVERRIDE { | 140 CookieOptions* options) OVERRIDE { |
| 139 return allow_all_cookies_; | 141 return allow_all_cookies_; |
| 140 } | 142 } |
| 141 | 143 |
| 142 size_t amount_sent() const { return amount_sent_; } | 144 size_t amount_sent() const { return amount_sent_; } |
| 143 const std::string& received_data() const { return received_data_; } | 145 const std::string& received_data() const { return received_data_; } |
| 144 | 146 |
| 145 private: | 147 private: |
| 146 int amount_sent_; | 148 int amount_sent_; |
| 147 bool allow_all_cookies_; | 149 bool allow_all_cookies_; |
| 148 std::string received_data_; | 150 std::string received_data_; |
| 149 base::Closure on_start_open_connection_; | 151 base::Closure on_start_open_connection_; |
| 150 base::Closure on_connected_; | 152 base::Closure on_connected_; |
| 151 base::Closure on_sent_data_; | 153 base::Closure on_sent_data_; |
| 152 base::Closure on_received_data_; | 154 base::Closure on_received_data_; |
| 153 base::Closure on_close_; | 155 base::Closure on_close_; |
| 154 }; | 156 }; |
| 155 | 157 |
| 156 class MockCookieStore : public net::CookieStore { | 158 class MockCookieStore : public CookieStore { |
| 157 public: | 159 public: |
| 158 struct Entry { | 160 struct Entry { |
| 159 GURL url; | 161 GURL url; |
| 160 std::string cookie_line; | 162 std::string cookie_line; |
| 161 net::CookieOptions options; | 163 CookieOptions options; |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 MockCookieStore() {} | 166 MockCookieStore() {} |
| 165 | 167 |
| 166 bool SetCookieWithOptions(const GURL& url, | 168 bool SetCookieWithOptions(const GURL& url, |
| 167 const std::string& cookie_line, | 169 const std::string& cookie_line, |
| 168 const net::CookieOptions& options) { | 170 const CookieOptions& options) { |
| 169 Entry entry; | 171 Entry entry; |
| 170 entry.url = url; | 172 entry.url = url; |
| 171 entry.cookie_line = cookie_line; | 173 entry.cookie_line = cookie_line; |
| 172 entry.options = options; | 174 entry.options = options; |
| 173 entries_.push_back(entry); | 175 entries_.push_back(entry); |
| 174 return true; | 176 return true; |
| 175 } | 177 } |
| 176 | 178 |
| 177 std::string GetCookiesWithOptions(const GURL& url, | 179 std::string GetCookiesWithOptions(const GURL& url, |
| 178 const net::CookieOptions& options) { | 180 const CookieOptions& options) { |
| 179 std::string result; | 181 std::string result; |
| 180 for (size_t i = 0; i < entries_.size(); i++) { | 182 for (size_t i = 0; i < entries_.size(); i++) { |
| 181 Entry& entry = entries_[i]; | 183 Entry& entry = entries_[i]; |
| 182 if (url == entry.url) { | 184 if (url == entry.url) { |
| 183 if (!result.empty()) { | 185 if (!result.empty()) { |
| 184 result += "; "; | 186 result += "; "; |
| 185 } | 187 } |
| 186 result += entry.cookie_line; | 188 result += entry.cookie_line; |
| 187 } | 189 } |
| 188 } | 190 } |
| 189 return result; | 191 return result; |
| 190 } | 192 } |
| 191 | 193 |
| 192 // CookieStore: | 194 // CookieStore: |
| 193 virtual void SetCookieWithOptionsAsync( | 195 virtual void SetCookieWithOptionsAsync( |
| 194 const GURL& url, | 196 const GURL& url, |
| 195 const std::string& cookie_line, | 197 const std::string& cookie_line, |
| 196 const net::CookieOptions& options, | 198 const CookieOptions& options, |
| 197 const SetCookiesCallback& callback) OVERRIDE { | 199 const SetCookiesCallback& callback) OVERRIDE { |
| 198 bool result = SetCookieWithOptions(url, cookie_line, options); | 200 bool result = SetCookieWithOptions(url, cookie_line, options); |
| 199 if (!callback.is_null()) | 201 if (!callback.is_null()) |
| 200 callback.Run(result); | 202 callback.Run(result); |
| 201 } | 203 } |
| 202 | 204 |
| 203 virtual void GetCookiesWithOptionsAsync( | 205 virtual void GetCookiesWithOptionsAsync( |
| 204 const GURL& url, | 206 const GURL& url, |
| 205 const net::CookieOptions& options, | 207 const CookieOptions& options, |
| 206 const GetCookiesCallback& callback) OVERRIDE { | 208 const GetCookiesCallback& callback) OVERRIDE { |
| 207 if (!callback.is_null()) | 209 if (!callback.is_null()) |
| 208 callback.Run(GetCookiesWithOptions(url, options)); | 210 callback.Run(GetCookiesWithOptions(url, options)); |
| 209 } | 211 } |
| 210 | 212 |
| 211 virtual void DeleteCookieAsync(const GURL& url, | 213 virtual void DeleteCookieAsync(const GURL& url, |
| 212 const std::string& cookie_name, | 214 const std::string& cookie_name, |
| 213 const base::Closure& callback) OVERRIDE { | 215 const base::Closure& callback) OVERRIDE { |
| 214 ADD_FAILURE(); | 216 ADD_FAILURE(); |
| 215 } | 217 } |
| 216 | 218 |
| 217 virtual void DeleteAllCreatedBetweenAsync( | 219 virtual void DeleteAllCreatedBetweenAsync( |
| 218 const base::Time& delete_begin, | 220 const base::Time& delete_begin, |
| 219 const base::Time& delete_end, | 221 const base::Time& delete_end, |
| 220 const DeleteCallback& callback) OVERRIDE { | 222 const DeleteCallback& callback) OVERRIDE { |
| 221 ADD_FAILURE(); | 223 ADD_FAILURE(); |
| 222 } | 224 } |
| 223 | 225 |
| 224 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE { | 226 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE { |
| 225 ADD_FAILURE(); | 227 ADD_FAILURE(); |
| 226 } | 228 } |
| 227 | 229 |
| 228 virtual net::CookieMonster* GetCookieMonster() OVERRIDE { return NULL; } | 230 virtual CookieMonster* GetCookieMonster() OVERRIDE { return NULL; } |
| 229 | 231 |
| 230 const std::vector<Entry>& entries() const { return entries_; } | 232 const std::vector<Entry>& entries() const { return entries_; } |
| 231 | 233 |
| 232 private: | 234 private: |
| 233 friend class base::RefCountedThreadSafe<MockCookieStore>; | 235 friend class base::RefCountedThreadSafe<MockCookieStore>; |
| 234 virtual ~MockCookieStore() {} | 236 virtual ~MockCookieStore() {} |
| 235 | 237 |
| 236 std::vector<Entry> entries_; | 238 std::vector<Entry> entries_; |
| 237 }; | 239 }; |
| 238 | 240 |
| 239 class MockSSLConfigService : public net::SSLConfigService { | 241 class MockSSLConfigService : public SSLConfigService { |
| 240 public: | 242 public: |
| 241 virtual void GetSSLConfig(net::SSLConfig* config) OVERRIDE {} | 243 virtual void GetSSLConfig(SSLConfig* config) OVERRIDE {} |
| 242 | 244 |
| 243 protected: | 245 protected: |
| 244 virtual ~MockSSLConfigService() {} | 246 virtual ~MockSSLConfigService() {} |
| 245 }; | 247 }; |
| 246 | 248 |
| 247 class MockURLRequestContext : public net::URLRequestContext { | 249 class MockURLRequestContext : public URLRequestContext { |
| 248 public: | 250 public: |
| 249 explicit MockURLRequestContext(net::CookieStore* cookie_store) | 251 explicit MockURLRequestContext(CookieStore* cookie_store) |
| 250 : transport_security_state_() { | 252 : transport_security_state_() { |
| 251 set_cookie_store(cookie_store); | 253 set_cookie_store(cookie_store); |
| 252 set_transport_security_state(&transport_security_state_); | 254 set_transport_security_state(&transport_security_state_); |
| 253 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); | 255 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
| 254 bool include_subdomains = false; | 256 bool include_subdomains = false; |
| 255 transport_security_state_.AddHSTS("upgrademe.com", expiry, | 257 transport_security_state_.AddHSTS("upgrademe.com", expiry, |
| 256 include_subdomains); | 258 include_subdomains); |
| 257 } | 259 } |
| 258 | 260 |
| 259 virtual ~MockURLRequestContext() {} | 261 virtual ~MockURLRequestContext() {} |
| 260 | 262 |
| 261 private: | 263 private: |
| 262 net::TransportSecurityState transport_security_state_; | 264 TransportSecurityState transport_security_state_; |
| 263 }; | 265 }; |
| 264 | 266 |
| 265 class MockHttpTransactionFactory : public net::HttpTransactionFactory { | 267 class MockHttpTransactionFactory : public HttpTransactionFactory { |
| 266 public: | 268 public: |
| 267 explicit MockHttpTransactionFactory(net::OrderedSocketData* data) { | 269 explicit MockHttpTransactionFactory(OrderedSocketData* data) { |
| 268 data_ = data; | 270 data_ = data; |
| 269 net::MockConnect connect_data(net::SYNCHRONOUS, net::OK); | 271 MockConnect connect_data(SYNCHRONOUS, OK); |
| 270 data_->set_connect_data(connect_data); | 272 data_->set_connect_data(connect_data); |
| 271 session_deps_.reset(new net::SpdySessionDependencies(net::kProtoSPDY3)); | 273 session_deps_.reset(new SpdySessionDependencies(kProtoSPDY3)); |
| 272 session_deps_->socket_factory->AddSocketDataProvider(data_); | 274 session_deps_->socket_factory->AddSocketDataProvider(data_); |
| 273 http_session_ = | 275 http_session_ = |
| 274 net::SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); | 276 SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); |
| 275 host_port_pair_.set_host("example.com"); | 277 host_port_pair_.set_host("example.com"); |
| 276 host_port_pair_.set_port(80); | 278 host_port_pair_.set_port(80); |
| 277 host_port_proxy_pair_.first = host_port_pair_; | 279 host_port_proxy_pair_.first = host_port_pair_; |
| 278 host_port_proxy_pair_.second = net::ProxyServer::Direct(); | 280 host_port_proxy_pair_.second = ProxyServer::Direct(); |
| 279 net::SpdySessionPool* spdy_session_pool = | 281 SpdySessionPool* spdy_session_pool = |
| 280 http_session_->spdy_session_pool(); | 282 http_session_->spdy_session_pool(); |
| 281 DCHECK(spdy_session_pool); | 283 DCHECK(spdy_session_pool); |
| 282 EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); | 284 EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); |
| 283 session_ = | 285 session_ = |
| 284 spdy_session_pool->Get(host_port_proxy_pair_, net::BoundNetLog()); | 286 spdy_session_pool->Get(host_port_proxy_pair_, BoundNetLog()); |
| 285 EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); | 287 EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); |
| 286 | 288 |
| 287 transport_params_ = | 289 transport_params_ = |
| 288 new net::TransportSocketParams(host_port_pair_, | 290 new TransportSocketParams(host_port_pair_, |
| 289 net::MEDIUM, | 291 MEDIUM, |
| 290 false, | 292 false, |
| 291 false, | 293 false, |
| 292 net::OnHostResolutionCallback()); | 294 OnHostResolutionCallback()); |
| 293 net::ClientSocketHandle* connection = new net::ClientSocketHandle; | 295 ClientSocketHandle* connection = new ClientSocketHandle; |
| 294 EXPECT_EQ(net::OK, | 296 EXPECT_EQ(OK, |
| 295 connection->Init(host_port_pair_.ToString(), transport_params_, | 297 connection->Init(host_port_pair_.ToString(), transport_params_, |
| 296 net::MEDIUM, net::CompletionCallback(), | 298 MEDIUM, CompletionCallback(), |
| 297 http_session_->GetTransportSocketPool( | 299 http_session_->GetTransportSocketPool( |
| 298 net::HttpNetworkSession::NORMAL_SOCKET_POOL), | 300 HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 299 net::BoundNetLog())); | 301 BoundNetLog())); |
| 300 EXPECT_EQ(net::OK, | 302 EXPECT_EQ(OK, |
| 301 session_->InitializeWithSocket(connection, false, net::OK)); | 303 session_->InitializeWithSocket(connection, false, OK)); |
| 302 } | 304 } |
| 303 virtual int CreateTransaction( | 305 virtual int CreateTransaction( |
| 304 net::RequestPriority priority, | 306 RequestPriority priority, |
| 305 scoped_ptr<net::HttpTransaction>* trans, | 307 scoped_ptr<HttpTransaction>* trans, |
| 306 net::HttpTransactionDelegate* delegate) OVERRIDE { | 308 HttpTransactionDelegate* delegate) OVERRIDE { |
| 307 NOTREACHED(); | 309 NOTREACHED(); |
| 308 return net::ERR_UNEXPECTED; | 310 return ERR_UNEXPECTED; |
| 309 } | 311 } |
| 310 virtual net::HttpCache* GetCache() OVERRIDE { | 312 virtual HttpCache* GetCache() OVERRIDE { |
| 311 NOTREACHED(); | 313 NOTREACHED(); |
| 312 return NULL; | 314 return NULL; |
| 313 } | 315 } |
| 314 virtual net::HttpNetworkSession* GetSession() OVERRIDE { | 316 virtual HttpNetworkSession* GetSession() OVERRIDE { |
| 315 return http_session_.get(); | 317 return http_session_.get(); |
| 316 } | 318 } |
| 317 private: | 319 private: |
| 318 net::OrderedSocketData* data_; | 320 OrderedSocketData* data_; |
| 319 scoped_ptr<net::SpdySessionDependencies> session_deps_; | 321 scoped_ptr<SpdySessionDependencies> session_deps_; |
| 320 scoped_refptr<net::HttpNetworkSession> http_session_; | 322 scoped_refptr<HttpNetworkSession> http_session_; |
| 321 scoped_refptr<net::TransportSocketParams> transport_params_; | 323 scoped_refptr<TransportSocketParams> transport_params_; |
| 322 scoped_refptr<net::SpdySession> session_; | 324 scoped_refptr<SpdySession> session_; |
| 323 net::HostPortPair host_port_pair_; | 325 HostPortPair host_port_pair_; |
| 324 net::HostPortProxyPair host_port_proxy_pair_; | 326 HostPortProxyPair host_port_proxy_pair_; |
| 325 }; | 327 }; |
| 326 | 328 |
| 327 } // namespace | 329 } // namespace |
| 328 | 330 |
| 329 namespace net { | |
| 330 | |
| 331 class WebSocketJobSpdy3Test : public PlatformTest { | 331 class WebSocketJobSpdy3Test : public PlatformTest { |
| 332 public: | 332 public: |
| 333 virtual void SetUp() { | 333 virtual void SetUp() { |
| 334 stream_type_ = STREAM_INVALID; | 334 stream_type_ = STREAM_INVALID; |
| 335 cookie_store_ = new MockCookieStore; | 335 cookie_store_ = new MockCookieStore; |
| 336 context_.reset(new MockURLRequestContext(cookie_store_.get())); | 336 context_.reset(new MockURLRequestContext(cookie_store_.get())); |
| 337 } | 337 } |
| 338 virtual void TearDown() { | 338 virtual void TearDown() { |
| 339 cookie_store_ = NULL; | 339 cookie_store_ = NULL; |
| 340 context_.reset(); | 340 context_.reset(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 socket_ = new MockSocketStream(url, websocket_.get()); | 381 socket_ = new MockSocketStream(url, websocket_.get()); |
| 382 | 382 |
| 383 if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) { | 383 if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) { |
| 384 if (stream_type == STREAM_SPDY_WEBSOCKET) { | 384 if (stream_type == STREAM_SPDY_WEBSOCKET) { |
| 385 http_factory_.reset(new MockHttpTransactionFactory(data_.get())); | 385 http_factory_.reset(new MockHttpTransactionFactory(data_.get())); |
| 386 context_->set_http_transaction_factory(http_factory_.get()); | 386 context_->set_http_transaction_factory(http_factory_.get()); |
| 387 } | 387 } |
| 388 | 388 |
| 389 ssl_config_service_ = new MockSSLConfigService(); | 389 ssl_config_service_ = new MockSSLConfigService(); |
| 390 context_->set_ssl_config_service(ssl_config_service_); | 390 context_->set_ssl_config_service(ssl_config_service_); |
| 391 proxy_service_.reset(net::ProxyService::CreateDirect()); | 391 proxy_service_.reset(ProxyService::CreateDirect()); |
| 392 context_->set_proxy_service(proxy_service_.get()); | 392 context_->set_proxy_service(proxy_service_.get()); |
| 393 host_resolver_.reset(new net::MockHostResolver); | 393 host_resolver_.reset(new MockHostResolver); |
| 394 context_->set_host_resolver(host_resolver_.get()); | 394 context_->set_host_resolver(host_resolver_.get()); |
| 395 | 395 |
| 396 socket_ = new SocketStream(url, websocket_.get()); | 396 socket_ = new SocketStream(url, websocket_.get()); |
| 397 socket_factory_.reset(new MockClientSocketFactory); | 397 socket_factory_.reset(new MockClientSocketFactory); |
| 398 DCHECK(data_.get()); | 398 DCHECK(data_.get()); |
| 399 socket_factory_->AddSocketDataProvider(data_.get()); | 399 socket_factory_->AddSocketDataProvider(data_.get()); |
| 400 socket_->SetClientSocketFactory(socket_factory_.get()); | 400 socket_->SetClientSocketFactory(socket_factory_.get()); |
| 401 } | 401 } |
| 402 | 402 |
| 403 websocket_->InitSocketStream(socket_.get()); | 403 websocket_->InitSocketStream(socket_.get()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling); | 454 void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling); |
| 455 | 455 |
| 456 StreamType stream_type_; | 456 StreamType stream_type_; |
| 457 scoped_refptr<MockCookieStore> cookie_store_; | 457 scoped_refptr<MockCookieStore> cookie_store_; |
| 458 scoped_refptr<WebSocketJob> websocket_; | 458 scoped_refptr<WebSocketJob> websocket_; |
| 459 scoped_refptr<SocketStream> socket_; | 459 scoped_refptr<SocketStream> socket_; |
| 460 scoped_ptr<MockClientSocketFactory> socket_factory_; | 460 scoped_ptr<MockClientSocketFactory> socket_factory_; |
| 461 scoped_ptr<OrderedSocketData> data_; | 461 scoped_ptr<OrderedSocketData> data_; |
| 462 TestCompletionCallback sync_test_callback_; | 462 TestCompletionCallback sync_test_callback_; |
| 463 scoped_refptr<MockSSLConfigService> ssl_config_service_; | 463 scoped_refptr<MockSSLConfigService> ssl_config_service_; |
| 464 scoped_ptr<net::ProxyService> proxy_service_; | 464 scoped_ptr<ProxyService> proxy_service_; |
| 465 scoped_ptr<net::MockHostResolver> host_resolver_; | 465 scoped_ptr<MockHostResolver> host_resolver_; |
| 466 scoped_ptr<MockHttpTransactionFactory> http_factory_; | 466 scoped_ptr<MockHttpTransactionFactory> http_factory_; |
| 467 scoped_ptr<MockURLRequestContext> context_; | 467 scoped_ptr<MockURLRequestContext> context_; |
| 468 | 468 |
| 469 static const char kHandshakeRequestWithoutCookie[]; | 469 static const char kHandshakeRequestWithoutCookie[]; |
| 470 static const char kHandshakeRequestWithCookie[]; | 470 static const char kHandshakeRequestWithCookie[]; |
| 471 static const char kHandshakeRequestWithFilteredCookie[]; | 471 static const char kHandshakeRequestWithFilteredCookie[]; |
| 472 static const char kHandshakeResponseWithoutCookie[]; | 472 static const char kHandshakeResponseWithoutCookie[]; |
| 473 static const char kHandshakeResponseWithCookie[]; | 473 static const char kHandshakeResponseWithCookie[]; |
| 474 static const char kDataHello[]; | 474 static const char kDataHello[]; |
| 475 static const char kDataWorld[]; | 475 static const char kDataWorld[]; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 630 |
| 631 TEST_F(WebSocketJobSpdy3Test, DelayedCookies) { | 631 TEST_F(WebSocketJobSpdy3Test, DelayedCookies) { |
| 632 WebSocketJob::set_websocket_over_spdy_enabled(true); | 632 WebSocketJob::set_websocket_over_spdy_enabled(true); |
| 633 GURL url("ws://example.com/demo"); | 633 GURL url("ws://example.com/demo"); |
| 634 GURL cookieUrl("http://example.com/demo"); | 634 GURL cookieUrl("http://example.com/demo"); |
| 635 CookieOptions cookie_options; | 635 CookieOptions cookie_options; |
| 636 scoped_refptr<DelayedCookieMonster> cookie_store = new DelayedCookieMonster(); | 636 scoped_refptr<DelayedCookieMonster> cookie_store = new DelayedCookieMonster(); |
| 637 context_->set_cookie_store(cookie_store); | 637 context_->set_cookie_store(cookie_store); |
| 638 cookie_store->SetCookieWithOptionsAsync( | 638 cookie_store->SetCookieWithOptionsAsync( |
| 639 cookieUrl, "CR-test=1", cookie_options, | 639 cookieUrl, "CR-test=1", cookie_options, |
| 640 net::CookieMonster::SetCookiesCallback()); | 640 CookieMonster::SetCookiesCallback()); |
| 641 cookie_options.set_include_httponly(); | 641 cookie_options.set_include_httponly(); |
| 642 cookie_store->SetCookieWithOptionsAsync( | 642 cookie_store->SetCookieWithOptionsAsync( |
| 643 cookieUrl, "CR-test-httponly=1", cookie_options, | 643 cookieUrl, "CR-test-httponly=1", cookie_options, |
| 644 net::CookieMonster::SetCookiesCallback()); | 644 CookieMonster::SetCookiesCallback()); |
| 645 | 645 |
| 646 MockSocketStreamDelegate delegate; | 646 MockSocketStreamDelegate delegate; |
| 647 InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET); | 647 InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET); |
| 648 SkipToConnecting(); | 648 SkipToConnecting(); |
| 649 | 649 |
| 650 bool sent = websocket_->SendData(kHandshakeRequestWithCookie, | 650 bool sent = websocket_->SendData(kHandshakeRequestWithCookie, |
| 651 kHandshakeRequestWithCookieLength); | 651 kHandshakeRequestWithCookieLength); |
| 652 EXPECT_TRUE(sent); | 652 EXPECT_TRUE(sent); |
| 653 MessageLoop::current()->RunUntilIdle(); | 653 MessageLoop::current()->RunUntilIdle(); |
| 654 EXPECT_EQ(kHandshakeRequestWithFilteredCookie, sent_data()); | 654 EXPECT_EQ(kHandshakeRequestWithFilteredCookie, sent_data()); |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 TEST_F(WebSocketJobSpdy3Test, ThrottlingSpdySpdyEnabled) { | 1089 TEST_F(WebSocketJobSpdy3Test, ThrottlingSpdySpdyEnabled) { |
| 1090 WebSocketJob::set_websocket_over_spdy_enabled(true); | 1090 WebSocketJob::set_websocket_over_spdy_enabled(true); |
| 1091 TestConnectBySpdy(SPDY_ON, THROTTLING_ON); | 1091 TestConnectBySpdy(SPDY_ON, THROTTLING_ON); |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation. | 1094 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation. |
| 1095 // TODO(toyoshim,yutak): Add tests to verify closing handshake. | 1095 // TODO(toyoshim,yutak): Add tests to verify closing handshake. |
| 1096 } // namespace net | 1096 } // namespace net |
| OLD | NEW |