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

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

Issue 2053133002: Remove MessageLoop::current()->RunUntilIdle() in net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/ssl/default_channel_id_store_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 <stddef.h> 8 #include <stddef.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include <iostream> 11 #include <iostream>
12 #include <iterator> 12 #include <iterator>
13 #include <memory> 13 #include <memory>
14 #include <string> 14 #include <string>
15 #include <utility> 15 #include <utility>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/bind.h" 18 #include "base/bind.h"
19 #include "base/bind_helpers.h" 19 #include "base/bind_helpers.h"
20 #include "base/callback.h" 20 #include "base/callback.h"
21 #include "base/location.h" 21 #include "base/location.h"
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/memory/ptr_util.h" 23 #include "base/memory/ptr_util.h"
24 #include "base/memory/weak_ptr.h" 24 #include "base/memory/weak_ptr.h"
25 #include "base/message_loop/message_loop.h" 25 #include "base/message_loop/message_loop.h"
26 #include "base/run_loop.h"
26 #include "base/single_thread_task_runner.h" 27 #include "base/single_thread_task_runner.h"
27 #include "base/strings/string_piece.h" 28 #include "base/strings/string_piece.h"
28 #include "base/threading/thread_task_runner_handle.h" 29 #include "base/threading/thread_task_runner_handle.h"
29 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
30 #include "net/base/test_completion_callback.h" 31 #include "net/base/test_completion_callback.h"
31 #include "net/http/http_response_headers.h" 32 #include "net/http/http_response_headers.h"
32 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
33 #include "net/websockets/websocket_errors.h" 34 #include "net/websockets/websocket_errors.h"
34 #include "net/websockets/websocket_event_interface.h" 35 #include "net/websockets/websocket_event_interface.h"
35 #include "net/websockets/websocket_handshake_request_info.h" 36 #include "net/websockets/websocket_handshake_request_info.h"
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1062 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1062 new ReadableFakeWebSocketStream); 1063 new ReadableFakeWebSocketStream);
1063 static const InitFrame frames[] = { 1064 static const InitFrame frames[] = {
1064 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1065 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1065 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1066 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1066 set_stream(std::move(stream)); 1067 set_stream(std::move(stream));
1067 deleting_ = EVENT_ON_DATA_FRAME; 1068 deleting_ = EVENT_ON_DATA_FRAME;
1068 1069
1069 CreateChannelAndConnectSuccessfully(); 1070 CreateChannelAndConnectSuccessfully();
1070 EXPECT_TRUE(channel_); 1071 EXPECT_TRUE(channel_);
1071 base::MessageLoop::current()->RunUntilIdle(); 1072 base::RunLoop().RunUntilIdle();
1072 EXPECT_EQ(nullptr, channel_.get()); 1073 EXPECT_EQ(nullptr, channel_.get());
1073 } 1074 }
1074 1075
1075 TEST_F(WebSocketChannelDeletingTest, OnFlowControlAfterConnect) { 1076 TEST_F(WebSocketChannelDeletingTest, OnFlowControlAfterConnect) {
1076 deleting_ = EVENT_ON_FLOW_CONTROL; 1077 deleting_ = EVENT_ON_FLOW_CONTROL;
1077 1078
1078 CreateChannelAndConnectSuccessfully(); 1079 CreateChannelAndConnectSuccessfully();
1079 EXPECT_EQ(nullptr, channel_.get()); 1080 EXPECT_EQ(nullptr, channel_.get());
1080 } 1081 }
1081 1082
(...skipping 27 matching lines...) Expand all
1109 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1110 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1110 new ReadableFakeWebSocketStream); 1111 new ReadableFakeWebSocketStream);
1111 static const InitFrame frames[] = { 1112 static const InitFrame frames[] = {
1112 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, 1113 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose,
1113 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; 1114 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}};
1114 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1115 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1115 set_stream(std::move(stream)); 1116 set_stream(std::move(stream));
1116 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; 1117 deleting_ = EVENT_ON_CLOSING_HANDSHAKE;
1117 CreateChannelAndConnectSuccessfully(); 1118 CreateChannelAndConnectSuccessfully();
1118 ASSERT_TRUE(channel_); 1119 ASSERT_TRUE(channel_);
1119 base::MessageLoop::current()->RunUntilIdle(); 1120 base::RunLoop().RunUntilIdle();
1120 EXPECT_EQ(nullptr, channel_.get()); 1121 EXPECT_EQ(nullptr, channel_.get());
1121 } 1122 }
1122 1123
1123 TEST_F(WebSocketChannelDeletingTest, OnDropChannelWriteError) { 1124 TEST_F(WebSocketChannelDeletingTest, OnDropChannelWriteError) {
1124 set_stream(base::WrapUnique(new UnWriteableFakeWebSocketStream)); 1125 set_stream(base::WrapUnique(new UnWriteableFakeWebSocketStream));
1125 deleting_ = EVENT_ON_DROP_CHANNEL; 1126 deleting_ = EVENT_ON_DROP_CHANNEL;
1126 CreateChannelAndConnectSuccessfully(); 1127 CreateChannelAndConnectSuccessfully();
1127 ASSERT_TRUE(channel_); 1128 ASSERT_TRUE(channel_);
1128 channel_->SendFrame( 1129 channel_->SendFrame(
1129 true, WebSocketFrameHeader::kOpCodeText, AsVector("this will fail")); 1130 true, WebSocketFrameHeader::kOpCodeText, AsVector("this will fail"));
1130 EXPECT_EQ(nullptr, channel_.get()); 1131 EXPECT_EQ(nullptr, channel_.get());
1131 } 1132 }
1132 1133
1133 TEST_F(WebSocketChannelDeletingTest, OnDropChannelReadError) { 1134 TEST_F(WebSocketChannelDeletingTest, OnDropChannelReadError) {
1134 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1135 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1135 new ReadableFakeWebSocketStream); 1136 new ReadableFakeWebSocketStream);
1136 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1137 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1137 ERR_FAILED); 1138 ERR_FAILED);
1138 set_stream(std::move(stream)); 1139 set_stream(std::move(stream));
1139 deleting_ = EVENT_ON_DROP_CHANNEL; 1140 deleting_ = EVENT_ON_DROP_CHANNEL;
1140 CreateChannelAndConnectSuccessfully(); 1141 CreateChannelAndConnectSuccessfully();
1141 ASSERT_TRUE(channel_); 1142 ASSERT_TRUE(channel_);
1142 base::MessageLoop::current()->RunUntilIdle(); 1143 base::RunLoop().RunUntilIdle();
1143 EXPECT_EQ(nullptr, channel_.get()); 1144 EXPECT_EQ(nullptr, channel_.get());
1144 } 1145 }
1145 1146
1146 TEST_F(WebSocketChannelDeletingTest, OnNotifyStartOpeningHandshakeError) { 1147 TEST_F(WebSocketChannelDeletingTest, OnNotifyStartOpeningHandshakeError) {
1147 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1148 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1148 new ReadableFakeWebSocketStream); 1149 new ReadableFakeWebSocketStream);
1149 static const InitFrame frames[] = { 1150 static const InitFrame frames[] = {
1150 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1151 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1151 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1152 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1152 set_stream(std::move(stream)); 1153 set_stream(std::move(stream));
1153 deleting_ = EVENT_ON_START_OPENING_HANDSHAKE; 1154 deleting_ = EVENT_ON_START_OPENING_HANDSHAKE;
1154 1155
1155 CreateChannelAndConnectSuccessfully(); 1156 CreateChannelAndConnectSuccessfully();
1156 ASSERT_TRUE(channel_); 1157 ASSERT_TRUE(channel_);
1157 channel_->OnStartOpeningHandshake( 1158 channel_->OnStartOpeningHandshake(
1158 std::unique_ptr<WebSocketHandshakeRequestInfo>( 1159 std::unique_ptr<WebSocketHandshakeRequestInfo>(
1159 new WebSocketHandshakeRequestInfo(GURL("http://www.example.com/"), 1160 new WebSocketHandshakeRequestInfo(GURL("http://www.example.com/"),
1160 base::Time()))); 1161 base::Time())));
1161 base::MessageLoop::current()->RunUntilIdle(); 1162 base::RunLoop().RunUntilIdle();
1162 EXPECT_EQ(nullptr, channel_.get()); 1163 EXPECT_EQ(nullptr, channel_.get());
1163 } 1164 }
1164 1165
1165 TEST_F(WebSocketChannelDeletingTest, OnNotifyFinishOpeningHandshakeError) { 1166 TEST_F(WebSocketChannelDeletingTest, OnNotifyFinishOpeningHandshakeError) {
1166 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1167 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1167 new ReadableFakeWebSocketStream); 1168 new ReadableFakeWebSocketStream);
1168 static const InitFrame frames[] = { 1169 static const InitFrame frames[] = {
1169 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1170 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
1170 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1171 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1171 set_stream(std::move(stream)); 1172 set_stream(std::move(stream));
1172 deleting_ = EVENT_ON_FINISH_OPENING_HANDSHAKE; 1173 deleting_ = EVENT_ON_FINISH_OPENING_HANDSHAKE;
1173 1174
1174 CreateChannelAndConnectSuccessfully(); 1175 CreateChannelAndConnectSuccessfully();
1175 ASSERT_TRUE(channel_); 1176 ASSERT_TRUE(channel_);
1176 scoped_refptr<HttpResponseHeaders> response_headers( 1177 scoped_refptr<HttpResponseHeaders> response_headers(
1177 new HttpResponseHeaders("")); 1178 new HttpResponseHeaders(""));
1178 channel_->OnFinishOpeningHandshake( 1179 channel_->OnFinishOpeningHandshake(
1179 base::WrapUnique(new WebSocketHandshakeResponseInfo( 1180 base::WrapUnique(new WebSocketHandshakeResponseInfo(
1180 GURL("http://www.example.com/"), 200, "OK", response_headers, 1181 GURL("http://www.example.com/"), 200, "OK", response_headers,
1181 base::Time()))); 1182 base::Time())));
1182 base::MessageLoop::current()->RunUntilIdle(); 1183 base::RunLoop().RunUntilIdle();
1183 EXPECT_EQ(nullptr, channel_.get()); 1184 EXPECT_EQ(nullptr, channel_.get());
1184 } 1185 }
1185 1186
1186 TEST_F(WebSocketChannelDeletingTest, FailChannelInSendFrame) { 1187 TEST_F(WebSocketChannelDeletingTest, FailChannelInSendFrame) {
1187 set_stream(base::WrapUnique(new WriteableFakeWebSocketStream)); 1188 set_stream(base::WrapUnique(new WriteableFakeWebSocketStream));
1188 deleting_ = EVENT_ON_FAIL_CHANNEL; 1189 deleting_ = EVENT_ON_FAIL_CHANNEL;
1189 CreateChannelAndConnectSuccessfully(); 1190 CreateChannelAndConnectSuccessfully();
1190 ASSERT_TRUE(channel_); 1191 ASSERT_TRUE(channel_);
1191 channel_->SendFrame(true, 1192 channel_->SendFrame(true,
1192 WebSocketFrameHeader::kOpCodeText, 1193 WebSocketFrameHeader::kOpCodeText,
1193 std::vector<char>(kDefaultInitialQuota * 2, 'T')); 1194 std::vector<char>(kDefaultInitialQuota * 2, 'T'));
1194 EXPECT_EQ(nullptr, channel_.get()); 1195 EXPECT_EQ(nullptr, channel_.get());
1195 } 1196 }
1196 1197
1197 TEST_F(WebSocketChannelDeletingTest, FailChannelInOnReadDone) { 1198 TEST_F(WebSocketChannelDeletingTest, FailChannelInOnReadDone) {
1198 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1199 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1199 new ReadableFakeWebSocketStream); 1200 new ReadableFakeWebSocketStream);
1200 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1201 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1201 ERR_WS_PROTOCOL_ERROR); 1202 ERR_WS_PROTOCOL_ERROR);
1202 set_stream(std::move(stream)); 1203 set_stream(std::move(stream));
1203 deleting_ = EVENT_ON_FAIL_CHANNEL; 1204 deleting_ = EVENT_ON_FAIL_CHANNEL;
1204 CreateChannelAndConnectSuccessfully(); 1205 CreateChannelAndConnectSuccessfully();
1205 ASSERT_TRUE(channel_); 1206 ASSERT_TRUE(channel_);
1206 base::MessageLoop::current()->RunUntilIdle(); 1207 base::RunLoop().RunUntilIdle();
1207 EXPECT_EQ(nullptr, channel_.get()); 1208 EXPECT_EQ(nullptr, channel_.get());
1208 } 1209 }
1209 1210
1210 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToMaskedFrame) { 1211 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToMaskedFrame) {
1211 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1212 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1212 new ReadableFakeWebSocketStream); 1213 new ReadableFakeWebSocketStream);
1213 static const InitFrame frames[] = { 1214 static const InitFrame frames[] = {
1214 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}}; 1215 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}};
1215 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1216 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1216 set_stream(std::move(stream)); 1217 set_stream(std::move(stream));
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 EXPECT_CALL(checkpoint, Call(1)); 1447 EXPECT_CALL(checkpoint, Call(1));
1447 EXPECT_CALL( 1448 EXPECT_CALL(
1448 *event_interface_, 1449 *event_interface_,
1449 OnDataFrame( 1450 OnDataFrame(
1450 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO"))); 1451 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO")));
1451 EXPECT_CALL(checkpoint, Call(2)); 1452 EXPECT_CALL(checkpoint, Call(2));
1452 } 1453 }
1453 1454
1454 CreateChannelAndConnectSuccessfully(); 1455 CreateChannelAndConnectSuccessfully();
1455 checkpoint.Call(1); 1456 checkpoint.Call(1);
1456 base::MessageLoop::current()->RunUntilIdle(); 1457 base::RunLoop().RunUntilIdle();
1457 checkpoint.Call(2); 1458 checkpoint.Call(2);
1458 } 1459 }
1459 1460
1460 // Extra data can arrive while a read is being processed, resulting in the next 1461 // Extra data can arrive while a read is being processed, resulting in the next
1461 // read completing synchronously. 1462 // read completing synchronously.
1462 TEST_F(WebSocketChannelEventInterfaceTest, AsyncThenSyncRead) { 1463 TEST_F(WebSocketChannelEventInterfaceTest, AsyncThenSyncRead) {
1463 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1464 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1464 new ReadableFakeWebSocketStream); 1465 new ReadableFakeWebSocketStream);
1465 static const InitFrame frames1[] = { 1466 static const InitFrame frames1[] = {
1466 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}}; 1467 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "HELLO"}};
(...skipping 10 matching lines...) Expand all
1477 *event_interface_, 1478 *event_interface_,
1478 OnDataFrame( 1479 OnDataFrame(
1479 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO"))); 1480 true, WebSocketFrameHeader::kOpCodeText, AsVector("HELLO")));
1480 EXPECT_CALL( 1481 EXPECT_CALL(
1481 *event_interface_, 1482 *event_interface_,
1482 OnDataFrame( 1483 OnDataFrame(
1483 true, WebSocketFrameHeader::kOpCodeText, AsVector("WORLD"))); 1484 true, WebSocketFrameHeader::kOpCodeText, AsVector("WORLD")));
1484 } 1485 }
1485 1486
1486 CreateChannelAndConnectSuccessfully(); 1487 CreateChannelAndConnectSuccessfully();
1487 base::MessageLoop::current()->RunUntilIdle(); 1488 base::RunLoop().RunUntilIdle();
1488 } 1489 }
1489 1490
1490 // Data frames are delivered the same regardless of how many reads they arrive 1491 // Data frames are delivered the same regardless of how many reads they arrive
1491 // as. 1492 // as.
1492 TEST_F(WebSocketChannelEventInterfaceTest, FragmentedMessage) { 1493 TEST_F(WebSocketChannelEventInterfaceTest, FragmentedMessage) {
1493 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1494 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1494 new ReadableFakeWebSocketStream); 1495 new ReadableFakeWebSocketStream);
1495 // Here we have one message which arrived in five frames split across three 1496 // Here we have one message which arrived in five frames split across three
1496 // reads. It may have been reframed on arrival, but this class doesn't care 1497 // reads. It may have been reframed on arrival, but this class doesn't care
1497 // about that. 1498 // about that.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 *event_interface_, 1532 *event_interface_,
1532 OnDataFrame( 1533 OnDataFrame(
1533 false, WebSocketFrameHeader::kOpCodeContinuation, AsVector(" "))); 1534 false, WebSocketFrameHeader::kOpCodeContinuation, AsVector(" ")));
1534 EXPECT_CALL(*event_interface_, 1535 EXPECT_CALL(*event_interface_,
1535 OnDataFrame(true, 1536 OnDataFrame(true,
1536 WebSocketFrameHeader::kOpCodeContinuation, 1537 WebSocketFrameHeader::kOpCodeContinuation,
1537 AsVector("FRAMES"))); 1538 AsVector("FRAMES")));
1538 } 1539 }
1539 1540
1540 CreateChannelAndConnectSuccessfully(); 1541 CreateChannelAndConnectSuccessfully();
1541 base::MessageLoop::current()->RunUntilIdle(); 1542 base::RunLoop().RunUntilIdle();
1542 } 1543 }
1543 1544
1544 // A message can consist of one frame with null payload. 1545 // A message can consist of one frame with null payload.
1545 TEST_F(WebSocketChannelEventInterfaceTest, NullMessage) { 1546 TEST_F(WebSocketChannelEventInterfaceTest, NullMessage) {
1546 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1547 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1547 new ReadableFakeWebSocketStream); 1548 new ReadableFakeWebSocketStream);
1548 static const InitFrame frames[] = { 1549 static const InitFrame frames[] = {
1549 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, nullptr}}; 1550 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, nullptr}};
1550 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1551 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
1551 set_stream(std::move(stream)); 1552 set_stream(std::move(stream));
(...skipping 14 matching lines...) Expand all
1566 set_stream(std::move(stream)); 1567 set_stream(std::move(stream));
1567 { 1568 {
1568 InSequence s; 1569 InSequence s;
1569 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1570 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1570 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1571 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1571 EXPECT_CALL(*event_interface_, 1572 EXPECT_CALL(*event_interface_,
1572 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)); 1573 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
1573 } 1574 }
1574 1575
1575 CreateChannelAndConnectSuccessfully(); 1576 CreateChannelAndConnectSuccessfully();
1576 base::MessageLoop::current()->RunUntilIdle(); 1577 base::RunLoop().RunUntilIdle();
1577 } 1578 }
1578 1579
1579 // A connection reset should produce the same event as an unexpected closure. 1580 // A connection reset should produce the same event as an unexpected closure.
1580 TEST_F(WebSocketChannelEventInterfaceTest, ConnectionReset) { 1581 TEST_F(WebSocketChannelEventInterfaceTest, ConnectionReset) {
1581 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1582 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1582 new ReadableFakeWebSocketStream); 1583 new ReadableFakeWebSocketStream);
1583 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1584 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1584 ERR_CONNECTION_RESET); 1585 ERR_CONNECTION_RESET);
1585 set_stream(std::move(stream)); 1586 set_stream(std::move(stream));
1586 { 1587 {
1587 InSequence s; 1588 InSequence s;
1588 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1589 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1589 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1590 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1590 EXPECT_CALL(*event_interface_, 1591 EXPECT_CALL(*event_interface_,
1591 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)); 1592 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _));
1592 } 1593 }
1593 1594
1594 CreateChannelAndConnectSuccessfully(); 1595 CreateChannelAndConnectSuccessfully();
1595 base::MessageLoop::current()->RunUntilIdle(); 1596 base::RunLoop().RunUntilIdle();
1596 } 1597 }
1597 1598
1598 // RFC6455 5.1 "A client MUST close a connection if it detects a masked frame." 1599 // RFC6455 5.1 "A client MUST close a connection if it detects a masked frame."
1599 TEST_F(WebSocketChannelEventInterfaceTest, MaskedFramesAreRejected) { 1600 TEST_F(WebSocketChannelEventInterfaceTest, MaskedFramesAreRejected) {
1600 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1601 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1601 new ReadableFakeWebSocketStream); 1602 new ReadableFakeWebSocketStream);
1602 static const InitFrame frames[] = { 1603 static const InitFrame frames[] = {
1603 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}}; 1604 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}};
1604 1605
1605 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1606 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1606 set_stream(std::move(stream)); 1607 set_stream(std::move(stream));
1607 { 1608 {
1608 InSequence s; 1609 InSequence s;
1609 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1610 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1610 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1611 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1611 EXPECT_CALL( 1612 EXPECT_CALL(
1612 *event_interface_, 1613 *event_interface_,
1613 OnFailChannel( 1614 OnFailChannel(
1614 "A server must not mask any frames that it sends to the client.")); 1615 "A server must not mask any frames that it sends to the client."));
1615 } 1616 }
1616 1617
1617 CreateChannelAndConnectSuccessfully(); 1618 CreateChannelAndConnectSuccessfully();
1618 base::MessageLoop::current()->RunUntilIdle(); 1619 base::RunLoop().RunUntilIdle();
1619 } 1620 }
1620 1621
1621 // RFC6455 5.2 "If an unknown opcode is received, the receiving endpoint MUST 1622 // RFC6455 5.2 "If an unknown opcode is received, the receiving endpoint MUST
1622 // _Fail the WebSocket Connection_." 1623 // _Fail the WebSocket Connection_."
1623 TEST_F(WebSocketChannelEventInterfaceTest, UnknownOpCodeIsRejected) { 1624 TEST_F(WebSocketChannelEventInterfaceTest, UnknownOpCodeIsRejected) {
1624 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1625 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1625 new ReadableFakeWebSocketStream); 1626 new ReadableFakeWebSocketStream);
1626 static const InitFrame frames[] = {{FINAL_FRAME, 4, NOT_MASKED, "HELLO"}}; 1627 static const InitFrame frames[] = {{FINAL_FRAME, 4, NOT_MASKED, "HELLO"}};
1627 1628
1628 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1629 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1629 set_stream(std::move(stream)); 1630 set_stream(std::move(stream));
1630 { 1631 {
1631 InSequence s; 1632 InSequence s;
1632 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1633 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1633 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1634 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1634 EXPECT_CALL(*event_interface_, 1635 EXPECT_CALL(*event_interface_,
1635 OnFailChannel("Unrecognized frame opcode: 4")); 1636 OnFailChannel("Unrecognized frame opcode: 4"));
1636 } 1637 }
1637 1638
1638 CreateChannelAndConnectSuccessfully(); 1639 CreateChannelAndConnectSuccessfully();
1639 base::MessageLoop::current()->RunUntilIdle(); 1640 base::RunLoop().RunUntilIdle();
1640 } 1641 }
1641 1642
1642 // RFC6455 5.4 "Control frames ... MAY be injected in the middle of a 1643 // RFC6455 5.4 "Control frames ... MAY be injected in the middle of a
1643 // fragmented message." 1644 // fragmented message."
1644 TEST_F(WebSocketChannelEventInterfaceTest, ControlFrameInDataMessage) { 1645 TEST_F(WebSocketChannelEventInterfaceTest, ControlFrameInDataMessage) {
1645 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1646 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1646 new ReadableFakeWebSocketStream); 1647 new ReadableFakeWebSocketStream);
1647 // We have one message of type Text split into two frames. In the middle is a 1648 // We have one message of type Text split into two frames. In the middle is a
1648 // control message of type Pong. 1649 // control message of type Pong.
1649 static const InitFrame frames1[] = { 1650 static const InitFrame frames1[] = {
(...skipping 16 matching lines...) Expand all
1666 *event_interface_, 1667 *event_interface_,
1667 OnDataFrame( 1668 OnDataFrame(
1668 false, WebSocketFrameHeader::kOpCodeText, AsVector("SPLIT "))); 1669 false, WebSocketFrameHeader::kOpCodeText, AsVector("SPLIT ")));
1669 EXPECT_CALL(*event_interface_, 1670 EXPECT_CALL(*event_interface_,
1670 OnDataFrame(true, 1671 OnDataFrame(true,
1671 WebSocketFrameHeader::kOpCodeContinuation, 1672 WebSocketFrameHeader::kOpCodeContinuation,
1672 AsVector("MESSAGE"))); 1673 AsVector("MESSAGE")));
1673 } 1674 }
1674 1675
1675 CreateChannelAndConnectSuccessfully(); 1676 CreateChannelAndConnectSuccessfully();
1676 base::MessageLoop::current()->RunUntilIdle(); 1677 base::RunLoop().RunUntilIdle();
1677 } 1678 }
1678 1679
1679 // It seems redundant to repeat the entirety of the above test, so just test a 1680 // It seems redundant to repeat the entirety of the above test, so just test a
1680 // Pong with null data. 1681 // Pong with null data.
1681 TEST_F(WebSocketChannelEventInterfaceTest, PongWithNullData) { 1682 TEST_F(WebSocketChannelEventInterfaceTest, PongWithNullData) {
1682 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1683 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1683 new ReadableFakeWebSocketStream); 1684 new ReadableFakeWebSocketStream);
1684 static const InitFrame frames[] = { 1685 static const InitFrame frames[] = {
1685 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, nullptr}}; 1686 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, nullptr}};
1686 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1687 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1687 set_stream(std::move(stream)); 1688 set_stream(std::move(stream));
1688 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1689 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1689 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1690 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1690 1691
1691 CreateChannelAndConnectSuccessfully(); 1692 CreateChannelAndConnectSuccessfully();
1692 base::MessageLoop::current()->RunUntilIdle(); 1693 base::RunLoop().RunUntilIdle();
1693 } 1694 }
1694 1695
1695 // If a frame has an invalid header, then the connection is closed and 1696 // If a frame has an invalid header, then the connection is closed and
1696 // subsequent frames must not trigger events. 1697 // subsequent frames must not trigger events.
1697 TEST_F(WebSocketChannelEventInterfaceTest, FrameAfterInvalidFrame) { 1698 TEST_F(WebSocketChannelEventInterfaceTest, FrameAfterInvalidFrame) {
1698 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1699 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1699 new ReadableFakeWebSocketStream); 1700 new ReadableFakeWebSocketStream);
1700 static const InitFrame frames[] = { 1701 static const InitFrame frames[] = {
1701 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"}, 1702 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "HELLO"},
1702 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, " WORLD"}}; 1703 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, " WORLD"}};
1703 1704
1704 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); 1705 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames);
1705 set_stream(std::move(stream)); 1706 set_stream(std::move(stream));
1706 { 1707 {
1707 InSequence s; 1708 InSequence s;
1708 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1709 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1709 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1710 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1710 EXPECT_CALL( 1711 EXPECT_CALL(
1711 *event_interface_, 1712 *event_interface_,
1712 OnFailChannel( 1713 OnFailChannel(
1713 "A server must not mask any frames that it sends to the client.")); 1714 "A server must not mask any frames that it sends to the client."));
1714 } 1715 }
1715 1716
1716 CreateChannelAndConnectSuccessfully(); 1717 CreateChannelAndConnectSuccessfully();
1717 base::MessageLoop::current()->RunUntilIdle(); 1718 base::RunLoop().RunUntilIdle();
1718 } 1719 }
1719 1720
1720 // If the renderer sends lots of small writes, we don't want to update the quota 1721 // If the renderer sends lots of small writes, we don't want to update the quota
1721 // for each one. 1722 // for each one.
1722 TEST_F(WebSocketChannelEventInterfaceTest, SmallWriteDoesntUpdateQuota) { 1723 TEST_F(WebSocketChannelEventInterfaceTest, SmallWriteDoesntUpdateQuota) {
1723 set_stream(base::WrapUnique(new WriteableFakeWebSocketStream)); 1724 set_stream(base::WrapUnique(new WriteableFakeWebSocketStream));
1724 { 1725 {
1725 InSequence s; 1726 InSequence s;
1726 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1727 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1727 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1728 EXPECT_CALL(*event_interface_, OnFlowControl(_));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1832 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1832 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1833 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1833 EXPECT_CALL(*event_interface_, 1834 EXPECT_CALL(*event_interface_,
1834 OnDropChannel(true, kWebSocketNormalClosure, "Fred")); 1835 OnDropChannel(true, kWebSocketNormalClosure, "Fred"));
1835 } 1836 }
1836 1837
1837 CreateChannelAndConnectSuccessfully(); 1838 CreateChannelAndConnectSuccessfully();
1838 1839
1839 ASSERT_EQ(CHANNEL_ALIVE, 1840 ASSERT_EQ(CHANNEL_ALIVE,
1840 channel_->StartClosingHandshake(kWebSocketNormalClosure, "Fred")); 1841 channel_->StartClosingHandshake(kWebSocketNormalClosure, "Fred"));
1841 base::MessageLoop::current()->RunUntilIdle(); 1842 base::RunLoop().RunUntilIdle();
1842 } 1843 }
1843 1844
1844 // StartClosingHandshake() also works before connection completes, and calls 1845 // StartClosingHandshake() also works before connection completes, and calls
1845 // OnDropChannel. 1846 // OnDropChannel.
1846 TEST_F(WebSocketChannelEventInterfaceTest, CloseDuringConnection) { 1847 TEST_F(WebSocketChannelEventInterfaceTest, CloseDuringConnection) {
1847 EXPECT_CALL(*event_interface_, 1848 EXPECT_CALL(*event_interface_,
1848 OnDropChannel(false, kWebSocketErrorAbnormalClosure, "")); 1849 OnDropChannel(false, kWebSocketErrorAbnormalClosure, ""));
1849 1850
1850 CreateChannelAndConnect(); 1851 CreateChannelAndConnect();
1851 ASSERT_EQ(CHANNEL_DELETED, 1852 ASSERT_EQ(CHANNEL_DELETED,
1852 channel_->StartClosingHandshake(kWebSocketNormalClosure, "Joe")); 1853 channel_->StartClosingHandshake(kWebSocketNormalClosure, "Joe"));
1853 } 1854 }
1854 1855
1855 // OnDropChannel() is only called once when a write() on the socket triggers a 1856 // OnDropChannel() is only called once when a write() on the socket triggers a
1856 // connection reset. 1857 // connection reset.
1857 TEST_F(WebSocketChannelEventInterfaceTest, OnDropChannelCalledOnce) { 1858 TEST_F(WebSocketChannelEventInterfaceTest, OnDropChannelCalledOnce) {
1858 set_stream(base::WrapUnique(new ResetOnWriteFakeWebSocketStream)); 1859 set_stream(base::WrapUnique(new ResetOnWriteFakeWebSocketStream));
1859 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1860 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1860 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1861 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1861 1862
1862 EXPECT_CALL(*event_interface_, 1863 EXPECT_CALL(*event_interface_,
1863 OnDropChannel(false, kWebSocketErrorAbnormalClosure, "")) 1864 OnDropChannel(false, kWebSocketErrorAbnormalClosure, ""))
1864 .Times(1); 1865 .Times(1);
1865 1866
1866 CreateChannelAndConnectSuccessfully(); 1867 CreateChannelAndConnectSuccessfully();
1867 1868
1868 channel_->SendFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector("yt?")); 1869 channel_->SendFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector("yt?"));
1869 base::MessageLoop::current()->RunUntilIdle(); 1870 base::RunLoop().RunUntilIdle();
1870 } 1871 }
1871 1872
1872 // When the remote server sends a Close frame with an empty payload, 1873 // When the remote server sends a Close frame with an empty payload,
1873 // WebSocketChannel should report code 1005, kWebSocketErrorNoStatusReceived. 1874 // WebSocketChannel should report code 1005, kWebSocketErrorNoStatusReceived.
1874 TEST_F(WebSocketChannelEventInterfaceTest, CloseWithNoPayloadGivesStatus1005) { 1875 TEST_F(WebSocketChannelEventInterfaceTest, CloseWithNoPayloadGivesStatus1005) {
1875 std::unique_ptr<ReadableFakeWebSocketStream> stream( 1876 std::unique_ptr<ReadableFakeWebSocketStream> stream(
1876 new ReadableFakeWebSocketStream); 1877 new ReadableFakeWebSocketStream);
1877 static const InitFrame frames[] = { 1878 static const InitFrame frames[] = {
1878 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, ""}}; 1879 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, ""}};
1879 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 1880 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 new ReadableFakeWebSocketStream); 1932 new ReadableFakeWebSocketStream);
1932 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC, 1933 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::ASYNC,
1933 ERR_WS_PROTOCOL_ERROR); 1934 ERR_WS_PROTOCOL_ERROR);
1934 set_stream(std::move(stream)); 1935 set_stream(std::move(stream));
1935 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1936 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1936 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1937 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1937 1938
1938 EXPECT_CALL(*event_interface_, OnFailChannel("Invalid frame header")); 1939 EXPECT_CALL(*event_interface_, OnFailChannel("Invalid frame header"));
1939 1940
1940 CreateChannelAndConnectSuccessfully(); 1941 CreateChannelAndConnectSuccessfully();
1941 base::MessageLoop::current()->RunUntilIdle(); 1942 base::RunLoop().RunUntilIdle();
1942 } 1943 }
1943 1944
1944 TEST_F(WebSocketChannelEventInterfaceTest, StartHandshakeRequest) { 1945 TEST_F(WebSocketChannelEventInterfaceTest, StartHandshakeRequest) {
1945 { 1946 {
1946 InSequence s; 1947 InSequence s;
1947 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1948 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1948 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1949 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1949 EXPECT_CALL(*event_interface_, OnStartOpeningHandshakeCalled()); 1950 EXPECT_CALL(*event_interface_, OnStartOpeningHandshakeCalled());
1950 } 1951 }
1951 1952
1952 CreateChannelAndConnectSuccessfully(); 1953 CreateChannelAndConnectSuccessfully();
1953 1954
1954 std::unique_ptr<WebSocketHandshakeRequestInfo> request_info( 1955 std::unique_ptr<WebSocketHandshakeRequestInfo> request_info(
1955 new WebSocketHandshakeRequestInfo(GURL("ws://www.example.com/"), 1956 new WebSocketHandshakeRequestInfo(GURL("ws://www.example.com/"),
1956 base::Time())); 1957 base::Time()));
1957 connect_data_.creator.connect_delegate->OnStartOpeningHandshake( 1958 connect_data_.creator.connect_delegate->OnStartOpeningHandshake(
1958 std::move(request_info)); 1959 std::move(request_info));
1959 1960
1960 base::MessageLoop::current()->RunUntilIdle(); 1961 base::RunLoop().RunUntilIdle();
1961 } 1962 }
1962 1963
1963 TEST_F(WebSocketChannelEventInterfaceTest, FinishHandshakeRequest) { 1964 TEST_F(WebSocketChannelEventInterfaceTest, FinishHandshakeRequest) {
1964 { 1965 {
1965 InSequence s; 1966 InSequence s;
1966 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 1967 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
1967 EXPECT_CALL(*event_interface_, OnFlowControl(_)); 1968 EXPECT_CALL(*event_interface_, OnFlowControl(_));
1968 EXPECT_CALL(*event_interface_, OnFinishOpeningHandshakeCalled()); 1969 EXPECT_CALL(*event_interface_, OnFinishOpeningHandshakeCalled());
1969 } 1970 }
1970 1971
1971 CreateChannelAndConnectSuccessfully(); 1972 CreateChannelAndConnectSuccessfully();
1972 1973
1973 scoped_refptr<HttpResponseHeaders> response_headers( 1974 scoped_refptr<HttpResponseHeaders> response_headers(
1974 new HttpResponseHeaders("")); 1975 new HttpResponseHeaders(""));
1975 std::unique_ptr<WebSocketHandshakeResponseInfo> response_info( 1976 std::unique_ptr<WebSocketHandshakeResponseInfo> response_info(
1976 new WebSocketHandshakeResponseInfo(GURL("ws://www.example.com/"), 200, 1977 new WebSocketHandshakeResponseInfo(GURL("ws://www.example.com/"), 200,
1977 "OK", response_headers, base::Time())); 1978 "OK", response_headers, base::Time()));
1978 connect_data_.creator.connect_delegate->OnFinishOpeningHandshake( 1979 connect_data_.creator.connect_delegate->OnFinishOpeningHandshake(
1979 std::move(response_info)); 1980 std::move(response_info));
1980 base::MessageLoop::current()->RunUntilIdle(); 1981 base::RunLoop().RunUntilIdle();
1981 } 1982 }
1982 1983
1983 TEST_F(WebSocketChannelEventInterfaceTest, FailJustAfterHandshake) { 1984 TEST_F(WebSocketChannelEventInterfaceTest, FailJustAfterHandshake) {
1984 { 1985 {
1985 InSequence s; 1986 InSequence s;
1986 EXPECT_CALL(*event_interface_, OnStartOpeningHandshakeCalled()); 1987 EXPECT_CALL(*event_interface_, OnStartOpeningHandshakeCalled());
1987 EXPECT_CALL(*event_interface_, OnFinishOpeningHandshakeCalled()); 1988 EXPECT_CALL(*event_interface_, OnFinishOpeningHandshakeCalled());
1988 EXPECT_CALL(*event_interface_, OnFailChannel("bye")); 1989 EXPECT_CALL(*event_interface_, OnFailChannel("bye"));
1989 } 1990 }
1990 1991
1991 CreateChannelAndConnect(); 1992 CreateChannelAndConnect();
1992 1993
1993 WebSocketStream::ConnectDelegate* connect_delegate = 1994 WebSocketStream::ConnectDelegate* connect_delegate =
1994 connect_data_.creator.connect_delegate.get(); 1995 connect_data_.creator.connect_delegate.get();
1995 GURL url("ws://www.example.com/"); 1996 GURL url("ws://www.example.com/");
1996 std::unique_ptr<WebSocketHandshakeRequestInfo> request_info( 1997 std::unique_ptr<WebSocketHandshakeRequestInfo> request_info(
1997 new WebSocketHandshakeRequestInfo(url, base::Time())); 1998 new WebSocketHandshakeRequestInfo(url, base::Time()));
1998 scoped_refptr<HttpResponseHeaders> response_headers( 1999 scoped_refptr<HttpResponseHeaders> response_headers(
1999 new HttpResponseHeaders("")); 2000 new HttpResponseHeaders(""));
2000 std::unique_ptr<WebSocketHandshakeResponseInfo> response_info( 2001 std::unique_ptr<WebSocketHandshakeResponseInfo> response_info(
2001 new WebSocketHandshakeResponseInfo(url, 200, "OK", response_headers, 2002 new WebSocketHandshakeResponseInfo(url, 200, "OK", response_headers,
2002 base::Time())); 2003 base::Time()));
2003 connect_delegate->OnStartOpeningHandshake(std::move(request_info)); 2004 connect_delegate->OnStartOpeningHandshake(std::move(request_info));
2004 connect_delegate->OnFinishOpeningHandshake(std::move(response_info)); 2005 connect_delegate->OnFinishOpeningHandshake(std::move(response_info));
2005 2006
2006 connect_delegate->OnFailure("bye"); 2007 connect_delegate->OnFailure("bye");
2007 base::MessageLoop::current()->RunUntilIdle(); 2008 base::RunLoop().RunUntilIdle();
2008 } 2009 }
2009 2010
2010 // Any frame after close is invalid. This test uses a Text frame. See also 2011 // Any frame after close is invalid. This test uses a Text frame. See also
2011 // test "PingAfterCloseIfRejected". 2012 // test "PingAfterCloseIfRejected".
2012 TEST_F(WebSocketChannelEventInterfaceTest, DataAfterCloseIsRejected) { 2013 TEST_F(WebSocketChannelEventInterfaceTest, DataAfterCloseIsRejected) {
2013 std::unique_ptr<ReadableFakeWebSocketStream> stream( 2014 std::unique_ptr<ReadableFakeWebSocketStream> stream(
2014 new ReadableFakeWebSocketStream); 2015 new ReadableFakeWebSocketStream);
2015 static const InitFrame frames[] = { 2016 static const InitFrame frames[] = {
2016 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, 2017 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED,
2017 CLOSE_DATA(NORMAL_CLOSURE, "OK")}, 2018 CLOSE_DATA(NORMAL_CLOSURE, "OK")},
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 false, WebSocketFrameHeader::kOpCodeContinuation, AsVector("U"))); 2358 false, WebSocketFrameHeader::kOpCodeContinuation, AsVector("U")));
2358 EXPECT_CALL(checkpoint, Call(3)); 2359 EXPECT_CALL(checkpoint, Call(3));
2359 EXPECT_CALL( 2360 EXPECT_CALL(
2360 *event_interface_, 2361 *event_interface_,
2361 OnDataFrame( 2362 OnDataFrame(
2362 true, WebSocketFrameHeader::kOpCodeContinuation, AsVector("R"))); 2363 true, WebSocketFrameHeader::kOpCodeContinuation, AsVector("R")));
2363 } 2364 }
2364 2365
2365 CreateChannelAndConnectWithQuota(2); 2366 CreateChannelAndConnectWithQuota(2);
2366 checkpoint.Call(1); 2367 checkpoint.Call(1);
2367 base::MessageLoop::current()->RunUntilIdle(); 2368 base::RunLoop().RunUntilIdle();
2368 checkpoint.Call(2); 2369 checkpoint.Call(2);
2369 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(1)); 2370 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(1));
2370 checkpoint.Call(3); 2371 checkpoint.Call(3);
2371 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(1)); 2372 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(1));
2372 } 2373 }
2373 2374
2374 // A message split into multiple frames which is further split due to quota 2375 // A message split into multiple frames which is further split due to quota
2375 // restrictions should stil be correct. 2376 // restrictions should stil be correct.
2376 // TODO(ricea): The message ends up split into more frames than are strictly 2377 // TODO(ricea): The message ends up split into more frames than are strictly
2377 // necessary. The complexity/performance tradeoffs here need further 2378 // necessary. The complexity/performance tradeoffs here need further
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
3035 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "\xff"}}; 3036 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "\xff"}};
3036 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); 3037 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
3037 set_stream(std::move(stream)); 3038 set_stream(std::move(stream));
3038 3039
3039 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _)); 3040 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
3040 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); 3041 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota));
3041 EXPECT_CALL(*event_interface_, 3042 EXPECT_CALL(*event_interface_,
3042 OnFailChannel("Could not decode a text frame as UTF-8.")); 3043 OnFailChannel("Could not decode a text frame as UTF-8."));
3043 3044
3044 CreateChannelAndConnectSuccessfully(); 3045 CreateChannelAndConnectSuccessfully();
3045 base::MessageLoop::current()->RunUntilIdle(); 3046 base::RunLoop().RunUntilIdle();
3046 } 3047 }
3047 3048
3048 // Invalid UTF-8 is not sent over the network. 3049 // Invalid UTF-8 is not sent over the network.
3049 TEST_F(WebSocketChannelStreamTest, InvalidUtf8TextFrameNotSent) { 3050 TEST_F(WebSocketChannelStreamTest, InvalidUtf8TextFrameNotSent) {
3050 static const InitFrame expected[] = {{FINAL_FRAME, 3051 static const InitFrame expected[] = {{FINAL_FRAME,
3051 WebSocketFrameHeader::kOpCodeClose, 3052 WebSocketFrameHeader::kOpCodeClose,
3052 MASKED, CLOSE_DATA(GOING_AWAY, "")}}; 3053 MASKED, CLOSE_DATA(GOING_AWAY, "")}};
3053 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); 3054 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber());
3054 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); 3055 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber());
3055 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) 3056 EXPECT_CALL(*mock_stream_, ReadFrames(_, _))
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
3492 3493
3493 channel_->SendFrame( 3494 channel_->SendFrame(
3494 true, WebSocketFrameHeader::kOpCodeText, 3495 true, WebSocketFrameHeader::kOpCodeText,
3495 std::vector<char>(static_cast<size_t>(kMessageSize), 'a')); 3496 std::vector<char>(static_cast<size_t>(kMessageSize), 'a'));
3496 int new_send_quota = channel_->current_send_quota(); 3497 int new_send_quota = channel_->current_send_quota();
3497 EXPECT_EQ(kMessageSize, initial_send_quota - new_send_quota); 3498 EXPECT_EQ(kMessageSize, initial_send_quota - new_send_quota);
3498 } 3499 }
3499 3500
3500 } // namespace 3501 } // namespace
3501 } // namespace net 3502 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/default_channel_id_store_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698