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

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

Issue 2845033002: Avoid sending double responding close control frames in WebSockets (Closed)
Patch Set: Add unit test Created 3 years, 7 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') | 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
(...skipping 2524 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 CreateChannelAndConnectWithQuota(6); 2535 CreateChannelAndConnectWithQuota(6);
2536 checkpoint.Call(1); 2536 checkpoint.Call(1);
2537 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6)); 2537 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
2538 checkpoint.Call(2); 2538 checkpoint.Call(2);
2539 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6)); 2539 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
2540 checkpoint.Call(3); 2540 checkpoint.Call(3);
2541 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6)); 2541 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
2542 checkpoint.Call(4); 2542 checkpoint.Call(4);
2543 } 2543 }
2544 2544
2545 // SendFlowControl calls should not trigger multiple close respond frames.
2546 TEST_F(WebSocketChannelFlowControlTest, DoNotSendMultipleCloseRespondFrames) {
2547 std::unique_ptr<ReadableFakeWebSocketStream> stream(
2548 new ReadableFakeWebSocketStream);
2549 static const InitFrame frames[] = {
yhirano 2017/04/28 10:01:53 constexpr
2550 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED,
2551 "FIRST SECOND"},
2552 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED,
2553 CLOSE_DATA(NORMAL_CLOSURE, "GOOD BYE")},
2554 };
2555 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames);
2556 set_stream(std::move(stream));
2557 Checkpoint checkpoint;
2558 InSequence s;
2559 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _));
2560 EXPECT_CALL(*event_interface_, OnFlowControl(_));
2561 EXPECT_CALL(*event_interface_,
2562 OnDataFrameVector(false, WebSocketFrameHeader::kOpCodeText,
2563 AsVector("FIRST ")));
2564 EXPECT_CALL(checkpoint, Call(1));
2565 EXPECT_CALL(*event_interface_,
2566 OnDataFrameVector(true, WebSocketFrameHeader::kOpCodeContinuation,
2567 AsVector("SECOND")));
2568 EXPECT_CALL(*event_interface_, OnClosingHandshake());
2569 EXPECT_CALL(checkpoint, Call(2));
2570
2571 CreateChannelAndConnectWithQuota(6);
2572 checkpoint.Call(1);
2573 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
2574 checkpoint.Call(2);
2575 ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
2576 }
2577
2545 // RFC6455 5.1 "a client MUST mask all frames that it sends to the server". 2578 // RFC6455 5.1 "a client MUST mask all frames that it sends to the server".
2546 // WebSocketChannel actually only sets the mask bit in the header, it doesn't 2579 // WebSocketChannel actually only sets the mask bit in the header, it doesn't
2547 // perform masking itself (not all transports actually use masking). 2580 // perform masking itself (not all transports actually use masking).
2548 TEST_F(WebSocketChannelStreamTest, SentFramesAreMasked) { 2581 TEST_F(WebSocketChannelStreamTest, SentFramesAreMasked) {
2549 static const InitFrame expected[] = { 2582 static const InitFrame expected[] = {
2550 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, 2583 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText,
2551 MASKED, "NEEDS MASKING"}}; 2584 MASKED, "NEEDS MASKING"}};
2552 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); 2585 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber());
2553 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); 2586 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber());
2554 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); 2587 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING));
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
3526 channel_->SendFrame( 3559 channel_->SendFrame(
3527 true, WebSocketFrameHeader::kOpCodeText, 3560 true, WebSocketFrameHeader::kOpCodeText,
3528 AsIOBuffer(std::string(static_cast<size_t>(kMessageSize), 'a')), 3561 AsIOBuffer(std::string(static_cast<size_t>(kMessageSize), 'a')),
3529 static_cast<size_t>(kMessageSize)); 3562 static_cast<size_t>(kMessageSize));
3530 int new_send_quota = channel_->current_send_quota(); 3563 int new_send_quota = channel_->current_send_quota();
3531 EXPECT_EQ(kMessageSize, initial_send_quota - new_send_quota); 3564 EXPECT_EQ(kMessageSize, initial_send_quota - new_send_quota);
3532 } 3565 }
3533 3566
3534 } // namespace 3567 } // namespace
3535 } // namespace net 3568 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_channel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698