OLD | NEW |
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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <iostream> | 9 #include <iostream> |
10 #include <string> | 10 #include <string> |
(...skipping 2057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2068 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 2068 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
2069 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 2069 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
2070 EXPECT_CALL( | 2070 EXPECT_CALL( |
2071 *event_interface_, | 2071 *event_interface_, |
2072 OnFailChannel( | 2072 OnFailChannel( |
2073 "Received a broken close frame containing invalid UTF-8.")); | 2073 "Received a broken close frame containing invalid UTF-8.")); |
2074 | 2074 |
2075 CreateChannelAndConnectSuccessfully(); | 2075 CreateChannelAndConnectSuccessfully(); |
2076 } | 2076 } |
2077 | 2077 |
| 2078 // The reserved bits must all be clear on received frames. Extensions should |
| 2079 // clear the bits when they are set correctly before passing on the frame. |
| 2080 TEST_F(WebSocketChannelEventInterfaceTest, ReservedBitsMustNotBeSet) { |
| 2081 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 2082 new ReadableFakeWebSocketStream); |
| 2083 static const InitFrame frames[] = { |
| 2084 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, |
| 2085 NOT_MASKED, "sakana"}}; |
| 2086 // It is not worth adding support for reserved bits to InitFrame just for this |
| 2087 // one test, so set the bit manually. |
| 2088 ScopedVector<WebSocketFrame> raw_frames = CreateFrameVector(frames); |
| 2089 raw_frames[0]->header.reserved1 = true; |
| 2090 stream->PrepareRawReadFrames( |
| 2091 ReadableFakeWebSocketStream::SYNC, OK, raw_frames.Pass()); |
| 2092 set_stream(stream.Pass()); |
| 2093 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 2094 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 2095 EXPECT_CALL( |
| 2096 *event_interface_, |
| 2097 OnFailChannel("Received a frame with an invalid reserved bit set.")); |
| 2098 |
| 2099 CreateChannelAndConnectSuccessfully(); |
| 2100 } |
| 2101 |
2078 // The closing handshake times out and sends an OnDropChannel event if no | 2102 // The closing handshake times out and sends an OnDropChannel event if no |
2079 // response to the client Close message is received. | 2103 // response to the client Close message is received. |
2080 TEST_F(WebSocketChannelEventInterfaceTest, | 2104 TEST_F(WebSocketChannelEventInterfaceTest, |
2081 ClientInitiatedClosingHandshakeTimesOut) { | 2105 ClientInitiatedClosingHandshakeTimesOut) { |
2082 scoped_ptr<ReadableFakeWebSocketStream> stream( | 2106 scoped_ptr<ReadableFakeWebSocketStream> stream( |
2083 new ReadableFakeWebSocketStream); | 2107 new ReadableFakeWebSocketStream); |
2084 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, | 2108 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, |
2085 ERR_IO_PENDING); | 2109 ERR_IO_PENDING); |
2086 set_stream(stream.Pass()); | 2110 set_stream(stream.Pass()); |
2087 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 2111 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3056 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); | 3080 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); |
3057 ASSERT_TRUE(read_frames); | 3081 ASSERT_TRUE(read_frames); |
3058 // Provide the "Close" message from the server. | 3082 // Provide the "Close" message from the server. |
3059 *read_frames = CreateFrameVector(frames); | 3083 *read_frames = CreateFrameVector(frames); |
3060 read_callback.Run(OK); | 3084 read_callback.Run(OK); |
3061 completion.WaitForResult(); | 3085 completion.WaitForResult(); |
3062 } | 3086 } |
3063 | 3087 |
3064 } // namespace | 3088 } // namespace |
3065 } // namespace net | 3089 } // namespace net |
OLD | NEW |