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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
« no previous file with comments | « net/websockets/websocket_channel.cc ('k') | net/websockets/websocket_deflate_stream.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_channel.h" 5 #include "net/websockets/websocket_channel.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <iostream> 10 #include <iostream>
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 new WebSocketFrame(source_frame.opcode)); 331 new WebSocketFrame(source_frame.opcode));
332 size_t frame_length = source_frame.data ? strlen(source_frame.data) : 0; 332 size_t frame_length = source_frame.data ? strlen(source_frame.data) : 0;
333 WebSocketFrameHeader& result_header = result_frame->header; 333 WebSocketFrameHeader& result_header = result_frame->header;
334 result_header.final = (source_frame.final == FINAL_FRAME); 334 result_header.final = (source_frame.final == FINAL_FRAME);
335 result_header.masked = (source_frame.masked == MASKED); 335 result_header.masked = (source_frame.masked == MASKED);
336 result_header.payload_length = frame_length; 336 result_header.payload_length = frame_length;
337 if (source_frame.data) { 337 if (source_frame.data) {
338 result_frame->data = new IOBuffer(frame_length); 338 result_frame->data = new IOBuffer(frame_length);
339 memcpy(result_frame->data->data(), source_frame.data, frame_length); 339 memcpy(result_frame->data->data(), source_frame.data, frame_length);
340 } 340 }
341 result_frames.push_back(result_frame.Pass()); 341 result_frames.push_back(std::move(result_frame));
342 } 342 }
343 return result_frames; 343 return result_frames;
344 } 344 }
345 345
346 // A GoogleMock action which can be used to respond to call to ReadFrames with 346 // A GoogleMock action which can be used to respond to call to ReadFrames with
347 // some frames. Use like ReadFrames(_, _).WillOnce(ReturnFrames(&frames)); 347 // some frames. Use like ReadFrames(_, _).WillOnce(ReturnFrames(&frames));
348 // |frames| is an array of InitFrame. |frames| needs to be passed by pointer 348 // |frames| is an array of InitFrame. |frames| needs to be passed by pointer
349 // because otherwise it will be treated as a pointer and the array size 349 // because otherwise it will be treated as a pointer and the array size
350 // information will be lost. 350 // information will be lost.
351 ACTION_P(ReturnFrames, source_frames) { 351 ACTION_P(ReturnFrames, source_frames) {
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 const std::vector<std::string>& requested_subprotocols, 695 const std::vector<std::string>& requested_subprotocols,
696 const url::Origin& origin, 696 const url::Origin& origin,
697 URLRequestContext* url_request_context, 697 URLRequestContext* url_request_context,
698 const BoundNetLog& net_log, 698 const BoundNetLog& net_log,
699 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { 699 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
700 this->socket_url = socket_url; 700 this->socket_url = socket_url;
701 this->requested_subprotocols = requested_subprotocols; 701 this->requested_subprotocols = requested_subprotocols;
702 this->origin = origin; 702 this->origin = origin;
703 this->url_request_context = url_request_context; 703 this->url_request_context = url_request_context;
704 this->net_log = net_log; 704 this->net_log = net_log;
705 this->connect_delegate = connect_delegate.Pass(); 705 this->connect_delegate = std::move(connect_delegate);
706 return make_scoped_ptr(new WebSocketStreamRequest); 706 return make_scoped_ptr(new WebSocketStreamRequest);
707 } 707 }
708 708
709 GURL socket_url; 709 GURL socket_url;
710 url::Origin origin; 710 url::Origin origin;
711 std::vector<std::string> requested_subprotocols; 711 std::vector<std::string> requested_subprotocols;
712 URLRequestContext* url_request_context; 712 URLRequestContext* url_request_context;
713 BoundNetLog net_log; 713 BoundNetLog net_log;
714 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate; 714 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate;
715 }; 715 };
(...skipping 30 matching lines...) Expand all
746 base::Unretained(&connect_data_.creator))); 746 base::Unretained(&connect_data_.creator)));
747 } 747 }
748 748
749 // Same as CreateChannelAndConnect(), but calls the on_success callback as 749 // Same as CreateChannelAndConnect(), but calls the on_success callback as
750 // well. This method is virtual so that subclasses can also set the stream. 750 // well. This method is virtual so that subclasses can also set the stream.
751 virtual void CreateChannelAndConnectSuccessfully() { 751 virtual void CreateChannelAndConnectSuccessfully() {
752 CreateChannelAndConnect(); 752 CreateChannelAndConnect();
753 // Most tests aren't concerned with flow control from the renderer, so allow 753 // Most tests aren't concerned with flow control from the renderer, so allow
754 // MAX_INT quota units. 754 // MAX_INT quota units.
755 channel_->SendFlowControl(kPlentyOfQuota); 755 channel_->SendFlowControl(kPlentyOfQuota);
756 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 756 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
757 } 757 }
758 758
759 // Returns a WebSocketEventInterface to be passed to the WebSocketChannel. 759 // Returns a WebSocketEventInterface to be passed to the WebSocketChannel.
760 // This implementation returns a newly-created fake. Subclasses may return a 760 // This implementation returns a newly-created fake. Subclasses may return a
761 // mock instead. 761 // mock instead.
762 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() { 762 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() {
763 return scoped_ptr<WebSocketEventInterface>(new FakeWebSocketEventInterface); 763 return scoped_ptr<WebSocketEventInterface>(new FakeWebSocketEventInterface);
764 } 764 }
765 765
766 // This method serves no other purpose than to provide a nice syntax for 766 // This method serves no other purpose than to provide a nice syntax for
767 // assigning to stream_. class T must be a subclass of WebSocketStream or you 767 // assigning to stream_. class T must be a subclass of WebSocketStream or you
768 // will have unpleasant compile errors. 768 // will have unpleasant compile errors.
769 template <class T> 769 template <class T>
770 void set_stream(scoped_ptr<T> stream) { 770 void set_stream(scoped_ptr<T> stream) {
771 stream_ = stream.Pass(); 771 stream_ = std::move(stream);
772 } 772 }
773 773
774 // A struct containing the data that will be used to connect the channel. 774 // A struct containing the data that will be used to connect the channel.
775 // Grouped for readability. 775 // Grouped for readability.
776 struct ConnectData { 776 struct ConnectData {
777 ConnectData() : socket_url("ws://ws/"), origin(GURL("http://ws")) {} 777 ConnectData() : socket_url("ws://ws/"), origin(GURL("http://ws")) {}
778 778
779 // URLRequestContext object. 779 // URLRequestContext object.
780 URLRequestContext url_request_context; 780 URLRequestContext url_request_context;
781 781
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 }; 938 };
939 939
940 // Base class for tests which verify that WebSocketStream methods are called 940 // Base class for tests which verify that WebSocketStream methods are called
941 // appropriately by using a MockWebSocketStream. 941 // appropriately by using a MockWebSocketStream.
942 class WebSocketChannelStreamTest : public WebSocketChannelTest { 942 class WebSocketChannelStreamTest : public WebSocketChannelTest {
943 protected: 943 protected:
944 WebSocketChannelStreamTest() 944 WebSocketChannelStreamTest()
945 : mock_stream_(new StrictMock<MockWebSocketStream>) {} 945 : mock_stream_(new StrictMock<MockWebSocketStream>) {}
946 946
947 void CreateChannelAndConnectSuccessfully() override { 947 void CreateChannelAndConnectSuccessfully() override {
948 set_stream(mock_stream_.Pass()); 948 set_stream(std::move(mock_stream_));
949 WebSocketChannelTest::CreateChannelAndConnectSuccessfully(); 949 WebSocketChannelTest::CreateChannelAndConnectSuccessfully();
950 } 950 }
951 951
952 scoped_ptr<MockWebSocketStream> mock_stream_; 952 scoped_ptr<MockWebSocketStream> mock_stream_;
953 }; 953 };
954 954
955 // Fixture for tests which test UTF-8 validation of sent Text frames via the 955 // Fixture for tests which test UTF-8 validation of sent Text frames via the
956 // EventInterface. 956 // EventInterface.
957 class WebSocketChannelSendUtf8Test 957 class WebSocketChannelSendUtf8Test
958 : public WebSocketChannelEventInterfaceTest { 958 : public WebSocketChannelEventInterfaceTest {
(...skipping 11 matching lines...) Expand all
970 970
971 // Fixture for tests which test use of receive quota from the renderer. 971 // Fixture for tests which test use of receive quota from the renderer.
972 class WebSocketChannelFlowControlTest 972 class WebSocketChannelFlowControlTest
973 : public WebSocketChannelEventInterfaceTest { 973 : public WebSocketChannelEventInterfaceTest {
974 protected: 974 protected:
975 // Tests using this fixture should use CreateChannelAndConnectWithQuota() 975 // Tests using this fixture should use CreateChannelAndConnectWithQuota()
976 // instead of CreateChannelAndConnectSuccessfully(). 976 // instead of CreateChannelAndConnectSuccessfully().
977 void CreateChannelAndConnectWithQuota(int64_t quota) { 977 void CreateChannelAndConnectWithQuota(int64_t quota) {
978 CreateChannelAndConnect(); 978 CreateChannelAndConnect();
979 channel_->SendFlowControl(quota); 979 channel_->SendFlowControl(quota);
980 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 980 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
981 } 981 }
982 982
983 virtual void CreateChannelAndConnectSuccesfully() { NOTREACHED(); } 983 virtual void CreateChannelAndConnectSuccesfully() { NOTREACHED(); }
984 }; 984 };
985 985
986 // Fixture for tests which test UTF-8 validation of received Text frames using a 986 // Fixture for tests which test UTF-8 validation of received Text frames using a
987 // mock WebSocketStream. 987 // mock WebSocketStream.
988 class WebSocketChannelReceiveUtf8Test : public WebSocketChannelStreamTest { 988 class WebSocketChannelReceiveUtf8Test : public WebSocketChannelStreamTest {
989 public: 989 public:
990 void SetUp() override { 990 void SetUp() override {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 CreateChannelAndConnectSuccessfully(); 1039 CreateChannelAndConnectSuccessfully();
1040 EXPECT_EQ(NULL, channel_.get()); 1040 EXPECT_EQ(NULL, channel_.get());
1041 } 1041 }
1042 1042
1043 TEST_F(WebSocketChannelDeletingTest, OnDataFrameSync) { 1043 TEST_F(WebSocketChannelDeletingTest, OnDataFrameSync) {
1044 scoped_ptr<ReadableFakeWebSocketStream> stream( 1044 scoped_ptr<ReadableFakeWebSocketStream> stream(
1045 new ReadableFakeWebSocketStream); 1045 new ReadableFakeWebSocketStream);
1046 static const InitFrame frames[] = { 1046 static const InitFrame frames[] = {
1047 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1047 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1048 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1048 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1049 set_stream(stream.Pass()); 1049 set_stream(std::move(stream));
1050 deleting_ = EVENT_ON_DATA_FRAME; 1050 deleting_ = EVENT_ON_DATA_FRAME;
1051 1051
1052 CreateChannelAndConnectSuccessfully(); 1052 CreateChannelAndConnectSuccessfully();
1053 EXPECT_EQ(NULL, channel_.get()); 1053 EXPECT_EQ(NULL, channel_.get());
1054 } 1054 }
1055 1055
1056 TEST_F(WebSocketChannelDeletingTest, OnDataFrameAsync) { 1056 TEST_F(WebSocketChannelDeletingTest, OnDataFrameAsync) {
1057 scoped_ptr<ReadableFakeWebSocketStream> stream( 1057 scoped_ptr<ReadableFakeWebSocketStream> stream(
1058 new ReadableFakeWebSocketStream); 1058 new ReadableFakeWebSocketStream);
1059 static const InitFrame frames[] = { 1059 static const InitFrame frames[] = {
1060 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1060 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1061 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1061 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1062 set_stream(stream.Pass()); 1062 set_stream(std::move(stream));
1063 deleting_ = EVENT_ON_DATA_FRAME; 1063 deleting_ = EVENT_ON_DATA_FRAME;
1064 1064
1065 CreateChannelAndConnectSuccessfully(); 1065 CreateChannelAndConnectSuccessfully();
1066 EXPECT_TRUE(channel_); 1066 EXPECT_TRUE(channel_);
1067 base::MessageLoop::current()->RunUntilIdle(); 1067 base::MessageLoop::current()->RunUntilIdle();
1068 EXPECT_EQ(NULL, channel_.get()); 1068 EXPECT_EQ(NULL, channel_.get());
1069 } 1069 }
1070 1070
1071 TEST_F(WebSocketChannelDeletingTest, OnFlowControlAfterConnect) { 1071 TEST_F(WebSocketChannelDeletingTest, OnFlowControlAfterConnect) {
1072 deleting_ = EVENT_ON_FLOW_CONTROL; 1072 deleting_ = EVENT_ON_FLOW_CONTROL;
(...skipping 15 matching lines...) Expand all
1088 EXPECT_EQ(NULL, channel_.get()); 1088 EXPECT_EQ(NULL, channel_.get());
1089 } 1089 }
1090 1090
1091 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeSync) { 1091 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeSync) {
1092 scoped_ptr<ReadableFakeWebSocketStream> stream( 1092 scoped_ptr<ReadableFakeWebSocketStream> stream(
1093 new ReadableFakeWebSocketStream); 1093 new ReadableFakeWebSocketStream);
1094 static const InitFrame frames[] = { 1094 static const InitFrame frames[] = {
1095 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 1095 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
1096 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; 1096 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}};
1097 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1097 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1098 set_stream(stream.Pass()); 1098 set_stream(std::move(stream));
1099 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; 1099 deleting_ = EVENT_ON_CLOSING_HANDSHAKE;
1100 CreateChannelAndConnectSuccessfully(); 1100 CreateChannelAndConnectSuccessfully();
1101 EXPECT_EQ(NULL, channel_.get()); 1101 EXPECT_EQ(NULL, channel_.get());
1102 } 1102 }
1103 1103
1104 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeAsync) { 1104 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeAsync) {
1105 scoped_ptr<ReadableFakeWebSocketStream> stream( 1105 scoped_ptr<ReadableFakeWebSocketStream> stream(
1106 new ReadableFakeWebSocketStream); 1106 new ReadableFakeWebSocketStream);
1107 static const InitFrame frames[] = { 1107 static const InitFrame frames[] = {
1108 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 1108 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
1109 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; 1109 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}};
1110 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1110 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1111 set_stream(stream.Pass()); 1111 set_stream(std::move(stream));
1112 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; 1112 deleting_ = EVENT_ON_CLOSING_HANDSHAKE;
1113 CreateChannelAndConnectSuccessfully(); 1113 CreateChannelAndConnectSuccessfully();
1114 ASSERT_TRUE(channel_); 1114 ASSERT_TRUE(channel_);
1115 base::MessageLoop::current()->RunUntilIdle(); 1115 base::MessageLoop::current()->RunUntilIdle();
1116 EXPECT_EQ(NULL, channel_.get()); 1116 EXPECT_EQ(NULL, channel_.get());
1117 } 1117 }
1118 1118
1119 TEST_F(WebSocketChannelDeletingTest, OnDropChannelWriteError) { 1119 TEST_F(WebSocketChannelDeletingTest, OnDropChannelWriteError) {
1120 set_stream(make_scoped_ptr(new UnWriteableFakeWebSocketStream)); 1120 set_stream(make_scoped_ptr(new UnWriteableFakeWebSocketStream));
1121 deleting_ = EVENT_ON_DROP_CHANNEL; 1121 deleting_ = EVENT_ON_DROP_CHANNEL;
1122 CreateChannelAndConnectSuccessfully(); 1122 CreateChannelAndConnectSuccessfully();
1123 ASSERT_TRUE(channel_); 1123 ASSERT_TRUE(channel_);
1124 channel_->SendFrame( 1124 channel_->SendFrame(
1125 true, WebSocketFrameHeader::kOpCodeText, AsVector("this will fail")); 1125 true, WebSocketFrameHeader::kOpCodeText, AsVector("this will fail"));
1126 EXPECT_EQ(NULL, channel_.get()); 1126 EXPECT_EQ(NULL, channel_.get());
1127 } 1127 }
1128 1128
1129 TEST_F(WebSocketChannelDeletingTest, OnDropChannelReadError) { 1129 TEST_F(WebSocketChannelDeletingTest, OnDropChannelReadError) {
1130 scoped_ptr<ReadableFakeWebSocketStream> stream( 1130 scoped_ptr<ReadableFakeWebSocketStream> stream(
1131 new ReadableFakeWebSocketStream); 1131 new ReadableFakeWebSocketStream);
1132 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1132 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1133 ERR_FAILED); 1133 ERR_FAILED);
1134 set_stream(stream.Pass()); 1134 set_stream(std::move(stream));
1135 deleting_ = EVENT_ON_DROP_CHANNEL; 1135 deleting_ = EVENT_ON_DROP_CHANNEL;
1136 CreateChannelAndConnectSuccessfully(); 1136 CreateChannelAndConnectSuccessfully();
1137 ASSERT_TRUE(channel_); 1137 ASSERT_TRUE(channel_);
1138 base::MessageLoop::current()->RunUntilIdle(); 1138 base::MessageLoop::current()->RunUntilIdle();
1139 EXPECT_EQ(NULL, channel_.get()); 1139 EXPECT_EQ(NULL, channel_.get());
1140 } 1140 }
1141 1141
1142 TEST_F(WebSocketChannelDeletingTest, OnNotifyStartOpeningHandshakeError) { 1142 TEST_F(WebSocketChannelDeletingTest, OnNotifyStartOpeningHandshakeError) {
1143 scoped_ptr<ReadableFakeWebSocketStream> stream( 1143 scoped_ptr<ReadableFakeWebSocketStream> stream(
1144 new ReadableFakeWebSocketStream); 1144 new ReadableFakeWebSocketStream);
1145 static const InitFrame frames[] = { 1145 static const InitFrame frames[] = {
1146 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1146 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1147 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1147 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1148 set_stream(stream.Pass()); 1148 set_stream(std::move(stream));
1149 deleting_ = EVENT_ON_START_OPENING_HANDSHAKE; 1149 deleting_ = EVENT_ON_START_OPENING_HANDSHAKE;
1150 1150
1151 CreateChannelAndConnectSuccessfully(); 1151 CreateChannelAndConnectSuccessfully();
1152 ASSERT_TRUE(channel_); 1152 ASSERT_TRUE(channel_);
1153 channel_->OnStartOpeningHandshake(scoped_ptr<WebSocketHandshakeRequestInfo>( 1153 channel_->OnStartOpeningHandshake(scoped_ptr<WebSocketHandshakeRequestInfo>(
1154 new WebSocketHandshakeRequestInfo(GURL("http://www.example.com/"), 1154 new WebSocketHandshakeRequestInfo(GURL("http://www.example.com/"),
1155 base::Time()))); 1155 base::Time())));
1156 base::MessageLoop::current()->RunUntilIdle(); 1156 base::MessageLoop::current()->RunUntilIdle();
1157 EXPECT_EQ(NULL, channel_.get()); 1157 EXPECT_EQ(NULL, channel_.get());
1158 } 1158 }
1159 1159
1160 TEST_F(WebSocketChannelDeletingTest, OnNotifyFinishOpeningHandshakeError) { 1160 TEST_F(WebSocketChannelDeletingTest, OnNotifyFinishOpeningHandshakeError) {
1161 scoped_ptr<ReadableFakeWebSocketStream> stream( 1161 scoped_ptr<ReadableFakeWebSocketStream> stream(
1162 new ReadableFakeWebSocketStream); 1162 new ReadableFakeWebSocketStream);
1163 static const InitFrame frames[] = { 1163 static const InitFrame frames[] = {
1164 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1164 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1165 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1165 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1166 set_stream(stream.Pass()); 1166 set_stream(std::move(stream));
1167 deleting_ = EVENT_ON_FINISH_OPENING_HANDSHAKE; 1167 deleting_ = EVENT_ON_FINISH_OPENING_HANDSHAKE;
1168 1168
1169 CreateChannelAndConnectSuccessfully(); 1169 CreateChannelAndConnectSuccessfully();
1170 ASSERT_TRUE(channel_); 1170 ASSERT_TRUE(channel_);
1171 scoped_refptr<HttpResponseHeaders> response_headers( 1171 scoped_refptr<HttpResponseHeaders> response_headers(
1172 new HttpResponseHeaders("")); 1172 new HttpResponseHeaders(""));
1173 channel_->OnFinishOpeningHandshake(scoped_ptr<WebSocketHandshakeResponseInfo>( 1173 channel_->OnFinishOpeningHandshake(scoped_ptr<WebSocketHandshakeResponseInfo>(
1174 new WebSocketHandshakeResponseInfo(GURL("http://www.example.com/"), 1174 new WebSocketHandshakeResponseInfo(GURL("http://www.example.com/"),
1175 200, 1175 200,
1176 "OK", 1176 "OK",
(...skipping 12 matching lines...) Expand all
1189 WebSocketFrameHeader::kOpCodeText, 1189 WebSocketFrameHeader::kOpCodeText,
1190 std::vector<char>(kDefaultInitialQuota * 2, 'T')); 1190 std::vector<char>(kDefaultInitialQuota * 2, 'T'));
1191 EXPECT_EQ(NULL, channel_.get()); 1191 EXPECT_EQ(NULL, channel_.get());
1192 } 1192 }
1193 1193
1194 TEST_F(WebSocketChannelDeletingTest, FailChannelInOnReadDone) { 1194 TEST_F(WebSocketChannelDeletingTest, FailChannelInOnReadDone) {
1195 scoped_ptr<ReadableFakeWebSocketStream> stream( 1195 scoped_ptr<ReadableFakeWebSocketStream> stream(
1196 new ReadableFakeWebSocketStream); 1196 new ReadableFakeWebSocketStream);
1197 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1197 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1198 ERR_WS_PROTOCOL_ERROR); 1198 ERR_WS_PROTOCOL_ERROR);
1199 set_stream(stream.Pass()); 1199 set_stream(std::move(stream));
1200 deleting_ = EVENT_ON_FAIL_CHANNEL; 1200 deleting_ = EVENT_ON_FAIL_CHANNEL;
1201 CreateChannelAndConnectSuccessfully(); 1201 CreateChannelAndConnectSuccessfully();
1202 ASSERT_TRUE(channel_); 1202 ASSERT_TRUE(channel_);
1203 base::MessageLoop::current()->RunUntilIdle(); 1203 base::MessageLoop::current()->RunUntilIdle();
1204 EXPECT_EQ(NULL, channel_.get()); 1204 EXPECT_EQ(NULL, channel_.get());
1205 } 1205 }
1206 1206
1207 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToMaskedFrame) { 1207 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToMaskedFrame) {
1208 scoped_ptr<ReadableFakeWebSocketStream> stream( 1208 scoped_ptr<ReadableFakeWebSocketStream> stream(
1209 new ReadableFakeWebSocketStream); 1209 new ReadableFakeWebSocketStream);
1210 static const InitFrame frames[] = { 1210 static const InitFrame frames[] = {
1211 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}}; 1211 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}};
1212 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1212 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1213 set_stream(stream.Pass()); 1213 set_stream(std::move(stream));
1214 deleting_ = EVENT_ON_FAIL_CHANNEL; 1214 deleting_ = EVENT_ON_FAIL_CHANNEL;
1215 1215
1216 CreateChannelAndConnectSuccessfully(); 1216 CreateChannelAndConnectSuccessfully();
1217 EXPECT_EQ(NULL, channel_.get()); 1217 EXPECT_EQ(NULL, channel_.get());
1218 } 1218 }
1219 1219
1220 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrame) { 1220 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrame) {
1221 scoped_ptr<ReadableFakeWebSocketStream> stream( 1221 scoped_ptr<ReadableFakeWebSocketStream> stream(
1222 new ReadableFakeWebSocketStream); 1222 new ReadableFakeWebSocketStream);
1223 static const InitFrame frames[] = { 1223 static const InitFrame frames[] = {
1224 {FINAL_FRAME, 0xF, NOT_MASKED, ""}}; 1224 {FINAL_FRAME, 0xF, NOT_MASKED, ""}};
1225 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1225 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1226 set_stream(stream.Pass()); 1226 set_stream(std::move(stream));
1227 deleting_ = EVENT_ON_FAIL_CHANNEL; 1227 deleting_ = EVENT_ON_FAIL_CHANNEL;
1228 1228
1229 CreateChannelAndConnectSuccessfully(); 1229 CreateChannelAndConnectSuccessfully();
1230 EXPECT_EQ(NULL, channel_.get()); 1230 EXPECT_EQ(NULL, channel_.get());
1231 } 1231 }
1232 1232
1233 // Version of above test with NULL data. 1233 // Version of above test with NULL data.
1234 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrameNull) { 1234 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrameNull) {
1235 scoped_ptr<ReadableFakeWebSocketStream> stream( 1235 scoped_ptr<ReadableFakeWebSocketStream> stream(
1236 new ReadableFakeWebSocketStream); 1236 new ReadableFakeWebSocketStream);
1237 static const InitFrame frames[] = { 1237 static const InitFrame frames[] = {
1238 {FINAL_FRAME, 0xF, NOT_MASKED, NULL}}; 1238 {FINAL_FRAME, 0xF, NOT_MASKED, NULL}};
1239 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1239 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1240 set_stream(stream.Pass()); 1240 set_stream(std::move(stream));
1241 deleting_ = EVENT_ON_FAIL_CHANNEL; 1241 deleting_ = EVENT_ON_FAIL_CHANNEL;
1242 1242
1243 CreateChannelAndConnectSuccessfully(); 1243 CreateChannelAndConnectSuccessfully();
1244 EXPECT_EQ(NULL, channel_.get()); 1244 EXPECT_EQ(NULL, channel_.get());
1245 } 1245 }
1246 1246
1247 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToPongAfterClose) { 1247 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToPongAfterClose) {
1248 scoped_ptr<ReadableFakeWebSocketStream> stream( 1248 scoped_ptr<ReadableFakeWebSocketStream> stream(
1249 new ReadableFakeWebSocketStream); 1249 new ReadableFakeWebSocketStream);
1250 static const InitFrame frames[] = { 1250 static const InitFrame frames[] = {
1251 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, 1251 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED,
1252 CLOSE_DATA(NORMAL_CLOSURE, "Success")}, 1252 CLOSE_DATA(NORMAL_CLOSURE, "Success")},
1253 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, ""}}; 1253 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, ""}};
1254 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1254 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1255 set_stream(stream.Pass()); 1255 set_stream(std::move(stream));
1256 deleting_ = EVENT_ON_FAIL_CHANNEL; 1256 deleting_ = EVENT_ON_FAIL_CHANNEL;
1257 1257
1258 CreateChannelAndConnectSuccessfully(); 1258 CreateChannelAndConnectSuccessfully();
1259 EXPECT_EQ(NULL, channel_.get()); 1259 EXPECT_EQ(NULL, channel_.get());
1260 } 1260 }
1261 1261
1262 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToPongAfterCloseNull) { 1262 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToPongAfterCloseNull) {
1263 scoped_ptr<ReadableFakeWebSocketStream> stream( 1263 scoped_ptr<ReadableFakeWebSocketStream> stream(
1264 new ReadableFakeWebSocketStream); 1264 new ReadableFakeWebSocketStream);
1265 static const InitFrame frames[] = { 1265 static const InitFrame frames[] = {
1266 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, 1266 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED,
1267 CLOSE_DATA(NORMAL_CLOSURE, "Success")}, 1267 CLOSE_DATA(NORMAL_CLOSURE, "Success")},
1268 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, NULL}}; 1268 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, NULL}};
1269 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1269 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1270 set_stream(stream.Pass()); 1270 set_stream(std::move(stream));
1271 deleting_ = EVENT_ON_FAIL_CHANNEL; 1271 deleting_ = EVENT_ON_FAIL_CHANNEL;
1272 1272
1273 CreateChannelAndConnectSuccessfully(); 1273 CreateChannelAndConnectSuccessfully();
1274 EXPECT_EQ(NULL, channel_.get()); 1274 EXPECT_EQ(NULL, channel_.get());
1275 } 1275 }
1276 1276
1277 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToUnknownOpCode) { 1277 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToUnknownOpCode) {
1278 scoped_ptr<ReadableFakeWebSocketStream> stream( 1278 scoped_ptr<ReadableFakeWebSocketStream> stream(
1279 new ReadableFakeWebSocketStream); 1279 new ReadableFakeWebSocketStream);
1280 static const InitFrame frames[] = {{FINAL_FRAME, 0x7, NOT_MASKED, ""}}; 1280 static const InitFrame frames[] = {{FINAL_FRAME, 0x7, NOT_MASKED, ""}};
1281 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1281 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1282 set_stream(stream.Pass()); 1282 set_stream(std::move(stream));
1283 deleting_ = EVENT_ON_FAIL_CHANNEL; 1283 deleting_ = EVENT_ON_FAIL_CHANNEL;
1284 1284
1285 CreateChannelAndConnectSuccessfully(); 1285 CreateChannelAndConnectSuccessfully();
1286 EXPECT_EQ(NULL, channel_.get()); 1286 EXPECT_EQ(NULL, channel_.get());
1287 } 1287 }
1288 1288
1289 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToUnknownOpCodeNull) { 1289 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToUnknownOpCodeNull) {
1290 scoped_ptr<ReadableFakeWebSocketStream> stream( 1290 scoped_ptr<ReadableFakeWebSocketStream> stream(
1291 new ReadableFakeWebSocketStream); 1291 new ReadableFakeWebSocketStream);
1292 static const InitFrame frames[] = {{FINAL_FRAME, 0x7, NOT_MASKED, NULL}}; 1292 static const InitFrame frames[] = {{FINAL_FRAME, 0x7, NOT_MASKED, NULL}};
1293 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1293 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1294 set_stream(stream.Pass()); 1294 set_stream(std::move(stream));
1295 deleting_ = EVENT_ON_FAIL_CHANNEL; 1295 deleting_ = EVENT_ON_FAIL_CHANNEL;
1296 1296
1297 CreateChannelAndConnectSuccessfully(); 1297 CreateChannelAndConnectSuccessfully();
1298 EXPECT_EQ(NULL, channel_.get()); 1298 EXPECT_EQ(NULL, channel_.get());
1299 } 1299 }
1300 1300
1301 TEST_F(WebSocketChannelDeletingTest, FailChannelDueInvalidCloseReason) { 1301 TEST_F(WebSocketChannelDeletingTest, FailChannelDueInvalidCloseReason) {
1302 scoped_ptr<ReadableFakeWebSocketStream> stream( 1302 scoped_ptr<ReadableFakeWebSocketStream> stream(
1303 new ReadableFakeWebSocketStream); 1303 new ReadableFakeWebSocketStream);
1304 static const InitFrame frames[] = { 1304 static const InitFrame frames[] = {
1305 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 1305 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
1306 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}}; 1306 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}};
1307 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1307 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1308 set_stream(stream.Pass()); 1308 set_stream(std::move(stream));
1309 deleting_ = EVENT_ON_FAIL_CHANNEL; 1309 deleting_ = EVENT_ON_FAIL_CHANNEL;
1310 1310
1311 CreateChannelAndConnectSuccessfully(); 1311 CreateChannelAndConnectSuccessfully();
1312 EXPECT_EQ(NULL, channel_.get()); 1312 EXPECT_EQ(NULL, channel_.get());
1313 } 1313 }
1314 1314
1315 TEST_F(WebSocketChannelEventInterfaceTest, ConnectSuccessReported) { 1315 TEST_F(WebSocketChannelEventInterfaceTest, ConnectSuccessReported) {
1316 // false means success. 1316 // false means success.
1317 EXPECT_CALL(*event_interface_, OnAddChannelResponse("", "")); 1317 EXPECT_CALL(*event_interface_, OnAddChannelResponse("", ""));
1318 // OnFlowControl is always called immediately after connect to provide initial 1318 // OnFlowControl is always called immediately after connect to provide initial
1319 // quota to the renderer. 1319 // quota to the renderer.
1320 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1320 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1321 1321
1322 CreateChannelAndConnect(); 1322 CreateChannelAndConnect();
1323 1323
1324 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 1324 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
1325 } 1325 }
1326 1326
1327 TEST_F(WebSocketChannelEventInterfaceTest, ConnectFailureReported) { 1327 TEST_F(WebSocketChannelEventInterfaceTest, ConnectFailureReported) {
1328 EXPECT_CALL(*event_interface_, OnFailChannel("hello")); 1328 EXPECT_CALL(*event_interface_, OnFailChannel("hello"));
1329 1329
1330 CreateChannelAndConnect(); 1330 CreateChannelAndConnect();
1331 1331
1332 connect_data_.creator.connect_delegate->OnFailure("hello"); 1332 connect_data_.creator.connect_delegate->OnFailure("hello");
1333 } 1333 }
1334 1334
(...skipping 26 matching lines...) Expand all
1361 1361
1362 // The first frames from the server can arrive together with the handshake, in 1362 // The first frames from the server can arrive together with the handshake, in
1363 // which case they will be available as soon as ReadFrames() is called the first 1363 // which case they will be available as soon as ReadFrames() is called the first
1364 // time. 1364 // time.
1365 TEST_F(WebSocketChannelEventInterfaceTest, DataLeftFromHandshake) { 1365 TEST_F(WebSocketChannelEventInterfaceTest, DataLeftFromHandshake) {
1366 scoped_ptr<ReadableFakeWebSocketStream> stream( 1366 scoped_ptr<ReadableFakeWebSocketStream> stream(
1367 new ReadableFakeWebSocketStream); 1367 new ReadableFakeWebSocketStream);
1368 static const InitFrame frames[] = { 1368 static const InitFrame frames[] = {
1369 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1369 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1370 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1370 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1371 set_stream(stream.Pass()); 1371 set_stream(std::move(stream));
1372 { 1372 {
1373 InSequence s; 1373 InSequence s;
1374 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1374 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1375 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1375 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1376 EXPECT_CALL( 1376 EXPECT_CALL(
1377 *event_interface_, 1377 *event_interface_,
1378 OnDataFrame( 1378 OnDataFrame(
1379 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO"))); 1379 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO")));
1380 } 1380 }
1381 1381
1382 CreateChannelAndConnectSuccessfully(); 1382 CreateChannelAndConnectSuccessfully();
1383 } 1383 }
1384 1384
1385 // A remote server could accept the handshake, but then immediately send a 1385 // A remote server could accept the handshake, but then immediately send a
1386 // Close frame. 1386 // Close frame.
1387 TEST_F(WebSocketChannelEventInterfaceTest, CloseAfterHandshake) { 1387 TEST_F(WebSocketChannelEventInterfaceTest, CloseAfterHandshake) {
1388 scoped_ptr<ReadableFakeWebSocketStream> stream( 1388 scoped_ptr<ReadableFakeWebSocketStream> stream(
1389 new ReadableFakeWebSocketStream); 1389 new ReadableFakeWebSocketStream);
1390 static const InitFrame frames[] = { 1390 static const InitFrame frames[] = {
1391 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 1391 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
1392 NOT_MASKED, CLOSE_DATA(SERVER_ERROR, "Internal Server Error")}}; 1392 NOT_MASKED, CLOSE_DATA(SERVER_ERROR, "Internal Server Error")}};
1393 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1393 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1394 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, 1394 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC,
1395 ERR_CONNECTION_CLOSED); 1395 ERR_CONNECTION_CLOSED);
1396 set_stream(stream.Pass()); 1396 set_stream(std::move(stream));
1397 { 1397 {
1398 InSequence s; 1398 InSequence s;
1399 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1399 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1400 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1400 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1401 EXPECT_CALL(*event_interface_, OnClosingHandshake()); 1401 EXPECT_CALL(*event_interface_, OnClosingHandshake());
1402 EXPECT_CALL( 1402 EXPECT_CALL(
1403 *event_interface_, 1403 *event_interface_,
1404 OnDropChannel( 1404 OnDropChannel(
1405 true, kWebSocketErrorInternalServerError, "Internal Server Error")); 1405 true, kWebSocketErrorInternalServerError, "Internal Server Error"));
1406 } 1406 }
1407 1407
1408 CreateChannelAndConnectSuccessfully(); 1408 CreateChannelAndConnectSuccessfully();
1409 } 1409 }
1410 1410
1411 // A remote server could close the connection immediately after sending the 1411 // A remote server could close the connection immediately after sending the
1412 // handshake response (most likely a bug in the server). 1412 // handshake response (most likely a bug in the server).
1413 TEST_F(WebSocketChannelEventInterfaceTest, ConnectionCloseAfterHandshake) { 1413 TEST_F(WebSocketChannelEventInterfaceTest, ConnectionCloseAfterHandshake) {
1414 scoped_ptr<ReadableFakeWebSocketStream> stream( 1414 scoped_ptr<ReadableFakeWebSocketStream> stream(
1415 new ReadableFakeWebSocketStream); 1415 new ReadableFakeWebSocketStream);
1416 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, 1416 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC,
1417 ERR_CONNECTION_CLOSED); 1417 ERR_CONNECTION_CLOSED);
1418 set_stream(stream.Pass()); 1418 set_stream(std::move(stream));
1419 { 1419 {
1420 InSequence s; 1420 InSequence s;
1421 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1421 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1422 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1422 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1423 EXPECT_CALL(*event_interface_, 1423 EXPECT_CALL(*event_interface_,
1424 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)); 1424 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
1425 } 1425 }
1426 1426
1427 CreateChannelAndConnectSuccessfully(); 1427 CreateChannelAndConnectSuccessfully();
1428 } 1428 }
1429 1429
1430 TEST_F(WebSocketChannelEventInterfaceTest, NormalAsyncRead) { 1430 TEST_F(WebSocketChannelEventInterfaceTest, NormalAsyncRead) {
1431 scoped_ptr<ReadableFakeWebSocketStream> stream( 1431 scoped_ptr<ReadableFakeWebSocketStream> stream(
1432 new ReadableFakeWebSocketStream); 1432 new ReadableFakeWebSocketStream);
1433 static const InitFrame frames[] = { 1433 static const InitFrame frames[] = {
1434 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1434 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1435 // We use this checkpoint object to verify that the callback isn't called 1435 // We use this checkpoint object to verify that the callback isn't called
1436 // until we expect it to be. 1436 // until we expect it to be.
1437 Checkpoint checkpoint; 1437 Checkpoint checkpoint;
1438 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1438 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1439 set_stream(stream.Pass()); 1439 set_stream(std::move(stream));
1440 { 1440 {
1441 InSequence s; 1441 InSequence s;
1442 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1442 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1443 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1443 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1444 EXPECT_CALL(checkpoint, Call(1)); 1444 EXPECT_CALL(checkpoint, Call(1));
1445 EXPECT_CALL( 1445 EXPECT_CALL(
1446 *event_interface_, 1446 *event_interface_,
1447 OnDataFrame( 1447 OnDataFrame(
1448 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO"))); 1448 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO")));
1449 EXPECT_CALL(checkpoint, Call(2)); 1449 EXPECT_CALL(checkpoint, Call(2));
1450 } 1450 }
1451 1451
1452 CreateChannelAndConnectSuccessfully(); 1452 CreateChannelAndConnectSuccessfully();
1453 checkpoint.Call(1); 1453 checkpoint.Call(1);
1454 base::MessageLoop::current()->RunUntilIdle(); 1454 base::MessageLoop::current()->RunUntilIdle();
1455 checkpoint.Call(2); 1455 checkpoint.Call(2);
1456 } 1456 }
1457 1457
1458 // Extra data can arrive while a read is being processed, resulting in the next 1458 // Extra data can arrive while a read is being processed, resulting in the next
1459 // read completing synchronously. 1459 // read completing synchronously.
1460 TEST_F(WebSocketChannelEventInterfaceTest, AsyncThenSyncRead) { 1460 TEST_F(WebSocketChannelEventInterfaceTest, AsyncThenSyncRead) {
1461 scoped_ptr<ReadableFakeWebSocketStream> stream( 1461 scoped_ptr<ReadableFakeWebSocketStream> stream(
1462 new ReadableFakeWebSocketStream); 1462 new ReadableFakeWebSocketStream);
1463 static const InitFrame frames1[] = { 1463 static const InitFrame frames1[] = {
1464 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1464 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1465 static const InitFrame frames2[] = { 1465 static const InitFrame frames2[] = {
1466 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "WORLD"}}; 1466 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "WORLD"}};
1467 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1); 1467 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1);
1468 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames2); 1468 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames2);
1469 set_stream(stream.Pass()); 1469 set_stream(std::move(stream));
1470 { 1470 {
1471 InSequence s; 1471 InSequence s;
1472 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1472 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1473 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1473 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1474 EXPECT_CALL( 1474 EXPECT_CALL(
1475 *event_interface_, 1475 *event_interface_,
1476 OnDataFrame( 1476 OnDataFrame(
1477 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO"))); 1477 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO")));
1478 EXPECT_CALL( 1478 EXPECT_CALL(
1479 *event_interface_, 1479 *event_interface_,
(...skipping 21 matching lines...) Expand all
1501 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, 1501 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
1502 NOT_MASKED, "SMALL"}}; 1502 NOT_MASKED, "SMALL"}};
1503 static const InitFrame frames3[] = { 1503 static const InitFrame frames3[] = {
1504 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, 1504 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
1505 NOT_MASKED, " "}, 1505 NOT_MASKED, " "},
1506 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, 1506 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
1507 NOT_MASKED, "FRAMES"}}; 1507 NOT_MASKED, "FRAMES"}};
1508 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1); 1508 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1);
1509 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames2); 1509 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames2);
1510 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames3); 1510 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames3);
1511 set_stream(stream.Pass()); 1511 set_stream(std::move(stream));
1512 { 1512 {
1513 InSequence s; 1513 InSequence s;
1514 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1514 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1515 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1515 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1516 EXPECT_CALL( 1516 EXPECT_CALL(
1517 *event_interface_, 1517 *event_interface_,
1518 OnDataFrame( 1518 OnDataFrame(
1519 false, WebSocketFrameHeader::kOpCodeText, AsVector("THREE"))); 1519 false, WebSocketFrameHeader::kOpCodeText, AsVector("THREE")));
1520 EXPECT_CALL( 1520 EXPECT_CALL(
1521 *event_interface_, 1521 *event_interface_,
(...skipping 17 matching lines...) Expand all
1539 base::MessageLoop::current()->RunUntilIdle(); 1539 base::MessageLoop::current()->RunUntilIdle();
1540 } 1540 }
1541 1541
1542 // A message can consist of one frame with NULL payload. 1542 // A message can consist of one frame with NULL payload.
1543 TEST_F(WebSocketChannelEventInterfaceTest, NullMessage) { 1543 TEST_F(WebSocketChannelEventInterfaceTest, NullMessage) {
1544 scoped_ptr<ReadableFakeWebSocketStream> stream( 1544 scoped_ptr<ReadableFakeWebSocketStream> stream(
1545 new ReadableFakeWebSocketStream); 1545 new ReadableFakeWebSocketStream);
1546 static const InitFrame frames[] = { 1546 static const InitFrame frames[] = {
1547 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, NULL}}; 1547 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, NULL}};
1548 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1548 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1549 set_stream(stream.Pass()); 1549 set_stream(std::move(stream));
1550 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1550 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1551 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1551 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1552 EXPECT_CALL( 1552 EXPECT_CALL(
1553 *event_interface_, 1553 *event_interface_,
1554 OnDataFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector(""))); 1554 OnDataFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector("")));
1555 CreateChannelAndConnectSuccessfully(); 1555 CreateChannelAndConnectSuccessfully();
1556 } 1556 }
1557 1557
1558 // Connection closed by the remote host without a closing handshake. 1558 // Connection closed by the remote host without a closing handshake.
1559 TEST_F(WebSocketChannelEventInterfaceTest, AsyncAbnormalClosure) { 1559 TEST_F(WebSocketChannelEventInterfaceTest, AsyncAbnormalClosure) {
1560 scoped_ptr<ReadableFakeWebSocketStream> stream( 1560 scoped_ptr<ReadableFakeWebSocketStream> stream(
1561 new ReadableFakeWebSocketStream); 1561 new ReadableFakeWebSocketStream);
1562 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1562 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1563 ERR_CONNECTION_CLOSED); 1563 ERR_CONNECTION_CLOSED);
1564 set_stream(stream.Pass()); 1564 set_stream(std::move(stream));
1565 { 1565 {
1566 InSequence s; 1566 InSequence s;
1567 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1567 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1568 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1568 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1569 EXPECT_CALL(*event_interface_, 1569 EXPECT_CALL(*event_interface_,
1570 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)); 1570 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
1571 } 1571 }
1572 1572
1573 CreateChannelAndConnectSuccessfully(); 1573 CreateChannelAndConnectSuccessfully();
1574 base::MessageLoop::current()->RunUntilIdle(); 1574 base::MessageLoop::current()->RunUntilIdle();
1575 } 1575 }
1576 1576
1577 // A connection reset should produce the same event as an unexpected closure. 1577 // A connection reset should produce the same event as an unexpected closure.
1578 TEST_F(WebSocketChannelEventInterfaceTest, ConnectionReset) { 1578 TEST_F(WebSocketChannelEventInterfaceTest, ConnectionReset) {
1579 scoped_ptr<ReadableFakeWebSocketStream> stream( 1579 scoped_ptr<ReadableFakeWebSocketStream> stream(
1580 new ReadableFakeWebSocketStream); 1580 new ReadableFakeWebSocketStream);
1581 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1581 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1582 ERR_CONNECTION_RESET); 1582 ERR_CONNECTION_RESET);
1583 set_stream(stream.Pass()); 1583 set_stream(std::move(stream));
1584 { 1584 {
1585 InSequence s; 1585 InSequence s;
1586 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1586 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1587 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1587 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1588 EXPECT_CALL(*event_interface_, 1588 EXPECT_CALL(*event_interface_,
1589 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)); 1589 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
1590 } 1590 }
1591 1591
1592 CreateChannelAndConnectSuccessfully(); 1592 CreateChannelAndConnectSuccessfully();
1593 base::MessageLoop::current()->RunUntilIdle(); 1593 base::MessageLoop::current()->RunUntilIdle();
1594 } 1594 }
1595 1595
1596 // RFC6455 5.1 "A client MUST close a connection if it detects a masked frame." 1596 // RFC6455 5.1 "A client MUST close a connection if it detects a masked frame."
1597 TEST_F(WebSocketChannelEventInterfaceTest, MaskedFramesAreRejected) { 1597 TEST_F(WebSocketChannelEventInterfaceTest, MaskedFramesAreRejected) {
1598 scoped_ptr<ReadableFakeWebSocketStream> stream( 1598 scoped_ptr<ReadableFakeWebSocketStream> stream(
1599 new ReadableFakeWebSocketStream); 1599 new ReadableFakeWebSocketStream);
1600 static const InitFrame frames[] = { 1600 static const InitFrame frames[] = {
1601 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}}; 1601 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}};
1602 1602
1603 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1603 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1604 set_stream(stream.Pass()); 1604 set_stream(std::move(stream));
1605 { 1605 {
1606 InSequence s; 1606 InSequence s;
1607 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1607 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1608 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1608 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1609 EXPECT_CALL( 1609 EXPECT_CALL(
1610 *event_interface_, 1610 *event_interface_,
1611 OnFailChannel( 1611 OnFailChannel(
1612 "A server must not mask any frames that it sends to the client.")); 1612 "A server must not mask any frames that it sends to the client."));
1613 } 1613 }
1614 1614
1615 CreateChannelAndConnectSuccessfully(); 1615 CreateChannelAndConnectSuccessfully();
1616 base::MessageLoop::current()->RunUntilIdle(); 1616 base::MessageLoop::current()->RunUntilIdle();
1617 } 1617 }
1618 1618
1619 // RFC6455 5.2 "If an unknown opcode is received, the receiving endpoint MUST 1619 // RFC6455 5.2 "If an unknown opcode is received, the receiving endpoint MUST
1620 // _Fail the WebSocket Connection_." 1620 // _Fail the WebSocket Connection_."
1621 TEST_F(WebSocketChannelEventInterfaceTest, UnknownOpCodeIsRejected) { 1621 TEST_F(WebSocketChannelEventInterfaceTest, UnknownOpCodeIsRejected) {
1622 scoped_ptr<ReadableFakeWebSocketStream> stream( 1622 scoped_ptr<ReadableFakeWebSocketStream> stream(
1623 new ReadableFakeWebSocketStream); 1623 new ReadableFakeWebSocketStream);
1624 static const InitFrame frames[] = {{FINAL_FRAME, 4, NOT_MASKED, "HELLO"}}; 1624 static const InitFrame frames[] = {{FINAL_FRAME, 4, NOT_MASKED, "HELLO"}};
1625 1625
1626 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1626 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1627 set_stream(stream.Pass()); 1627 set_stream(std::move(stream));
1628 { 1628 {
1629 InSequence s; 1629 InSequence s;
1630 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1630 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1631 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1631 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1632 EXPECT_CALL(*event_interface_, 1632 EXPECT_CALL(*event_interface_,
1633 OnFailChannel("Unrecognized frame opcode: 4")); 1633 OnFailChannel("Unrecognized frame opcode: 4"));
1634 } 1634 }
1635 1635
1636 CreateChannelAndConnectSuccessfully(); 1636 CreateChannelAndConnectSuccessfully();
1637 base::MessageLoop::current()->RunUntilIdle(); 1637 base::MessageLoop::current()->RunUntilIdle();
(...skipping 10 matching lines...) Expand all
1648 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, 1648 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
1649 NOT_MASKED, "SPLIT "}}; 1649 NOT_MASKED, "SPLIT "}};
1650 static const InitFrame frames2[] = { 1650 static const InitFrame frames2[] = {
1651 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, ""}}; 1651 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, ""}};
1652 static const InitFrame frames3[] = { 1652 static const InitFrame frames3[] = {
1653 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, 1653 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
1654 NOT_MASKED, "MESSAGE"}}; 1654 NOT_MASKED, "MESSAGE"}};
1655 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1); 1655 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1);
1656 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames2); 1656 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames2);
1657 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames3); 1657 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames3);
1658 set_stream(stream.Pass()); 1658 set_stream(std::move(stream));
1659 { 1659 {
1660 InSequence s; 1660 InSequence s;
1661 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1661 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1662 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1662 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1663 EXPECT_CALL( 1663 EXPECT_CALL(
1664 *event_interface_, 1664 *event_interface_,
1665 OnDataFrame( 1665 OnDataFrame(
1666 false, WebSocketFrameHeader::kOpCodeText, AsVector("SPLIT "))); 1666 false, WebSocketFrameHeader::kOpCodeText, AsVector("SPLIT ")));
1667 EXPECT_CALL(*event_interface_, 1667 EXPECT_CALL(*event_interface_,
1668 OnDataFrame(true, 1668 OnDataFrame(true,
1669 WebSocketFrameHeader::kOpCodeContinuation, 1669 WebSocketFrameHeader::kOpCodeContinuation,
1670 AsVector("MESSAGE"))); 1670 AsVector("MESSAGE")));
1671 } 1671 }
1672 1672
1673 CreateChannelAndConnectSuccessfully(); 1673 CreateChannelAndConnectSuccessfully();
1674 base::MessageLoop::current()->RunUntilIdle(); 1674 base::MessageLoop::current()->RunUntilIdle();
1675 } 1675 }
1676 1676
1677 // It seems redundant to repeat the entirety of the above test, so just test a 1677 // It seems redundant to repeat the entirety of the above test, so just test a
1678 // Pong with NULL data. 1678 // Pong with NULL data.
1679 TEST_F(WebSocketChannelEventInterfaceTest, PongWithNullData) { 1679 TEST_F(WebSocketChannelEventInterfaceTest, PongWithNullData) {
1680 scoped_ptr<ReadableFakeWebSocketStream> stream( 1680 scoped_ptr<ReadableFakeWebSocketStream> stream(
1681 new ReadableFakeWebSocketStream); 1681 new ReadableFakeWebSocketStream);
1682 static const InitFrame frames[] = { 1682 static const InitFrame frames[] = {
1683 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, NULL}}; 1683 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, NULL}};
1684 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1684 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1685 set_stream(stream.Pass()); 1685 set_stream(std::move(stream));
1686 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1686 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1687 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1687 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1688 1688
1689 CreateChannelAndConnectSuccessfully(); 1689 CreateChannelAndConnectSuccessfully();
1690 base::MessageLoop::current()->RunUntilIdle(); 1690 base::MessageLoop::current()->RunUntilIdle();
1691 } 1691 }
1692 1692
1693 // If a frame has an invalid header, then the connection is closed and 1693 // If a frame has an invalid header, then the connection is closed and
1694 // subsequent frames must not trigger events. 1694 // subsequent frames must not trigger events.
1695 TEST_F(WebSocketChannelEventInterfaceTest, FrameAfterInvalidFrame) { 1695 TEST_F(WebSocketChannelEventInterfaceTest, FrameAfterInvalidFrame) {
1696 scoped_ptr<ReadableFakeWebSocketStream> stream( 1696 scoped_ptr<ReadableFakeWebSocketStream> stream(
1697 new ReadableFakeWebSocketStream); 1697 new ReadableFakeWebSocketStream);
1698 static const InitFrame frames[] = { 1698 static const InitFrame frames[] = {
1699 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}, 1699 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"},
1700 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, " WORLD"}}; 1700 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, " WORLD"}};
1701 1701
1702 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1702 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1703 set_stream(stream.Pass()); 1703 set_stream(std::move(stream));
1704 { 1704 {
1705 InSequence s; 1705 InSequence s;
1706 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1706 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1707 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1707 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1708 EXPECT_CALL( 1708 EXPECT_CALL(
1709 *event_interface_, 1709 *event_interface_,
1710 OnFailChannel( 1710 OnFailChannel(
1711 "A server must not mask any frames that it sends to the client.")); 1711 "A server must not mask any frames that it sends to the client."));
1712 } 1712 }
1713 1713
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 // When the remote server sends a Close frame with an empty payload, 1868 // When the remote server sends a Close frame with an empty payload,
1869 // WebSocketChannel should report code 1005, kWebSocketErrorNoStatusReceived. 1869 // WebSocketChannel should report code 1005, kWebSocketErrorNoStatusReceived.
1870 TEST_F(WebSocketChannelEventInterfaceTest, CloseWithNoPayloadGivesStatus1005) { 1870 TEST_F(WebSocketChannelEventInterfaceTest, CloseWithNoPayloadGivesStatus1005) {
1871 scoped_ptr<ReadableFakeWebSocketStream> stream( 1871 scoped_ptr<ReadableFakeWebSocketStream> stream(
1872 new ReadableFakeWebSocketStream); 1872 new ReadableFakeWebSocketStream);
1873 static const InitFrame frames[] = { 1873 static const InitFrame frames[] = {
1874 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, ""}}; 1874 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, ""}};
1875 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1875 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1876 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, 1876 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC,
1877 ERR_CONNECTION_CLOSED); 1877 ERR_CONNECTION_CLOSED);
1878 set_stream(stream.Pass()); 1878 set_stream(std::move(stream));
1879 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1879 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1880 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1880 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1881 EXPECT_CALL(*event_interface_, OnClosingHandshake()); 1881 EXPECT_CALL(*event_interface_, OnClosingHandshake());
1882 EXPECT_CALL(*event_interface_, 1882 EXPECT_CALL(*event_interface_,
1883 OnDropChannel(true, kWebSocketErrorNoStatusReceived, _)); 1883 OnDropChannel(true, kWebSocketErrorNoStatusReceived, _));
1884 1884
1885 CreateChannelAndConnectSuccessfully(); 1885 CreateChannelAndConnectSuccessfully();
1886 } 1886 }
1887 1887
1888 // A version of the above test with NULL payload. 1888 // A version of the above test with NULL payload.
1889 TEST_F(WebSocketChannelEventInterfaceTest, 1889 TEST_F(WebSocketChannelEventInterfaceTest,
1890 CloseWithNullPayloadGivesStatus1005) { 1890 CloseWithNullPayloadGivesStatus1005) {
1891 scoped_ptr<ReadableFakeWebSocketStream> stream( 1891 scoped_ptr<ReadableFakeWebSocketStream> stream(
1892 new ReadableFakeWebSocketStream); 1892 new ReadableFakeWebSocketStream);
1893 static const InitFrame frames[] = { 1893 static const InitFrame frames[] = {
1894 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, NULL}}; 1894 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, NULL}};
1895 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1895 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1896 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, 1896 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC,
1897 ERR_CONNECTION_CLOSED); 1897 ERR_CONNECTION_CLOSED);
1898 set_stream(stream.Pass()); 1898 set_stream(std::move(stream));
1899 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1899 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1900 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1900 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1901 EXPECT_CALL(*event_interface_, OnClosingHandshake()); 1901 EXPECT_CALL(*event_interface_, OnClosingHandshake());
1902 EXPECT_CALL(*event_interface_, 1902 EXPECT_CALL(*event_interface_,
1903 OnDropChannel(true, kWebSocketErrorNoStatusReceived, _)); 1903 OnDropChannel(true, kWebSocketErrorNoStatusReceived, _));
1904 1904
1905 CreateChannelAndConnectSuccessfully(); 1905 CreateChannelAndConnectSuccessfully();
1906 } 1906 }
1907 1907
1908 // If ReadFrames() returns ERR_WS_PROTOCOL_ERROR, then the connection must be 1908 // If ReadFrames() returns ERR_WS_PROTOCOL_ERROR, then the connection must be
1909 // failed. 1909 // failed.
1910 TEST_F(WebSocketChannelEventInterfaceTest, SyncProtocolErrorGivesStatus1002) { 1910 TEST_F(WebSocketChannelEventInterfaceTest, SyncProtocolErrorGivesStatus1002) {
1911 scoped_ptr<ReadableFakeWebSocketStream> stream( 1911 scoped_ptr<ReadableFakeWebSocketStream> stream(
1912 new ReadableFakeWebSocketStream); 1912 new ReadableFakeWebSocketStream);
1913 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, 1913 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC,
1914 ERR_WS_PROTOCOL_ERROR); 1914 ERR_WS_PROTOCOL_ERROR);
1915 set_stream(stream.Pass()); 1915 set_stream(std::move(stream));
1916 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1916 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1917 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1917 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1918 1918
1919 EXPECT_CALL(*event_interface_, OnFailChannel("Invalid frame header")); 1919 EXPECT_CALL(*event_interface_, OnFailChannel("Invalid frame header"));
1920 1920
1921 CreateChannelAndConnectSuccessfully(); 1921 CreateChannelAndConnectSuccessfully();
1922 } 1922 }
1923 1923
1924 // Async version of above test. 1924 // Async version of above test.
1925 TEST_F(WebSocketChannelEventInterfaceTest, AsyncProtocolErrorGivesStatus1002) { 1925 TEST_F(WebSocketChannelEventInterfaceTest, AsyncProtocolErrorGivesStatus1002) {
1926 scoped_ptr<ReadableFakeWebSocketStream> stream( 1926 scoped_ptr<ReadableFakeWebSocketStream> stream(
1927 new ReadableFakeWebSocketStream); 1927 new ReadableFakeWebSocketStream);
1928 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1928 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1929 ERR_WS_PROTOCOL_ERROR); 1929 ERR_WS_PROTOCOL_ERROR);
1930 set_stream(stream.Pass()); 1930 set_stream(std::move(stream));
1931 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1931 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1932 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1932 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1933 1933
1934 EXPECT_CALL(*event_interface_, OnFailChannel("Invalid frame header")); 1934 EXPECT_CALL(*event_interface_, OnFailChannel("Invalid frame header"));
1935 1935
1936 CreateChannelAndConnectSuccessfully(); 1936 CreateChannelAndConnectSuccessfully();
1937 base::MessageLoop::current()->RunUntilIdle(); 1937 base::MessageLoop::current()->RunUntilIdle();
1938 } 1938 }
1939 1939
1940 TEST_F(WebSocketChannelEventInterfaceTest, StartHandshakeRequest) { 1940 TEST_F(WebSocketChannelEventInterfaceTest, StartHandshakeRequest) {
1941 { 1941 {
1942 InSequence s; 1942 InSequence s;
1943 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1943 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1944 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1944 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1945 EXPECT_CALL(*event_interface_, OnStartOpeningHandshakeCalled()); 1945 EXPECT_CALL(*event_interface_, OnStartOpeningHandshakeCalled());
1946 } 1946 }
1947 1947
1948 CreateChannelAndConnectSuccessfully(); 1948 CreateChannelAndConnectSuccessfully();
1949 1949
1950 scoped_ptr<WebSocketHandshakeRequestInfo> request_info( 1950 scoped_ptr<WebSocketHandshakeRequestInfo> request_info(
1951 new WebSocketHandshakeRequestInfo(GURL("ws://www.example.com/"), 1951 new WebSocketHandshakeRequestInfo(GURL("ws://www.example.com/"),
1952 base::Time())); 1952 base::Time()));
1953 connect_data_.creator.connect_delegate->OnStartOpeningHandshake( 1953 connect_data_.creator.connect_delegate->OnStartOpeningHandshake(
1954 request_info.Pass()); 1954 std::move(request_info));
1955 1955
1956 base::MessageLoop::current()->RunUntilIdle(); 1956 base::MessageLoop::current()->RunUntilIdle();
1957 } 1957 }
1958 1958
1959 TEST_F(WebSocketChannelEventInterfaceTest, FinishHandshakeRequest) { 1959 TEST_F(WebSocketChannelEventInterfaceTest, FinishHandshakeRequest) {
1960 { 1960 {
1961 InSequence s; 1961 InSequence s;
1962 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1962 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1963 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1963 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1964 EXPECT_CALL(*event_interface_, OnFinishOpeningHandshakeCalled()); 1964 EXPECT_CALL(*event_interface_, OnFinishOpeningHandshakeCalled());
1965 } 1965 }
1966 1966
1967 CreateChannelAndConnectSuccessfully(); 1967 CreateChannelAndConnectSuccessfully();
1968 1968
1969 scoped_refptr<HttpResponseHeaders> response_headers( 1969 scoped_refptr<HttpResponseHeaders> response_headers(
1970 new HttpResponseHeaders("")); 1970 new HttpResponseHeaders(""));
1971 scoped_ptr<WebSocketHandshakeResponseInfo> response_info( 1971 scoped_ptr<WebSocketHandshakeResponseInfo> response_info(
1972 new WebSocketHandshakeResponseInfo(GURL("ws://www.example.com/"), 1972 new WebSocketHandshakeResponseInfo(GURL("ws://www.example.com/"),
1973 200, 1973 200,
1974 "OK", 1974 "OK",
1975 response_headers, 1975 response_headers,
1976 base::Time())); 1976 base::Time()));
1977 connect_data_.creator.connect_delegate->OnFinishOpeningHandshake( 1977 connect_data_.creator.connect_delegate->OnFinishOpeningHandshake(
1978 response_info.Pass()); 1978 std::move(response_info));
1979 base::MessageLoop::current()->RunUntilIdle(); 1979 base::MessageLoop::current()->RunUntilIdle();
1980 } 1980 }
1981 1981
1982 TEST_F(WebSocketChannelEventInterfaceTest, FailJustAfterHandshake) { 1982 TEST_F(WebSocketChannelEventInterfaceTest, FailJustAfterHandshake) {
1983 { 1983 {
1984 InSequence s; 1984 InSequence s;
1985 EXPECT_CALL(*event_interface_, OnStartOpeningHandshakeCalled()); 1985 EXPECT_CALL(*event_interface_, OnStartOpeningHandshakeCalled());
1986 EXPECT_CALL(*event_interface_, OnFinishOpeningHandshakeCalled()); 1986 EXPECT_CALL(*event_interface_, OnFinishOpeningHandshakeCalled());
1987 EXPECT_CALL(*event_interface_, OnFailChannel("bye")); 1987 EXPECT_CALL(*event_interface_, OnFailChannel("bye"));
1988 } 1988 }
1989 1989
1990 CreateChannelAndConnect(); 1990 CreateChannelAndConnect();
1991 1991
1992 WebSocketStream::ConnectDelegate* connect_delegate = 1992 WebSocketStream::ConnectDelegate* connect_delegate =
1993 connect_data_.creator.connect_delegate.get(); 1993 connect_data_.creator.connect_delegate.get();
1994 GURL url("ws://www.example.com/"); 1994 GURL url("ws://www.example.com/");
1995 scoped_ptr<WebSocketHandshakeRequestInfo> request_info( 1995 scoped_ptr<WebSocketHandshakeRequestInfo> request_info(
1996 new WebSocketHandshakeRequestInfo(url, base::Time())); 1996 new WebSocketHandshakeRequestInfo(url, base::Time()));
1997 scoped_refptr<HttpResponseHeaders> response_headers( 1997 scoped_refptr<HttpResponseHeaders> response_headers(
1998 new HttpResponseHeaders("")); 1998 new HttpResponseHeaders(""));
1999 scoped_ptr<WebSocketHandshakeResponseInfo> response_info( 1999 scoped_ptr<WebSocketHandshakeResponseInfo> response_info(
2000 new WebSocketHandshakeResponseInfo(url, 2000 new WebSocketHandshakeResponseInfo(url,
2001 200, 2001 200,
2002 "OK", 2002 "OK",
2003 response_headers, 2003 response_headers,
2004 base::Time())); 2004 base::Time()));
2005 connect_delegate->OnStartOpeningHandshake(request_info.Pass()); 2005 connect_delegate->OnStartOpeningHandshake(std::move(request_info));
2006 connect_delegate->OnFinishOpeningHandshake(response_info.Pass()); 2006 connect_delegate->OnFinishOpeningHandshake(std::move(response_info));
2007 2007
2008 connect_delegate->OnFailure("bye"); 2008 connect_delegate->OnFailure("bye");
2009 base::MessageLoop::current()->RunUntilIdle(); 2009 base::MessageLoop::current()->RunUntilIdle();
2010 } 2010 }
2011 2011
2012 // Any frame after close is invalid. This test uses a Text frame. See also 2012 // Any frame after close is invalid. This test uses a Text frame. See also
2013 // test "PingAfterCloseIfRejected". 2013 // test "PingAfterCloseIfRejected".
2014 TEST_F(WebSocketChannelEventInterfaceTest, DataAfterCloseIsRejected) { 2014 TEST_F(WebSocketChannelEventInterfaceTest, DataAfterCloseIsRejected) {
2015 scoped_ptr<ReadableFakeWebSocketStream> stream( 2015 scoped_ptr<ReadableFakeWebSocketStream> stream(
2016 new ReadableFakeWebSocketStream); 2016 new ReadableFakeWebSocketStream);
2017 static const InitFrame frames[] = { 2017 static const InitFrame frames[] = {
2018 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, 2018 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED,
2019 CLOSE_DATA(NORMAL_CLOSURE, "OK")}, 2019 CLOSE_DATA(NORMAL_CLOSURE, "OK")},
2020 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "Payload"}}; 2020 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "Payload"}};
2021 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 2021 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2022 set_stream(stream.Pass()); 2022 set_stream(std::move(stream));
2023 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2023 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2024 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2024 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2025 2025
2026 { 2026 {
2027 InSequence s; 2027 InSequence s;
2028 EXPECT_CALL(*event_interface_, OnClosingHandshake()); 2028 EXPECT_CALL(*event_interface_, OnClosingHandshake());
2029 EXPECT_CALL(*event_interface_, 2029 EXPECT_CALL(*event_interface_,
2030 OnFailChannel("Data frame received after close")); 2030 OnFailChannel("Data frame received after close"));
2031 } 2031 }
2032 2032
2033 CreateChannelAndConnectSuccessfully(); 2033 CreateChannelAndConnectSuccessfully();
2034 } 2034 }
2035 2035
2036 // A Close frame with a one-byte payload elicits a specific console error 2036 // A Close frame with a one-byte payload elicits a specific console error
2037 // message. 2037 // message.
2038 TEST_F(WebSocketChannelEventInterfaceTest, OneByteClosePayloadMessage) { 2038 TEST_F(WebSocketChannelEventInterfaceTest, OneByteClosePayloadMessage) {
2039 scoped_ptr<ReadableFakeWebSocketStream> stream( 2039 scoped_ptr<ReadableFakeWebSocketStream> stream(
2040 new ReadableFakeWebSocketStream); 2040 new ReadableFakeWebSocketStream);
2041 static const InitFrame frames[] = { 2041 static const InitFrame frames[] = {
2042 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, "\x03"}}; 2042 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, "\x03"}};
2043 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 2043 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2044 set_stream(stream.Pass()); 2044 set_stream(std::move(stream));
2045 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2045 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2046 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2046 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2047 EXPECT_CALL( 2047 EXPECT_CALL(
2048 *event_interface_, 2048 *event_interface_,
2049 OnFailChannel( 2049 OnFailChannel(
2050 "Received a broken close frame containing an invalid size body.")); 2050 "Received a broken close frame containing an invalid size body."));
2051 2051
2052 CreateChannelAndConnectSuccessfully(); 2052 CreateChannelAndConnectSuccessfully();
2053 } 2053 }
2054 2054
2055 // A Close frame with a reserved status code also elicits a specific console 2055 // A Close frame with a reserved status code also elicits a specific console
2056 // error message. 2056 // error message.
2057 TEST_F(WebSocketChannelEventInterfaceTest, ClosePayloadReservedStatusMessage) { 2057 TEST_F(WebSocketChannelEventInterfaceTest, ClosePayloadReservedStatusMessage) {
2058 scoped_ptr<ReadableFakeWebSocketStream> stream( 2058 scoped_ptr<ReadableFakeWebSocketStream> stream(
2059 new ReadableFakeWebSocketStream); 2059 new ReadableFakeWebSocketStream);
2060 static const InitFrame frames[] = { 2060 static const InitFrame frames[] = {
2061 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 2061 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
2062 NOT_MASKED, CLOSE_DATA(ABNORMAL_CLOSURE, "Not valid on wire")}}; 2062 NOT_MASKED, CLOSE_DATA(ABNORMAL_CLOSURE, "Not valid on wire")}};
2063 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 2063 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2064 set_stream(stream.Pass()); 2064 set_stream(std::move(stream));
2065 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2065 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2066 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2066 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2067 EXPECT_CALL( 2067 EXPECT_CALL(
2068 *event_interface_, 2068 *event_interface_,
2069 OnFailChannel( 2069 OnFailChannel(
2070 "Received a broken close frame containing a reserved status code.")); 2070 "Received a broken close frame containing a reserved status code."));
2071 2071
2072 CreateChannelAndConnectSuccessfully(); 2072 CreateChannelAndConnectSuccessfully();
2073 } 2073 }
2074 2074
2075 // A Close frame with invalid UTF-8 also elicits a specific console error 2075 // A Close frame with invalid UTF-8 also elicits a specific console error
2076 // message. 2076 // message.
2077 TEST_F(WebSocketChannelEventInterfaceTest, ClosePayloadInvalidReason) { 2077 TEST_F(WebSocketChannelEventInterfaceTest, ClosePayloadInvalidReason) {
2078 scoped_ptr<ReadableFakeWebSocketStream> stream( 2078 scoped_ptr<ReadableFakeWebSocketStream> stream(
2079 new ReadableFakeWebSocketStream); 2079 new ReadableFakeWebSocketStream);
2080 static const InitFrame frames[] = { 2080 static const InitFrame frames[] = {
2081 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 2081 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
2082 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}}; 2082 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}};
2083 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 2083 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2084 set_stream(stream.Pass()); 2084 set_stream(std::move(stream));
2085 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2085 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2086 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2086 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2087 EXPECT_CALL( 2087 EXPECT_CALL(
2088 *event_interface_, 2088 *event_interface_,
2089 OnFailChannel( 2089 OnFailChannel(
2090 "Received a broken close frame containing invalid UTF-8.")); 2090 "Received a broken close frame containing invalid UTF-8."));
2091 2091
2092 CreateChannelAndConnectSuccessfully(); 2092 CreateChannelAndConnectSuccessfully();
2093 } 2093 }
2094 2094
2095 // The reserved bits must all be clear on received frames. Extensions should 2095 // The reserved bits must all be clear on received frames. Extensions should
2096 // clear the bits when they are set correctly before passing on the frame. 2096 // clear the bits when they are set correctly before passing on the frame.
2097 TEST_F(WebSocketChannelEventInterfaceTest, ReservedBitsMustNotBeSet) { 2097 TEST_F(WebSocketChannelEventInterfaceTest, ReservedBitsMustNotBeSet) {
2098 scoped_ptr<ReadableFakeWebSocketStream> stream( 2098 scoped_ptr<ReadableFakeWebSocketStream> stream(
2099 new ReadableFakeWebSocketStream); 2099 new ReadableFakeWebSocketStream);
2100 static const InitFrame frames[] = { 2100 static const InitFrame frames[] = {
2101 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, 2101 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
2102 NOT_MASKED, "sakana"}}; 2102 NOT_MASKED, "sakana"}};
2103 // It is not worth adding support for reserved bits to InitFrame just for this 2103 // It is not worth adding support for reserved bits to InitFrame just for this
2104 // one test, so set the bit manually. 2104 // one test, so set the bit manually.
2105 std::vector<scoped_ptr<WebSocketFrame>> raw_frames = 2105 std::vector<scoped_ptr<WebSocketFrame>> raw_frames =
2106 CreateFrameVector(frames); 2106 CreateFrameVector(frames);
2107 raw_frames[0]->header.reserved1 = true; 2107 raw_frames[0]->header.reserved1 = true;
2108 stream->PrepareRawReadFrames(ReadableFakeWebSocketStream::SYNC, OK, 2108 stream->PrepareRawReadFrames(ReadableFakeWebSocketStream::SYNC, OK,
2109 std::move(raw_frames)); 2109 std::move(raw_frames));
2110 set_stream(stream.Pass()); 2110 set_stream(std::move(stream));
2111 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2111 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2112 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2112 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2113 EXPECT_CALL(*event_interface_, 2113 EXPECT_CALL(*event_interface_,
2114 OnFailChannel( 2114 OnFailChannel(
2115 "One or more reserved bits are on: reserved1 = 1, " 2115 "One or more reserved bits are on: reserved1 = 1, "
2116 "reserved2 = 0, reserved3 = 0")); 2116 "reserved2 = 0, reserved3 = 0"));
2117 2117
2118 CreateChannelAndConnectSuccessfully(); 2118 CreateChannelAndConnectSuccessfully();
2119 } 2119 }
2120 2120
2121 // The closing handshake times out and sends an OnDropChannel event if no 2121 // The closing handshake times out and sends an OnDropChannel event if no
2122 // response to the client Close message is received. 2122 // response to the client Close message is received.
2123 TEST_F(WebSocketChannelEventInterfaceTest, 2123 TEST_F(WebSocketChannelEventInterfaceTest,
2124 ClientInitiatedClosingHandshakeTimesOut) { 2124 ClientInitiatedClosingHandshakeTimesOut) {
2125 scoped_ptr<ReadableFakeWebSocketStream> stream( 2125 scoped_ptr<ReadableFakeWebSocketStream> stream(
2126 new ReadableFakeWebSocketStream); 2126 new ReadableFakeWebSocketStream);
2127 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, 2127 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC,
2128 ERR_IO_PENDING); 2128 ERR_IO_PENDING);
2129 set_stream(stream.Pass()); 2129 set_stream(std::move(stream));
2130 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2130 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2131 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2131 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2132 // This checkpoint object verifies that the OnDropChannel message comes after 2132 // This checkpoint object verifies that the OnDropChannel message comes after
2133 // the timeout. 2133 // the timeout.
2134 Checkpoint checkpoint; 2134 Checkpoint checkpoint;
2135 TestClosure completion; 2135 TestClosure completion;
2136 { 2136 {
2137 InSequence s; 2137 InSequence s;
2138 EXPECT_CALL(checkpoint, Call(1)); 2138 EXPECT_CALL(checkpoint, Call(1));
2139 EXPECT_CALL(*event_interface_, 2139 EXPECT_CALL(*event_interface_,
(...skipping 16 matching lines...) Expand all
2156 // The closing handshake times out and sends an OnDropChannel event if a Close 2156 // The closing handshake times out and sends an OnDropChannel event if a Close
2157 // message is received but the connection isn't closed by the remote host. 2157 // message is received but the connection isn't closed by the remote host.
2158 TEST_F(WebSocketChannelEventInterfaceTest, 2158 TEST_F(WebSocketChannelEventInterfaceTest,
2159 ServerInitiatedClosingHandshakeTimesOut) { 2159 ServerInitiatedClosingHandshakeTimesOut) {
2160 scoped_ptr<ReadableFakeWebSocketStream> stream( 2160 scoped_ptr<ReadableFakeWebSocketStream> stream(
2161 new ReadableFakeWebSocketStream); 2161 new ReadableFakeWebSocketStream);
2162 static const InitFrame frames[] = { 2162 static const InitFrame frames[] = {
2163 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 2163 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
2164 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; 2164 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}};
2165 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 2165 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
2166 set_stream(stream.Pass()); 2166 set_stream(std::move(stream));
2167 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2167 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2168 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2168 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2169 Checkpoint checkpoint; 2169 Checkpoint checkpoint;
2170 TestClosure completion; 2170 TestClosure completion;
2171 { 2171 {
2172 InSequence s; 2172 InSequence s;
2173 EXPECT_CALL(checkpoint, Call(1)); 2173 EXPECT_CALL(checkpoint, Call(1));
2174 EXPECT_CALL(*event_interface_, OnClosingHandshake()); 2174 EXPECT_CALL(*event_interface_, OnClosingHandshake());
2175 EXPECT_CALL(*event_interface_, 2175 EXPECT_CALL(*event_interface_,
2176 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)) 2176 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _))
(...skipping 15 matching lines...) Expand all
2192 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); 2192 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber());
2193 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); 2193 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber());
2194 { 2194 {
2195 InSequence s; 2195 InSequence s;
2196 EXPECT_CALL(checkpoint, Call(1)); 2196 EXPECT_CALL(checkpoint, Call(1));
2197 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 2197 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
2198 .WillOnce(Return(ERR_IO_PENDING)); 2198 .WillOnce(Return(ERR_IO_PENDING));
2199 EXPECT_CALL(checkpoint, Call(2)); 2199 EXPECT_CALL(checkpoint, Call(2));
2200 } 2200 }
2201 2201
2202 set_stream(mock_stream_.Pass()); 2202 set_stream(std::move(mock_stream_));
2203 CreateChannelAndConnect(); 2203 CreateChannelAndConnect();
2204 channel_->SendFlowControl(kPlentyOfQuota); 2204 channel_->SendFlowControl(kPlentyOfQuota);
2205 checkpoint.Call(1); 2205 checkpoint.Call(1);
2206 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 2206 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
2207 checkpoint.Call(2); 2207 checkpoint.Call(2);
2208 } 2208 }
2209 2209
2210 // If for some reason the connect succeeds before the renderer sends us quota, 2210 // If for some reason the connect succeeds before the renderer sends us quota,
2211 // we shouldn't call ReadFrames() immediately. 2211 // we shouldn't call ReadFrames() immediately.
2212 // TODO(ricea): Actually we should call ReadFrames() with a small limit so we 2212 // TODO(ricea): Actually we should call ReadFrames() with a small limit so we
2213 // can still handle control frames. This should be done once we have any API to 2213 // can still handle control frames. This should be done once we have any API to
2214 // expose quota to the lower levels. 2214 // expose quota to the lower levels.
2215 TEST_F(WebSocketChannelStreamTest, FlowControlLate) { 2215 TEST_F(WebSocketChannelStreamTest, FlowControlLate) {
2216 Checkpoint checkpoint; 2216 Checkpoint checkpoint;
2217 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); 2217 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber());
2218 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); 2218 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber());
2219 { 2219 {
2220 InSequence s; 2220 InSequence s;
2221 EXPECT_CALL(checkpoint, Call(1)); 2221 EXPECT_CALL(checkpoint, Call(1));
2222 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 2222 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
2223 .WillOnce(Return(ERR_IO_PENDING)); 2223 .WillOnce(Return(ERR_IO_PENDING));
2224 EXPECT_CALL(checkpoint, Call(2)); 2224 EXPECT_CALL(checkpoint, Call(2));
2225 } 2225 }
2226 2226
2227 set_stream(mock_stream_.Pass()); 2227 set_stream(std::move(mock_stream_));
2228 CreateChannelAndConnect(); 2228 CreateChannelAndConnect();
2229 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 2229 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
2230 checkpoint.Call(1); 2230 checkpoint.Call(1);
2231 channel_->SendFlowControl(kPlentyOfQuota); 2231 channel_->SendFlowControl(kPlentyOfQuota);
2232 checkpoint.Call(2); 2232 checkpoint.Call(2);
2233 } 2233 }
2234 2234
2235 // We should stop calling ReadFrames() when all quota is used. 2235 // We should stop calling ReadFrames() when all quota is used.
2236 TEST_F(WebSocketChannelStreamTest, FlowControlStopsReadFrames) { 2236 TEST_F(WebSocketChannelStreamTest, FlowControlStopsReadFrames) {
2237 static const InitFrame frames[] = { 2237 static const InitFrame frames[] = {
2238 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}}; 2238 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}};
2239 2239
2240 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); 2240 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber());
2241 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); 2241 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber());
2242 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 2242 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
2243 .WillOnce(ReturnFrames(&frames)); 2243 .WillOnce(ReturnFrames(&frames));
2244 2244
2245 set_stream(mock_stream_.Pass()); 2245 set_stream(std::move(mock_stream_));
2246 CreateChannelAndConnect(); 2246 CreateChannelAndConnect();
2247 channel_->SendFlowControl(4); 2247 channel_->SendFlowControl(4);
2248 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 2248 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
2249 } 2249 }
2250 2250
2251 // Providing extra quota causes ReadFrames() to be called again. 2251 // Providing extra quota causes ReadFrames() to be called again.
2252 TEST_F(WebSocketChannelStreamTest, FlowControlStartsWithMoreQuota) { 2252 TEST_F(WebSocketChannelStreamTest, FlowControlStartsWithMoreQuota) {
2253 static const InitFrame frames[] = { 2253 static const InitFrame frames[] = {
2254 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}}; 2254 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}};
2255 Checkpoint checkpoint; 2255 Checkpoint checkpoint;
2256 2256
2257 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); 2257 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber());
2258 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); 2258 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber());
2259 { 2259 {
2260 InSequence s; 2260 InSequence s;
2261 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 2261 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
2262 .WillOnce(ReturnFrames(&frames)); 2262 .WillOnce(ReturnFrames(&frames));
2263 EXPECT_CALL(checkpoint, Call(1)); 2263 EXPECT_CALL(checkpoint, Call(1));
2264 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 2264 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
2265 .WillOnce(Return(ERR_IO_PENDING)); 2265 .WillOnce(Return(ERR_IO_PENDING));
2266 } 2266 }
2267 2267
2268 set_stream(mock_stream_.Pass()); 2268 set_stream(std::move(mock_stream_));
2269 CreateChannelAndConnect(); 2269 CreateChannelAndConnect();
2270 channel_->SendFlowControl(4); 2270 channel_->SendFlowControl(4);
2271 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 2271 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
2272 checkpoint.Call(1); 2272 checkpoint.Call(1);
2273 channel_->SendFlowControl(4); 2273 channel_->SendFlowControl(4);
2274 } 2274 }
2275 2275
2276 // ReadFrames() isn't called again until all pending data has been passed to 2276 // ReadFrames() isn't called again until all pending data has been passed to
2277 // the renderer. 2277 // the renderer.
2278 TEST_F(WebSocketChannelStreamTest, ReadFramesNotCalledUntilQuotaAvailable) { 2278 TEST_F(WebSocketChannelStreamTest, ReadFramesNotCalledUntilQuotaAvailable) {
2279 static const InitFrame frames[] = { 2279 static const InitFrame frames[] = {
2280 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}}; 2280 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}};
2281 Checkpoint checkpoint; 2281 Checkpoint checkpoint;
2282 2282
2283 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); 2283 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber());
2284 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); 2284 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber());
2285 { 2285 {
2286 InSequence s; 2286 InSequence s;
2287 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 2287 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
2288 .WillOnce(ReturnFrames(&frames)); 2288 .WillOnce(ReturnFrames(&frames));
2289 EXPECT_CALL(checkpoint, Call(1)); 2289 EXPECT_CALL(checkpoint, Call(1));
2290 EXPECT_CALL(checkpoint, Call(2)); 2290 EXPECT_CALL(checkpoint, Call(2));
2291 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 2291 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
2292 .WillOnce(Return(ERR_IO_PENDING)); 2292 .WillOnce(Return(ERR_IO_PENDING));
2293 } 2293 }
2294 2294
2295 set_stream(mock_stream_.Pass()); 2295 set_stream(std::move(mock_stream_));
2296 CreateChannelAndConnect(); 2296 CreateChannelAndConnect();
2297 channel_->SendFlowControl(2); 2297 channel_->SendFlowControl(2);
2298 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 2298 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
2299 checkpoint.Call(1); 2299 checkpoint.Call(1);
2300 channel_->SendFlowControl(2); 2300 channel_->SendFlowControl(2);
2301 checkpoint.Call(2); 2301 checkpoint.Call(2);
2302 channel_->SendFlowControl(2); 2302 channel_->SendFlowControl(2);
2303 } 2303 }
2304 2304
2305 // A message that needs to be split into frames to fit within quota should 2305 // A message that needs to be split into frames to fit within quota should
2306 // maintain correct semantics. 2306 // maintain correct semantics.
2307 TEST_F(WebSocketChannelFlowControlTest, SingleFrameMessageSplitSync) { 2307 TEST_F(WebSocketChannelFlowControlTest, SingleFrameMessageSplitSync) {
2308 scoped_ptr<ReadableFakeWebSocketStream> stream( 2308 scoped_ptr<ReadableFakeWebSocketStream> stream(
2309 new ReadableFakeWebSocketStream); 2309 new ReadableFakeWebSocketStream);
2310 static const InitFrame frames[] = { 2310 static const InitFrame frames[] = {
2311 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}}; 2311 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}};
2312 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 2312 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2313 set_stream(stream.Pass()); 2313 set_stream(std::move(stream));
2314 { 2314 {
2315 InSequence s; 2315 InSequence s;
2316 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2316 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2317 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2317 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2318 EXPECT_CALL( 2318 EXPECT_CALL(
2319 *event_interface_, 2319 *event_interface_,
2320 OnDataFrame(false, WebSocketFrameHeader::kOpCodeText, AsVector("FO"))); 2320 OnDataFrame(false, WebSocketFrameHeader::kOpCodeText, AsVector("FO")));
2321 EXPECT_CALL( 2321 EXPECT_CALL(
2322 *event_interface_, 2322 *event_interface_,
2323 OnDataFrame( 2323 OnDataFrame(
(...skipping 10 matching lines...) Expand all
2334 } 2334 }
2335 2335
2336 // The code path for async messages is slightly different, so test it 2336 // The code path for async messages is slightly different, so test it
2337 // separately. 2337 // separately.
2338 TEST_F(WebSocketChannelFlowControlTest, SingleFrameMessageSplitAsync) { 2338 TEST_F(WebSocketChannelFlowControlTest, SingleFrameMessageSplitAsync) {
2339 scoped_ptr<ReadableFakeWebSocketStream> stream( 2339 scoped_ptr<ReadableFakeWebSocketStream> stream(
2340 new ReadableFakeWebSocketStream); 2340 new ReadableFakeWebSocketStream);
2341 static const InitFrame frames[] = { 2341 static const InitFrame frames[] = {
2342 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}}; 2342 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}};
2343 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 2343 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
2344 set_stream(stream.Pass()); 2344 set_stream(std::move(stream));
2345 Checkpoint checkpoint; 2345 Checkpoint checkpoint;
2346 { 2346 {
2347 InSequence s; 2347 InSequence s;
2348 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2348 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2349 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2349 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2350 EXPECT_CALL(checkpoint, Call(1)); 2350 EXPECT_CALL(checkpoint, Call(1));
2351 EXPECT_CALL( 2351 EXPECT_CALL(
2352 *event_interface_, 2352 *event_interface_,
2353 OnDataFrame(false, WebSocketFrameHeader::kOpCodeText, AsVector("FO"))); 2353 OnDataFrame(false, WebSocketFrameHeader::kOpCodeText, AsVector("FO")));
2354 EXPECT_CALL(checkpoint, Call(2)); 2354 EXPECT_CALL(checkpoint, Call(2));
(...skipping 26 matching lines...) Expand all
2381 scoped_ptr<ReadableFakeWebSocketStream> stream( 2381 scoped_ptr<ReadableFakeWebSocketStream> stream(
2382 new ReadableFakeWebSocketStream); 2382 new ReadableFakeWebSocketStream);
2383 static const InitFrame frames[] = { 2383 static const InitFrame frames[] = {
2384 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, 2384 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
2385 NOT_MASKED, "FIRST FRAME IS 25 BYTES. "}, 2385 NOT_MASKED, "FIRST FRAME IS 25 BYTES. "},
2386 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, 2386 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
2387 NOT_MASKED, "SECOND FRAME IS 26 BYTES. "}, 2387 NOT_MASKED, "SECOND FRAME IS 26 BYTES. "},
2388 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, 2388 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
2389 NOT_MASKED, "FINAL FRAME IS 24 BYTES."}}; 2389 NOT_MASKED, "FINAL FRAME IS 24 BYTES."}};
2390 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 2390 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2391 set_stream(stream.Pass()); 2391 set_stream(std::move(stream));
2392 { 2392 {
2393 InSequence s; 2393 InSequence s;
2394 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2394 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2395 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2395 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2396 EXPECT_CALL(*event_interface_, 2396 EXPECT_CALL(*event_interface_,
2397 OnDataFrame(false, 2397 OnDataFrame(false,
2398 WebSocketFrameHeader::kOpCodeText, 2398 WebSocketFrameHeader::kOpCodeText,
2399 AsVector("FIRST FRAME IS"))); 2399 AsVector("FIRST FRAME IS")));
2400 EXPECT_CALL(*event_interface_, 2400 EXPECT_CALL(*event_interface_,
2401 OnDataFrame(false, 2401 OnDataFrame(false,
(...skipping 23 matching lines...) Expand all
2425 scoped_ptr<ReadableFakeWebSocketStream> stream( 2425 scoped_ptr<ReadableFakeWebSocketStream> stream(
2426 new ReadableFakeWebSocketStream); 2426 new ReadableFakeWebSocketStream);
2427 static const InitFrame frames[] = { 2427 static const InitFrame frames[] = {
2428 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, 2428 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
2429 NOT_MASKED, "FIRST MESSAGE"}, 2429 NOT_MASKED, "FIRST MESSAGE"},
2430 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, 2430 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
2431 NOT_MASKED, NULL}, 2431 NOT_MASKED, NULL},
2432 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, 2432 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
2433 NOT_MASKED, "THIRD MESSAGE"}}; 2433 NOT_MASKED, "THIRD MESSAGE"}};
2434 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 2434 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2435 set_stream(stream.Pass()); 2435 set_stream(std::move(stream));
2436 { 2436 {
2437 InSequence s; 2437 InSequence s;
2438 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2438 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2439 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2439 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2440 EXPECT_CALL(*event_interface_, 2440 EXPECT_CALL(*event_interface_,
2441 OnDataFrame(false, 2441 OnDataFrame(false,
2442 WebSocketFrameHeader::kOpCodeText, 2442 WebSocketFrameHeader::kOpCodeText,
2443 AsVector("FIRST "))); 2443 AsVector("FIRST ")));
2444 EXPECT_CALL(*event_interface_, 2444 EXPECT_CALL(*event_interface_,
2445 OnDataFrame(true, 2445 OnDataFrame(true,
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
2855 // Test the read path for 8-bit cleanliness as well. 2855 // Test the read path for 8-bit cleanliness as well.
2856 TEST_F(WebSocketChannelEventInterfaceTest, ReadBinaryFramesAre8BitClean) { 2856 TEST_F(WebSocketChannelEventInterfaceTest, ReadBinaryFramesAre8BitClean) {
2857 scoped_ptr<WebSocketFrame> frame( 2857 scoped_ptr<WebSocketFrame> frame(
2858 new WebSocketFrame(WebSocketFrameHeader::kOpCodeBinary)); 2858 new WebSocketFrame(WebSocketFrameHeader::kOpCodeBinary));
2859 WebSocketFrameHeader& frame_header = frame->header; 2859 WebSocketFrameHeader& frame_header = frame->header;
2860 frame_header.final = true; 2860 frame_header.final = true;
2861 frame_header.payload_length = kBinaryBlobSize; 2861 frame_header.payload_length = kBinaryBlobSize;
2862 frame->data = new IOBuffer(kBinaryBlobSize); 2862 frame->data = new IOBuffer(kBinaryBlobSize);
2863 memcpy(frame->data->data(), kBinaryBlob, kBinaryBlobSize); 2863 memcpy(frame->data->data(), kBinaryBlob, kBinaryBlobSize);
2864 std::vector<scoped_ptr<WebSocketFrame>> frames; 2864 std::vector<scoped_ptr<WebSocketFrame>> frames;
2865 frames.push_back(frame.Pass()); 2865 frames.push_back(std::move(frame));
2866 scoped_ptr<ReadableFakeWebSocketStream> stream( 2866 scoped_ptr<ReadableFakeWebSocketStream> stream(
2867 new ReadableFakeWebSocketStream); 2867 new ReadableFakeWebSocketStream);
2868 stream->PrepareRawReadFrames(ReadableFakeWebSocketStream::SYNC, OK, 2868 stream->PrepareRawReadFrames(ReadableFakeWebSocketStream::SYNC, OK,
2869 std::move(frames)); 2869 std::move(frames));
2870 set_stream(stream.Pass()); 2870 set_stream(std::move(stream));
2871 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2871 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2872 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 2872 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2873 EXPECT_CALL(*event_interface_, 2873 EXPECT_CALL(*event_interface_,
2874 OnDataFrame(true, 2874 OnDataFrame(true,
2875 WebSocketFrameHeader::kOpCodeBinary, 2875 WebSocketFrameHeader::kOpCodeBinary,
2876 std::vector<char>(kBinaryBlob, 2876 std::vector<char>(kBinaryBlob,
2877 kBinaryBlob + kBinaryBlobSize))); 2877 kBinaryBlob + kBinaryBlobSize)));
2878 2878
2879 CreateChannelAndConnectSuccessfully(); 2879 CreateChannelAndConnectSuccessfully();
2880 } 2880 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2976 channel_->SendFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector("bar")); 2976 channel_->SendFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector("bar"));
2977 } 2977 }
2978 2978
2979 // UTF-8 validation is enforced on received Text frames. 2979 // UTF-8 validation is enforced on received Text frames.
2980 TEST_F(WebSocketChannelEventInterfaceTest, ReceivedInvalidUtf8) { 2980 TEST_F(WebSocketChannelEventInterfaceTest, ReceivedInvalidUtf8) {
2981 scoped_ptr<ReadableFakeWebSocketStream> stream( 2981 scoped_ptr<ReadableFakeWebSocketStream> stream(
2982 new ReadableFakeWebSocketStream); 2982 new ReadableFakeWebSocketStream);
2983 static const InitFrame frames[] = { 2983 static const InitFrame frames[] = {
2984 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "\xff"}}; 2984 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "\xff"}};
2985 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 2985 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2986 set_stream(stream.Pass()); 2986 set_stream(std::move(stream));
2987 2987
2988 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 2988 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2989 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); 2989 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota));
2990 EXPECT_CALL(*event_interface_, 2990 EXPECT_CALL(*event_interface_,
2991 OnFailChannel("Could not decode a text frame as UTF-8.")); 2991 OnFailChannel("Could not decode a text frame as UTF-8."));
2992 2992
2993 CreateChannelAndConnectSuccessfully(); 2993 CreateChannelAndConnectSuccessfully();
2994 base::MessageLoop::current()->RunUntilIdle(); 2994 base::MessageLoop::current()->RunUntilIdle();
2995 } 2995 }
2996 2996
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
3168 // A new data message cannot start in the middle of another data message. 3168 // A new data message cannot start in the middle of another data message.
3169 TEST_F(WebSocketChannelEventInterfaceTest, BogusContinuation) { 3169 TEST_F(WebSocketChannelEventInterfaceTest, BogusContinuation) {
3170 scoped_ptr<ReadableFakeWebSocketStream> stream( 3170 scoped_ptr<ReadableFakeWebSocketStream> stream(
3171 new ReadableFakeWebSocketStream); 3171 new ReadableFakeWebSocketStream);
3172 static const InitFrame frames[] = { 3172 static const InitFrame frames[] = {
3173 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeBinary, 3173 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeBinary,
3174 NOT_MASKED, "frame1"}, 3174 NOT_MASKED, "frame1"},
3175 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, 3175 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
3176 NOT_MASKED, "frame2"}}; 3176 NOT_MASKED, "frame2"}};
3177 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 3177 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
3178 set_stream(stream.Pass()); 3178 set_stream(std::move(stream));
3179 3179
3180 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 3180 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
3181 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); 3181 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota));
3182 EXPECT_CALL( 3182 EXPECT_CALL(
3183 *event_interface_, 3183 *event_interface_,
3184 OnDataFrame( 3184 OnDataFrame(
3185 false, WebSocketFrameHeader::kOpCodeBinary, AsVector("frame1"))); 3185 false, WebSocketFrameHeader::kOpCodeBinary, AsVector("frame1")));
3186 EXPECT_CALL( 3186 EXPECT_CALL(
3187 *event_interface_, 3187 *event_interface_,
3188 OnFailChannel( 3188 OnFailChannel(
3189 "Received start of new message but previous message is unfinished.")); 3189 "Received start of new message but previous message is unfinished."));
3190 3190
3191 CreateChannelAndConnectSuccessfully(); 3191 CreateChannelAndConnectSuccessfully();
3192 } 3192 }
3193 3193
3194 // A new message cannot start with a Continuation frame. 3194 // A new message cannot start with a Continuation frame.
3195 TEST_F(WebSocketChannelEventInterfaceTest, MessageStartingWithContinuation) { 3195 TEST_F(WebSocketChannelEventInterfaceTest, MessageStartingWithContinuation) {
3196 scoped_ptr<ReadableFakeWebSocketStream> stream( 3196 scoped_ptr<ReadableFakeWebSocketStream> stream(
3197 new ReadableFakeWebSocketStream); 3197 new ReadableFakeWebSocketStream);
3198 static const InitFrame frames[] = { 3198 static const InitFrame frames[] = {
3199 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, 3199 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
3200 NOT_MASKED, "continuation"}}; 3200 NOT_MASKED, "continuation"}};
3201 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 3201 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
3202 set_stream(stream.Pass()); 3202 set_stream(std::move(stream));
3203 3203
3204 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 3204 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
3205 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); 3205 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota));
3206 EXPECT_CALL(*event_interface_, 3206 EXPECT_CALL(*event_interface_,
3207 OnFailChannel("Received unexpected continuation frame.")); 3207 OnFailChannel("Received unexpected continuation frame."));
3208 3208
3209 CreateChannelAndConnectSuccessfully(); 3209 CreateChannelAndConnectSuccessfully();
3210 } 3210 }
3211 3211
3212 // A frame passed to the renderer must be either non-empty or have the final bit 3212 // A frame passed to the renderer must be either non-empty or have the final bit
3213 // set. 3213 // set.
3214 TEST_F(WebSocketChannelEventInterfaceTest, DataFramesNonEmptyOrFinal) { 3214 TEST_F(WebSocketChannelEventInterfaceTest, DataFramesNonEmptyOrFinal) {
3215 scoped_ptr<ReadableFakeWebSocketStream> stream( 3215 scoped_ptr<ReadableFakeWebSocketStream> stream(
3216 new ReadableFakeWebSocketStream); 3216 new ReadableFakeWebSocketStream);
3217 static const InitFrame frames[] = { 3217 static const InitFrame frames[] = {
3218 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, ""}, 3218 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, ""},
3219 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, 3219 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation,
3220 NOT_MASKED, ""}, 3220 NOT_MASKED, ""},
3221 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, ""}}; 3221 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, ""}};
3222 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 3222 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
3223 set_stream(stream.Pass()); 3223 set_stream(std::move(stream));
3224 3224
3225 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 3225 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
3226 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); 3226 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota));
3227 EXPECT_CALL( 3227 EXPECT_CALL(
3228 *event_interface_, 3228 *event_interface_,
3229 OnDataFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector(""))); 3229 OnDataFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector("")));
3230 3230
3231 CreateChannelAndConnectSuccessfully(); 3231 CreateChannelAndConnectSuccessfully();
3232 } 3232 }
3233 3233
3234 // Calls to OnSSLCertificateError() must be passed through to the event 3234 // Calls to OnSSLCertificateError() must be passed through to the event
3235 // interface with the correct URL attached. 3235 // interface with the correct URL attached.
3236 TEST_F(WebSocketChannelEventInterfaceTest, OnSSLCertificateErrorCalled) { 3236 TEST_F(WebSocketChannelEventInterfaceTest, OnSSLCertificateErrorCalled) {
3237 const GURL wss_url("wss://example.com/sslerror"); 3237 const GURL wss_url("wss://example.com/sslerror");
3238 connect_data_.socket_url = wss_url; 3238 connect_data_.socket_url = wss_url;
3239 const SSLInfo ssl_info; 3239 const SSLInfo ssl_info;
3240 const bool fatal = true; 3240 const bool fatal = true;
3241 scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> fake_callbacks( 3241 scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> fake_callbacks(
3242 new FakeSSLErrorCallbacks); 3242 new FakeSSLErrorCallbacks);
3243 3243
3244 EXPECT_CALL(*event_interface_, 3244 EXPECT_CALL(*event_interface_,
3245 OnSSLCertificateErrorCalled(NotNull(), wss_url, _, fatal)); 3245 OnSSLCertificateErrorCalled(NotNull(), wss_url, _, fatal));
3246 3246
3247 CreateChannelAndConnect(); 3247 CreateChannelAndConnect();
3248 connect_data_.creator.connect_delegate->OnSSLCertificateError( 3248 connect_data_.creator.connect_delegate->OnSSLCertificateError(
3249 fake_callbacks.Pass(), ssl_info, fatal); 3249 std::move(fake_callbacks), ssl_info, fatal);
3250 } 3250 }
3251 3251
3252 // If we receive another frame after Close, it is not valid. It is not 3252 // If we receive another frame after Close, it is not valid. It is not
3253 // completely clear what behaviour is required from the standard in this case, 3253 // completely clear what behaviour is required from the standard in this case,
3254 // but the current implementation fails the connection. Since a Close has 3254 // but the current implementation fails the connection. Since a Close has
3255 // already been sent, this just means closing the connection. 3255 // already been sent, this just means closing the connection.
3256 TEST_F(WebSocketChannelStreamTest, PingAfterCloseIsRejected) { 3256 TEST_F(WebSocketChannelStreamTest, PingAfterCloseIsRejected) {
3257 static const InitFrame frames[] = { 3257 static const InitFrame frames[] = {
3258 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 3258 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
3259 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}, 3259 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")},
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3297 3297
3298 CreateChannelAndConnectSuccessfully(); 3298 CreateChannelAndConnectSuccessfully();
3299 } 3299 }
3300 3300
3301 // Set the closing handshake timeout to a very tiny value before connecting. 3301 // Set the closing handshake timeout to a very tiny value before connecting.
3302 class WebSocketChannelStreamTimeoutTest : public WebSocketChannelStreamTest { 3302 class WebSocketChannelStreamTimeoutTest : public WebSocketChannelStreamTest {
3303 protected: 3303 protected:
3304 WebSocketChannelStreamTimeoutTest() {} 3304 WebSocketChannelStreamTimeoutTest() {}
3305 3305
3306 void CreateChannelAndConnectSuccessfully() override { 3306 void CreateChannelAndConnectSuccessfully() override {
3307 set_stream(mock_stream_.Pass()); 3307 set_stream(std::move(mock_stream_));
3308 CreateChannelAndConnect(); 3308 CreateChannelAndConnect();
3309 channel_->SendFlowControl(kPlentyOfQuota); 3309 channel_->SendFlowControl(kPlentyOfQuota);
3310 channel_->SetClosingHandshakeTimeoutForTesting( 3310 channel_->SetClosingHandshakeTimeoutForTesting(
3311 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); 3311 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis));
3312 channel_->SetUnderlyingConnectionCloseTimeoutForTesting( 3312 channel_->SetUnderlyingConnectionCloseTimeoutForTesting(
3313 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); 3313 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis));
3314 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); 3314 connect_data_.creator.connect_delegate->OnSuccess(std::move(stream_));
3315 } 3315 }
3316 }; 3316 };
3317 3317
3318 // In this case the server initiates the closing handshake with a Close 3318 // In this case the server initiates the closing handshake with a Close
3319 // message. WebSocketChannel responds with a matching Close message, and waits 3319 // message. WebSocketChannel responds with a matching Close message, and waits
3320 // for the server to close the TCP/IP connection. The server never closes the 3320 // for the server to close the TCP/IP connection. The server never closes the
3321 // connection, so the closing handshake times out and WebSocketChannel closes 3321 // connection, so the closing handshake times out and WebSocketChannel closes
3322 // the connection itself. 3322 // the connection itself.
3323 TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) { 3323 TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) {
3324 static const InitFrame frames[] = { 3324 static const InitFrame frames[] = {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3416 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); 3416 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK");
3417 ASSERT_TRUE(read_frames); 3417 ASSERT_TRUE(read_frames);
3418 // Provide the "Close" message from the server. 3418 // Provide the "Close" message from the server.
3419 *read_frames = CreateFrameVector(frames); 3419 *read_frames = CreateFrameVector(frames);
3420 read_callback.Run(OK); 3420 read_callback.Run(OK);
3421 completion.WaitForResult(); 3421 completion.WaitForResult();
3422 } 3422 }
3423 3423
3424 } // namespace 3424 } // namespace
3425 } // namespace net 3425 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_channel.cc ('k') | net/websockets/websocket_deflate_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698