OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/bluetooth_throttler_impl.h" | 5 #include "components/proximity_auth/bluetooth_throttler_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/test/simple_test_tick_clock.h" | 11 #include "base/test/simple_test_tick_clock.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "components/proximity_auth/fake_connection.h" | 13 #include "components/proximity_auth/fake_connection.h" |
13 #include "components/proximity_auth/wire_message.h" | 14 #include "components/proximity_auth/wire_message.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace proximity_auth { | 17 namespace proximity_auth { |
17 namespace { | 18 namespace { |
18 | 19 |
19 class TestBluetoothThrottler : public BluetoothThrottlerImpl { | 20 class TestBluetoothThrottler : public BluetoothThrottlerImpl { |
20 public: | 21 public: |
21 explicit TestBluetoothThrottler(scoped_ptr<base::TickClock> clock) | 22 explicit TestBluetoothThrottler(std::unique_ptr<base::TickClock> clock) |
22 : BluetoothThrottlerImpl(std::move(clock)) {} | 23 : BluetoothThrottlerImpl(std::move(clock)) {} |
23 ~TestBluetoothThrottler() override {} | 24 ~TestBluetoothThrottler() override {} |
24 | 25 |
25 // Increase visibility for testing. | 26 // Increase visibility for testing. |
26 using BluetoothThrottlerImpl::GetCooldownTimeDelta; | 27 using BluetoothThrottlerImpl::GetCooldownTimeDelta; |
27 | 28 |
28 private: | 29 private: |
29 DISALLOW_COPY_AND_ASSIGN(TestBluetoothThrottler); | 30 DISALLOW_COPY_AND_ASSIGN(TestBluetoothThrottler); |
30 }; | 31 }; |
31 | 32 |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 class ProximityAuthBluetoothThrottlerImplTest : public testing::Test { | 35 class ProximityAuthBluetoothThrottlerImplTest : public testing::Test { |
35 public: | 36 public: |
36 ProximityAuthBluetoothThrottlerImplTest() | 37 ProximityAuthBluetoothThrottlerImplTest() |
37 : clock_(new base::SimpleTestTickClock), | 38 : clock_(new base::SimpleTestTickClock), |
38 throttler_(make_scoped_ptr(clock_)) { | 39 throttler_(base::WrapUnique(clock_)) { |
39 // The throttler treats null times as special, so start with a non-null | 40 // The throttler treats null times as special, so start with a non-null |
40 // time. | 41 // time. |
41 clock_->Advance(base::TimeDelta::FromSeconds(1)); | 42 clock_->Advance(base::TimeDelta::FromSeconds(1)); |
42 } | 43 } |
43 | 44 |
44 void PerformConnectionStateTransition(Connection::Status old_status, | 45 void PerformConnectionStateTransition(Connection::Status old_status, |
45 Connection::Status new_status) { | 46 Connection::Status new_status) { |
46 FakeConnection connection((RemoteDevice())); | 47 FakeConnection connection((RemoteDevice())); |
47 throttler_.OnConnection(&connection); | 48 throttler_.OnConnection(&connection); |
48 static_cast<ConnectionObserver*>(&throttler_) | 49 static_cast<ConnectionObserver*>(&throttler_) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 GetDelay_DelayedConnectionAfterInProgressDisconnectIsNotThrottled) { | 92 GetDelay_DelayedConnectionAfterInProgressDisconnectIsNotThrottled) { |
92 // Simulate an attempt to connect (in progress connection) followed by a | 93 // Simulate an attempt to connect (in progress connection) followed by a |
93 // disconnection, then allow the cooldown period to elapse. | 94 // disconnection, then allow the cooldown period to elapse. |
94 PerformConnectionStateTransition(Connection::IN_PROGRESS, | 95 PerformConnectionStateTransition(Connection::IN_PROGRESS, |
95 Connection::DISCONNECTED); | 96 Connection::DISCONNECTED); |
96 clock_->Advance(throttler_.GetCooldownTimeDelta()); | 97 clock_->Advance(throttler_.GetCooldownTimeDelta()); |
97 EXPECT_EQ(base::TimeDelta(), throttler_.GetDelay()); | 98 EXPECT_EQ(base::TimeDelta(), throttler_.GetDelay()); |
98 } | 99 } |
99 | 100 |
100 } // namespace proximity_auth | 101 } // namespace proximity_auth |
OLD | NEW |