| 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 |
| 11 #include <string.h> // for memcpy() and memset(). | 11 #include <string.h> // for memcpy() and memset(). |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/big_endian.h" | 16 #include "base/big_endian.h" |
| 17 #include "base/port.h" | 17 #include "base/port.h" |
| 18 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
| 19 #include "net/log/capturing_net_log.h" | 19 #include "net/log/test_net_log.h" |
| 20 #include "net/socket/socket_test_util.h" | 20 #include "net/socket/socket_test_util.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 #define WEBSOCKET_BASIC_STREAM_TEST_DEFINE_CONSTANT(name, value) \ | 26 #define WEBSOCKET_BASIC_STREAM_TEST_DEFINE_CONSTANT(name, value) \ |
| 27 const char k##name[] = value; \ | 27 const char k##name[] = value; \ |
| 28 const size_t k##name##Size = arraysize(k##name) - 1; | 28 const size_t k##name##Size = arraysize(k##name) - 1; |
| 29 | 29 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 WebSocketMaskingKey GenerateNulMaskingKey() { return kNulMaskingKey; } | 68 WebSocketMaskingKey GenerateNulMaskingKey() { return kNulMaskingKey; } |
| 69 | 69 |
| 70 // A masking key generation function which generates a fixed masking key with no | 70 // A masking key generation function which generates a fixed masking key with no |
| 71 // nul characters. | 71 // nul characters. |
| 72 WebSocketMaskingKey GenerateNonNulMaskingKey() { return kNonNulMaskingKey; } | 72 WebSocketMaskingKey GenerateNonNulMaskingKey() { return kNonNulMaskingKey; } |
| 73 | 73 |
| 74 // Base class for WebSocketBasicStream test fixtures. | 74 // Base class for WebSocketBasicStream test fixtures. |
| 75 class WebSocketBasicStreamTest : public ::testing::Test { | 75 class WebSocketBasicStreamTest : public ::testing::Test { |
| 76 protected: | 76 protected: |
| 77 scoped_ptr<WebSocketBasicStream> stream_; | 77 scoped_ptr<WebSocketBasicStream> stream_; |
| 78 CapturingNetLog net_log_; | 78 TestNetLog net_log_; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // A subclass of StaticSocketDataProvider modified to require that all data | 81 // A subclass of StaticSocketDataProvider modified to require that all data |
| 82 // expected to be read or written actually is. | 82 // expected to be read or written actually is. |
| 83 class StrictStaticSocketDataProvider : public StaticSocketDataProvider { | 83 class StrictStaticSocketDataProvider : public StaticSocketDataProvider { |
| 84 public: | 84 public: |
| 85 StrictStaticSocketDataProvider(MockRead* reads, | 85 StrictStaticSocketDataProvider(MockRead* reads, |
| 86 size_t reads_count, | 86 size_t reads_count, |
| 87 MockWrite* writes, | 87 MockWrite* writes, |
| 88 size_t writes_count, | 88 size_t writes_count, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 template <size_t N> | 157 template <size_t N> |
| 158 void CreateReadOnly(MockRead (&reads)[N]) { | 158 void CreateReadOnly(MockRead (&reads)[N]) { |
| 159 CreateStream(reads, N, NULL, 0); | 159 CreateStream(reads, N, NULL, 0); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void CreateNullStream() { CreateStream(NULL, 0, NULL, 0); } | 162 void CreateNullStream() { CreateStream(NULL, 0, NULL, 0); } |
| 163 | 163 |
| 164 scoped_ptr<SocketDataProvider> socket_data_; | 164 scoped_ptr<SocketDataProvider> socket_data_; |
| 165 MockClientSocketFactory factory_; | 165 MockClientSocketFactory factory_; |
| 166 MockTransportClientSocketPool pool_; | 166 MockTransportClientSocketPool pool_; |
| 167 CapturingBoundNetLog(bound_net_log_); | 167 BoundTestNetLog(bound_net_log_); |
| 168 ScopedVector<WebSocketFrame> frames_; | 168 ScopedVector<WebSocketFrame> frames_; |
| 169 TestCompletionCallback cb_; | 169 TestCompletionCallback cb_; |
| 170 scoped_refptr<GrowableIOBuffer> http_read_buffer_; | 170 scoped_refptr<GrowableIOBuffer> http_read_buffer_; |
| 171 std::string sub_protocol_; | 171 std::string sub_protocol_; |
| 172 std::string extensions_; | 172 std::string extensions_; |
| 173 WebSocketBasicStream::WebSocketMaskingKeyGeneratorFunction generator_; | 173 WebSocketBasicStream::WebSocketMaskingKeyGeneratorFunction generator_; |
| 174 bool expect_all_io_to_complete_; | 174 bool expect_all_io_to_complete_; |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 // A test fixture for the common case of tests that only perform a single read. | 177 // A test fixture for the common case of tests that only perform a single read. |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 | 934 |
| 935 TEST_F(WebSocketBasicStreamSocketTest, GetSubProtocolWorks) { | 935 TEST_F(WebSocketBasicStreamSocketTest, GetSubProtocolWorks) { |
| 936 sub_protocol_ = "cyberchat"; | 936 sub_protocol_ = "cyberchat"; |
| 937 CreateNullStream(); | 937 CreateNullStream(); |
| 938 | 938 |
| 939 EXPECT_EQ("cyberchat", stream_->GetSubProtocol()); | 939 EXPECT_EQ("cyberchat", stream_->GetSubProtocol()); |
| 940 } | 940 } |
| 941 | 941 |
| 942 } // namespace | 942 } // namespace |
| 943 } // namespace net | 943 } // namespace net |
| OLD | NEW |