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

Unified 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: Fix Windows compilation error, take 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/proximity_auth/bluetooth_throttler_impl.cc ('k') | components/proximity_auth/client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/proximity_auth/bluetooth_throttler_impl_unittest.cc
diff --git a/components/proximity_auth/bluetooth_throttler_impl_unittest.cc b/components/proximity_auth/bluetooth_throttler_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1bca940fa858f5960786f6e35eaf568a23e2eb1c
--- /dev/null
+++ b/components/proximity_auth/bluetooth_throttler_impl_unittest.cc
@@ -0,0 +1,88 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/proximity_auth/bluetooth_throttler_impl.h"
+
+#include "base/test/simple_test_tick_clock.h"
+#include "base/time/time.h"
+#include "components/proximity_auth/wire_message.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace proximity_auth {
+namespace {
+
+class StubConnection : public Connection {
+ public:
+ StubConnection() : Connection(RemoteDevice()) {}
+ ~StubConnection() override {}
+
+ void Connect() override {}
+ void Disconnect() override {}
+ void SendMessageImpl(scoped_ptr<WireMessage> message) override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(StubConnection);
+};
+
+class TestBluetoothThrottler : public BluetoothThrottlerImpl {
+ public:
+ explicit TestBluetoothThrottler(scoped_ptr<base::TickClock> clock)
+ : BluetoothThrottlerImpl(clock.Pass()) {}
+ ~TestBluetoothThrottler() override {}
+
+ // Increase visibility for testing.
+ using BluetoothThrottlerImpl::GetCooldownTimeDelta;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestBluetoothThrottler);
+};
+
+} // namespace
+
+class ProximityAuthBluetoothThrottlerImplTest : public testing::Test {
+ public:
+ ProximityAuthBluetoothThrottlerImplTest()
+ : clock_(new base::SimpleTestTickClock),
+ throttler_(make_scoped_ptr(clock_)) {
+ // The throttler treats null times as special, so start with a non-null
+ // time.
+ clock_->Advance(base::TimeDelta::FromSeconds(1));
+ }
+
+ protected:
+ // The clock is owned by the |throttler_|.
+ base::SimpleTestTickClock* clock_;
+ TestBluetoothThrottler throttler_;
+};
+
+TEST_F(ProximityAuthBluetoothThrottlerImplTest,
+ GetDelay_FirstConnectionIsNotThrottled) {
+ EXPECT_EQ(base::TimeDelta(), throttler_.GetDelay());
+}
+
+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);
+ EXPECT_GT(throttler_.GetDelay(), base::TimeDelta());
+}
+
+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);
+ clock_->Advance(throttler_.GetCooldownTimeDelta());
+ EXPECT_EQ(base::TimeDelta(), throttler_.GetDelay());
+}
+
+} // namespace proximity_auth
« no previous file with comments | « components/proximity_auth/bluetooth_throttler_impl.cc ('k') | components/proximity_auth/client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698