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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 explicit MockURLRequestContext(net::CookieStore* cookie_store) | 252 explicit MockURLRequestContext(net::CookieStore* cookie_store) |
253 : transport_security_state_() { | 253 : transport_security_state_() { |
254 set_cookie_store(cookie_store); | 254 set_cookie_store(cookie_store); |
255 set_transport_security_state(&transport_security_state_); | 255 set_transport_security_state(&transport_security_state_); |
256 net::TransportSecurityState::DomainState state; | 256 net::TransportSecurityState::DomainState state; |
257 state.upgrade_expiry = base::Time::Now() + | 257 state.upgrade_expiry = base::Time::Now() + |
258 base::TimeDelta::FromSeconds(1000); | 258 base::TimeDelta::FromSeconds(1000); |
259 transport_security_state_.EnableHost("upgrademe.com", state); | 259 transport_security_state_.EnableHost("upgrademe.com", state); |
260 } | 260 } |
261 | 261 |
262 protected: | |
263 friend class base::RefCountedThreadSafe<MockURLRequestContext>; | |
264 virtual ~MockURLRequestContext() {} | 262 virtual ~MockURLRequestContext() {} |
265 | 263 |
266 private: | 264 private: |
267 net::TransportSecurityState transport_security_state_; | 265 net::TransportSecurityState transport_security_state_; |
268 }; | 266 }; |
269 | 267 |
270 class MockHttpTransactionFactory : public net::HttpTransactionFactory { | 268 class MockHttpTransactionFactory : public net::HttpTransactionFactory { |
271 public: | 269 public: |
272 explicit MockHttpTransactionFactory(net::OrderedSocketData* data) { | 270 explicit MockHttpTransactionFactory(net::OrderedSocketData* data) { |
273 data_ = data; | 271 data_ = data; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } // namespace | 329 } // namespace |
332 | 330 |
333 namespace net { | 331 namespace net { |
334 | 332 |
335 class WebSocketJobSpdy2Test : public PlatformTest { | 333 class WebSocketJobSpdy2Test : public PlatformTest { |
336 public: | 334 public: |
337 virtual void SetUp() OVERRIDE { | 335 virtual void SetUp() OVERRIDE { |
338 SpdySession::set_default_protocol(kProtoSPDY2); | 336 SpdySession::set_default_protocol(kProtoSPDY2); |
339 stream_type_ = STREAM_INVALID; | 337 stream_type_ = STREAM_INVALID; |
340 cookie_store_ = new MockCookieStore; | 338 cookie_store_ = new MockCookieStore; |
341 context_ = new MockURLRequestContext(cookie_store_.get()); | 339 context_.reset(new MockURLRequestContext(cookie_store_.get())); |
342 } | 340 } |
343 virtual void TearDown() OVERRIDE { | 341 virtual void TearDown() OVERRIDE { |
344 cookie_store_ = NULL; | 342 cookie_store_ = NULL; |
345 context_ = NULL; | 343 context_.reset(); |
346 websocket_ = NULL; | 344 websocket_ = NULL; |
347 socket_ = NULL; | 345 socket_ = NULL; |
348 } | 346 } |
349 void DoSendRequest() { | 347 void DoSendRequest() { |
350 EXPECT_TRUE(websocket_->SendData(kHandshakeRequestWithoutCookie, | 348 EXPECT_TRUE(websocket_->SendData(kHandshakeRequestWithoutCookie, |
351 kHandshakeRequestWithoutCookieLength)); | 349 kHandshakeRequestWithoutCookieLength)); |
352 } | 350 } |
353 void DoSendData() { | 351 void DoSendData() { |
354 if (received_data().size() == kHandshakeResponseWithoutCookieLength) | 352 if (received_data().size() == kHandshakeResponseWithoutCookieLength) |
355 websocket_->SendData(kDataHello, kDataHelloLength); | 353 websocket_->SendData(kDataHello, kDataHelloLength); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 void TestSlowHandshake(); | 454 void TestSlowHandshake(); |
457 void TestHandshakeWithCookie(); | 455 void TestHandshakeWithCookie(); |
458 void TestHandshakeWithCookieButNotAllowed(); | 456 void TestHandshakeWithCookieButNotAllowed(); |
459 void TestHSTSUpgrade(); | 457 void TestHSTSUpgrade(); |
460 void TestInvalidSendData(); | 458 void TestInvalidSendData(); |
461 void TestConnectByWebSocket(ThrottlingOption throttling); | 459 void TestConnectByWebSocket(ThrottlingOption throttling); |
462 void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling); | 460 void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling); |
463 | 461 |
464 StreamType stream_type_; | 462 StreamType stream_type_; |
465 scoped_refptr<MockCookieStore> cookie_store_; | 463 scoped_refptr<MockCookieStore> cookie_store_; |
466 scoped_refptr<MockURLRequestContext> context_; | 464 scoped_ptr<MockURLRequestContext> context_; |
467 scoped_refptr<WebSocketJob> websocket_; | 465 scoped_refptr<WebSocketJob> websocket_; |
468 scoped_refptr<SocketStream> socket_; | 466 scoped_refptr<SocketStream> socket_; |
469 scoped_ptr<MockClientSocketFactory> socket_factory_; | 467 scoped_ptr<MockClientSocketFactory> socket_factory_; |
470 scoped_ptr<OrderedSocketData> data_; | 468 scoped_ptr<OrderedSocketData> data_; |
471 TestCompletionCallback sync_test_callback_; | 469 TestCompletionCallback sync_test_callback_; |
472 scoped_refptr<MockSSLConfigService> ssl_config_service_; | 470 scoped_refptr<MockSSLConfigService> ssl_config_service_; |
473 scoped_ptr<net::ProxyService> proxy_service_; | 471 scoped_ptr<net::ProxyService> proxy_service_; |
474 scoped_ptr<net::MockHostResolver> host_resolver_; | 472 scoped_ptr<net::MockHostResolver> host_resolver_; |
475 scoped_ptr<MockHttpTransactionFactory> http_factory_; | 473 scoped_ptr<MockHttpTransactionFactory> http_factory_; |
476 | 474 |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 | 1108 |
1111 TEST_F(WebSocketJobSpdy2Test, ThrottlingSpdySpdyEnabled) { | 1109 TEST_F(WebSocketJobSpdy2Test, ThrottlingSpdySpdyEnabled) { |
1112 WebSocketJob::set_websocket_over_spdy_enabled(true); | 1110 WebSocketJob::set_websocket_over_spdy_enabled(true); |
1113 TestConnectBySpdy(SPDY_ON, THROTTLING_ON); | 1111 TestConnectBySpdy(SPDY_ON, THROTTLING_ON); |
1114 } | 1112 } |
1115 | 1113 |
1116 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation. | 1114 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation. |
1117 // TODO(toyoshim,yutak): Add tests to verify closing handshake. | 1115 // TODO(toyoshim,yutak): Add tests to verify closing handshake. |
1118 | 1116 |
1119 } // namespace net | 1117 } // namespace net |
OLD | NEW |