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