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 845 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 |