| 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 // Tests for WebSocketBasicStream. Note that we do not attempt to verify that | 5 // Tests for WebSocketBasicStream. Note that we do not attempt to verify that |
| 6 // frame parsing itself functions correctly, as that is covered by the | 6 // frame parsing itself functions correctly, as that is covered by the |
| 7 // WebSocketFrameParser tests. | 7 // WebSocketFrameParser tests. |
| 8 | 8 |
| 9 #include "net/websockets/websocket_basic_stream.h" | 9 #include "net/websockets/websocket_basic_stream.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 WEBSOCKET_BASIC_STREAM_TEST_DEFINE_CONSTANT(WriteFrame, | 58 WEBSOCKET_BASIC_STREAM_TEST_DEFINE_CONSTANT(WriteFrame, |
| 59 "\x81\x85\x00\x00\x00\x00Write"); | 59 "\x81\x85\x00\x00\x00\x00Write"); |
| 60 WEBSOCKET_BASIC_STREAM_TEST_DEFINE_CONSTANT(MaskedEmptyPong, | 60 WEBSOCKET_BASIC_STREAM_TEST_DEFINE_CONSTANT(MaskedEmptyPong, |
| 61 "\x8A\x80\x00\x00\x00\x00"); | 61 "\x8A\x80\x00\x00\x00\x00"); |
| 62 const WebSocketMaskingKey kNulMaskingKey = {{'\0', '\0', '\0', '\0'}}; | 62 const WebSocketMaskingKey kNulMaskingKey = {{'\0', '\0', '\0', '\0'}}; |
| 63 const WebSocketMaskingKey kNonNulMaskingKey = { | 63 const WebSocketMaskingKey kNonNulMaskingKey = { |
| 64 {'\x0d', '\x1b', '\x06', '\x17'}}; | 64 {'\x0d', '\x1b', '\x06', '\x17'}}; |
| 65 | 65 |
| 66 // A masking key generator function which generates the identity mask, | 66 // A masking key generator function which generates the identity mask, |
| 67 // ie. "\0\0\0\0". | 67 // ie. "\0\0\0\0". |
| 68 WebSocketMaskingKey GenerateNulMaskingKey() { return kNulMaskingKey; } | 68 WebSocketMaskingKey GenerateNulMaskingKey() { |
| 69 return kNulMaskingKey; |
| 70 } |
| 69 | 71 |
| 70 // A masking key generation function which generates a fixed masking key with no | 72 // A masking key generation function which generates a fixed masking key with no |
| 71 // nul characters. | 73 // nul characters. |
| 72 WebSocketMaskingKey GenerateNonNulMaskingKey() { return kNonNulMaskingKey; } | 74 WebSocketMaskingKey GenerateNonNulMaskingKey() { |
| 75 return kNonNulMaskingKey; |
| 76 } |
| 73 | 77 |
| 74 // Base class for WebSocketBasicStream test fixtures. | 78 // Base class for WebSocketBasicStream test fixtures. |
| 75 class WebSocketBasicStreamTest : public ::testing::Test { | 79 class WebSocketBasicStreamTest : public ::testing::Test { |
| 76 protected: | 80 protected: |
| 77 scoped_ptr<WebSocketBasicStream> stream_; | 81 scoped_ptr<WebSocketBasicStream> stream_; |
| 78 CapturingNetLog net_log_; | 82 CapturingNetLog net_log_; |
| 79 }; | 83 }; |
| 80 | 84 |
| 81 // A subclass of StaticSocketDataProvider modified to require that all data | 85 // A subclass of StaticSocketDataProvider modified to require that all data |
| 82 // expected to be read or written actually is. | 86 // expected to be read or written actually is. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 194 |
| 191 // A test fixture for tests that perform chunked reads. | 195 // A test fixture for tests that perform chunked reads. |
| 192 class WebSocketBasicStreamSocketChunkedReadTest | 196 class WebSocketBasicStreamSocketChunkedReadTest |
| 193 : public WebSocketBasicStreamSocketTest { | 197 : public WebSocketBasicStreamSocketTest { |
| 194 protected: | 198 protected: |
| 195 // Specify the behaviour if there aren't enough chunks to use all the data. If | 199 // Specify the behaviour if there aren't enough chunks to use all the data. If |
| 196 // LAST_FRAME_BIG is specified, then the rest of the data will be | 200 // LAST_FRAME_BIG is specified, then the rest of the data will be |
| 197 // put in the last chunk. If LAST_FRAME_NOT_BIG is specified, then the last | 201 // put in the last chunk. If LAST_FRAME_NOT_BIG is specified, then the last |
| 198 // frame will be no bigger than the rest of the frames (but it can be smaller, | 202 // frame will be no bigger than the rest of the frames (but it can be smaller, |
| 199 // if not enough data remains). | 203 // if not enough data remains). |
| 200 enum LastFrameBehaviour { | 204 enum LastFrameBehaviour { LAST_FRAME_BIG, LAST_FRAME_NOT_BIG }; |
| 201 LAST_FRAME_BIG, | |
| 202 LAST_FRAME_NOT_BIG | |
| 203 }; | |
| 204 | 205 |
| 205 // Prepares a read from |data| of |data_size|, split into |number_of_chunks|, | 206 // Prepares a read from |data| of |data_size|, split into |number_of_chunks|, |
| 206 // each of |chunk_size| (except that the last chunk may be larger or | 207 // each of |chunk_size| (except that the last chunk may be larger or |
| 207 // smaller). All reads must be either SYNCHRONOUS or ASYNC (not a mixture), | 208 // smaller). All reads must be either SYNCHRONOUS or ASYNC (not a mixture), |
| 208 // and errors cannot be simulated. Once data is exhausted, further reads will | 209 // and errors cannot be simulated. Once data is exhausted, further reads will |
| 209 // return 0 (ie. connection closed). | 210 // return 0 (ie. connection closed). |
| 210 void CreateChunkedRead(IoMode mode, | 211 void CreateChunkedRead(IoMode mode, |
| 211 const char data[], | 212 const char data[], |
| 212 size_t data_size, | 213 size_t data_size, |
| 213 int chunk_size, | 214 int chunk_size, |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 | 937 |
| 937 TEST_F(WebSocketBasicStreamSocketTest, GetSubProtocolWorks) { | 938 TEST_F(WebSocketBasicStreamSocketTest, GetSubProtocolWorks) { |
| 938 sub_protocol_ = "cyberchat"; | 939 sub_protocol_ = "cyberchat"; |
| 939 CreateNullStream(); | 940 CreateNullStream(); |
| 940 | 941 |
| 941 EXPECT_EQ("cyberchat", stream_->GetSubProtocol()); | 942 EXPECT_EQ("cyberchat", stream_->GetSubProtocol()); |
| 942 } | 943 } |
| 943 | 944 |
| 944 } // namespace | 945 } // namespace |
| 945 } // namespace net | 946 } // namespace net |
| OLD | NEW |