| 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_spdy2.h" | 31 #include "net/spdy/spdy_websocket_test_util_spdy2.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_spdy2; | 39 using namespace net::test_spdy2; |
| 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 virtual void Connect() OVERRIDE {} | 50 virtual void Connect() OVERRIDE {} |
| 49 virtual bool SendData(const char* data, int len) OVERRIDE { | 51 virtual bool SendData(const char* data, int len) OVERRIDE { |
| 50 sent_data_ += std::string(data, len); | 52 sent_data_ += std::string(data, len); |
| 51 return true; | 53 return true; |
| 52 } | 54 } |
| 53 | 55 |
| 54 virtual void Close() OVERRIDE {} | 56 virtual void Close() OVERRIDE {} |
| 55 virtual void RestartWithAuth( | 57 virtual void RestartWithAuth( |
| 56 const net::AuthCredentials& credentials) OVERRIDE { | 58 const AuthCredentials& credentials) OVERRIDE { |
| 57 } | 59 } |
| 58 | 60 |
| 59 virtual void DetachDelegate() OVERRIDE { | 61 virtual void DetachDelegate() OVERRIDE { |
| 60 delegate_ = NULL; | 62 delegate_ = NULL; |
| 61 } | 63 } |
| 62 | 64 |
| 63 const std::string& sent_data() const { | 65 const std::string& sent_data() const { |
| 64 return sent_data_; | 66 return sent_data_; |
| 65 } | 67 } |
| 66 | 68 |
| 67 protected: | 69 protected: |
| 68 virtual ~MockSocketStream() {} | 70 virtual ~MockSocketStream() {} |
| 69 | 71 |
| 70 private: | 72 private: |
| 71 std::string sent_data_; | 73 std::string sent_data_; |
| 72 }; | 74 }; |
| 73 | 75 |
| 74 class MockSocketStreamDelegate : public net::SocketStream::Delegate { | 76 class MockSocketStreamDelegate : public SocketStream::Delegate { |
| 75 public: | 77 public: |
| 76 MockSocketStreamDelegate() | 78 MockSocketStreamDelegate() |
| 77 : amount_sent_(0), allow_all_cookies_(true) {} | 79 : amount_sent_(0), allow_all_cookies_(true) {} |
| 78 void set_allow_all_cookies(bool allow_all_cookies) { | 80 void set_allow_all_cookies(bool allow_all_cookies) { |
| 79 allow_all_cookies_ = allow_all_cookies; | 81 allow_all_cookies_ = allow_all_cookies; |
| 80 } | 82 } |
| 81 virtual ~MockSocketStreamDelegate() {} | 83 virtual ~MockSocketStreamDelegate() {} |
| 82 | 84 |
| 83 void SetOnStartOpenConnection(const base::Closure& callback) { | 85 void SetOnStartOpenConnection(const base::Closure& callback) { |
| 84 on_start_open_connection_ = callback; | 86 on_start_open_connection_ = callback; |
| 85 } | 87 } |
| 86 void SetOnConnected(const base::Closure& callback) { | 88 void SetOnConnected(const base::Closure& callback) { |
| 87 on_connected_ = callback; | 89 on_connected_ = callback; |
| 88 } | 90 } |
| 89 void SetOnSentData(const base::Closure& callback) { | 91 void SetOnSentData(const base::Closure& callback) { |
| 90 on_sent_data_ = callback; | 92 on_sent_data_ = callback; |
| 91 } | 93 } |
| 92 void SetOnReceivedData(const base::Closure& callback) { | 94 void SetOnReceivedData(const base::Closure& callback) { |
| 93 on_received_data_ = callback; | 95 on_received_data_ = callback; |
| 94 } | 96 } |
| 95 void SetOnClose(const base::Closure& callback) { | 97 void SetOnClose(const base::Closure& callback) { |
| 96 on_close_ = callback; | 98 on_close_ = callback; |
| 97 } | 99 } |
| 98 | 100 |
| 99 virtual int OnStartOpenConnection( | 101 virtual int OnStartOpenConnection( |
| 100 net::SocketStream* socket, | 102 SocketStream* socket, |
| 101 const net::CompletionCallback& callback) OVERRIDE { | 103 const CompletionCallback& callback) OVERRIDE { |
| 102 if (!on_start_open_connection_.is_null()) | 104 if (!on_start_open_connection_.is_null()) |
| 103 on_start_open_connection_.Run(); | 105 on_start_open_connection_.Run(); |
| 104 return net::OK; | 106 return OK; |
| 105 } | 107 } |
| 106 virtual void OnConnected(net::SocketStream* socket, | 108 virtual void OnConnected(SocketStream* socket, |
| 107 int max_pending_send_allowed) OVERRIDE { | 109 int max_pending_send_allowed) OVERRIDE { |
| 108 if (!on_connected_.is_null()) | 110 if (!on_connected_.is_null()) |
| 109 on_connected_.Run(); | 111 on_connected_.Run(); |
| 110 } | 112 } |
| 111 virtual void OnSentData(net::SocketStream* socket, | 113 virtual void OnSentData(SocketStream* socket, |
| 112 int amount_sent) OVERRIDE { | 114 int amount_sent) OVERRIDE { |
| 113 amount_sent_ += amount_sent; | 115 amount_sent_ += amount_sent; |
| 114 if (!on_sent_data_.is_null()) | 116 if (!on_sent_data_.is_null()) |
| 115 on_sent_data_.Run(); | 117 on_sent_data_.Run(); |
| 116 } | 118 } |
| 117 virtual void OnReceivedData(net::SocketStream* socket, | 119 virtual void OnReceivedData(SocketStream* socket, |
| 118 const char* data, int len) OVERRIDE { | 120 const char* data, int len) OVERRIDE { |
| 119 received_data_ += std::string(data, len); | 121 received_data_ += std::string(data, len); |
| 120 if (!on_received_data_.is_null()) | 122 if (!on_received_data_.is_null()) |
| 121 on_received_data_.Run(); | 123 on_received_data_.Run(); |
| 122 } | 124 } |
| 123 virtual void OnClose(net::SocketStream* socket) OVERRIDE { | 125 virtual void OnClose(SocketStream* socket) OVERRIDE { |
| 124 if (!on_close_.is_null()) | 126 if (!on_close_.is_null()) |
| 125 on_close_.Run(); | 127 on_close_.Run(); |
| 126 } | 128 } |
| 127 virtual bool CanGetCookies(net::SocketStream* socket, | 129 virtual bool CanGetCookies(SocketStream* socket, |
| 128 const GURL& url) OVERRIDE { | 130 const GURL& url) OVERRIDE { |
| 129 return allow_all_cookies_; | 131 return allow_all_cookies_; |
| 130 } | 132 } |
| 131 virtual bool CanSetCookie(net::SocketStream* request, | 133 virtual bool CanSetCookie(SocketStream* request, |
| 132 const GURL& url, | 134 const GURL& url, |
| 133 const std::string& cookie_line, | 135 const std::string& cookie_line, |
| 134 net::CookieOptions* options) OVERRIDE { | 136 CookieOptions* options) OVERRIDE { |
| 135 return allow_all_cookies_; | 137 return allow_all_cookies_; |
| 136 } | 138 } |
| 137 | 139 |
| 138 size_t amount_sent() const { return amount_sent_; } | 140 size_t amount_sent() const { return amount_sent_; } |
| 139 const std::string& received_data() const { return received_data_; } | 141 const std::string& received_data() const { return received_data_; } |
| 140 | 142 |
| 141 private: | 143 private: |
| 142 int amount_sent_; | 144 int amount_sent_; |
| 143 bool allow_all_cookies_; | 145 bool allow_all_cookies_; |
| 144 std::string received_data_; | 146 std::string received_data_; |
| 145 base::Closure on_start_open_connection_; | 147 base::Closure on_start_open_connection_; |
| 146 base::Closure on_connected_; | 148 base::Closure on_connected_; |
| 147 base::Closure on_sent_data_; | 149 base::Closure on_sent_data_; |
| 148 base::Closure on_received_data_; | 150 base::Closure on_received_data_; |
| 149 base::Closure on_close_; | 151 base::Closure on_close_; |
| 150 }; | 152 }; |
| 151 | 153 |
| 152 class MockCookieStore : public net::CookieStore { | 154 class MockCookieStore : public CookieStore { |
| 153 public: | 155 public: |
| 154 struct Entry { | 156 struct Entry { |
| 155 GURL url; | 157 GURL url; |
| 156 std::string cookie_line; | 158 std::string cookie_line; |
| 157 net::CookieOptions options; | 159 CookieOptions options; |
| 158 }; | 160 }; |
| 159 | 161 |
| 160 MockCookieStore() {} | 162 MockCookieStore() {} |
| 161 | 163 |
| 162 bool SetCookieWithOptions(const GURL& url, | 164 bool SetCookieWithOptions(const GURL& url, |
| 163 const std::string& cookie_line, | 165 const std::string& cookie_line, |
| 164 const net::CookieOptions& options) { | 166 const CookieOptions& options) { |
| 165 Entry entry; | 167 Entry entry; |
| 166 entry.url = url; | 168 entry.url = url; |
| 167 entry.cookie_line = cookie_line; | 169 entry.cookie_line = cookie_line; |
| 168 entry.options = options; | 170 entry.options = options; |
| 169 entries_.push_back(entry); | 171 entries_.push_back(entry); |
| 170 return true; | 172 return true; |
| 171 } | 173 } |
| 172 | 174 |
| 173 std::string GetCookiesWithOptions(const GURL& url, | 175 std::string GetCookiesWithOptions(const GURL& url, |
| 174 const net::CookieOptions& options) { | 176 const CookieOptions& options) { |
| 175 std::string result; | 177 std::string result; |
| 176 for (size_t i = 0; i < entries_.size(); i++) { | 178 for (size_t i = 0; i < entries_.size(); i++) { |
| 177 Entry& entry = entries_[i]; | 179 Entry& entry = entries_[i]; |
| 178 if (url == entry.url) { | 180 if (url == entry.url) { |
| 179 if (!result.empty()) { | 181 if (!result.empty()) { |
| 180 result += "; "; | 182 result += "; "; |
| 181 } | 183 } |
| 182 result += entry.cookie_line; | 184 result += entry.cookie_line; |
| 183 } | 185 } |
| 184 } | 186 } |
| 185 return result; | 187 return result; |
| 186 } | 188 } |
| 187 | 189 |
| 188 // CookieStore: | 190 // CookieStore: |
| 189 virtual void SetCookieWithOptionsAsync( | 191 virtual void SetCookieWithOptionsAsync( |
| 190 const GURL& url, | 192 const GURL& url, |
| 191 const std::string& cookie_line, | 193 const std::string& cookie_line, |
| 192 const net::CookieOptions& options, | 194 const CookieOptions& options, |
| 193 const SetCookiesCallback& callback) OVERRIDE { | 195 const SetCookiesCallback& callback) OVERRIDE { |
| 194 bool result = SetCookieWithOptions(url, cookie_line, options); | 196 bool result = SetCookieWithOptions(url, cookie_line, options); |
| 195 if (!callback.is_null()) | 197 if (!callback.is_null()) |
| 196 callback.Run(result); | 198 callback.Run(result); |
| 197 } | 199 } |
| 198 | 200 |
| 199 virtual void GetCookiesWithOptionsAsync( | 201 virtual void GetCookiesWithOptionsAsync( |
| 200 const GURL& url, | 202 const GURL& url, |
| 201 const net::CookieOptions& options, | 203 const CookieOptions& options, |
| 202 const GetCookiesCallback& callback) OVERRIDE { | 204 const GetCookiesCallback& callback) OVERRIDE { |
| 203 if (!callback.is_null()) | 205 if (!callback.is_null()) |
| 204 callback.Run(GetCookiesWithOptions(url, options)); | 206 callback.Run(GetCookiesWithOptions(url, options)); |
| 205 } | 207 } |
| 206 | 208 |
| 207 virtual void DeleteCookieAsync(const GURL& url, | 209 virtual void DeleteCookieAsync(const GURL& url, |
| 208 const std::string& cookie_name, | 210 const std::string& cookie_name, |
| 209 const base::Closure& callback) OVERRIDE { | 211 const base::Closure& callback) OVERRIDE { |
| 210 ADD_FAILURE(); | 212 ADD_FAILURE(); |
| 211 } | 213 } |
| 212 | 214 |
| 213 virtual void DeleteAllCreatedBetweenAsync( | 215 virtual void DeleteAllCreatedBetweenAsync( |
| 214 const base::Time& delete_begin, | 216 const base::Time& delete_begin, |
| 215 const base::Time& delete_end, | 217 const base::Time& delete_end, |
| 216 const DeleteCallback& callback) OVERRIDE { | 218 const DeleteCallback& callback) OVERRIDE { |
| 217 ADD_FAILURE(); | 219 ADD_FAILURE(); |
| 218 } | 220 } |
| 219 | 221 |
| 220 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE { | 222 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE { |
| 221 ADD_FAILURE(); | 223 ADD_FAILURE(); |
| 222 } | 224 } |
| 223 | 225 |
| 224 virtual net::CookieMonster* GetCookieMonster() OVERRIDE { return NULL; } | 226 virtual CookieMonster* GetCookieMonster() OVERRIDE { return NULL; } |
| 225 | 227 |
| 226 const std::vector<Entry>& entries() const { return entries_; } | 228 const std::vector<Entry>& entries() const { return entries_; } |
| 227 | 229 |
| 228 private: | 230 private: |
| 229 friend class base::RefCountedThreadSafe<MockCookieStore>; | 231 friend class base::RefCountedThreadSafe<MockCookieStore>; |
| 230 virtual ~MockCookieStore() {} | 232 virtual ~MockCookieStore() {} |
| 231 | 233 |
| 232 std::vector<Entry> entries_; | 234 std::vector<Entry> entries_; |
| 233 }; | 235 }; |
| 234 | 236 |
| 235 class MockSSLConfigService : public net::SSLConfigService { | 237 class MockSSLConfigService : public SSLConfigService { |
| 236 public: | 238 public: |
| 237 virtual void GetSSLConfig(net::SSLConfig* config) OVERRIDE {} | 239 virtual void GetSSLConfig(SSLConfig* config) OVERRIDE {} |
| 238 | 240 |
| 239 protected: | 241 protected: |
| 240 virtual ~MockSSLConfigService() {} | 242 virtual ~MockSSLConfigService() {} |
| 241 }; | 243 }; |
| 242 | 244 |
| 243 class MockURLRequestContext : public net::URLRequestContext { | 245 class MockURLRequestContext : public URLRequestContext { |
| 244 public: | 246 public: |
| 245 explicit MockURLRequestContext(net::CookieStore* cookie_store) | 247 explicit MockURLRequestContext(CookieStore* cookie_store) |
| 246 : transport_security_state_() { | 248 : transport_security_state_() { |
| 247 set_cookie_store(cookie_store); | 249 set_cookie_store(cookie_store); |
| 248 set_transport_security_state(&transport_security_state_); | 250 set_transport_security_state(&transport_security_state_); |
| 249 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); | 251 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
| 250 bool include_subdomains = false; | 252 bool include_subdomains = false; |
| 251 transport_security_state_.AddHSTS("upgrademe.com", expiry, | 253 transport_security_state_.AddHSTS("upgrademe.com", expiry, |
| 252 include_subdomains); | 254 include_subdomains); |
| 253 } | 255 } |
| 254 | 256 |
| 255 virtual ~MockURLRequestContext() {} | 257 virtual ~MockURLRequestContext() {} |
| 256 | 258 |
| 257 private: | 259 private: |
| 258 net::TransportSecurityState transport_security_state_; | 260 TransportSecurityState transport_security_state_; |
| 259 }; | 261 }; |
| 260 | 262 |
| 261 class MockHttpTransactionFactory : public net::HttpTransactionFactory { | 263 class MockHttpTransactionFactory : public HttpTransactionFactory { |
| 262 public: | 264 public: |
| 263 explicit MockHttpTransactionFactory(net::OrderedSocketData* data) { | 265 explicit MockHttpTransactionFactory(OrderedSocketData* data) { |
| 264 data_ = data; | 266 data_ = data; |
| 265 net::MockConnect connect_data(net::SYNCHRONOUS, net::OK); | 267 MockConnect connect_data(SYNCHRONOUS, OK); |
| 266 data_->set_connect_data(connect_data); | 268 data_->set_connect_data(connect_data); |
| 267 session_deps_.reset(new net::SpdySessionDependencies(net::kProtoSPDY2)); | 269 session_deps_.reset(new SpdySessionDependencies(kProtoSPDY2)); |
| 268 session_deps_->socket_factory->AddSocketDataProvider(data_); | 270 session_deps_->socket_factory->AddSocketDataProvider(data_); |
| 269 http_session_ = | 271 http_session_ = |
| 270 net::SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); | 272 SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); |
| 271 host_port_pair_.set_host("example.com"); | 273 host_port_pair_.set_host("example.com"); |
| 272 host_port_pair_.set_port(80); | 274 host_port_pair_.set_port(80); |
| 273 host_port_proxy_pair_.first = host_port_pair_; | 275 host_port_proxy_pair_.first = host_port_pair_; |
| 274 host_port_proxy_pair_.second = net::ProxyServer::Direct(); | 276 host_port_proxy_pair_.second = ProxyServer::Direct(); |
| 275 net::SpdySessionPool* spdy_session_pool = | 277 SpdySessionPool* spdy_session_pool = |
| 276 http_session_->spdy_session_pool(); | 278 http_session_->spdy_session_pool(); |
| 277 DCHECK(spdy_session_pool); | 279 DCHECK(spdy_session_pool); |
| 278 EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); | 280 EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); |
| 279 session_ = | 281 session_ = |
| 280 spdy_session_pool->Get(host_port_proxy_pair_, net::BoundNetLog()); | 282 spdy_session_pool->Get(host_port_proxy_pair_, BoundNetLog()); |
| 281 EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); | 283 EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); |
| 282 | 284 |
| 283 transport_params_ = | 285 transport_params_ = |
| 284 new net::TransportSocketParams(host_port_pair_, | 286 new TransportSocketParams(host_port_pair_, |
| 285 net::MEDIUM, | 287 MEDIUM, |
| 286 false, | 288 false, |
| 287 false, | 289 false, |
| 288 net::OnHostResolutionCallback()); | 290 OnHostResolutionCallback()); |
| 289 net::ClientSocketHandle* connection = new net::ClientSocketHandle; | 291 ClientSocketHandle* connection = new ClientSocketHandle; |
| 290 EXPECT_EQ(net::OK, | 292 EXPECT_EQ(OK, |
| 291 connection->Init(host_port_pair_.ToString(), transport_params_, | 293 connection->Init(host_port_pair_.ToString(), transport_params_, |
| 292 net::MEDIUM, net::CompletionCallback(), | 294 MEDIUM, CompletionCallback(), |
| 293 http_session_->GetTransportSocketPool( | 295 http_session_->GetTransportSocketPool( |
| 294 net::HttpNetworkSession::NORMAL_SOCKET_POOL), | 296 HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 295 net::BoundNetLog())); | 297 BoundNetLog())); |
| 296 EXPECT_EQ(net::OK, | 298 EXPECT_EQ(OK, |
| 297 session_->InitializeWithSocket(connection, false, net::OK)); | 299 session_->InitializeWithSocket(connection, false, OK)); |
| 298 } | 300 } |
| 299 | 301 |
| 300 virtual int CreateTransaction( | 302 virtual int CreateTransaction( |
| 301 net::RequestPriority priority, | 303 RequestPriority priority, |
| 302 scoped_ptr<net::HttpTransaction>* trans, | 304 scoped_ptr<HttpTransaction>* trans, |
| 303 net::HttpTransactionDelegate* delegate) OVERRIDE { | 305 HttpTransactionDelegate* delegate) OVERRIDE { |
| 304 NOTREACHED(); | 306 NOTREACHED(); |
| 305 return net::ERR_UNEXPECTED; | 307 return ERR_UNEXPECTED; |
| 306 } | 308 } |
| 307 | 309 |
| 308 virtual net::HttpCache* GetCache() OVERRIDE { | 310 virtual HttpCache* GetCache() OVERRIDE { |
| 309 NOTREACHED(); | 311 NOTREACHED(); |
| 310 return NULL; | 312 return NULL; |
| 311 } | 313 } |
| 312 | 314 |
| 313 virtual net::HttpNetworkSession* GetSession() OVERRIDE { | 315 virtual HttpNetworkSession* GetSession() OVERRIDE { |
| 314 return http_session_.get(); | 316 return http_session_.get(); |
| 315 } | 317 } |
| 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 WebSocketJobSpdy2Test : public PlatformTest { | 331 class WebSocketJobSpdy2Test : public PlatformTest { |
| 332 public: | 332 public: |
| 333 virtual void SetUp() OVERRIDE { | 333 virtual void SetUp() OVERRIDE { |
| 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() OVERRIDE { | 338 virtual void TearDown() OVERRIDE { |
| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 | 455 |
| 456 StreamType stream_type_; | 456 StreamType stream_type_; |
| 457 scoped_refptr<MockCookieStore> cookie_store_; | 457 scoped_refptr<MockCookieStore> cookie_store_; |
| 458 scoped_ptr<MockURLRequestContext> context_; | 458 scoped_ptr<MockURLRequestContext> context_; |
| 459 scoped_refptr<WebSocketJob> websocket_; | 459 scoped_refptr<WebSocketJob> websocket_; |
| 460 scoped_refptr<SocketStream> socket_; | 460 scoped_refptr<SocketStream> socket_; |
| 461 scoped_ptr<MockClientSocketFactory> socket_factory_; | 461 scoped_ptr<MockClientSocketFactory> socket_factory_; |
| 462 scoped_ptr<OrderedSocketData> data_; | 462 scoped_ptr<OrderedSocketData> data_; |
| 463 TestCompletionCallback sync_test_callback_; | 463 TestCompletionCallback sync_test_callback_; |
| 464 scoped_refptr<MockSSLConfigService> ssl_config_service_; | 464 scoped_refptr<MockSSLConfigService> ssl_config_service_; |
| 465 scoped_ptr<net::ProxyService> proxy_service_; | 465 scoped_ptr<ProxyService> proxy_service_; |
| 466 scoped_ptr<net::MockHostResolver> host_resolver_; | 466 scoped_ptr<MockHostResolver> host_resolver_; |
| 467 scoped_ptr<MockHttpTransactionFactory> http_factory_; | 467 scoped_ptr<MockHttpTransactionFactory> http_factory_; |
| 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[]; |
| 476 static const char* const kHandshakeRequestForSpdy[]; | 476 static const char* const kHandshakeRequestForSpdy[]; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 630 |
| 631 TEST_F(WebSocketJobSpdy2Test, DelayedCookies) { | 631 TEST_F(WebSocketJobSpdy2Test, 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(WebSocketJobSpdy2Test, ThrottlingSpdySpdyEnabled) { | 1089 TEST_F(WebSocketJobSpdy2Test, 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 |