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

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

Powered by Google App Engine
This is Rietveld 408576698