Commit 414f5801 authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

[WebSocket] Add test for WebSocketChannel::ReadFrames() on closing.

This test adds procedure when we receive close frame while there are
pending frames.

Bug: 865001
Change-Id: I0ac7b406004139ab48b67985cccff8cbf3d70313
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775685Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693098}
parent 1869f509
......@@ -585,7 +585,6 @@ ChannelState WebSocketChannel::ReadFrames() {
return CHANNEL_ALIVE;
}
// TODO(yoichio): Add test for this case.
if (!InClosingState() && has_received_close_frame_) {
DCHECK(!event_interface_->HasPendingDataFrames());
// We've been waiting for the client to consume the frames before
......
......@@ -1078,6 +1078,41 @@ TEST_F(WebSocketChannelEventInterfaceTest, CloseAfterHandshake) {
CreateChannelAndConnectSuccessfully();
}
// Do not close until browser has sent all pending frames.
TEST_F(WebSocketChannelEventInterfaceTest, ShouldCloseWhileNoDataFrames) {
auto stream = std::make_unique<ReadableFakeWebSocketStream>();
static const InitFrame frames[] = {
{FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED,
CLOSE_DATA(SERVER_ERROR, "Internal Server Error")}};
stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC,
ERR_CONNECTION_CLOSED);
set_stream(std::move(stream));
Checkpoint checkpoint;
{
InSequence s;
EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
EXPECT_CALL(*event_interface_, OnSendFlowControlQuotaAdded(_));
EXPECT_CALL(*event_interface_, HasPendingDataFrames())
.WillOnce(Return(false))
.WillOnce(Return(true))
.WillOnce(Return(true));
EXPECT_CALL(checkpoint, Call(1));
#if DCHECK_IS_ON()
EXPECT_CALL(*event_interface_, HasPendingDataFrames())
.WillOnce(Return(false));
#endif
EXPECT_CALL(*event_interface_, OnClosingHandshake());
EXPECT_CALL(*event_interface_,
OnDropChannel(true, kWebSocketErrorInternalServerError,
"Internal Server Error"));
}
CreateChannelAndConnectSuccessfully();
checkpoint.Call(1);
ASSERT_EQ(CHANNEL_DELETED, channel_->ReadFrames());
}
// A remote server could close the connection immediately after sending the
// handshake response (most likely a bug in the server).
TEST_F(WebSocketChannelEventInterfaceTest, ConnectionCloseAfterHandshake) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment