Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: net/websockets/websocket_job_unittest.cc

Issue 9251019: Fixes to socket_test_util.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed blocked_ -> read_in_progress_. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_websocket_stream_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 249
250 private: 250 private:
251 friend class base::RefCountedThreadSafe<MockURLRequestContext>; 251 friend class base::RefCountedThreadSafe<MockURLRequestContext>;
252 virtual ~MockURLRequestContext() {} 252 virtual ~MockURLRequestContext() {}
253 253
254 net::TransportSecurityState transport_security_state_; 254 net::TransportSecurityState transport_security_state_;
255 }; 255 };
256 256
257 class MockHttpTransactionFactory : public net::HttpTransactionFactory { 257 class MockHttpTransactionFactory : public net::HttpTransactionFactory {
258 public: 258 public:
259 MockHttpTransactionFactory(scoped_refptr<net::OrderedSocketData>& data) { 259 MockHttpTransactionFactory(net::OrderedSocketData* data) {
260 data_ = data; 260 data_ = data;
261 net::MockConnect connect_data(false, net::OK); 261 net::MockConnect connect_data(false, net::OK);
262 data_->set_connect_data(connect_data); 262 data_->set_connect_data(connect_data);
263 session_deps_.reset(new net::SpdySessionDependencies); 263 session_deps_.reset(new net::SpdySessionDependencies);
264 session_deps_->socket_factory->AddSocketDataProvider(data_.get()); 264 session_deps_->socket_factory->AddSocketDataProvider(data_);
265 http_session_ = 265 http_session_ =
266 net::SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); 266 net::SpdySessionDependencies::SpdyCreateSession(session_deps_.get());
267 host_port_pair_.set_host("example.com"); 267 host_port_pair_.set_host("example.com");
268 host_port_pair_.set_port(80); 268 host_port_pair_.set_port(80);
269 host_port_proxy_pair_.first = host_port_pair_; 269 host_port_proxy_pair_.first = host_port_pair_;
270 host_port_proxy_pair_.second = net::ProxyServer::Direct(); 270 host_port_proxy_pair_.second = net::ProxyServer::Direct();
271 net::SpdySessionPool* spdy_session_pool = 271 net::SpdySessionPool* spdy_session_pool =
272 http_session_->spdy_session_pool(); 272 http_session_->spdy_session_pool();
273 DCHECK(spdy_session_pool); 273 DCHECK(spdy_session_pool);
274 EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_)); 274 EXPECT_FALSE(spdy_session_pool->HasSession(host_port_proxy_pair_));
(...skipping 19 matching lines...) Expand all
294 return net::ERR_UNEXPECTED; 294 return net::ERR_UNEXPECTED;
295 } 295 }
296 virtual net::HttpCache* GetCache() { 296 virtual net::HttpCache* GetCache() {
297 NOTREACHED(); 297 NOTREACHED();
298 return NULL; 298 return NULL;
299 } 299 }
300 virtual net::HttpNetworkSession* GetSession() { 300 virtual net::HttpNetworkSession* GetSession() {
301 return http_session_.get(); 301 return http_session_.get();
302 } 302 }
303 private: 303 private:
304 scoped_refptr<net::OrderedSocketData> data_; 304 net::OrderedSocketData* data_;
305 scoped_ptr<net::SpdySessionDependencies> session_deps_; 305 scoped_ptr<net::SpdySessionDependencies> session_deps_;
306 scoped_refptr<net::HttpNetworkSession> http_session_; 306 scoped_refptr<net::HttpNetworkSession> http_session_;
307 scoped_refptr<net::TransportSocketParams> transport_params_; 307 scoped_refptr<net::TransportSocketParams> transport_params_;
308 scoped_refptr<net::SpdySession> session_; 308 scoped_refptr<net::SpdySession> session_;
309 net::HostPortPair host_port_pair_; 309 net::HostPortPair host_port_pair_;
310 net::HostPortProxyPair host_port_proxy_pair_; 310 net::HostPortProxyPair host_port_proxy_pair_;
311 }; 311 };
312 } 312 }
313 313
314 namespace net { 314 namespace net {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 StreamType stream_type) { 361 StreamType stream_type) {
362 DCHECK_NE(STREAM_INVALID, stream_type); 362 DCHECK_NE(STREAM_INVALID, stream_type);
363 stream_type_ = stream_type; 363 stream_type_ = stream_type;
364 websocket_ = new WebSocketJob(delegate); 364 websocket_ = new WebSocketJob(delegate);
365 365
366 if (stream_type == STREAM_MOCK_SOCKET) 366 if (stream_type == STREAM_MOCK_SOCKET)
367 socket_ = new MockSocketStream(url, websocket_.get()); 367 socket_ = new MockSocketStream(url, websocket_.get());
368 368
369 if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) { 369 if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) {
370 if (stream_type == STREAM_SPDY_WEBSOCKET) { 370 if (stream_type == STREAM_SPDY_WEBSOCKET) {
371 http_factory_.reset(new MockHttpTransactionFactory(data_)); 371 http_factory_.reset(new MockHttpTransactionFactory(data_.get()));
372 context_->set_http_transaction_factory(http_factory_.get()); 372 context_->set_http_transaction_factory(http_factory_.get());
373 } 373 }
374 374
375 ssl_config_service_ = new MockSSLConfigService(); 375 ssl_config_service_ = new MockSSLConfigService();
376 context_->set_ssl_config_service(ssl_config_service_); 376 context_->set_ssl_config_service(ssl_config_service_);
377 proxy_service_.reset(net::ProxyService::CreateDirect()); 377 proxy_service_.reset(net::ProxyService::CreateDirect());
378 context_->set_proxy_service(proxy_service_.get()); 378 context_->set_proxy_service(proxy_service_.get());
379 host_resolver_.reset(new net::MockHostResolver); 379 host_resolver_.reset(new net::MockHostResolver);
380 context_->set_host_resolver(host_resolver_.get()); 380 context_->set_host_resolver(host_resolver_.get());
381 381
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 void TestInvalidSendData(); 441 void TestInvalidSendData();
442 void TestConnectByWebSocket(ThrottlingOption throttling); 442 void TestConnectByWebSocket(ThrottlingOption throttling);
443 void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling); 443 void TestConnectBySpdy(SpdyOption spdy, ThrottlingOption throttling);
444 444
445 StreamType stream_type_; 445 StreamType stream_type_;
446 scoped_refptr<MockCookieStore> cookie_store_; 446 scoped_refptr<MockCookieStore> cookie_store_;
447 scoped_refptr<MockURLRequestContext> context_; 447 scoped_refptr<MockURLRequestContext> context_;
448 scoped_refptr<WebSocketJob> websocket_; 448 scoped_refptr<WebSocketJob> websocket_;
449 scoped_refptr<SocketStream> socket_; 449 scoped_refptr<SocketStream> socket_;
450 scoped_ptr<MockClientSocketFactory> socket_factory_; 450 scoped_ptr<MockClientSocketFactory> socket_factory_;
451 scoped_refptr<OrderedSocketData> data_; 451 scoped_ptr<OrderedSocketData> data_;
452 TestCompletionCallback sync_test_callback_; 452 TestCompletionCallback sync_test_callback_;
453 scoped_refptr<MockSSLConfigService> ssl_config_service_; 453 scoped_refptr<MockSSLConfigService> ssl_config_service_;
454 scoped_ptr<net::ProxyService> proxy_service_; 454 scoped_ptr<net::ProxyService> proxy_service_;
455 scoped_ptr<net::MockHostResolver> host_resolver_; 455 scoped_ptr<net::MockHostResolver> host_resolver_;
456 scoped_ptr<MockHttpTransactionFactory> http_factory_; 456 scoped_ptr<MockHttpTransactionFactory> http_factory_;
457 457
458 static const char kHandshakeRequestWithoutCookie[]; 458 static const char kHandshakeRequestWithoutCookie[];
459 static const char kHandshakeRequestWithCookie[]; 459 static const char kHandshakeRequestWithCookie[];
460 static const char kHandshakeRequestWithFilteredCookie[]; 460 static const char kHandshakeRequestWithFilteredCookie[];
461 static const char kHandshakeResponseWithoutCookie[]; 461 static const char kHandshakeResponseWithoutCookie[];
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 MockRead(true, 820 MockRead(true,
821 kHandshakeResponseWithoutCookie, 821 kHandshakeResponseWithoutCookie,
822 kHandshakeResponseWithoutCookieLength, 822 kHandshakeResponseWithoutCookieLength,
823 2), 823 2),
824 MockRead(true, 824 MockRead(true,
825 kDataWorld, 825 kDataWorld,
826 kDataWorldLength, 826 kDataWorldLength,
827 4), 827 4),
828 MockRead(false, 0, 5) // EOF 828 MockRead(false, 0, 5) // EOF
829 }; 829 };
830 data_ = new OrderedSocketData( 830 data_.reset(new OrderedSocketData(
831 reads, arraysize(reads), writes, arraysize(writes)); 831 reads, arraysize(reads), writes, arraysize(writes)));
832 832
833 GURL url("ws://example.com/demo"); 833 GURL url("ws://example.com/demo");
834 MockSocketStreamDelegate delegate; 834 MockSocketStreamDelegate delegate;
835 WebSocketJobTest* test = this; 835 WebSocketJobTest* test = this;
836 if (throttling == THROTTLING_ON) 836 if (throttling == THROTTLING_ON)
837 delegate.SetOnStartOpenConnection( 837 delegate.SetOnStartOpenConnection(
838 base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test))); 838 base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
839 delegate.SetOnConnected( 839 delegate.SetOnConnected(
840 base::Bind(&WebSocketJobTest::DoSendRequest, base::Unretained(test))); 840 base::Bind(&WebSocketJobTest::DoSendRequest, base::Unretained(test)));
841 delegate.SetOnReceivedData( 841 delegate.SetOnReceivedData(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 CreateMockWrite(*request_frame.get(), 1), 930 CreateMockWrite(*request_frame.get(), 1),
931 CreateMockWrite(*data_hello_frame.get(), 3), 931 CreateMockWrite(*data_hello_frame.get(), 3),
932 }; 932 };
933 MockRead reads_spdy[] = { 933 MockRead reads_spdy[] = {
934 CreateMockRead(*response_frame.get(), 2), 934 CreateMockRead(*response_frame.get(), 2),
935 CreateMockRead(*data_world_frame.get(), 4), 935 CreateMockRead(*data_world_frame.get(), 4),
936 MockRead(false, 0, 5) // EOF 936 MockRead(false, 0, 5) // EOF
937 }; 937 };
938 938
939 if (spdy == SPDY_ON) 939 if (spdy == SPDY_ON)
940 data_ = new OrderedSocketData( 940 data_.reset(new OrderedSocketData(
941 reads_spdy, arraysize(reads_spdy), 941 reads_spdy, arraysize(reads_spdy),
942 writes_spdy, arraysize(writes_spdy)); 942 writes_spdy, arraysize(writes_spdy)));
943 else 943 else
944 data_ = new OrderedSocketData( 944 data_.reset(new OrderedSocketData(
945 reads_websocket, arraysize(reads_websocket), 945 reads_websocket, arraysize(reads_websocket),
946 writes_websocket, arraysize(writes_websocket)); 946 writes_websocket, arraysize(writes_websocket)));
947 947
948 GURL url("ws://example.com/demo"); 948 GURL url("ws://example.com/demo");
949 MockSocketStreamDelegate delegate; 949 MockSocketStreamDelegate delegate;
950 WebSocketJobTest* test = this; 950 WebSocketJobTest* test = this;
951 if (throttling == THROTTLING_ON) 951 if (throttling == THROTTLING_ON)
952 delegate.SetOnStartOpenConnection( 952 delegate.SetOnStartOpenConnection(
953 base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test))); 953 base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
954 delegate.SetOnConnected( 954 delegate.SetOnConnected(
955 base::Bind(&WebSocketJobTest::DoSendRequest, base::Unretained(test))); 955 base::Bind(&WebSocketJobTest::DoSendRequest, base::Unretained(test)));
956 delegate.SetOnReceivedData( 956 delegate.SetOnReceivedData(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 1085
1086 TEST_F(WebSocketJobTest, ThrottlingSpdySpdyEnabled) { 1086 TEST_F(WebSocketJobTest, ThrottlingSpdySpdyEnabled) {
1087 WebSocketJob::set_websocket_over_spdy_enabled(true); 1087 WebSocketJob::set_websocket_over_spdy_enabled(true);
1088 TestConnectBySpdy(SPDY_ON, THROTTLING_ON); 1088 TestConnectBySpdy(SPDY_ON, THROTTLING_ON);
1089 } 1089 }
1090 1090
1091 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation. 1091 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation.
1092 // TODO(toyoshim,yutak): Add tests to verify closing handshake. 1092 // TODO(toyoshim,yutak): Add tests to verify closing handshake.
1093 1093
1094 } // namespace net 1094 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_websocket_stream_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698