| 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 "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 RunUntilIdle(); | 285 RunUntilIdle(); |
| 286 EXPECT_TRUE(waiters[1].called()); | 286 EXPECT_TRUE(waiters[1].called()); |
| 287 | 287 |
| 288 UnlockDummyEndpoint(1); | 288 UnlockDummyEndpoint(1); |
| 289 } | 289 } |
| 290 | 290 |
| 291 // UnlockEndpoint() should normally have a delay. | 291 // UnlockEndpoint() should normally have a delay. |
| 292 TEST_F(WebSocketEndpointLockManagerTest, UnlockEndpointIsDelayed) { | 292 TEST_F(WebSocketEndpointLockManagerTest, UnlockEndpointIsDelayed) { |
| 293 using base::TimeTicks; | 293 using base::TimeTicks; |
| 294 | 294 |
| 295 // This 1ms delay is too short for very slow environments (usually those |
| 296 // running memory checkers). In those environments, the code takes >1ms to run |
| 297 // and no delay is needed. Rather than increase the delay and slow down the |
| 298 // test everywhere, the test doesn't explicitly verify that a delay has been |
| 299 // applied. Instead it just verifies that the whole thing took >=1ms. 1ms is |
| 300 // easily enough for normal compiles even on Android, so the fact that there |
| 301 // is a delay is still checked on every platform. |
| 295 const base::TimeDelta unlock_delay = base::TimeDelta::FromMilliseconds(1); | 302 const base::TimeDelta unlock_delay = base::TimeDelta::FromMilliseconds(1); |
| 296 instance()->SetUnlockDelayForTesting(unlock_delay); | 303 instance()->SetUnlockDelayForTesting(unlock_delay); |
| 297 FakeWaiter fake_waiter; | 304 FakeWaiter fake_waiter; |
| 298 BlockingWaiter blocking_waiter; | 305 BlockingWaiter blocking_waiter; |
| 299 EXPECT_EQ(OK, instance()->LockEndpoint(DummyEndpoint(), &fake_waiter)); | 306 EXPECT_EQ(OK, instance()->LockEndpoint(DummyEndpoint(), &fake_waiter)); |
| 300 EXPECT_EQ(ERR_IO_PENDING, | 307 EXPECT_EQ(ERR_IO_PENDING, |
| 301 instance()->LockEndpoint(DummyEndpoint(), &blocking_waiter)); | 308 instance()->LockEndpoint(DummyEndpoint(), &blocking_waiter)); |
| 302 | 309 |
| 303 TimeTicks before_unlock = TimeTicks::Now(); | 310 TimeTicks before_unlock = TimeTicks::Now(); |
| 304 instance()->UnlockEndpoint(DummyEndpoint()); | 311 instance()->UnlockEndpoint(DummyEndpoint()); |
| 305 RunUntilIdle(); | |
| 306 EXPECT_FALSE(blocking_waiter.called()); | |
| 307 blocking_waiter.WaitForLock(); | 312 blocking_waiter.WaitForLock(); |
| 308 TimeTicks after_unlock = TimeTicks::Now(); | 313 TimeTicks after_unlock = TimeTicks::Now(); |
| 309 EXPECT_GE(after_unlock - before_unlock, unlock_delay); | 314 EXPECT_GE(after_unlock - before_unlock, unlock_delay); |
| 310 instance()->SetUnlockDelayForTesting(base::TimeDelta()); | 315 instance()->SetUnlockDelayForTesting(base::TimeDelta()); |
| 311 UnlockDummyEndpoint(1); | 316 UnlockDummyEndpoint(1); |
| 312 } | 317 } |
| 313 | 318 |
| 314 } // namespace | 319 } // namespace |
| 315 | 320 |
| 316 } // namespace net | 321 } // namespace net |
| OLD | NEW |