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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 // The amount of quota a new connection gets by default. | 121 // The amount of quota a new connection gets by default. |
122 // TODO(ricea): If kDefaultSendQuotaHighWaterMark changes, then this value will | 122 // TODO(ricea): If kDefaultSendQuotaHighWaterMark changes, then this value will |
123 // need to be updated. | 123 // need to be updated. |
124 const size_t kDefaultInitialQuota = 1 << 17; | 124 const size_t kDefaultInitialQuota = 1 << 17; |
125 // 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 |
126 // quota refresh. TODO(ricea): Change this if kDefaultSendQuotaHighWaterMark or | 126 // quota refresh. TODO(ricea): Change this if kDefaultSendQuotaHighWaterMark or |
127 // kDefaultSendQuotaLowWaterMark change. | 127 // kDefaultSendQuotaLowWaterMark change. |
128 const size_t kDefaultQuotaRefreshTrigger = (1 << 16) + 1; | 128 const size_t kDefaultQuotaRefreshTrigger = (1 << 16) + 1; |
129 | 129 |
| 130 const int kVeryBigTimeoutMillis = 60 * 60 * 24 * 1000; |
| 131 |
130 // TestTimeouts::tiny_timeout() is 100ms! I could run halfway around the world | 132 // TestTimeouts::tiny_timeout() is 100ms! I could run halfway around the world |
131 // in that time! I would like my tests to run a bit quicker. | 133 // in that time! I would like my tests to run a bit quicker. |
132 const int kVeryTinyTimeoutMillis = 1; | 134 const int kVeryTinyTimeoutMillis = 1; |
133 | 135 |
134 // Enough quota to pass any test. | 136 // Enough quota to pass any test. |
135 const int64 kPlentyOfQuota = INT_MAX; | 137 const int64 kPlentyOfQuota = INT_MAX; |
136 | 138 |
137 typedef WebSocketEventInterface::ChannelState ChannelState; | 139 typedef WebSocketEventInterface::ChannelState ChannelState; |
138 const ChannelState CHANNEL_ALIVE = WebSocketEventInterface::CHANNEL_ALIVE; | 140 const ChannelState CHANNEL_ALIVE = WebSocketEventInterface::CHANNEL_ALIVE; |
139 const ChannelState CHANNEL_DELETED = WebSocketEventInterface::CHANNEL_DELETED; | 141 const ChannelState CHANNEL_DELETED = WebSocketEventInterface::CHANNEL_DELETED; |
(...skipping 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2138 EXPECT_CALL(*event_interface_, | 2140 EXPECT_CALL(*event_interface_, |
2139 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)) | 2141 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)) |
2140 .WillOnce(InvokeClosureReturnDeleted(completion.closure())); | 2142 .WillOnce(InvokeClosureReturnDeleted(completion.closure())); |
2141 } | 2143 } |
2142 CreateChannelAndConnectSuccessfully(); | 2144 CreateChannelAndConnectSuccessfully(); |
2143 // OneShotTimer is not very friendly to testing; there is no apparent way to | 2145 // OneShotTimer is not very friendly to testing; there is no apparent way to |
2144 // set an expectation on it. Instead the tests need to infer that the timeout | 2146 // set an expectation on it. Instead the tests need to infer that the timeout |
2145 // was fired by the behaviour of the WebSocketChannel object. | 2147 // was fired by the behaviour of the WebSocketChannel object. |
2146 channel_->SetClosingHandshakeTimeoutForTesting( | 2148 channel_->SetClosingHandshakeTimeoutForTesting( |
2147 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); | 2149 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); |
| 2150 channel_->SetUnderlyingConnectionCloseTimeoutForTesting( |
| 2151 TimeDelta::FromMilliseconds(kVeryBigTimeoutMillis)); |
2148 channel_->StartClosingHandshake(kWebSocketNormalClosure, ""); | 2152 channel_->StartClosingHandshake(kWebSocketNormalClosure, ""); |
2149 checkpoint.Call(1); | 2153 checkpoint.Call(1); |
2150 completion.WaitForResult(); | 2154 completion.WaitForResult(); |
2151 } | 2155 } |
2152 | 2156 |
2153 // The closing handshake times out and sends an OnDropChannel event if a Close | 2157 // The closing handshake times out and sends an OnDropChannel event if a Close |
2154 // message is received but the connection isn't closed by the remote host. | 2158 // message is received but the connection isn't closed by the remote host. |
2155 TEST_F(WebSocketChannelEventInterfaceTest, | 2159 TEST_F(WebSocketChannelEventInterfaceTest, |
2156 ServerInitiatedClosingHandshakeTimesOut) { | 2160 ServerInitiatedClosingHandshakeTimesOut) { |
2157 scoped_ptr<ReadableFakeWebSocketStream> stream( | 2161 scoped_ptr<ReadableFakeWebSocketStream> stream( |
(...skipping 10 matching lines...) Expand all Loading... |
2168 { | 2172 { |
2169 InSequence s; | 2173 InSequence s; |
2170 EXPECT_CALL(checkpoint, Call(1)); | 2174 EXPECT_CALL(checkpoint, Call(1)); |
2171 EXPECT_CALL(*event_interface_, OnClosingHandshake()); | 2175 EXPECT_CALL(*event_interface_, OnClosingHandshake()); |
2172 EXPECT_CALL(*event_interface_, | 2176 EXPECT_CALL(*event_interface_, |
2173 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)) | 2177 OnDropChannel(false, kWebSocketErrorAbnormalClosure, _)) |
2174 .WillOnce(InvokeClosureReturnDeleted(completion.closure())); | 2178 .WillOnce(InvokeClosureReturnDeleted(completion.closure())); |
2175 } | 2179 } |
2176 CreateChannelAndConnectSuccessfully(); | 2180 CreateChannelAndConnectSuccessfully(); |
2177 channel_->SetClosingHandshakeTimeoutForTesting( | 2181 channel_->SetClosingHandshakeTimeoutForTesting( |
| 2182 TimeDelta::FromMilliseconds(kVeryBigTimeoutMillis)); |
| 2183 channel_->SetUnderlyingConnectionCloseTimeoutForTesting( |
2178 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); | 2184 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); |
2179 checkpoint.Call(1); | 2185 checkpoint.Call(1); |
2180 completion.WaitForResult(); | 2186 completion.WaitForResult(); |
2181 } | 2187 } |
2182 | 2188 |
2183 // The renderer should provide us with some quota immediately, and then | 2189 // The renderer should provide us with some quota immediately, and then |
2184 // WebSocketChannel calls ReadFrames as soon as the stream is available. | 2190 // WebSocketChannel calls ReadFrames as soon as the stream is available. |
2185 TEST_F(WebSocketChannelStreamTest, FlowControlEarly) { | 2191 TEST_F(WebSocketChannelStreamTest, FlowControlEarly) { |
2186 Checkpoint checkpoint; | 2192 Checkpoint checkpoint; |
2187 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); | 2193 EXPECT_CALL(*mock_stream_, GetSubProtocol()).Times(AnyNumber()); |
(...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3297 class WebSocketChannelStreamTimeoutTest : public WebSocketChannelStreamTest { | 3303 class WebSocketChannelStreamTimeoutTest : public WebSocketChannelStreamTest { |
3298 protected: | 3304 protected: |
3299 WebSocketChannelStreamTimeoutTest() {} | 3305 WebSocketChannelStreamTimeoutTest() {} |
3300 | 3306 |
3301 void CreateChannelAndConnectSuccessfully() override { | 3307 void CreateChannelAndConnectSuccessfully() override { |
3302 set_stream(mock_stream_.Pass()); | 3308 set_stream(mock_stream_.Pass()); |
3303 CreateChannelAndConnect(); | 3309 CreateChannelAndConnect(); |
3304 channel_->SendFlowControl(kPlentyOfQuota); | 3310 channel_->SendFlowControl(kPlentyOfQuota); |
3305 channel_->SetClosingHandshakeTimeoutForTesting( | 3311 channel_->SetClosingHandshakeTimeoutForTesting( |
3306 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); | 3312 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); |
| 3313 channel_->SetUnderlyingConnectionCloseTimeoutForTesting( |
| 3314 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); |
3307 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); | 3315 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); |
3308 } | 3316 } |
3309 }; | 3317 }; |
3310 | 3318 |
3311 // In this case the server initiates the closing handshake with a Close | 3319 // In this case the server initiates the closing handshake with a Close |
3312 // message. WebSocketChannel responds with a matching Close message, and waits | 3320 // message. WebSocketChannel responds with a matching Close message, and waits |
3313 // for the server to close the TCP/IP connection. The server never closes the | 3321 // for the server to close the TCP/IP connection. The server never closes the |
3314 // connection, so the closing handshake times out and WebSocketChannel closes | 3322 // connection, so the closing handshake times out and WebSocketChannel closes |
3315 // the connection itself. | 3323 // the connection itself. |
3316 TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) { | 3324 TEST_F(WebSocketChannelStreamTimeoutTest, ServerInitiatedCloseTimesOut) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3409 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); | 3417 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); |
3410 ASSERT_TRUE(read_frames); | 3418 ASSERT_TRUE(read_frames); |
3411 // Provide the "Close" message from the server. | 3419 // Provide the "Close" message from the server. |
3412 *read_frames = CreateFrameVector(frames); | 3420 *read_frames = CreateFrameVector(frames); |
3413 read_callback.Run(OK); | 3421 read_callback.Run(OK); |
3414 completion.WaitForResult(); | 3422 completion.WaitForResult(); |
3415 } | 3423 } |
3416 | 3424 |
3417 } // namespace | 3425 } // namespace |
3418 } // namespace net | 3426 } // namespace net |
OLD | NEW |