diff options
author | sacomoto <sacomoto@chromium.org> | 2015-07-29 03:56:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-29 10:57:03 +0000 |
commit | 25875b29dd5686d9251811f508527cf015a59639 (patch) | |
tree | 3f73fdba1616afb40774130cda2ec1bce38e19b4 /components/proximity_auth | |
parent | 6b996d532f7781fbc44cdecfba600a26d98d8d9a (diff) | |
download | chromium_src-25875b29dd5686d9251811f508527cf015a59639.zip chromium_src-25875b29dd5686d9251811f508527cf015a59639.tar.gz chromium_src-25875b29dd5686d9251811f508527cf015a59639.tar.bz2 |
Also throttling reconnects after failed connection attempts.
Currently, proximity_auth::BluetoothThrottles only throttles reconnect
attempts following a successful connection, i.e. when the connection
state changes from Connection::CONNECTED to Connection::DISCONNECT.
In order to reuse this class as a workaround for crbug.com/508919,
we also need to consider the reconnect attempts following an in
progress connection attempt, i.e. when the connection state changes
from Connection::IN_PROGRESS to Connection::DISCONNECT.
BUG=514626
Review URL: https://codereview.chromium.org/1260453005
Cr-Commit-Position: refs/heads/master@{#340873}
Diffstat (limited to 'components/proximity_auth')
-rw-r--r-- | components/proximity_auth/bluetooth_throttler_impl.cc | 3 | ||||
-rw-r--r-- | components/proximity_auth/bluetooth_throttler_impl_unittest.cc | 41 |
2 files changed, 32 insertions, 12 deletions
diff --git a/components/proximity_auth/bluetooth_throttler_impl.cc b/components/proximity_auth/bluetooth_throttler_impl.cc index 9963fb0..a44ce1e 100644 --- a/components/proximity_auth/bluetooth_throttler_impl.cc +++ b/components/proximity_auth/bluetooth_throttler_impl.cc @@ -55,8 +55,7 @@ void BluetoothThrottlerImpl::OnConnectionStatusChanged( Connection::Status old_status, Connection::Status new_status) { DCHECK(ContainsKey(connections_, connection)); - if (old_status == Connection::CONNECTED && - new_status == Connection::DISCONNECTED) { + if (new_status == Connection::DISCONNECTED) { last_disconnect_time_ = clock_->NowTicks(); connection->RemoveObserver(this); connections_.erase(connection); diff --git a/components/proximity_auth/bluetooth_throttler_impl_unittest.cc b/components/proximity_auth/bluetooth_throttler_impl_unittest.cc index 1bca940..8b43941 100644 --- a/components/proximity_auth/bluetooth_throttler_impl_unittest.cc +++ b/components/proximity_auth/bluetooth_throttler_impl_unittest.cc @@ -50,6 +50,14 @@ class ProximityAuthBluetoothThrottlerImplTest : public testing::Test { clock_->Advance(base::TimeDelta::FromSeconds(1)); } + void PerformConnectionStateTransition(Connection::Status old_status, + Connection::Status new_status) { + StubConnection connection; + throttler_.OnConnection(&connection); + static_cast<ConnectionObserver*>(&throttler_) + ->OnConnectionStatusChanged(&connection, old_status, new_status); + } + protected: // The clock is owned by the |throttler_|. base::SimpleTestTickClock* clock_; @@ -64,11 +72,17 @@ TEST_F(ProximityAuthBluetoothThrottlerImplTest, TEST_F(ProximityAuthBluetoothThrottlerImplTest, GetDelay_ConnectionAfterDisconnectIsThrottled) { // Simulate a connection followed by a disconnection. - StubConnection connection; - throttler_.OnConnection(&connection); - static_cast<ConnectionObserver*>(&throttler_) - ->OnConnectionStatusChanged(&connection, Connection::CONNECTED, - Connection::DISCONNECTED); + PerformConnectionStateTransition(Connection::CONNECTED, + Connection::DISCONNECTED); + EXPECT_GT(throttler_.GetDelay(), base::TimeDelta()); +} + +TEST_F(ProximityAuthBluetoothThrottlerImplTest, + GetDelay_ConnectionAfterIsProgressDisconnectIsThrottled) { + // Simulate an attempt to connect (in progress connection) followed by a + // disconnection. + PerformConnectionStateTransition(Connection::IN_PROGRESS, + Connection::DISCONNECTED); EXPECT_GT(throttler_.GetDelay(), base::TimeDelta()); } @@ -76,11 +90,18 @@ TEST_F(ProximityAuthBluetoothThrottlerImplTest, GetDelay_DelayedConnectionAfterDisconnectIsNotThrottled) { // Simulate a connection followed by a disconnection, then allow the cooldown // period to elapse. - StubConnection connection; - throttler_.OnConnection(&connection); - static_cast<ConnectionObserver*>(&throttler_) - ->OnConnectionStatusChanged(&connection, Connection::CONNECTED, - Connection::DISCONNECTED); + PerformConnectionStateTransition(Connection::CONNECTED, + Connection::DISCONNECTED); + clock_->Advance(throttler_.GetCooldownTimeDelta()); + EXPECT_EQ(base::TimeDelta(), throttler_.GetDelay()); +} + +TEST_F(ProximityAuthBluetoothThrottlerImplTest, + GetDelay_DelayedConnectionAfterInProgressDisconnectIsNotThrottled) { + // Simulate an attempt to connect (in progress connection) followed by a + // disconnection, then allow the cooldown period to elapse. + PerformConnectionStateTransition(Connection::IN_PROGRESS, + Connection::DISCONNECTED); clock_->Advance(throttler_.GetCooldownTimeDelta()); EXPECT_EQ(base::TimeDelta(), throttler_.GetDelay()); } |