Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: components/proximity_auth/bluetooth_throttler_impl_unittest.cc

Issue 663693002: [Easy Unlock] Port the BluetoothThrottler class to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/proximity_auth/bluetooth_throttler_impl.h"
6
7 #include "base/test/simple_test_tick_clock.h"
8 #include "base/time/time.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace proximity_auth {
12 namespace {
13
14 class TestBluetoothThrottler : public BluetoothThrottlerImpl {
15 public:
16 explicit TestBluetoothThrottler(scoped_ptr<base::TickClock> clock)
17 : BluetoothThrottlerImpl(clock.Pass()) {}
18 ~TestBluetoothThrottler() override {}
19
20 // Increase visibility for testing.
21 using BluetoothThrottlerImpl::GetCooldownTimeDelta;
22
23 private:
24 DISALLOW_COPY_AND_ASSIGN(TestBluetoothThrottler);
25 };
26
27 } // namespace
28
29 class ProximityAuthBluetoothThrottlerImplTest : public testing::Test {
30 public:
31 ProximityAuthBluetoothThrottlerImplTest()
32 : clock_(new base::SimpleTestTickClock),
33 throttler_(make_scoped_ptr(clock_)) {
34 // The throttler treats null times as special, so start with a non-null
35 // time.
36 clock_->Advance(base::TimeDelta::FromSeconds(1));
37 }
38
39 protected:
40 // The clock is owned by the |throttler_|.
41 base::SimpleTestTickClock* clock_;
42 TestBluetoothThrottler throttler_;
43 };
44
45 TEST_F(ProximityAuthBluetoothThrottlerImplTest,
46 GetDelay_FirstConnectionIsNotThrottled) {
47 EXPECT_EQ(base::TimeDelta(), throttler_.GetDelay());
48 }
49
50 TEST_F(ProximityAuthBluetoothThrottlerImplTest,
51 GetDelay_ConnectionAfterDisconnectIsThrottled) {
52 // Simulate a disconnection.
53 throttler_.OnConnectionClosed();
54 EXPECT_GT(throttler_.GetDelay(), base::TimeDelta());
55 }
56
57 TEST_F(ProximityAuthBluetoothThrottlerImplTest,
58 GetDelay_DelayedConnectionAfterDisconnectIsNotThrottled) {
59 // Simulate a disconnection, then allow the cooldown period to elapse.
60 throttler_.OnConnectionClosed();
61 clock_->Advance(throttler_.GetCooldownTimeDelta());
62 EXPECT_EQ(base::TimeDelta(), throttler_.GetDelay());
63 }
64
65 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698