| 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 <limits.h> | 7 #include <limits.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <iostream> | 10 #include <iostream> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 using ::testing::DefaultValue; | 97 using ::testing::DefaultValue; |
| 98 using ::testing::InSequence; | 98 using ::testing::InSequence; |
| 99 using ::testing::MockFunction; | 99 using ::testing::MockFunction; |
| 100 using ::testing::Return; | 100 using ::testing::Return; |
| 101 using ::testing::SaveArg; | 101 using ::testing::SaveArg; |
| 102 using ::testing::StrictMock; | 102 using ::testing::StrictMock; |
| 103 using ::testing::_; | 103 using ::testing::_; |
| 104 | 104 |
| 105 // A selection of characters that have traditionally been mangled in some | 105 // A selection of characters that have traditionally been mangled in some |
| 106 // environment or other, for testing 8-bit cleanliness. | 106 // environment or other, for testing 8-bit cleanliness. |
| 107 const char kBinaryBlob[] = {'\n', '\r', // BACKWARDS CRNL | 107 const char kBinaryBlob[] = { |
| 108 '\0', // nul | 108 '\n', '\r', // BACKWARDS CRNL |
| 109 '\x7F', // DEL | 109 '\0', // nul |
| 110 '\x80', '\xFF', // NOT VALID UTF-8 | 110 '\x7F', // DEL |
| 111 '\x1A', // Control-Z, EOF on DOS | 111 '\x80', '\xFF', // NOT VALID UTF-8 |
| 112 '\x03', // Control-C | 112 '\x1A', // Control-Z, EOF on DOS |
| 113 '\x04', // EOT, special for Unix terms | 113 '\x03', // Control-C |
| 114 '\x1B', // ESC, often special | 114 '\x04', // EOT, special for Unix terms |
| 115 '\b', // backspace | 115 '\x1B', // ESC, often special |
| 116 '\'', // single-quote, special in PHP | 116 '\b', // backspace |
| 117 '\'', // single-quote, special in PHP |
| 117 }; | 118 }; |
| 118 const size_t kBinaryBlobSize = arraysize(kBinaryBlob); | 119 const size_t kBinaryBlobSize = arraysize(kBinaryBlob); |
| 119 | 120 |
| 120 // The amount of quota a new connection gets by default. | 121 // The amount of quota a new connection gets by default. |
| 121 // TODO(ricea): If kDefaultSendQuotaHighWaterMark changes, then this value will | 122 // TODO(ricea): If kDefaultSendQuotaHighWaterMark changes, then this value will |
| 122 // need to be updated. | 123 // need to be updated. |
| 123 const size_t kDefaultInitialQuota = 1 << 17; | 124 const size_t kDefaultInitialQuota = 1 << 17; |
| 124 // The amount of bytes we need to send after the initial connection to trigger a | 125 // The amount of bytes we need to send after the initial connection to trigger a |
| 125 // quota refresh. TODO(ricea): Change this if kDefaultSendQuotaHighWaterMark or | 126 // quota refresh. TODO(ricea): Change this if kDefaultSendQuotaHighWaterMark or |
| 126 // kDefaultSendQuotaLowWaterMark change. | 127 // kDefaultSendQuotaLowWaterMark change. |
| 127 const size_t kDefaultQuotaRefreshTrigger = (1 << 16) + 1; | 128 const size_t kDefaultQuotaRefreshTrigger = (1 << 16) + 1; |
| 128 | 129 |
| 129 // TestTimeouts::tiny_timeout() is 100ms! I could run halfway around the world | 130 // TestTimeouts::tiny_timeout() is 100ms! I could run halfway around the world |
| 130 // in that time! I would like my tests to run a bit quicker. | 131 // in that time! I would like my tests to run a bit quicker. |
| 131 const int kVeryTinyTimeoutMillis = 1; | 132 const int kVeryTinyTimeoutMillis = 1; |
| 132 | 133 |
| 133 // Enough quota to pass any test. | 134 // Enough quota to pass any test. |
| 134 const int64 kPlentyOfQuota = INT_MAX; | 135 const int64 kPlentyOfQuota = INT_MAX; |
| 135 | 136 |
| 136 typedef WebSocketEventInterface::ChannelState ChannelState; | 137 typedef WebSocketEventInterface::ChannelState ChannelState; |
| 137 const ChannelState CHANNEL_ALIVE = WebSocketEventInterface::CHANNEL_ALIVE; | 138 const ChannelState CHANNEL_ALIVE = WebSocketEventInterface::CHANNEL_ALIVE; |
| 138 const ChannelState CHANNEL_DELETED = WebSocketEventInterface::CHANNEL_DELETED; | 139 const ChannelState CHANNEL_DELETED = WebSocketEventInterface::CHANNEL_DELETED; |
| 139 | 140 |
| 140 // This typedef mainly exists to avoid having to repeat the "NOLINT" incantation | 141 // This typedef mainly exists to avoid having to repeat the "NOLINT" incantation |
| 141 // all over the place. | 142 // all over the place. |
| 142 typedef StrictMock< MockFunction<void(int)> > Checkpoint; // NOLINT | 143 typedef StrictMock<MockFunction<void(int)> > Checkpoint; // NOLINT |
| 143 | 144 |
| 144 // This mock is for testing expectations about how the EventInterface is used. | 145 // This mock is for testing expectations about how the EventInterface is used. |
| 145 class MockWebSocketEventInterface : public WebSocketEventInterface { | 146 class MockWebSocketEventInterface : public WebSocketEventInterface { |
| 146 public: | 147 public: |
| 147 MockWebSocketEventInterface() {} | 148 MockWebSocketEventInterface() {} |
| 148 | 149 |
| 149 MOCK_METHOD3(OnAddChannelResponse, | 150 MOCK_METHOD3(OnAddChannelResponse, |
| 150 ChannelState(bool, | 151 ChannelState(bool, |
| 151 const std::string&, | 152 const std::string&, |
| 152 const std::string&)); // NOLINT | 153 const std::string&)); // NOLINT |
| 153 MOCK_METHOD3(OnDataFrame, | 154 MOCK_METHOD3(OnDataFrame, |
| 154 ChannelState(bool, | 155 ChannelState(bool, |
| 155 WebSocketMessageType, | 156 WebSocketMessageType, |
| 156 const std::vector<char>&)); // NOLINT | 157 const std::vector<char>&)); // NOLINT |
| 157 MOCK_METHOD1(OnFlowControl, ChannelState(int64)); // NOLINT | 158 MOCK_METHOD1(OnFlowControl, ChannelState(int64)); // NOLINT |
| 158 MOCK_METHOD0(OnClosingHandshake, ChannelState(void)); // NOLINT | 159 MOCK_METHOD0(OnClosingHandshake, ChannelState(void)); // NOLINT |
| 159 MOCK_METHOD1(OnFailChannel, ChannelState(const std::string&)); // NOLINT | 160 MOCK_METHOD1(OnFailChannel, ChannelState(const std::string&)); // NOLINT |
| 160 MOCK_METHOD3(OnDropChannel, | 161 MOCK_METHOD3(OnDropChannel, |
| 161 ChannelState(bool, uint16, const std::string&)); // NOLINT | 162 ChannelState(bool, uint16, const std::string&)); // NOLINT |
| 162 | 163 |
| 163 // We can't use GMock with scoped_ptr. | 164 // We can't use GMock with scoped_ptr. |
| 164 ChannelState OnStartOpeningHandshake( | 165 ChannelState OnStartOpeningHandshake( |
| 165 scoped_ptr<WebSocketHandshakeRequestInfo>) OVERRIDE { | 166 scoped_ptr<WebSocketHandshakeRequestInfo>) OVERRIDE { |
| 166 OnStartOpeningHandshakeCalled(); | 167 OnStartOpeningHandshakeCalled(); |
| 167 return CHANNEL_ALIVE; | 168 return CHANNEL_ALIVE; |
| 168 } | 169 } |
| 169 ChannelState OnFinishOpeningHandshake( | 170 ChannelState OnFinishOpeningHandshake( |
| 170 scoped_ptr<WebSocketHandshakeResponseInfo>) OVERRIDE { | 171 scoped_ptr<WebSocketHandshakeResponseInfo>) OVERRIDE { |
| 171 OnFinishOpeningHandshakeCalled(); | 172 OnFinishOpeningHandshakeCalled(); |
| 172 return CHANNEL_ALIVE; | 173 return CHANNEL_ALIVE; |
| 173 } | 174 } |
| 174 | 175 |
| 175 MOCK_METHOD0(OnStartOpeningHandshakeCalled, void()); // NOLINT | 176 MOCK_METHOD0(OnStartOpeningHandshakeCalled, void()); // NOLINT |
| 176 MOCK_METHOD0(OnFinishOpeningHandshakeCalled, void()); // NOLINT | 177 MOCK_METHOD0(OnFinishOpeningHandshakeCalled, void()); // NOLINT |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 // This fake EventInterface is for tests which need a WebSocketEventInterface | 180 // This fake EventInterface is for tests which need a WebSocketEventInterface |
| 180 // implementation but are not verifying how it is used. | 181 // implementation but are not verifying how it is used. |
| 181 class FakeWebSocketEventInterface : public WebSocketEventInterface { | 182 class FakeWebSocketEventInterface : public WebSocketEventInterface { |
| 182 virtual ChannelState OnAddChannelResponse( | 183 virtual ChannelState OnAddChannelResponse( |
| 183 bool fail, | 184 bool fail, |
| 184 const std::string& selected_protocol, | 185 const std::string& selected_protocol, |
| 185 const std::string& extensions) OVERRIDE { | 186 const std::string& extensions) OVERRIDE { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 base::Closure closure() { return base::Bind(callback_.callback(), OK); } | 412 base::Closure closure() { return base::Bind(callback_.callback(), OK); } |
| 412 | 413 |
| 413 void WaitForResult() { callback_.WaitForResult(); } | 414 void WaitForResult() { callback_.WaitForResult(); } |
| 414 | 415 |
| 415 private: | 416 private: |
| 416 // Delegate to TestCompletionCallback for the implementation. | 417 // Delegate to TestCompletionCallback for the implementation. |
| 417 TestCompletionCallback callback_; | 418 TestCompletionCallback callback_; |
| 418 }; | 419 }; |
| 419 | 420 |
| 420 // A GoogleMock action to run a Closure. | 421 // A GoogleMock action to run a Closure. |
| 421 ACTION_P(InvokeClosure, closure) { closure.Run(); } | 422 ACTION_P(InvokeClosure, closure) { |
| 423 closure.Run(); |
| 424 } |
| 422 | 425 |
| 423 // A GoogleMock action to run a Closure and return CHANNEL_DELETED. | 426 // A GoogleMock action to run a Closure and return CHANNEL_DELETED. |
| 424 ACTION_P(InvokeClosureReturnDeleted, closure) { | 427 ACTION_P(InvokeClosureReturnDeleted, closure) { |
| 425 closure.Run(); | 428 closure.Run(); |
| 426 return WebSocketEventInterface::CHANNEL_DELETED; | 429 return WebSocketEventInterface::CHANNEL_DELETED; |
| 427 } | 430 } |
| 428 | 431 |
| 429 // A FakeWebSocketStream whose ReadFrames() function returns data. | 432 // A FakeWebSocketStream whose ReadFrames() function returns data. |
| 430 class ReadableFakeWebSocketStream : public FakeWebSocketStream { | 433 class ReadableFakeWebSocketStream : public FakeWebSocketStream { |
| 431 public: | 434 public: |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 virtual void CreateChannelAndConnectSuccessfully() OVERRIDE { | 933 virtual void CreateChannelAndConnectSuccessfully() OVERRIDE { |
| 931 set_stream(mock_stream_.Pass()); | 934 set_stream(mock_stream_.Pass()); |
| 932 WebSocketChannelTest::CreateChannelAndConnectSuccessfully(); | 935 WebSocketChannelTest::CreateChannelAndConnectSuccessfully(); |
| 933 } | 936 } |
| 934 | 937 |
| 935 scoped_ptr<MockWebSocketStream> mock_stream_; | 938 scoped_ptr<MockWebSocketStream> mock_stream_; |
| 936 }; | 939 }; |
| 937 | 940 |
| 938 // Fixture for tests which test UTF-8 validation of sent Text frames via the | 941 // Fixture for tests which test UTF-8 validation of sent Text frames via the |
| 939 // EventInterface. | 942 // EventInterface. |
| 940 class WebSocketChannelSendUtf8Test | 943 class WebSocketChannelSendUtf8Test : public WebSocketChannelEventInterfaceTest { |
| 941 : public WebSocketChannelEventInterfaceTest { | |
| 942 public: | 944 public: |
| 943 virtual void SetUp() { | 945 virtual void SetUp() { |
| 944 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); | 946 set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); |
| 945 // For the purpose of the tests using this fixture, it doesn't matter | 947 // For the purpose of the tests using this fixture, it doesn't matter |
| 946 // whether these methods are called or not. | 948 // whether these methods are called or not. |
| 947 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _, _)) | 949 EXPECT_CALL(*event_interface_, OnAddChannelResponse(_, _, _)) |
| 948 .Times(AnyNumber()); | 950 .Times(AnyNumber()); |
| 949 EXPECT_CALL(*event_interface_, OnFlowControl(_)) | 951 EXPECT_CALL(*event_interface_, OnFlowControl(_)).Times(AnyNumber()); |
| 950 .Times(AnyNumber()); | |
| 951 } | 952 } |
| 952 }; | 953 }; |
| 953 | 954 |
| 954 // Fixture for tests which test use of receive quota from the renderer. | 955 // Fixture for tests which test use of receive quota from the renderer. |
| 955 class WebSocketChannelFlowControlTest | 956 class WebSocketChannelFlowControlTest |
| 956 : public WebSocketChannelEventInterfaceTest { | 957 : public WebSocketChannelEventInterfaceTest { |
| 957 protected: | 958 protected: |
| 958 // Tests using this fixture should use CreateChannelAndConnectWithQuota() | 959 // Tests using this fixture should use CreateChannelAndConnectWithQuota() |
| 959 // instead of CreateChannelAndConnectSuccessfully(). | 960 // instead of CreateChannelAndConnectSuccessfully(). |
| 960 void CreateChannelAndConnectWithQuota(int64 quota) { | 961 void CreateChannelAndConnectWithQuota(int64 quota) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 channel_->SendFrame(true, | 1069 channel_->SendFrame(true, |
| 1069 WebSocketFrameHeader::kOpCodeText, | 1070 WebSocketFrameHeader::kOpCodeText, |
| 1070 std::vector<char>(kDefaultInitialQuota, 'B')); | 1071 std::vector<char>(kDefaultInitialQuota, 'B')); |
| 1071 EXPECT_EQ(NULL, channel_.get()); | 1072 EXPECT_EQ(NULL, channel_.get()); |
| 1072 } | 1073 } |
| 1073 | 1074 |
| 1074 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeSync) { | 1075 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeSync) { |
| 1075 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1076 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 1076 new ReadableFakeWebSocketStream); | 1077 new ReadableFakeWebSocketStream); |
| 1077 static const InitFrame frames[] = { | 1078 static const InitFrame frames[] = { |
| 1078 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 1079 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 1079 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; | 1080 CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; |
| 1080 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 1081 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 1081 set_stream(stream.Pass()); | 1082 set_stream(stream.Pass()); |
| 1082 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; | 1083 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; |
| 1083 CreateChannelAndConnectSuccessfully(); | 1084 CreateChannelAndConnectSuccessfully(); |
| 1084 EXPECT_EQ(NULL, channel_.get()); | 1085 EXPECT_EQ(NULL, channel_.get()); |
| 1085 } | 1086 } |
| 1086 | 1087 |
| 1087 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeAsync) { | 1088 TEST_F(WebSocketChannelDeletingTest, OnClosingHandshakeAsync) { |
| 1088 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1089 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 1089 new ReadableFakeWebSocketStream); | 1090 new ReadableFakeWebSocketStream); |
| 1090 static const InitFrame frames[] = { | 1091 static const InitFrame frames[] = { |
| 1091 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 1092 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 1092 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; | 1093 CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; |
| 1093 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); | 1094 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); |
| 1094 set_stream(stream.Pass()); | 1095 set_stream(stream.Pass()); |
| 1095 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; | 1096 deleting_ = EVENT_ON_CLOSING_HANDSHAKE; |
| 1096 CreateChannelAndConnectSuccessfully(); | 1097 CreateChannelAndConnectSuccessfully(); |
| 1097 ASSERT_TRUE(channel_); | 1098 ASSERT_TRUE(channel_); |
| 1098 base::MessageLoop::current()->RunUntilIdle(); | 1099 base::MessageLoop::current()->RunUntilIdle(); |
| 1099 EXPECT_EQ(NULL, channel_.get()); | 1100 EXPECT_EQ(NULL, channel_.get()); |
| 1100 } | 1101 } |
| 1101 | 1102 |
| 1102 TEST_F(WebSocketChannelDeletingTest, OnDropChannelWriteError) { | 1103 TEST_F(WebSocketChannelDeletingTest, OnDropChannelWriteError) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 set_stream(stream.Pass()); | 1197 set_stream(stream.Pass()); |
| 1197 deleting_ = EVENT_ON_FAIL_CHANNEL; | 1198 deleting_ = EVENT_ON_FAIL_CHANNEL; |
| 1198 | 1199 |
| 1199 CreateChannelAndConnectSuccessfully(); | 1200 CreateChannelAndConnectSuccessfully(); |
| 1200 EXPECT_EQ(NULL, channel_.get()); | 1201 EXPECT_EQ(NULL, channel_.get()); |
| 1201 } | 1202 } |
| 1202 | 1203 |
| 1203 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrame) { | 1204 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrame) { |
| 1204 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1205 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 1205 new ReadableFakeWebSocketStream); | 1206 new ReadableFakeWebSocketStream); |
| 1206 static const InitFrame frames[] = { | 1207 static const InitFrame frames[] = {{FINAL_FRAME, 0xF, NOT_MASKED, ""}}; |
| 1207 {FINAL_FRAME, 0xF, NOT_MASKED, ""}}; | |
| 1208 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 1208 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 1209 set_stream(stream.Pass()); | 1209 set_stream(stream.Pass()); |
| 1210 deleting_ = EVENT_ON_FAIL_CHANNEL; | 1210 deleting_ = EVENT_ON_FAIL_CHANNEL; |
| 1211 | 1211 |
| 1212 CreateChannelAndConnectSuccessfully(); | 1212 CreateChannelAndConnectSuccessfully(); |
| 1213 EXPECT_EQ(NULL, channel_.get()); | 1213 EXPECT_EQ(NULL, channel_.get()); |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 // Version of above test with NULL data. | 1216 // Version of above test with NULL data. |
| 1217 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrameNull) { | 1217 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToBadControlFrameNull) { |
| 1218 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1218 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 1219 new ReadableFakeWebSocketStream); | 1219 new ReadableFakeWebSocketStream); |
| 1220 static const InitFrame frames[] = { | 1220 static const InitFrame frames[] = {{FINAL_FRAME, 0xF, NOT_MASKED, NULL}}; |
| 1221 {FINAL_FRAME, 0xF, NOT_MASKED, NULL}}; | |
| 1222 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 1221 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 1223 set_stream(stream.Pass()); | 1222 set_stream(stream.Pass()); |
| 1224 deleting_ = EVENT_ON_FAIL_CHANNEL; | 1223 deleting_ = EVENT_ON_FAIL_CHANNEL; |
| 1225 | 1224 |
| 1226 CreateChannelAndConnectSuccessfully(); | 1225 CreateChannelAndConnectSuccessfully(); |
| 1227 EXPECT_EQ(NULL, channel_.get()); | 1226 EXPECT_EQ(NULL, channel_.get()); |
| 1228 } | 1227 } |
| 1229 | 1228 |
| 1230 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToPongAfterClose) { | 1229 TEST_F(WebSocketChannelDeletingTest, FailChannelDueToPongAfterClose) { |
| 1231 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1230 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 deleting_ = EVENT_ON_FAIL_CHANNEL; | 1277 deleting_ = EVENT_ON_FAIL_CHANNEL; |
| 1279 | 1278 |
| 1280 CreateChannelAndConnectSuccessfully(); | 1279 CreateChannelAndConnectSuccessfully(); |
| 1281 EXPECT_EQ(NULL, channel_.get()); | 1280 EXPECT_EQ(NULL, channel_.get()); |
| 1282 } | 1281 } |
| 1283 | 1282 |
| 1284 TEST_F(WebSocketChannelDeletingTest, FailChannelDueInvalidCloseReason) { | 1283 TEST_F(WebSocketChannelDeletingTest, FailChannelDueInvalidCloseReason) { |
| 1285 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1284 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 1286 new ReadableFakeWebSocketStream); | 1285 new ReadableFakeWebSocketStream); |
| 1287 static const InitFrame frames[] = { | 1286 static const InitFrame frames[] = { |
| 1288 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 1287 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 1289 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}}; | 1288 CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}}; |
| 1290 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 1289 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 1291 set_stream(stream.Pass()); | 1290 set_stream(stream.Pass()); |
| 1292 deleting_ = EVENT_ON_FAIL_CHANNEL; | 1291 deleting_ = EVENT_ON_FAIL_CHANNEL; |
| 1293 | 1292 |
| 1294 CreateChannelAndConnectSuccessfully(); | 1293 CreateChannelAndConnectSuccessfully(); |
| 1295 EXPECT_EQ(NULL, channel_.get()); | 1294 EXPECT_EQ(NULL, channel_.get()); |
| 1296 } | 1295 } |
| 1297 | 1296 |
| 1298 TEST_F(WebSocketChannelEventInterfaceTest, ConnectSuccessReported) { | 1297 TEST_F(WebSocketChannelEventInterfaceTest, ConnectSuccessReported) { |
| 1299 // false means success. | 1298 // false means success. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 | 1363 |
| 1365 CreateChannelAndConnectSuccessfully(); | 1364 CreateChannelAndConnectSuccessfully(); |
| 1366 } | 1365 } |
| 1367 | 1366 |
| 1368 // A remote server could accept the handshake, but then immediately send a | 1367 // A remote server could accept the handshake, but then immediately send a |
| 1369 // Close frame. | 1368 // Close frame. |
| 1370 TEST_F(WebSocketChannelEventInterfaceTest, CloseAfterHandshake) { | 1369 TEST_F(WebSocketChannelEventInterfaceTest, CloseAfterHandshake) { |
| 1371 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1370 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 1372 new ReadableFakeWebSocketStream); | 1371 new ReadableFakeWebSocketStream); |
| 1373 static const InitFrame frames[] = { | 1372 static const InitFrame frames[] = { |
| 1374 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 1373 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 1375 NOT_MASKED, CLOSE_DATA(SERVER_ERROR, "Internal Server Error")}}; | 1374 CLOSE_DATA(SERVER_ERROR, "Internal Server Error")}}; |
| 1376 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 1375 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 1377 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, | 1376 stream->PrepareReadFramesError(ReadableFakeWebSocketStream::SYNC, |
| 1378 ERR_CONNECTION_CLOSED); | 1377 ERR_CONNECTION_CLOSED); |
| 1379 set_stream(stream.Pass()); | 1378 set_stream(stream.Pass()); |
| 1380 { | 1379 { |
| 1381 InSequence s; | 1380 InSequence s; |
| 1382 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 1381 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 1383 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1382 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 1384 EXPECT_CALL(*event_interface_, OnClosingHandshake()); | 1383 EXPECT_CALL(*event_interface_, OnClosingHandshake()); |
| 1385 EXPECT_CALL( | 1384 EXPECT_CALL( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 // Data frames are delivered the same regardless of how many reads they arrive | 1470 // Data frames are delivered the same regardless of how many reads they arrive |
| 1472 // as. | 1471 // as. |
| 1473 TEST_F(WebSocketChannelEventInterfaceTest, FragmentedMessage) { | 1472 TEST_F(WebSocketChannelEventInterfaceTest, FragmentedMessage) { |
| 1474 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1473 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 1475 new ReadableFakeWebSocketStream); | 1474 new ReadableFakeWebSocketStream); |
| 1476 // Here we have one message which arrived in five frames split across three | 1475 // Here we have one message which arrived in five frames split across three |
| 1477 // reads. It may have been reframed on arrival, but this class doesn't care | 1476 // reads. It may have been reframed on arrival, but this class doesn't care |
| 1478 // about that. | 1477 // about that. |
| 1479 static const InitFrame frames1[] = { | 1478 static const InitFrame frames1[] = { |
| 1480 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "THREE"}, | 1479 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "THREE"}, |
| 1481 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 1480 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 1482 NOT_MASKED, " "}}; | 1481 " "}}; |
| 1483 static const InitFrame frames2[] = { | 1482 static const InitFrame frames2[] = { |
| 1484 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 1483 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 1485 NOT_MASKED, "SMALL"}}; | 1484 "SMALL"}}; |
| 1486 static const InitFrame frames3[] = { | 1485 static const InitFrame frames3[] = { |
| 1487 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 1486 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 1488 NOT_MASKED, " "}, | 1487 " "}, |
| 1489 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 1488 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 1490 NOT_MASKED, "FRAMES"}}; | 1489 "FRAMES"}}; |
| 1491 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1); | 1490 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1); |
| 1492 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames2); | 1491 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames2); |
| 1493 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames3); | 1492 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames3); |
| 1494 set_stream(stream.Pass()); | 1493 set_stream(stream.Pass()); |
| 1495 { | 1494 { |
| 1496 InSequence s; | 1495 InSequence s; |
| 1497 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 1496 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 1498 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1497 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 1499 EXPECT_CALL( | 1498 EXPECT_CALL( |
| 1500 *event_interface_, | 1499 *event_interface_, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 base::MessageLoop::current()->RunUntilIdle(); | 1619 base::MessageLoop::current()->RunUntilIdle(); |
| 1621 } | 1620 } |
| 1622 | 1621 |
| 1623 // RFC6455 5.4 "Control frames ... MAY be injected in the middle of a | 1622 // RFC6455 5.4 "Control frames ... MAY be injected in the middle of a |
| 1624 // fragmented message." | 1623 // fragmented message." |
| 1625 TEST_F(WebSocketChannelEventInterfaceTest, ControlFrameInDataMessage) { | 1624 TEST_F(WebSocketChannelEventInterfaceTest, ControlFrameInDataMessage) { |
| 1626 scoped_ptr<ReadableFakeWebSocketStream> stream( | 1625 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 1627 new ReadableFakeWebSocketStream); | 1626 new ReadableFakeWebSocketStream); |
| 1628 // We have one message of type Text split into two frames. In the middle is a | 1627 // We have one message of type Text split into two frames. In the middle is a |
| 1629 // control message of type Pong. | 1628 // control message of type Pong. |
| 1630 static const InitFrame frames1[] = { | 1629 static const InitFrame frames1[] = {{NOT_FINAL_FRAME, |
| 1631 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, | 1630 WebSocketFrameHeader::kOpCodeText, |
| 1632 NOT_MASKED, "SPLIT "}}; | 1631 NOT_MASKED, "SPLIT "}}; |
| 1633 static const InitFrame frames2[] = { | 1632 static const InitFrame frames2[] = { |
| 1634 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, ""}}; | 1633 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, NOT_MASKED, ""}}; |
| 1635 static const InitFrame frames3[] = { | 1634 static const InitFrame frames3[] = { |
| 1636 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 1635 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 1637 NOT_MASKED, "MESSAGE"}}; | 1636 "MESSAGE"}}; |
| 1638 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1); | 1637 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames1); |
| 1639 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames2); | 1638 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames2); |
| 1640 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames3); | 1639 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames3); |
| 1641 set_stream(stream.Pass()); | 1640 set_stream(stream.Pass()); |
| 1642 { | 1641 { |
| 1643 InSequence s; | 1642 InSequence s; |
| 1644 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 1643 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 1645 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 1644 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 1646 EXPECT_CALL( | 1645 EXPECT_CALL( |
| 1647 *event_interface_, | 1646 *event_interface_, |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 CreateChannelAndConnect(); | 1972 CreateChannelAndConnect(); |
| 1974 | 1973 |
| 1975 WebSocketStream::ConnectDelegate* connect_delegate = | 1974 WebSocketStream::ConnectDelegate* connect_delegate = |
| 1976 connect_data_.creator.connect_delegate.get(); | 1975 connect_data_.creator.connect_delegate.get(); |
| 1977 GURL url("ws://www.example.com/"); | 1976 GURL url("ws://www.example.com/"); |
| 1978 scoped_ptr<WebSocketHandshakeRequestInfo> request_info( | 1977 scoped_ptr<WebSocketHandshakeRequestInfo> request_info( |
| 1979 new WebSocketHandshakeRequestInfo(url, base::Time())); | 1978 new WebSocketHandshakeRequestInfo(url, base::Time())); |
| 1980 scoped_refptr<HttpResponseHeaders> response_headers( | 1979 scoped_refptr<HttpResponseHeaders> response_headers( |
| 1981 new HttpResponseHeaders("")); | 1980 new HttpResponseHeaders("")); |
| 1982 scoped_ptr<WebSocketHandshakeResponseInfo> response_info( | 1981 scoped_ptr<WebSocketHandshakeResponseInfo> response_info( |
| 1983 new WebSocketHandshakeResponseInfo(url, | 1982 new WebSocketHandshakeResponseInfo( |
| 1984 200, | 1983 url, 200, "OK", response_headers, base::Time())); |
| 1985 "OK", | |
| 1986 response_headers, | |
| 1987 base::Time())); | |
| 1988 connect_delegate->OnStartOpeningHandshake(request_info.Pass()); | 1984 connect_delegate->OnStartOpeningHandshake(request_info.Pass()); |
| 1989 connect_delegate->OnFinishOpeningHandshake(response_info.Pass()); | 1985 connect_delegate->OnFinishOpeningHandshake(response_info.Pass()); |
| 1990 | 1986 |
| 1991 connect_delegate->OnFailure("bye"); | 1987 connect_delegate->OnFailure("bye"); |
| 1992 base::MessageLoop::current()->RunUntilIdle(); | 1988 base::MessageLoop::current()->RunUntilIdle(); |
| 1993 } | 1989 } |
| 1994 | 1990 |
| 1995 // Any frame after close is invalid. This test uses a Text frame. See also | 1991 // Any frame after close is invalid. This test uses a Text frame. See also |
| 1996 // test "PingAfterCloseIfRejected". | 1992 // test "PingAfterCloseIfRejected". |
| 1997 TEST_F(WebSocketChannelEventInterfaceTest, DataAfterCloseIsRejected) { | 1993 TEST_F(WebSocketChannelEventInterfaceTest, DataAfterCloseIsRejected) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 | 2030 |
| 2035 CreateChannelAndConnectSuccessfully(); | 2031 CreateChannelAndConnectSuccessfully(); |
| 2036 } | 2032 } |
| 2037 | 2033 |
| 2038 // A Close frame with a reserved status code also elicits a specific console | 2034 // A Close frame with a reserved status code also elicits a specific console |
| 2039 // error message. | 2035 // error message. |
| 2040 TEST_F(WebSocketChannelEventInterfaceTest, ClosePayloadReservedStatusMessage) { | 2036 TEST_F(WebSocketChannelEventInterfaceTest, ClosePayloadReservedStatusMessage) { |
| 2041 scoped_ptr<ReadableFakeWebSocketStream> stream( | 2037 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 2042 new ReadableFakeWebSocketStream); | 2038 new ReadableFakeWebSocketStream); |
| 2043 static const InitFrame frames[] = { | 2039 static const InitFrame frames[] = { |
| 2044 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2040 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 2045 NOT_MASKED, CLOSE_DATA(ABNORMAL_CLOSURE, "Not valid on wire")}}; | 2041 CLOSE_DATA(ABNORMAL_CLOSURE, "Not valid on wire")}}; |
| 2046 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 2042 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 2047 set_stream(stream.Pass()); | 2043 set_stream(stream.Pass()); |
| 2048 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 2044 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 2049 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 2045 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 2050 EXPECT_CALL( | 2046 EXPECT_CALL( |
| 2051 *event_interface_, | 2047 *event_interface_, |
| 2052 OnFailChannel( | 2048 OnFailChannel( |
| 2053 "Received a broken close frame containing a reserved status code.")); | 2049 "Received a broken close frame containing a reserved status code.")); |
| 2054 | 2050 |
| 2055 CreateChannelAndConnectSuccessfully(); | 2051 CreateChannelAndConnectSuccessfully(); |
| 2056 } | 2052 } |
| 2057 | 2053 |
| 2058 // A Close frame with invalid UTF-8 also elicits a specific console error | 2054 // A Close frame with invalid UTF-8 also elicits a specific console error |
| 2059 // message. | 2055 // message. |
| 2060 TEST_F(WebSocketChannelEventInterfaceTest, ClosePayloadInvalidReason) { | 2056 TEST_F(WebSocketChannelEventInterfaceTest, ClosePayloadInvalidReason) { |
| 2061 scoped_ptr<ReadableFakeWebSocketStream> stream( | 2057 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 2062 new ReadableFakeWebSocketStream); | 2058 new ReadableFakeWebSocketStream); |
| 2063 static const InitFrame frames[] = { | 2059 static const InitFrame frames[] = { |
| 2064 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2060 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 2065 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}}; | 2061 CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}}; |
| 2066 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 2062 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 2067 set_stream(stream.Pass()); | 2063 set_stream(stream.Pass()); |
| 2068 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 2064 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 2069 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 2065 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 2070 EXPECT_CALL( | 2066 EXPECT_CALL( |
| 2071 *event_interface_, | 2067 *event_interface_, |
| 2072 OnFailChannel( | 2068 OnFailChannel("Received a broken close frame containing invalid UTF-8.")); |
| 2073 "Received a broken close frame containing invalid UTF-8.")); | |
| 2074 | 2069 |
| 2075 CreateChannelAndConnectSuccessfully(); | 2070 CreateChannelAndConnectSuccessfully(); |
| 2076 } | 2071 } |
| 2077 | 2072 |
| 2078 // The reserved bits must all be clear on received frames. Extensions should | 2073 // 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. | 2074 // clear the bits when they are set correctly before passing on the frame. |
| 2080 TEST_F(WebSocketChannelEventInterfaceTest, ReservedBitsMustNotBeSet) { | 2075 TEST_F(WebSocketChannelEventInterfaceTest, ReservedBitsMustNotBeSet) { |
| 2081 scoped_ptr<ReadableFakeWebSocketStream> stream( | 2076 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 2082 new ReadableFakeWebSocketStream); | 2077 new ReadableFakeWebSocketStream); |
| 2083 static const InitFrame frames[] = { | 2078 static const InitFrame frames[] = { |
| 2084 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, | 2079 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "sakana"}}; |
| 2085 NOT_MASKED, "sakana"}}; | |
| 2086 // It is not worth adding support for reserved bits to InitFrame just for this | 2080 // It is not worth adding support for reserved bits to InitFrame just for this |
| 2087 // one test, so set the bit manually. | 2081 // one test, so set the bit manually. |
| 2088 ScopedVector<WebSocketFrame> raw_frames = CreateFrameVector(frames); | 2082 ScopedVector<WebSocketFrame> raw_frames = CreateFrameVector(frames); |
| 2089 raw_frames[0]->header.reserved1 = true; | 2083 raw_frames[0]->header.reserved1 = true; |
| 2090 stream->PrepareRawReadFrames( | 2084 stream->PrepareRawReadFrames( |
| 2091 ReadableFakeWebSocketStream::SYNC, OK, raw_frames.Pass()); | 2085 ReadableFakeWebSocketStream::SYNC, OK, raw_frames.Pass()); |
| 2092 set_stream(stream.Pass()); | 2086 set_stream(stream.Pass()); |
| 2093 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 2087 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 2094 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 2088 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 2095 EXPECT_CALL(*event_interface_, | 2089 EXPECT_CALL(*event_interface_, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 completion.WaitForResult(); | 2127 completion.WaitForResult(); |
| 2134 } | 2128 } |
| 2135 | 2129 |
| 2136 // The closing handshake times out and sends an OnDropChannel event if a Close | 2130 // The closing handshake times out and sends an OnDropChannel event if a Close |
| 2137 // message is received but the connection isn't closed by the remote host. | 2131 // message is received but the connection isn't closed by the remote host. |
| 2138 TEST_F(WebSocketChannelEventInterfaceTest, | 2132 TEST_F(WebSocketChannelEventInterfaceTest, |
| 2139 ServerInitiatedClosingHandshakeTimesOut) { | 2133 ServerInitiatedClosingHandshakeTimesOut) { |
| 2140 scoped_ptr<ReadableFakeWebSocketStream> stream( | 2134 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 2141 new ReadableFakeWebSocketStream); | 2135 new ReadableFakeWebSocketStream); |
| 2142 static const InitFrame frames[] = { | 2136 static const InitFrame frames[] = { |
| 2143 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2137 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 2144 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; | 2138 CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; |
| 2145 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); | 2139 stream->PrepareReadFrames(ReadableFakeWebSocketStream::ASYNC, OK, frames); |
| 2146 set_stream(stream.Pass()); | 2140 set_stream(stream.Pass()); |
| 2147 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 2141 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 2148 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 2142 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 2149 Checkpoint checkpoint; | 2143 Checkpoint checkpoint; |
| 2150 TestClosure completion; | 2144 TestClosure completion; |
| 2151 { | 2145 { |
| 2152 InSequence s; | 2146 InSequence s; |
| 2153 EXPECT_CALL(checkpoint, Call(1)); | 2147 EXPECT_CALL(checkpoint, Call(1)); |
| 2154 EXPECT_CALL(*event_interface_, OnClosingHandshake()); | 2148 EXPECT_CALL(*event_interface_, OnClosingHandshake()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2210 checkpoint.Call(2); | 2204 checkpoint.Call(2); |
| 2211 } | 2205 } |
| 2212 | 2206 |
| 2213 // We should stop calling ReadFrames() when all quota is used. | 2207 // We should stop calling ReadFrames() when all quota is used. |
| 2214 TEST_F(WebSocketChannelStreamTest, FlowControlStopsReadFrames) { | 2208 TEST_F(WebSocketChannelStreamTest, FlowControlStopsReadFrames) { |
| 2215 static const InitFrame frames[] = { | 2209 static const InitFrame frames[] = { |
| 2216 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}}; | 2210 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "FOUR"}}; |
| 2217 | 2211 |
| 2218 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2212 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2219 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2213 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2220 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 2214 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(ReturnFrames(&frames)); |
| 2221 .WillOnce(ReturnFrames(&frames)); | |
| 2222 | 2215 |
| 2223 set_stream(mock_stream_.Pass()); | 2216 set_stream(mock_stream_.Pass()); |
| 2224 CreateChannelAndConnect(); | 2217 CreateChannelAndConnect(); |
| 2225 channel_->SendFlowControl(4); | 2218 channel_->SendFlowControl(4); |
| 2226 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); | 2219 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); |
| 2227 } | 2220 } |
| 2228 | 2221 |
| 2229 // Providing extra quota causes ReadFrames() to be called again. | 2222 // Providing extra quota causes ReadFrames() to be called again. |
| 2230 TEST_F(WebSocketChannelStreamTest, FlowControlStartsWithMoreQuota) { | 2223 TEST_F(WebSocketChannelStreamTest, FlowControlStartsWithMoreQuota) { |
| 2231 static const InitFrame frames[] = { | 2224 static const InitFrame frames[] = { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2352 | 2345 |
| 2353 // A message split into multiple frames which is further split due to quota | 2346 // A message split into multiple frames which is further split due to quota |
| 2354 // restrictions should stil be correct. | 2347 // restrictions should stil be correct. |
| 2355 // TODO(ricea): The message ends up split into more frames than are strictly | 2348 // TODO(ricea): The message ends up split into more frames than are strictly |
| 2356 // necessary. The complexity/performance tradeoffs here need further | 2349 // necessary. The complexity/performance tradeoffs here need further |
| 2357 // examination. | 2350 // examination. |
| 2358 TEST_F(WebSocketChannelFlowControlTest, MultipleFrameSplit) { | 2351 TEST_F(WebSocketChannelFlowControlTest, MultipleFrameSplit) { |
| 2359 scoped_ptr<ReadableFakeWebSocketStream> stream( | 2352 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 2360 new ReadableFakeWebSocketStream); | 2353 new ReadableFakeWebSocketStream); |
| 2361 static const InitFrame frames[] = { | 2354 static const InitFrame frames[] = { |
| 2362 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, | 2355 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, |
| 2363 NOT_MASKED, "FIRST FRAME IS 25 BYTES. "}, | 2356 "FIRST FRAME IS 25 BYTES. "}, |
| 2364 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 2357 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 2365 NOT_MASKED, "SECOND FRAME IS 26 BYTES. "}, | 2358 "SECOND FRAME IS 26 BYTES. "}, |
| 2366 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 2359 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 2367 NOT_MASKED, "FINAL FRAME IS 24 BYTES."}}; | 2360 "FINAL FRAME IS 24 BYTES."}}; |
| 2368 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 2361 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 2369 set_stream(stream.Pass()); | 2362 set_stream(stream.Pass()); |
| 2370 { | 2363 { |
| 2371 InSequence s; | 2364 InSequence s; |
| 2372 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 2365 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 2373 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 2366 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 2374 EXPECT_CALL(*event_interface_, | 2367 EXPECT_CALL(*event_interface_, |
| 2375 OnDataFrame(false, | 2368 OnDataFrame(false, |
| 2376 WebSocketFrameHeader::kOpCodeText, | 2369 WebSocketFrameHeader::kOpCodeText, |
| 2377 AsVector("FIRST FRAME IS"))); | 2370 AsVector("FIRST FRAME IS"))); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2396 channel_->SendFlowControl(43); | 2389 channel_->SendFlowControl(43); |
| 2397 channel_->SendFlowControl(32); | 2390 channel_->SendFlowControl(32); |
| 2398 } | 2391 } |
| 2399 | 2392 |
| 2400 // An empty message handled when we are out of quota must not be delivered | 2393 // An empty message handled when we are out of quota must not be delivered |
| 2401 // out-of-order with respect to other messages. | 2394 // out-of-order with respect to other messages. |
| 2402 TEST_F(WebSocketChannelFlowControlTest, EmptyMessageNoQuota) { | 2395 TEST_F(WebSocketChannelFlowControlTest, EmptyMessageNoQuota) { |
| 2403 scoped_ptr<ReadableFakeWebSocketStream> stream( | 2396 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 2404 new ReadableFakeWebSocketStream); | 2397 new ReadableFakeWebSocketStream); |
| 2405 static const InitFrame frames[] = { | 2398 static const InitFrame frames[] = { |
| 2406 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, | 2399 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, |
| 2407 NOT_MASKED, "FIRST MESSAGE"}, | 2400 "FIRST MESSAGE"}, |
| 2408 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, | 2401 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, NULL}, |
| 2409 NOT_MASKED, NULL}, | 2402 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, |
| 2410 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, | 2403 "THIRD MESSAGE"}}; |
| 2411 NOT_MASKED, "THIRD MESSAGE"}}; | |
| 2412 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 2404 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 2413 set_stream(stream.Pass()); | 2405 set_stream(stream.Pass()); |
| 2414 { | 2406 { |
| 2415 InSequence s; | 2407 InSequence s; |
| 2416 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 2408 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 2417 EXPECT_CALL(*event_interface_, OnFlowControl(_)); | 2409 EXPECT_CALL(*event_interface_, OnFlowControl(_)); |
| 2418 EXPECT_CALL(*event_interface_, | 2410 EXPECT_CALL( |
| 2419 OnDataFrame(false, | 2411 *event_interface_, |
| 2420 WebSocketFrameHeader::kOpCodeText, | 2412 OnDataFrame( |
| 2421 AsVector("FIRST "))); | 2413 false, WebSocketFrameHeader::kOpCodeText, AsVector("FIRST "))); |
| 2422 EXPECT_CALL(*event_interface_, | 2414 EXPECT_CALL(*event_interface_, |
| 2423 OnDataFrame(true, | 2415 OnDataFrame(true, |
| 2424 WebSocketFrameHeader::kOpCodeContinuation, | 2416 WebSocketFrameHeader::kOpCodeContinuation, |
| 2425 AsVector("MESSAGE"))); | 2417 AsVector("MESSAGE"))); |
| 2418 EXPECT_CALL( |
| 2419 *event_interface_, |
| 2420 OnDataFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector(""))); |
| 2426 EXPECT_CALL(*event_interface_, | 2421 EXPECT_CALL(*event_interface_, |
| 2427 OnDataFrame(true, | 2422 OnDataFrame(true, |
| 2428 WebSocketFrameHeader::kOpCodeText, | 2423 WebSocketFrameHeader::kOpCodeText, |
| 2429 AsVector(""))); | |
| 2430 EXPECT_CALL(*event_interface_, | |
| 2431 OnDataFrame(true, | |
| 2432 WebSocketFrameHeader::kOpCodeText, | |
| 2433 AsVector("THIRD MESSAGE"))); | 2424 AsVector("THIRD MESSAGE"))); |
| 2434 } | 2425 } |
| 2435 | 2426 |
| 2436 CreateChannelAndConnectWithQuota(6); | 2427 CreateChannelAndConnectWithQuota(6); |
| 2437 channel_->SendFlowControl(128); | 2428 channel_->SendFlowControl(128); |
| 2438 } | 2429 } |
| 2439 | 2430 |
| 2440 // RFC6455 5.1 "a client MUST mask all frames that it sends to the server". | 2431 // RFC6455 5.1 "a client MUST mask all frames that it sends to the server". |
| 2441 // WebSocketChannel actually only sets the mask bit in the header, it doesn't | 2432 // WebSocketChannel actually only sets the mask bit in the header, it doesn't |
| 2442 // perform masking itself (not all transports actually use masking). | 2433 // perform masking itself (not all transports actually use masking). |
| 2443 TEST_F(WebSocketChannelStreamTest, SentFramesAreMasked) { | 2434 TEST_F(WebSocketChannelStreamTest, SentFramesAreMasked) { |
| 2444 static const InitFrame expected[] = { | 2435 static const InitFrame expected[] = {{FINAL_FRAME, |
| 2445 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, | 2436 WebSocketFrameHeader::kOpCodeText, |
| 2446 MASKED, "NEEDS MASKING"}}; | 2437 MASKED, "NEEDS MASKING"}}; |
| 2447 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2438 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2448 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2439 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2449 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); | 2440 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); |
| 2450 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2441 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 2451 .WillOnce(Return(OK)); | 2442 .WillOnce(Return(OK)); |
| 2452 | 2443 |
| 2453 CreateChannelAndConnectSuccessfully(); | 2444 CreateChannelAndConnectSuccessfully(); |
| 2454 channel_->SendFrame( | 2445 channel_->SendFrame( |
| 2455 true, WebSocketFrameHeader::kOpCodeText, AsVector("NEEDS MASKING")); | 2446 true, WebSocketFrameHeader::kOpCodeText, AsVector("NEEDS MASKING")); |
| 2456 } | 2447 } |
| 2457 | 2448 |
| 2458 // RFC6455 5.5.1 "The application MUST NOT send any more data frames after | 2449 // RFC6455 5.5.1 "The application MUST NOT send any more data frames after |
| 2459 // sending a Close frame." | 2450 // sending a Close frame." |
| 2460 TEST_F(WebSocketChannelStreamTest, NothingIsSentAfterClose) { | 2451 TEST_F(WebSocketChannelStreamTest, NothingIsSentAfterClose) { |
| 2461 static const InitFrame expected[] = { | 2452 static const InitFrame expected[] = { |
| 2462 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2453 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 2463 MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; | 2454 CLOSE_DATA(NORMAL_CLOSURE, "Success")}}; |
| 2464 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2455 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2465 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2456 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2466 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); | 2457 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); |
| 2467 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2458 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 2468 .WillOnce(Return(OK)); | 2459 .WillOnce(Return(OK)); |
| 2469 | 2460 |
| 2470 CreateChannelAndConnectSuccessfully(); | 2461 CreateChannelAndConnectSuccessfully(); |
| 2471 channel_->StartClosingHandshake(1000, "Success"); | 2462 channel_->StartClosingHandshake(1000, "Success"); |
| 2472 channel_->SendFrame( | 2463 channel_->SendFrame( |
| 2473 true, WebSocketFrameHeader::kOpCodeText, AsVector("SHOULD BE IGNORED")); | 2464 true, WebSocketFrameHeader::kOpCodeText, AsVector("SHOULD BE IGNORED")); |
| 2474 } | 2465 } |
| 2475 | 2466 |
| 2476 // RFC6455 5.5.1 "If an endpoint receives a Close frame and did not previously | 2467 // RFC6455 5.5.1 "If an endpoint receives a Close frame and did not previously |
| 2477 // send a Close frame, the endpoint MUST send a Close frame in response." | 2468 // send a Close frame, the endpoint MUST send a Close frame in response." |
| 2478 TEST_F(WebSocketChannelStreamTest, CloseIsEchoedBack) { | 2469 TEST_F(WebSocketChannelStreamTest, CloseIsEchoedBack) { |
| 2479 static const InitFrame frames[] = { | 2470 static const InitFrame frames[] = { |
| 2480 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2471 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 2481 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; | 2472 CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; |
| 2482 static const InitFrame expected[] = { | 2473 static const InitFrame expected[] = { |
| 2483 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2474 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 2484 MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; | 2475 CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; |
| 2485 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2476 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2486 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2477 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2487 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 2478 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 2488 .WillOnce(ReturnFrames(&frames)) | 2479 .WillOnce(ReturnFrames(&frames)) |
| 2489 .WillRepeatedly(Return(ERR_IO_PENDING)); | 2480 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 2490 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2481 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 2491 .WillOnce(Return(OK)); | 2482 .WillOnce(Return(OK)); |
| 2492 | 2483 |
| 2493 CreateChannelAndConnectSuccessfully(); | 2484 CreateChannelAndConnectSuccessfully(); |
| 2494 } | 2485 } |
| 2495 | 2486 |
| 2496 // The converse of the above case; after sending a Close frame, we should not | 2487 // The converse of the above case; after sending a Close frame, we should not |
| 2497 // send another one. | 2488 // send another one. |
| 2498 TEST_F(WebSocketChannelStreamTest, CloseOnlySentOnce) { | 2489 TEST_F(WebSocketChannelStreamTest, CloseOnlySentOnce) { |
| 2499 static const InitFrame expected[] = { | 2490 static const InitFrame expected[] = { |
| 2500 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2491 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 2501 MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; | 2492 CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; |
| 2502 static const InitFrame frames_init[] = { | 2493 static const InitFrame frames_init[] = { |
| 2503 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2494 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 2504 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; | 2495 CLOSE_DATA(NORMAL_CLOSURE, "Close")}}; |
| 2505 | 2496 |
| 2506 // We store the parameters that were passed to ReadFrames() so that we can | 2497 // We store the parameters that were passed to ReadFrames() so that we can |
| 2507 // call them explicitly later. | 2498 // call them explicitly later. |
| 2508 CompletionCallback read_callback; | 2499 CompletionCallback read_callback; |
| 2509 ScopedVector<WebSocketFrame>* frames = NULL; | 2500 ScopedVector<WebSocketFrame>* frames = NULL; |
| 2510 | 2501 |
| 2511 // These are not interesting. | 2502 // These are not interesting. |
| 2512 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2503 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2513 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2504 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2514 | 2505 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2536 channel_->StartClosingHandshake(kWebSocketNormalClosure, "Close"); | 2527 channel_->StartClosingHandshake(kWebSocketNormalClosure, "Close"); |
| 2537 checkpoint.Call(2); | 2528 checkpoint.Call(2); |
| 2538 | 2529 |
| 2539 *frames = CreateFrameVector(frames_init); | 2530 *frames = CreateFrameVector(frames_init); |
| 2540 read_callback.Run(OK); | 2531 read_callback.Run(OK); |
| 2541 checkpoint.Call(3); | 2532 checkpoint.Call(3); |
| 2542 } | 2533 } |
| 2543 | 2534 |
| 2544 // Invalid close status codes should not be sent on the network. | 2535 // Invalid close status codes should not be sent on the network. |
| 2545 TEST_F(WebSocketChannelStreamTest, InvalidCloseStatusCodeNotSent) { | 2536 TEST_F(WebSocketChannelStreamTest, InvalidCloseStatusCodeNotSent) { |
| 2546 static const InitFrame expected[] = { | 2537 static const InitFrame expected[] = {{FINAL_FRAME, |
| 2547 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2538 WebSocketFrameHeader::kOpCodeClose, |
| 2548 MASKED, CLOSE_DATA(SERVER_ERROR, "")}}; | 2539 MASKED, CLOSE_DATA(SERVER_ERROR, "")}}; |
| 2549 | 2540 |
| 2550 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2541 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2551 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2542 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2552 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 2543 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); |
| 2553 .WillOnce(Return(ERR_IO_PENDING)); | |
| 2554 | 2544 |
| 2555 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)); | 2545 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)); |
| 2556 | 2546 |
| 2557 CreateChannelAndConnectSuccessfully(); | 2547 CreateChannelAndConnectSuccessfully(); |
| 2558 channel_->StartClosingHandshake(999, ""); | 2548 channel_->StartClosingHandshake(999, ""); |
| 2559 } | 2549 } |
| 2560 | 2550 |
| 2561 // A Close frame with a reason longer than 123 bytes cannot be sent on the | 2551 // A Close frame with a reason longer than 123 bytes cannot be sent on the |
| 2562 // network. | 2552 // network. |
| 2563 TEST_F(WebSocketChannelStreamTest, LongCloseReasonNotSent) { | 2553 TEST_F(WebSocketChannelStreamTest, LongCloseReasonNotSent) { |
| 2564 static const InitFrame expected[] = { | 2554 static const InitFrame expected[] = {{FINAL_FRAME, |
| 2565 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2555 WebSocketFrameHeader::kOpCodeClose, |
| 2566 MASKED, CLOSE_DATA(SERVER_ERROR, "")}}; | 2556 MASKED, CLOSE_DATA(SERVER_ERROR, "")}}; |
| 2567 | 2557 |
| 2568 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2558 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2569 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2559 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2570 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 2560 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); |
| 2571 .WillOnce(Return(ERR_IO_PENDING)); | |
| 2572 | 2561 |
| 2573 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)); | 2562 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)); |
| 2574 | 2563 |
| 2575 CreateChannelAndConnectSuccessfully(); | 2564 CreateChannelAndConnectSuccessfully(); |
| 2576 channel_->StartClosingHandshake(1000, std::string(124, 'A')); | 2565 channel_->StartClosingHandshake(1000, std::string(124, 'A')); |
| 2577 } | 2566 } |
| 2578 | 2567 |
| 2579 // We generate code 1005, kWebSocketErrorNoStatusReceived, when there is no | 2568 // We generate code 1005, kWebSocketErrorNoStatusReceived, when there is no |
| 2580 // status in the Close message from the other side. Code 1005 is not allowed to | 2569 // status in the Close message from the other side. Code 1005 is not allowed to |
| 2581 // appear on the wire, so we should not echo it back. See test | 2570 // appear on the wire, so we should not echo it back. See test |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2610 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2599 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 2611 .WillOnce(Return(OK)); | 2600 .WillOnce(Return(OK)); |
| 2612 | 2601 |
| 2613 CreateChannelAndConnectSuccessfully(); | 2602 CreateChannelAndConnectSuccessfully(); |
| 2614 } | 2603 } |
| 2615 | 2604 |
| 2616 // Receiving an invalid UTF-8 payload in a Close frame causes us to fail the | 2605 // Receiving an invalid UTF-8 payload in a Close frame causes us to fail the |
| 2617 // connection. | 2606 // connection. |
| 2618 TEST_F(WebSocketChannelStreamTest, CloseFrameInvalidUtf8) { | 2607 TEST_F(WebSocketChannelStreamTest, CloseFrameInvalidUtf8) { |
| 2619 static const InitFrame frames[] = { | 2608 static const InitFrame frames[] = { |
| 2620 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2609 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 2621 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}}; | 2610 CLOSE_DATA(NORMAL_CLOSURE, "\xFF")}}; |
| 2622 static const InitFrame expected[] = { | 2611 static const InitFrame expected[] = { |
| 2623 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2612 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 2624 MASKED, CLOSE_DATA(PROTOCOL_ERROR, "Invalid UTF-8 in Close frame")}}; | 2613 CLOSE_DATA(PROTOCOL_ERROR, "Invalid UTF-8 in Close frame")}}; |
| 2625 | 2614 |
| 2626 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2615 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2627 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2616 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2628 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 2617 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 2629 .WillOnce(ReturnFrames(&frames)) | 2618 .WillOnce(ReturnFrames(&frames)) |
| 2630 .WillRepeatedly(Return(ERR_IO_PENDING)); | 2619 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 2631 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2620 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 2632 .WillOnce(Return(OK)); | 2621 .WillOnce(Return(OK)); |
| 2633 EXPECT_CALL(*mock_stream_, Close()); | 2622 EXPECT_CALL(*mock_stream_, Close()); |
| 2634 | 2623 |
| 2635 CreateChannelAndConnectSuccessfully(); | 2624 CreateChannelAndConnectSuccessfully(); |
| 2636 } | 2625 } |
| 2637 | 2626 |
| 2638 // RFC6455 5.5.2 "Upon receipt of a Ping frame, an endpoint MUST send a Pong | 2627 // RFC6455 5.5.2 "Upon receipt of a Ping frame, an endpoint MUST send a Pong |
| 2639 // frame in response" | 2628 // frame in response" |
| 2640 // 5.5.3 "A Pong frame sent in response to a Ping frame must have identical | 2629 // 5.5.3 "A Pong frame sent in response to a Ping frame must have identical |
| 2641 // "Application data" as found in the message body of the Ping frame being | 2630 // "Application data" as found in the message body of the Ping frame being |
| 2642 // replied to." | 2631 // replied to." |
| 2643 TEST_F(WebSocketChannelStreamTest, PingRepliedWithPong) { | 2632 TEST_F(WebSocketChannelStreamTest, PingRepliedWithPong) { |
| 2644 static const InitFrame frames[] = { | 2633 static const InitFrame frames[] = {{FINAL_FRAME, |
| 2645 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePing, | 2634 WebSocketFrameHeader::kOpCodePing, |
| 2646 NOT_MASKED, "Application data"}}; | 2635 NOT_MASKED, "Application data"}}; |
| 2647 static const InitFrame expected[] = { | 2636 static const InitFrame expected[] = {{FINAL_FRAME, |
| 2648 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, | 2637 WebSocketFrameHeader::kOpCodePong, |
| 2649 MASKED, "Application data"}}; | 2638 MASKED, "Application data"}}; |
| 2650 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2639 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2651 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2640 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2652 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 2641 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 2653 .WillOnce(ReturnFrames(&frames)) | 2642 .WillOnce(ReturnFrames(&frames)) |
| 2654 .WillRepeatedly(Return(ERR_IO_PENDING)); | 2643 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 2655 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2644 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 2656 .WillOnce(Return(OK)); | 2645 .WillOnce(Return(OK)); |
| 2657 | 2646 |
| 2658 CreateChannelAndConnectSuccessfully(); | 2647 CreateChannelAndConnectSuccessfully(); |
| 2659 } | 2648 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2670 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 2659 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 2671 .WillOnce(ReturnFrames(&frames)) | 2660 .WillOnce(ReturnFrames(&frames)) |
| 2672 .WillRepeatedly(Return(ERR_IO_PENDING)); | 2661 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 2673 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2662 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 2674 .WillOnce(Return(OK)); | 2663 .WillOnce(Return(OK)); |
| 2675 | 2664 |
| 2676 CreateChannelAndConnectSuccessfully(); | 2665 CreateChannelAndConnectSuccessfully(); |
| 2677 } | 2666 } |
| 2678 | 2667 |
| 2679 TEST_F(WebSocketChannelStreamTest, PongInTheMiddleOfDataMessage) { | 2668 TEST_F(WebSocketChannelStreamTest, PongInTheMiddleOfDataMessage) { |
| 2680 static const InitFrame frames[] = { | 2669 static const InitFrame frames[] = {{FINAL_FRAME, |
| 2681 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePing, | 2670 WebSocketFrameHeader::kOpCodePing, |
| 2682 NOT_MASKED, "Application data"}}; | 2671 NOT_MASKED, "Application data"}}; |
| 2683 static const InitFrame expected1[] = { | 2672 static const InitFrame expected1[] = { |
| 2684 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "Hello "}}; | 2673 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, MASKED, "Hello "}}; |
| 2685 static const InitFrame expected2[] = { | 2674 static const InitFrame expected2[] = {{FINAL_FRAME, |
| 2686 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePong, | 2675 WebSocketFrameHeader::kOpCodePong, |
| 2687 MASKED, "Application data"}}; | 2676 MASKED, "Application data"}}; |
| 2688 static const InitFrame expected3[] = { | 2677 static const InitFrame expected3[] = { |
| 2689 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 2678 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, MASKED, |
| 2690 MASKED, "World"}}; | 2679 "World"}}; |
| 2691 ScopedVector<WebSocketFrame>* read_frames; | 2680 ScopedVector<WebSocketFrame>* read_frames; |
| 2692 CompletionCallback read_callback; | 2681 CompletionCallback read_callback; |
| 2693 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2682 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2694 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2683 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2695 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 2684 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 2696 .WillOnce(DoAll(SaveArg<0>(&read_frames), | 2685 .WillOnce(DoAll(SaveArg<0>(&read_frames), |
| 2697 SaveArg<1>(&read_callback), | 2686 SaveArg<1>(&read_callback), |
| 2698 Return(ERR_IO_PENDING))) | 2687 Return(ERR_IO_PENDING))) |
| 2699 .WillRepeatedly(Return(ERR_IO_PENDING)); | 2688 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 2700 { | 2689 { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2782 channel_->SendFrame(true, | 2771 channel_->SendFrame(true, |
| 2783 WebSocketFrameHeader::kOpCodeText, | 2772 WebSocketFrameHeader::kOpCodeText, |
| 2784 std::vector<char>(1, input_letters[i])); | 2773 std::vector<char>(1, input_letters[i])); |
| 2785 } | 2774 } |
| 2786 write_callback.Run(OK); | 2775 write_callback.Run(OK); |
| 2787 } | 2776 } |
| 2788 | 2777 |
| 2789 // When the renderer sends more on a channel than it has quota for, we send the | 2778 // When the renderer sends more on a channel than it has quota for, we send the |
| 2790 // remote server a kWebSocketErrorGoingAway error code. | 2779 // remote server a kWebSocketErrorGoingAway error code. |
| 2791 TEST_F(WebSocketChannelStreamTest, SendGoingAwayOnRendererQuotaExceeded) { | 2780 TEST_F(WebSocketChannelStreamTest, SendGoingAwayOnRendererQuotaExceeded) { |
| 2792 static const InitFrame expected[] = { | 2781 static const InitFrame expected[] = {{FINAL_FRAME, |
| 2793 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 2782 WebSocketFrameHeader::kOpCodeClose, |
| 2794 MASKED, CLOSE_DATA(GOING_AWAY, "")}}; | 2783 MASKED, CLOSE_DATA(GOING_AWAY, "")}}; |
| 2795 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2784 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 2796 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 2785 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 2797 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); | 2786 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)).WillOnce(Return(ERR_IO_PENDING)); |
| 2798 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 2787 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 2799 .WillOnce(Return(OK)); | 2788 .WillOnce(Return(OK)); |
| 2800 EXPECT_CALL(*mock_stream_, Close()); | 2789 EXPECT_CALL(*mock_stream_, Close()); |
| 2801 | 2790 |
| 2802 CreateChannelAndConnectSuccessfully(); | 2791 CreateChannelAndConnectSuccessfully(); |
| 2803 channel_->SendFrame(true, | 2792 channel_->SendFrame(true, |
| 2804 WebSocketFrameHeader::kOpCodeText, | 2793 WebSocketFrameHeader::kOpCodeText, |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3060 EXPECT_CALL(*mock_stream_, Close()).Times(1); | 3049 EXPECT_CALL(*mock_stream_, Close()).Times(1); |
| 3061 | 3050 |
| 3062 CreateChannelAndConnectSuccessfully(); | 3051 CreateChannelAndConnectSuccessfully(); |
| 3063 } | 3052 } |
| 3064 | 3053 |
| 3065 // UTF-8 parsing context must be retained between received frames of the same | 3054 // UTF-8 parsing context must be retained between received frames of the same |
| 3066 // message. | 3055 // message. |
| 3067 TEST_F(WebSocketChannelReceiveUtf8Test, ReceivedParsingContextRetained) { | 3056 TEST_F(WebSocketChannelReceiveUtf8Test, ReceivedParsingContextRetained) { |
| 3068 static const InitFrame frames[] = { | 3057 static const InitFrame frames[] = { |
| 3069 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "\xf1"}, | 3058 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "\xf1"}, |
| 3070 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 3059 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 3071 NOT_MASKED, "\x80\xa0\xbf"}}; | 3060 "\x80\xa0\xbf"}}; |
| 3072 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3061 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3073 .WillOnce(ReturnFrames(&frames)) | 3062 .WillOnce(ReturnFrames(&frames)) |
| 3074 .WillRepeatedly(Return(ERR_IO_PENDING)); | 3063 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 3075 | 3064 |
| 3076 CreateChannelAndConnectSuccessfully(); | 3065 CreateChannelAndConnectSuccessfully(); |
| 3077 } | 3066 } |
| 3078 | 3067 |
| 3079 // An invalid character must be detected even if split between frames. | 3068 // An invalid character must be detected even if split between frames. |
| 3080 TEST_F(WebSocketChannelReceiveUtf8Test, SplitInvalidCharacterReceived) { | 3069 TEST_F(WebSocketChannelReceiveUtf8Test, SplitInvalidCharacterReceived) { |
| 3081 static const InitFrame frames[] = { | 3070 static const InitFrame frames[] = { |
| 3082 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "\xe1"}, | 3071 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "\xe1"}, |
| 3083 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 3072 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 3084 NOT_MASKED, "\x80\xa0\xbf"}}; | 3073 "\x80\xa0\xbf"}}; |
| 3085 static const InitFrame expected[] = { | 3074 static const InitFrame expected[] = { |
| 3086 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, | 3075 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 3087 CLOSE_DATA(PROTOCOL_ERROR, "Invalid UTF-8 in text frame")}}; | 3076 CLOSE_DATA(PROTOCOL_ERROR, "Invalid UTF-8 in text frame")}}; |
| 3088 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3077 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3089 .WillOnce(ReturnFrames(&frames)) | 3078 .WillOnce(ReturnFrames(&frames)) |
| 3090 .WillRepeatedly(Return(ERR_IO_PENDING)); | 3079 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 3091 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 3080 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 3092 .WillOnce(Return(OK)); | 3081 .WillOnce(Return(OK)); |
| 3093 EXPECT_CALL(*mock_stream_, Close()).Times(1); | 3082 EXPECT_CALL(*mock_stream_, Close()).Times(1); |
| 3094 | 3083 |
| 3095 CreateChannelAndConnectSuccessfully(); | 3084 CreateChannelAndConnectSuccessfully(); |
| 3096 } | 3085 } |
| 3097 | 3086 |
| 3098 // An invalid character received in a continuation frame must be detected. | 3087 // An invalid character received in a continuation frame must be detected. |
| 3099 TEST_F(WebSocketChannelReceiveUtf8Test, InvalidReceivedIncontinuation) { | 3088 TEST_F(WebSocketChannelReceiveUtf8Test, InvalidReceivedIncontinuation) { |
| 3100 static const InitFrame frames[] = { | 3089 static const InitFrame frames[] = { |
| 3101 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "foo"}, | 3090 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "foo"}, |
| 3102 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 3091 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 3103 NOT_MASKED, "bar"}, | 3092 "bar"}, |
| 3104 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 3093 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 3105 NOT_MASKED, "\xff"}}; | 3094 "\xff"}}; |
| 3106 static const InitFrame expected[] = { | 3095 static const InitFrame expected[] = { |
| 3107 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, | 3096 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 3108 CLOSE_DATA(PROTOCOL_ERROR, "Invalid UTF-8 in text frame")}}; | 3097 CLOSE_DATA(PROTOCOL_ERROR, "Invalid UTF-8 in text frame")}}; |
| 3109 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3098 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3110 .WillOnce(ReturnFrames(&frames)) | 3099 .WillOnce(ReturnFrames(&frames)) |
| 3111 .WillRepeatedly(Return(ERR_IO_PENDING)); | 3100 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 3112 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 3101 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 3113 .WillOnce(Return(OK)); | 3102 .WillOnce(Return(OK)); |
| 3114 EXPECT_CALL(*mock_stream_, Close()).Times(1); | 3103 EXPECT_CALL(*mock_stream_, Close()).Times(1); |
| 3115 | 3104 |
| 3116 CreateChannelAndConnectSuccessfully(); | 3105 CreateChannelAndConnectSuccessfully(); |
| 3117 } | 3106 } |
| 3118 | 3107 |
| 3119 // Continuations of binary frames must not be tested for UTF-8 validity. | 3108 // Continuations of binary frames must not be tested for UTF-8 validity. |
| 3120 TEST_F(WebSocketChannelReceiveUtf8Test, ReceivedBinaryNotUtf8Tested) { | 3109 TEST_F(WebSocketChannelReceiveUtf8Test, ReceivedBinaryNotUtf8Tested) { |
| 3121 static const InitFrame frames[] = { | 3110 static const InitFrame frames[] = { |
| 3122 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeBinary, NOT_MASKED, "foo"}, | 3111 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeBinary, NOT_MASKED, "foo"}, |
| 3123 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 3112 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 3124 NOT_MASKED, "bar"}, | 3113 "bar"}, |
| 3125 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 3114 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 3126 NOT_MASKED, "\xff"}}; | 3115 "\xff"}}; |
| 3127 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3116 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3128 .WillOnce(ReturnFrames(&frames)) | 3117 .WillOnce(ReturnFrames(&frames)) |
| 3129 .WillRepeatedly(Return(ERR_IO_PENDING)); | 3118 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 3130 | 3119 |
| 3131 CreateChannelAndConnectSuccessfully(); | 3120 CreateChannelAndConnectSuccessfully(); |
| 3132 } | 3121 } |
| 3133 | 3122 |
| 3134 // Multiple Text messages can be validated. | 3123 // Multiple Text messages can be validated. |
| 3135 TEST_F(WebSocketChannelReceiveUtf8Test, ValidateMultipleReceived) { | 3124 TEST_F(WebSocketChannelReceiveUtf8Test, ValidateMultipleReceived) { |
| 3136 static const InitFrame frames[] = { | 3125 static const InitFrame frames[] = { |
| 3137 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "foo"}, | 3126 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "foo"}, |
| 3138 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "bar"}}; | 3127 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "bar"}}; |
| 3139 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3128 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3140 .WillOnce(ReturnFrames(&frames)) | 3129 .WillOnce(ReturnFrames(&frames)) |
| 3141 .WillRepeatedly(Return(ERR_IO_PENDING)); | 3130 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 3142 | 3131 |
| 3143 CreateChannelAndConnectSuccessfully(); | 3132 CreateChannelAndConnectSuccessfully(); |
| 3144 } | 3133 } |
| 3145 | 3134 |
| 3146 // A new data message cannot start in the middle of another data message. | 3135 // A new data message cannot start in the middle of another data message. |
| 3147 TEST_F(WebSocketChannelEventInterfaceTest, BogusContinuation) { | 3136 TEST_F(WebSocketChannelEventInterfaceTest, BogusContinuation) { |
| 3148 scoped_ptr<ReadableFakeWebSocketStream> stream( | 3137 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 3149 new ReadableFakeWebSocketStream); | 3138 new ReadableFakeWebSocketStream); |
| 3150 static const InitFrame frames[] = { | 3139 static const InitFrame frames[] = { |
| 3151 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeBinary, | 3140 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeBinary, NOT_MASKED, |
| 3152 NOT_MASKED, "frame1"}, | 3141 "frame1"}, |
| 3153 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, | 3142 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, "frame2"}}; |
| 3154 NOT_MASKED, "frame2"}}; | |
| 3155 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 3143 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 3156 set_stream(stream.Pass()); | 3144 set_stream(stream.Pass()); |
| 3157 | 3145 |
| 3158 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 3146 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 3159 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); | 3147 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); |
| 3160 EXPECT_CALL( | 3148 EXPECT_CALL( |
| 3161 *event_interface_, | 3149 *event_interface_, |
| 3162 OnDataFrame( | 3150 OnDataFrame( |
| 3163 false, WebSocketFrameHeader::kOpCodeBinary, AsVector("frame1"))); | 3151 false, WebSocketFrameHeader::kOpCodeBinary, AsVector("frame1"))); |
| 3164 EXPECT_CALL( | 3152 EXPECT_CALL( |
| 3165 *event_interface_, | 3153 *event_interface_, |
| 3166 OnFailChannel( | 3154 OnFailChannel( |
| 3167 "Received start of new message but previous message is unfinished.")); | 3155 "Received start of new message but previous message is unfinished.")); |
| 3168 | 3156 |
| 3169 CreateChannelAndConnectSuccessfully(); | 3157 CreateChannelAndConnectSuccessfully(); |
| 3170 } | 3158 } |
| 3171 | 3159 |
| 3172 // A new message cannot start with a Continuation frame. | 3160 // A new message cannot start with a Continuation frame. |
| 3173 TEST_F(WebSocketChannelEventInterfaceTest, MessageStartingWithContinuation) { | 3161 TEST_F(WebSocketChannelEventInterfaceTest, MessageStartingWithContinuation) { |
| 3174 scoped_ptr<ReadableFakeWebSocketStream> stream( | 3162 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 3175 new ReadableFakeWebSocketStream); | 3163 new ReadableFakeWebSocketStream); |
| 3176 static const InitFrame frames[] = { | 3164 static const InitFrame frames[] = {{FINAL_FRAME, |
| 3177 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 3165 WebSocketFrameHeader::kOpCodeContinuation, |
| 3178 NOT_MASKED, "continuation"}}; | 3166 NOT_MASKED, "continuation"}}; |
| 3179 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 3167 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 3180 set_stream(stream.Pass()); | 3168 set_stream(stream.Pass()); |
| 3181 | 3169 |
| 3182 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 3170 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 3183 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); | 3171 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); |
| 3184 EXPECT_CALL(*event_interface_, | 3172 EXPECT_CALL(*event_interface_, |
| 3185 OnFailChannel("Received unexpected continuation frame.")); | 3173 OnFailChannel("Received unexpected continuation frame.")); |
| 3186 | 3174 |
| 3187 CreateChannelAndConnectSuccessfully(); | 3175 CreateChannelAndConnectSuccessfully(); |
| 3188 } | 3176 } |
| 3189 | 3177 |
| 3190 // A frame passed to the renderer must be either non-empty or have the final bit | 3178 // A frame passed to the renderer must be either non-empty or have the final bit |
| 3191 // set. | 3179 // set. |
| 3192 TEST_F(WebSocketChannelEventInterfaceTest, DataFramesNonEmptyOrFinal) { | 3180 TEST_F(WebSocketChannelEventInterfaceTest, DataFramesNonEmptyOrFinal) { |
| 3193 scoped_ptr<ReadableFakeWebSocketStream> stream( | 3181 scoped_ptr<ReadableFakeWebSocketStream> stream( |
| 3194 new ReadableFakeWebSocketStream); | 3182 new ReadableFakeWebSocketStream); |
| 3195 static const InitFrame frames[] = { | 3183 static const InitFrame frames[] = { |
| 3196 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, ""}, | 3184 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeText, NOT_MASKED, ""}, |
| 3197 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, | 3185 {NOT_FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, |
| 3198 NOT_MASKED, ""}, | 3186 ""}, |
| 3199 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, ""}}; | 3187 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeContinuation, NOT_MASKED, ""}}; |
| 3200 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); | 3188 stream->PrepareReadFrames(ReadableFakeWebSocketStream::SYNC, OK, frames); |
| 3201 set_stream(stream.Pass()); | 3189 set_stream(stream.Pass()); |
| 3202 | 3190 |
| 3203 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); | 3191 EXPECT_CALL(*event_interface_, OnAddChannelResponse(false, _, _)); |
| 3204 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); | 3192 EXPECT_CALL(*event_interface_, OnFlowControl(kDefaultInitialQuota)); |
| 3205 EXPECT_CALL( | 3193 EXPECT_CALL( |
| 3206 *event_interface_, | 3194 *event_interface_, |
| 3207 OnDataFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector(""))); | 3195 OnDataFrame(true, WebSocketFrameHeader::kOpCodeText, AsVector(""))); |
| 3208 | 3196 |
| 3209 CreateChannelAndConnectSuccessfully(); | 3197 CreateChannelAndConnectSuccessfully(); |
| 3210 } | 3198 } |
| 3211 | 3199 |
| 3212 // If we receive another frame after Close, it is not valid. It is not | 3200 // If we receive another frame after Close, it is not valid. It is not |
| 3213 // completely clear what behaviour is required from the standard in this case, | 3201 // completely clear what behaviour is required from the standard in this case, |
| 3214 // but the current implementation fails the connection. Since a Close has | 3202 // but the current implementation fails the connection. Since a Close has |
| 3215 // already been sent, this just means closing the connection. | 3203 // already been sent, this just means closing the connection. |
| 3216 TEST_F(WebSocketChannelStreamTest, PingAfterCloseIsRejected) { | 3204 TEST_F(WebSocketChannelStreamTest, PingAfterCloseIsRejected) { |
| 3217 static const InitFrame frames[] = { | 3205 static const InitFrame frames[] = { |
| 3218 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 3206 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 3219 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}, | 3207 CLOSE_DATA(NORMAL_CLOSURE, "OK")}, |
| 3220 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePing, | 3208 {FINAL_FRAME, WebSocketFrameHeader::kOpCodePing, NOT_MASKED, |
| 3221 NOT_MASKED, "Ping body"}}; | 3209 "Ping body"}}; |
| 3222 static const InitFrame expected[] = { | 3210 static const InitFrame expected[] = { |
| 3223 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 3211 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 3224 MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; | 3212 CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; |
| 3225 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 3213 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 3226 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 3214 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 3227 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3215 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3228 .WillOnce(ReturnFrames(&frames)) | 3216 .WillOnce(ReturnFrames(&frames)) |
| 3229 .WillRepeatedly(Return(ERR_IO_PENDING)); | 3217 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 3230 { | 3218 { |
| 3231 // We only need to verify the relative order of WriteFrames() and | 3219 // We only need to verify the relative order of WriteFrames() and |
| 3232 // Close(). The current implementation calls WriteFrames() for the Close | 3220 // Close(). The current implementation calls WriteFrames() for the Close |
| 3233 // frame before calling ReadFrames() again, but that is an implementation | 3221 // frame before calling ReadFrames() again, but that is an implementation |
| 3234 // detail and better not to consider required behaviour. | 3222 // detail and better not to consider required behaviour. |
| 3235 InSequence s; | 3223 InSequence s; |
| 3236 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 3224 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 3237 .WillOnce(Return(OK)); | 3225 .WillOnce(Return(OK)); |
| 3238 EXPECT_CALL(*mock_stream_, Close()).Times(1); | 3226 EXPECT_CALL(*mock_stream_, Close()).Times(1); |
| 3239 } | 3227 } |
| 3240 | 3228 |
| 3241 CreateChannelAndConnectSuccessfully(); | 3229 CreateChannelAndConnectSuccessfully(); |
| 3242 } | 3230 } |
| 3243 | 3231 |
| 3244 // A protocol error from the remote server should result in a close frame with | 3232 // A protocol error from the remote server should result in a close frame with |
| 3245 // status 1002, followed by the connection closing. | 3233 // status 1002, followed by the connection closing. |
| 3246 TEST_F(WebSocketChannelStreamTest, ProtocolError) { | 3234 TEST_F(WebSocketChannelStreamTest, ProtocolError) { |
| 3247 static const InitFrame expected[] = { | 3235 static const InitFrame expected[] = { |
| 3248 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 3236 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 3249 MASKED, CLOSE_DATA(PROTOCOL_ERROR, "WebSocket Protocol Error")}}; | 3237 CLOSE_DATA(PROTOCOL_ERROR, "WebSocket Protocol Error")}}; |
| 3250 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 3238 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 3251 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 3239 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 3252 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3240 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3253 .WillOnce(Return(ERR_WS_PROTOCOL_ERROR)); | 3241 .WillOnce(Return(ERR_WS_PROTOCOL_ERROR)); |
| 3254 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 3242 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 3255 .WillOnce(Return(OK)); | 3243 .WillOnce(Return(OK)); |
| 3256 EXPECT_CALL(*mock_stream_, Close()); | 3244 EXPECT_CALL(*mock_stream_, Close()); |
| 3257 | 3245 |
| 3258 CreateChannelAndConnectSuccessfully(); | 3246 CreateChannelAndConnectSuccessfully(); |
| 3259 } | 3247 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3273 } | 3261 } |
| 3274 }; | 3262 }; |
| 3275 | 3263 |
| 3276 // In this case the server initiates the closing handshake with a Close | 3264 // In this case the server initiates the closing handshake with a Close |
| 3277 // message. WebSocketChannel responds with a matching Close message, and waits | 3265 // message. WebSocketChannel responds with a matching Close message, and waits |
| 3278 // for the server to close the TCP/IP connection. The server never closes the | 3266 // for the server to close the TCP/IP connection. The server never closes the |
| 3279 // connection, so the closing handshake times out and WebSocketChannel closes | 3267 // connection, so the closing handshake times out and WebSocketChannel closes |
| 3280 // the connection itself. | 3268 // the connection itself. |
| 3281 TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) { | 3269 TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) { |
| 3282 static const InitFrame frames[] = { | 3270 static const InitFrame frames[] = { |
| 3283 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 3271 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 3284 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; | 3272 CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; |
| 3285 static const InitFrame expected[] = { | 3273 static const InitFrame expected[] = { |
| 3286 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 3274 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 3287 MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; | 3275 CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; |
| 3288 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 3276 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 3289 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 3277 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 3290 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3278 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3291 .WillOnce(ReturnFrames(&frames)) | 3279 .WillOnce(ReturnFrames(&frames)) |
| 3292 .WillRepeatedly(Return(ERR_IO_PENDING)); | 3280 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 3293 Checkpoint checkpoint; | 3281 Checkpoint checkpoint; |
| 3294 TestClosure completion; | 3282 TestClosure completion; |
| 3295 { | 3283 { |
| 3296 InSequence s; | 3284 InSequence s; |
| 3297 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 3285 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 3298 .WillOnce(Return(OK)); | 3286 .WillOnce(Return(OK)); |
| 3299 EXPECT_CALL(checkpoint, Call(1)); | 3287 EXPECT_CALL(checkpoint, Call(1)); |
| 3300 EXPECT_CALL(*mock_stream_, Close()) | 3288 EXPECT_CALL(*mock_stream_, Close()) |
| 3301 .WillOnce(InvokeClosure(completion.closure())); | 3289 .WillOnce(InvokeClosure(completion.closure())); |
| 3302 } | 3290 } |
| 3303 | 3291 |
| 3304 CreateChannelAndConnectSuccessfully(); | 3292 CreateChannelAndConnectSuccessfully(); |
| 3305 checkpoint.Call(1); | 3293 checkpoint.Call(1); |
| 3306 completion.WaitForResult(); | 3294 completion.WaitForResult(); |
| 3307 } | 3295 } |
| 3308 | 3296 |
| 3309 // In this case the client initiates the closing handshake by sending a Close | 3297 // In this case the client initiates the closing handshake by sending a Close |
| 3310 // message. WebSocketChannel waits for a Close message in response from the | 3298 // message. WebSocketChannel waits for a Close message in response from the |
| 3311 // server. The server never responds to the Close message, so the closing | 3299 // server. The server never responds to the Close message, so the closing |
| 3312 // handshake times out and WebSocketChannel closes the connection. | 3300 // handshake times out and WebSocketChannel closes the connection. |
| 3313 TEST_F(WebSocketChannelStreamTimeoutTest, ClientInitiatedCloseTimesOut) { | 3301 TEST_F(WebSocketChannelStreamTimeoutTest, ClientInitiatedCloseTimesOut) { |
| 3314 static const InitFrame expected[] = { | 3302 static const InitFrame expected[] = { |
| 3315 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 3303 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 3316 MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; | 3304 CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; |
| 3317 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 3305 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 3318 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 3306 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 3319 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3307 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| 3320 .WillRepeatedly(Return(ERR_IO_PENDING)); | 3308 .WillRepeatedly(Return(ERR_IO_PENDING)); |
| 3321 TestClosure completion; | 3309 TestClosure completion; |
| 3322 { | 3310 { |
| 3323 InSequence s; | 3311 InSequence s; |
| 3324 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) | 3312 EXPECT_CALL(*mock_stream_, WriteFrames(EqualsFrames(expected), _)) |
| 3325 .WillOnce(Return(OK)); | 3313 .WillOnce(Return(OK)); |
| 3326 EXPECT_CALL(*mock_stream_, Close()) | 3314 EXPECT_CALL(*mock_stream_, Close()) |
| 3327 .WillOnce(InvokeClosure(completion.closure())); | 3315 .WillOnce(InvokeClosure(completion.closure())); |
| 3328 } | 3316 } |
| 3329 | 3317 |
| 3330 CreateChannelAndConnectSuccessfully(); | 3318 CreateChannelAndConnectSuccessfully(); |
| 3331 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); | 3319 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); |
| 3332 completion.WaitForResult(); | 3320 completion.WaitForResult(); |
| 3333 } | 3321 } |
| 3334 | 3322 |
| 3335 // In this case the client initiates the closing handshake and the server | 3323 // In this case the client initiates the closing handshake and the server |
| 3336 // responds with a matching Close message. WebSocketChannel waits for the server | 3324 // responds with a matching Close message. WebSocketChannel waits for the server |
| 3337 // to close the TCP/IP connection, but it never does. The closing handshake | 3325 // to close the TCP/IP connection, but it never does. The closing handshake |
| 3338 // times out and WebSocketChannel closes the connection. | 3326 // times out and WebSocketChannel closes the connection. |
| 3339 TEST_F(WebSocketChannelStreamTimeoutTest, ConnectionCloseTimesOut) { | 3327 TEST_F(WebSocketChannelStreamTimeoutTest, ConnectionCloseTimesOut) { |
| 3340 static const InitFrame expected[] = { | 3328 static const InitFrame expected[] = { |
| 3341 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 3329 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, MASKED, |
| 3342 MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; | 3330 CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; |
| 3343 static const InitFrame frames[] = { | 3331 static const InitFrame frames[] = { |
| 3344 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, | 3332 {FINAL_FRAME, WebSocketFrameHeader::kOpCodeClose, NOT_MASKED, |
| 3345 NOT_MASKED, CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; | 3333 CLOSE_DATA(NORMAL_CLOSURE, "OK")}}; |
| 3346 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 3334 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
| 3347 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); | 3335 EXPECT_CALL(*mock_stream_, GetExtensions()).Times(AnyNumber()); |
| 3348 TestClosure completion; | 3336 TestClosure completion; |
| 3349 ScopedVector<WebSocketFrame>* read_frames = NULL; | 3337 ScopedVector<WebSocketFrame>* read_frames = NULL; |
| 3350 CompletionCallback read_callback; | 3338 CompletionCallback read_callback; |
| 3351 { | 3339 { |
| 3352 InSequence s; | 3340 InSequence s; |
| 3353 // Copy the arguments to ReadFrames so that the test can call the callback | 3341 // Copy the arguments to ReadFrames so that the test can call the callback |
| 3354 // after it has send the close message. | 3342 // after it has send the close message. |
| 3355 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) | 3343 EXPECT_CALL(*mock_stream_, ReadFrames(_, _)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3374 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); | 3362 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); |
| 3375 ASSERT_TRUE(read_frames); | 3363 ASSERT_TRUE(read_frames); |
| 3376 // Provide the "Close" message from the server. | 3364 // Provide the "Close" message from the server. |
| 3377 *read_frames = CreateFrameVector(frames); | 3365 *read_frames = CreateFrameVector(frames); |
| 3378 read_callback.Run(OK); | 3366 read_callback.Run(OK); |
| 3379 completion.WaitForResult(); | 3367 completion.WaitForResult(); |
| 3380 } | 3368 } |
| 3381 | 3369 |
| 3382 } // namespace | 3370 } // namespace |
| 3383 } // namespace net | 3371 } // namespace net |
| OLD | NEW |