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

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

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « net/websockets/websocket_job_spdy2_unittest.cc ('k') | ppapi/proxy/plugin_dispatcher.cc » ('j') | 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) 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (stream_type == STREAM_MOCK_SOCKET) 384 if (stream_type == STREAM_MOCK_SOCKET)
385 socket_ = new MockSocketStream(url, websocket_.get()); 385 socket_ = new MockSocketStream(url, websocket_.get());
386 386
387 if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) { 387 if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) {
388 if (stream_type == STREAM_SPDY_WEBSOCKET) { 388 if (stream_type == STREAM_SPDY_WEBSOCKET) {
389 http_factory_.reset(new MockHttpTransactionFactory(data_.get())); 389 http_factory_.reset(new MockHttpTransactionFactory(data_.get()));
390 context_->set_http_transaction_factory(http_factory_.get()); 390 context_->set_http_transaction_factory(http_factory_.get());
391 } 391 }
392 392
393 ssl_config_service_ = new MockSSLConfigService(); 393 ssl_config_service_ = new MockSSLConfigService();
394 context_->set_ssl_config_service(ssl_config_service_); 394 context_->set_ssl_config_service(ssl_config_service_.get());
395 proxy_service_.reset(net::ProxyService::CreateDirect()); 395 proxy_service_.reset(net::ProxyService::CreateDirect());
396 context_->set_proxy_service(proxy_service_.get()); 396 context_->set_proxy_service(proxy_service_.get());
397 host_resolver_.reset(new net::MockHostResolver); 397 host_resolver_.reset(new net::MockHostResolver);
398 context_->set_host_resolver(host_resolver_.get()); 398 context_->set_host_resolver(host_resolver_.get());
399 399
400 socket_ = new SocketStream(url, websocket_.get()); 400 socket_ = new SocketStream(url, websocket_.get());
401 socket_factory_.reset(new MockClientSocketFactory); 401 socket_factory_.reset(new MockClientSocketFactory);
402 DCHECK(data_.get()); 402 DCHECK(data_.get());
403 socket_factory_->AddSocketDataProvider(data_.get()); 403 socket_factory_->AddSocketDataProvider(data_.get());
404 socket_->SetClientSocketFactory(socket_factory_.get()); 404 socket_->SetClientSocketFactory(socket_factory_.get());
405 } 405 }
406 406
407 websocket_->InitSocketStream(socket_.get()); 407 websocket_->InitSocketStream(socket_.get());
408 websocket_->set_context(context_.get()); 408 websocket_->set_context(context_.get());
409 IPAddressNumber ip; 409 IPAddressNumber ip;
410 ParseIPLiteralToNumber("127.0.0.1", &ip); 410 ParseIPLiteralToNumber("127.0.0.1", &ip);
411 websocket_->addresses_ = AddressList::CreateFromIPAddress(ip, 0); 411 websocket_->addresses_ = AddressList::CreateFromIPAddress(ip, 0);
412 } 412 }
413 void SkipToConnecting() { 413 void SkipToConnecting() {
414 websocket_->state_ = WebSocketJob::CONNECTING; 414 websocket_->state_ = WebSocketJob::CONNECTING;
415 WebSocketThrottle::GetInstance()->PutInQueue(websocket_); 415 WebSocketThrottle::GetInstance()->PutInQueue(websocket_.get());
416 } 416 }
417 WebSocketJob::State GetWebSocketJobState() { 417 WebSocketJob::State GetWebSocketJobState() {
418 return websocket_->state_; 418 return websocket_->state_;
419 } 419 }
420 void CloseWebSocketJob() { 420 void CloseWebSocketJob() {
421 if (websocket_->socket_) { 421 if (websocket_->socket_.get()) {
422 websocket_->socket_->DetachDelegate(); 422 websocket_->socket_->DetachDelegate();
423 WebSocketThrottle::GetInstance()->RemoveFromQueue(websocket_); 423 WebSocketThrottle::GetInstance()->RemoveFromQueue(websocket_.get());
424 } 424 }
425 websocket_->state_ = WebSocketJob::CLOSED; 425 websocket_->state_ = WebSocketJob::CLOSED;
426 websocket_->delegate_ = NULL; 426 websocket_->delegate_ = NULL;
427 websocket_->socket_ = NULL; 427 websocket_->socket_ = NULL;
428 } 428 }
429 SocketStream* GetSocket(SocketStreamJob* job) { 429 SocketStream* GetSocket(SocketStreamJob* job) {
430 return job->socket_.get(); 430 return job->socket_.get();
431 } 431 }
432 const std::string& sent_data() const { 432 const std::string& sent_data() const {
433 DCHECK_EQ(STREAM_MOCK_SOCKET, stream_type_); 433 DCHECK_EQ(STREAM_MOCK_SOCKET, stream_type_);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); 609 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
610 websocket_->OnSentData(socket_.get(), 610 websocket_->OnSentData(socket_.get(),
611 kHandshakeRequestWithoutCookieLength); 611 kHandshakeRequestWithoutCookieLength);
612 EXPECT_EQ(kHandshakeRequestWithoutCookieLength, delegate.amount_sent()); 612 EXPECT_EQ(kHandshakeRequestWithoutCookieLength, delegate.amount_sent());
613 613
614 std::vector<std::string> lines; 614 std::vector<std::string> lines;
615 base::SplitString(kHandshakeResponseWithoutCookie, '\n', &lines); 615 base::SplitString(kHandshakeResponseWithoutCookie, '\n', &lines);
616 for (size_t i = 0; i < lines.size() - 2; i++) { 616 for (size_t i = 0; i < lines.size() - 2; i++) {
617 std::string line = lines[i] + "\r\n"; 617 std::string line = lines[i] + "\r\n";
618 SCOPED_TRACE("Line: " + line); 618 SCOPED_TRACE("Line: " + line);
619 websocket_->OnReceivedData(socket_, 619 websocket_->OnReceivedData(socket_.get(),
620 line.c_str(), 620 line.c_str(),
621 line.size()); 621 line.size());
622 MessageLoop::current()->RunAllPending(); 622 MessageLoop::current()->RunAllPending();
623 EXPECT_TRUE(delegate.received_data().empty()); 623 EXPECT_TRUE(delegate.received_data().empty());
624 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); 624 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
625 } 625 }
626 websocket_->OnReceivedData(socket_.get(), "\r\n", 2); 626 websocket_->OnReceivedData(socket_.get(), "\r\n", 2);
627 MessageLoop::current()->RunAllPending(); 627 MessageLoop::current()->RunAllPending();
628 EXPECT_FALSE(delegate.received_data().empty()); 628 EXPECT_FALSE(delegate.received_data().empty());
629 EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data()); 629 EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
630 EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState()); 630 EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
631 CloseWebSocketJob(); 631 CloseWebSocketJob();
632 } 632 }
633 633
634 TEST_F(WebSocketJobSpdy3Test, DelayedCookies) { 634 TEST_F(WebSocketJobSpdy3Test, DelayedCookies) {
635 WebSocketJob::set_websocket_over_spdy_enabled(true); 635 WebSocketJob::set_websocket_over_spdy_enabled(true);
636 GURL url("ws://example.com/demo"); 636 GURL url("ws://example.com/demo");
637 GURL cookieUrl("http://example.com/demo"); 637 GURL cookieUrl("http://example.com/demo");
638 CookieOptions cookie_options; 638 CookieOptions cookie_options;
639 scoped_refptr<DelayedCookieMonster> cookie_store = new DelayedCookieMonster(); 639 scoped_refptr<DelayedCookieMonster> cookie_store = new DelayedCookieMonster();
640 context_->set_cookie_store(cookie_store); 640 context_->set_cookie_store(cookie_store.get());
641 cookie_store->SetCookieWithOptionsAsync( 641 cookie_store->SetCookieWithOptionsAsync(
642 cookieUrl, "CR-test=1", cookie_options, 642 cookieUrl, "CR-test=1", cookie_options,
643 net::CookieMonster::SetCookiesCallback()); 643 net::CookieMonster::SetCookiesCallback());
644 cookie_options.set_include_httponly(); 644 cookie_options.set_include_httponly();
645 cookie_store->SetCookieWithOptionsAsync( 645 cookie_store->SetCookieWithOptionsAsync(
646 cookieUrl, "CR-test-httponly=1", cookie_options, 646 cookieUrl, "CR-test-httponly=1", cookie_options,
647 net::CookieMonster::SetCookiesCallback()); 647 net::CookieMonster::SetCookiesCallback());
648 648
649 MockSocketStreamDelegate delegate; 649 MockSocketStreamDelegate delegate;
650 InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET); 650 InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
651 SkipToConnecting(); 651 SkipToConnecting();
652 652
653 bool sent = websocket_->SendData(kHandshakeRequestWithCookie, 653 bool sent = websocket_->SendData(kHandshakeRequestWithCookie,
654 kHandshakeRequestWithCookieLength); 654 kHandshakeRequestWithCookieLength);
655 EXPECT_TRUE(sent); 655 EXPECT_TRUE(sent);
656 MessageLoop::current()->RunAllPending(); 656 MessageLoop::current()->RunAllPending();
657 EXPECT_EQ(kHandshakeRequestWithFilteredCookie, sent_data()); 657 EXPECT_EQ(kHandshakeRequestWithFilteredCookie, sent_data());
658 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); 658 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
659 websocket_->OnSentData(socket_, 659 websocket_->OnSentData(socket_.get(),
660 kHandshakeRequestWithFilteredCookieLength); 660 kHandshakeRequestWithFilteredCookieLength);
661 EXPECT_EQ(kHandshakeRequestWithCookieLength, 661 EXPECT_EQ(kHandshakeRequestWithCookieLength,
662 delegate.amount_sent()); 662 delegate.amount_sent());
663 663
664 websocket_->OnReceivedData(socket_.get(), 664 websocket_->OnReceivedData(socket_.get(),
665 kHandshakeResponseWithCookie, 665 kHandshakeResponseWithCookie,
666 kHandshakeResponseWithCookieLength); 666 kHandshakeResponseWithCookieLength);
667 MessageLoop::current()->RunAllPending(); 667 MessageLoop::current()->RunAllPending();
668 EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data()); 668 EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
669 EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState()); 669 EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
(...skipping 14 matching lines...) Expand all
684 MockSocketStreamDelegate delegate; 684 MockSocketStreamDelegate delegate;
685 InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET); 685 InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
686 SkipToConnecting(); 686 SkipToConnecting();
687 687
688 bool sent = websocket_->SendData(kHandshakeRequestWithCookie, 688 bool sent = websocket_->SendData(kHandshakeRequestWithCookie,
689 kHandshakeRequestWithCookieLength); 689 kHandshakeRequestWithCookieLength);
690 EXPECT_TRUE(sent); 690 EXPECT_TRUE(sent);
691 MessageLoop::current()->RunAllPending(); 691 MessageLoop::current()->RunAllPending();
692 EXPECT_EQ(kHandshakeRequestWithFilteredCookie, sent_data()); 692 EXPECT_EQ(kHandshakeRequestWithFilteredCookie, sent_data());
693 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); 693 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
694 websocket_->OnSentData(socket_, 694 websocket_->OnSentData(socket_.get(),
695 kHandshakeRequestWithFilteredCookieLength); 695 kHandshakeRequestWithFilteredCookieLength);
696 EXPECT_EQ(kHandshakeRequestWithCookieLength, 696 EXPECT_EQ(kHandshakeRequestWithCookieLength,
697 delegate.amount_sent()); 697 delegate.amount_sent());
698 698
699 websocket_->OnReceivedData(socket_.get(), 699 websocket_->OnReceivedData(socket_.get(),
700 kHandshakeResponseWithCookie, 700 kHandshakeResponseWithCookie,
701 kHandshakeResponseWithCookieLength); 701 kHandshakeResponseWithCookieLength);
702 MessageLoop::current()->RunAllPending(); 702 MessageLoop::current()->RunAllPending();
703 EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data()); 703 EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
704 EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState()); 704 EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
(...skipping 23 matching lines...) Expand all
728 delegate.set_allow_all_cookies(false); 728 delegate.set_allow_all_cookies(false);
729 InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET); 729 InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
730 SkipToConnecting(); 730 SkipToConnecting();
731 731
732 bool sent = websocket_->SendData(kHandshakeRequestWithCookie, 732 bool sent = websocket_->SendData(kHandshakeRequestWithCookie,
733 kHandshakeRequestWithCookieLength); 733 kHandshakeRequestWithCookieLength);
734 EXPECT_TRUE(sent); 734 EXPECT_TRUE(sent);
735 MessageLoop::current()->RunAllPending(); 735 MessageLoop::current()->RunAllPending();
736 EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data()); 736 EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data());
737 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); 737 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
738 websocket_->OnSentData(socket_, kHandshakeRequestWithoutCookieLength); 738 websocket_->OnSentData(socket_.get(), kHandshakeRequestWithoutCookieLength);
739 EXPECT_EQ(kHandshakeRequestWithCookieLength, 739 EXPECT_EQ(kHandshakeRequestWithCookieLength,
740 delegate.amount_sent()); 740 delegate.amount_sent());
741 741
742 websocket_->OnReceivedData(socket_.get(), 742 websocket_->OnReceivedData(socket_.get(),
743 kHandshakeResponseWithCookie, 743 kHandshakeResponseWithCookie,
744 kHandshakeResponseWithCookieLength); 744 kHandshakeResponseWithCookieLength);
745 MessageLoop::current()->RunAllPending(); 745 MessageLoop::current()->RunAllPending();
746 EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data()); 746 EXPECT_EQ(kHandshakeResponseWithoutCookie, delegate.received_data());
747 EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState()); 747 EXPECT_EQ(WebSocketJob::OPEN, GetWebSocketJobState());
748 748
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 } 858 }
859 859
860 websocket_->Connect(); 860 websocket_->Connect();
861 861
862 if (throttling == THROTTLING_ON) { 862 if (throttling == THROTTLING_ON) {
863 EXPECT_EQ(OK, WaitForResult()); 863 EXPECT_EQ(OK, WaitForResult());
864 EXPECT_TRUE(websocket_->IsWaiting()); 864 EXPECT_TRUE(websocket_->IsWaiting());
865 865
866 // Remove the former WebSocket object from throttling queue to unblock the 866 // Remove the former WebSocket object from throttling queue to unblock the
867 // latter. 867 // latter.
868 WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket); 868 WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket.get());
869 block_websocket->state_ = WebSocketJob::CLOSED; 869 block_websocket->state_ = WebSocketJob::CLOSED;
870 block_websocket = NULL; 870 block_websocket = NULL;
871 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary(); 871 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
872 } 872 }
873 873
874 EXPECT_EQ(OK, WaitForResult()); 874 EXPECT_EQ(OK, WaitForResult());
875 EXPECT_TRUE(data_->at_read_eof()); 875 EXPECT_TRUE(data_->at_read_eof());
876 EXPECT_TRUE(data_->at_write_eof()); 876 EXPECT_TRUE(data_->at_write_eof());
877 EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState()); 877 EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState());
878 } 878 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 } 974 }
975 975
976 websocket_->Connect(); 976 websocket_->Connect();
977 977
978 if (throttling == THROTTLING_ON) { 978 if (throttling == THROTTLING_ON) {
979 EXPECT_EQ(OK, WaitForResult()); 979 EXPECT_EQ(OK, WaitForResult());
980 EXPECT_TRUE(websocket_->IsWaiting()); 980 EXPECT_TRUE(websocket_->IsWaiting());
981 981
982 // Remove the former WebSocket object from throttling queue to unblock the 982 // Remove the former WebSocket object from throttling queue to unblock the
983 // latter. 983 // latter.
984 WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket); 984 WebSocketThrottle::GetInstance()->RemoveFromQueue(block_websocket.get());
985 block_websocket->state_ = WebSocketJob::CLOSED; 985 block_websocket->state_ = WebSocketJob::CLOSED;
986 block_websocket = NULL; 986 block_websocket = NULL;
987 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary(); 987 WebSocketThrottle::GetInstance()->WakeupSocketIfNecessary();
988 } 988 }
989 989
990 EXPECT_EQ(OK, WaitForResult()); 990 EXPECT_EQ(OK, WaitForResult());
991 EXPECT_TRUE(data_->at_read_eof()); 991 EXPECT_TRUE(data_->at_read_eof());
992 EXPECT_TRUE(data_->at_write_eof()); 992 EXPECT_TRUE(data_->at_write_eof());
993 EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState()); 993 EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState());
994 } 994 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 1091
1092 TEST_F(WebSocketJobSpdy3Test, ThrottlingSpdySpdyEnabled) { 1092 TEST_F(WebSocketJobSpdy3Test, ThrottlingSpdySpdyEnabled) {
1093 WebSocketJob::set_websocket_over_spdy_enabled(true); 1093 WebSocketJob::set_websocket_over_spdy_enabled(true);
1094 TestConnectBySpdy(SPDY_ON, THROTTLING_ON); 1094 TestConnectBySpdy(SPDY_ON, THROTTLING_ON);
1095 } 1095 }
1096 1096
1097 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation. 1097 // TODO(toyoshim): Add tests to verify throttling, SPDY stream limitation.
1098 // TODO(toyoshim,yutak): Add tests to verify closing handshake. 1098 // TODO(toyoshim,yutak): Add tests to verify closing handshake.
1099 1099
1100 } // namespace net 1100 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_job_spdy2_unittest.cc ('k') | ppapi/proxy/plugin_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698