OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/socket/websocket_endpoint_lock_manager.h" | 5 #include "net/socket/websocket_endpoint_lock_manager.h" |
6 | 6 |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
8 #include "net/socket/next_proto.h" | 8 #include "net/socket/next_proto.h" |
9 #include "net/socket/socket_test_util.h" | 9 #include "net/socket/socket_test_util.h" |
10 #include "net/socket/stream_socket.h" | 10 #include "net/socket/stream_socket.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 EXPECT_EQ(ERR_IO_PENDING, | 189 EXPECT_EQ(ERR_IO_PENDING, |
190 instance()->LockEndpoint(DummyEndpoint(), &waiters[1])); | 190 instance()->LockEndpoint(DummyEndpoint(), &waiters[1])); |
191 | 191 |
192 instance()->RememberSocket(&dummy_socket, DummyEndpoint()); | 192 instance()->RememberSocket(&dummy_socket, DummyEndpoint()); |
193 instance()->UnlockSocket(&dummy_socket); | 193 instance()->UnlockSocket(&dummy_socket); |
194 EXPECT_TRUE(waiters[1].called()); | 194 EXPECT_TRUE(waiters[1].called()); |
195 | 195 |
196 UnlockDummyEndpoint(1); | 196 UnlockDummyEndpoint(1); |
197 } | 197 } |
198 | 198 |
199 // Calling UnlockSocket() on the same socket a second time should be harmless. | 199 // UnlockEndpoint() should cause any sockets remembered for this endpoint |
200 TEST_F(WebSocketEndpointLockManagerTest, UnlockSocketTwice) { | 200 // to be forgotten. |
| 201 TEST_F(WebSocketEndpointLockManagerTest, SocketAssociationForgottenOnUnlock) { |
201 FakeWaiter waiter; | 202 FakeWaiter waiter; |
202 FakeStreamSocket dummy_socket; | 203 FakeStreamSocket dummy_socket; |
| 204 |
203 EXPECT_EQ(OK, instance()->LockEndpoint(DummyEndpoint(), &waiter)); | 205 EXPECT_EQ(OK, instance()->LockEndpoint(DummyEndpoint(), &waiter)); |
204 instance()->RememberSocket(&dummy_socket, DummyEndpoint()); | 206 instance()->RememberSocket(&dummy_socket, DummyEndpoint()); |
205 instance()->UnlockSocket(&dummy_socket); | 207 instance()->UnlockEndpoint(DummyEndpoint()); |
206 instance()->UnlockSocket(&dummy_socket); | 208 EXPECT_TRUE(instance()->IsEmpty()); |
| 209 } |
| 210 |
| 211 // When ownership of the endpoint is passed to a new waiter, the new waiter can |
| 212 // call RememberSocket() again. |
| 213 TEST_F(WebSocketEndpointLockManagerTest, NextWaiterCanCallRememberSocketAgain) { |
| 214 FakeWaiter waiters[2]; |
| 215 FakeStreamSocket dummy_sockets[2]; |
| 216 EXPECT_EQ(OK, instance()->LockEndpoint(DummyEndpoint(), &waiters[0])); |
| 217 EXPECT_EQ(ERR_IO_PENDING, |
| 218 instance()->LockEndpoint(DummyEndpoint(), &waiters[1])); |
| 219 |
| 220 instance()->RememberSocket(&dummy_sockets[0], DummyEndpoint()); |
| 221 instance()->UnlockEndpoint(DummyEndpoint()); |
| 222 EXPECT_TRUE(waiters[1].called()); |
| 223 instance()->RememberSocket(&dummy_sockets[1], DummyEndpoint()); |
| 224 |
| 225 UnlockDummyEndpoint(1); |
207 } | 226 } |
208 | 227 |
209 } // namespace | 228 } // namespace |
210 | 229 |
211 } // namespace net | 230 } // namespace net |
OLD | NEW |