| 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/throttled_bluetooth_connection_finder.h" | 5 #include "components/proximity_auth/throttled_bluetooth_connection_finder.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "components/cryptauth/bluetooth_throttler.h" |
| 15 #include "components/cryptauth/fake_connection.h" |
| 14 #include "components/cryptauth/remote_device.h" | 16 #include "components/cryptauth/remote_device.h" |
| 17 #include "components/cryptauth/wire_message.h" |
| 15 #include "components/proximity_auth/bluetooth_connection_finder.h" | 18 #include "components/proximity_auth/bluetooth_connection_finder.h" |
| 16 #include "components/proximity_auth/bluetooth_throttler.h" | |
| 17 #include "components/proximity_auth/fake_connection.h" | |
| 18 #include "components/proximity_auth/wire_message.h" | |
| 19 #include "device/bluetooth/bluetooth_uuid.h" | 19 #include "device/bluetooth/bluetooth_uuid.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 using testing::NiceMock; | 23 using testing::NiceMock; |
| 24 using testing::Return; | 24 using testing::Return; |
| 25 using testing::_; | 25 using testing::_; |
| 26 | 26 |
| 27 namespace proximity_auth { | 27 namespace proximity_auth { |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const int kPollingIntervalSeconds = 7; | 30 const int kPollingIntervalSeconds = 7; |
| 31 const char kUuid[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEF"; | 31 const char kUuid[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEF"; |
| 32 | 32 |
| 33 // A callback that stores a found |connection| into |out|. | 33 // A callback that stores a found |connection| into |out|. |
| 34 void SaveConnection(std::unique_ptr<Connection>* out, | 34 void SaveConnection(std::unique_ptr<Connection>* out, |
| 35 std::unique_ptr<Connection> connection) { | 35 std::unique_ptr<Connection> connection) { |
| 36 *out = std::move(connection); | 36 *out = std::move(connection); |
| 37 } | 37 } |
| 38 | 38 |
| 39 class MockBluetoothThrottler : public BluetoothThrottler { | 39 class MockBluetoothThrottler : public cryptauth::BluetoothThrottler { |
| 40 public: | 40 public: |
| 41 MockBluetoothThrottler() {} | 41 MockBluetoothThrottler() {} |
| 42 ~MockBluetoothThrottler() override {} | 42 ~MockBluetoothThrottler() override {} |
| 43 | 43 |
| 44 MOCK_CONST_METHOD0(GetDelay, base::TimeDelta()); | 44 MOCK_CONST_METHOD0(GetDelay, base::TimeDelta()); |
| 45 MOCK_METHOD1(OnConnection, void(Connection* connection)); | 45 MOCK_METHOD1(OnConnection, void(Connection* connection)); |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(MockBluetoothThrottler); | 48 DISALLOW_COPY_AND_ASSIGN(MockBluetoothThrottler); |
| 49 }; | 49 }; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 ThrottledBluetoothConnectionFinder connection_finder( | 116 ThrottledBluetoothConnectionFinder connection_finder( |
| 117 base::WrapUnique(new FakeBluetoothConnectionFinder), task_runner_, | 117 base::WrapUnique(new FakeBluetoothConnectionFinder), task_runner_, |
| 118 &throttler_); | 118 &throttler_); |
| 119 std::unique_ptr<Connection> connection; | 119 std::unique_ptr<Connection> connection; |
| 120 EXPECT_CALL(throttler_, OnConnection(_)); | 120 EXPECT_CALL(throttler_, OnConnection(_)); |
| 121 connection_finder.Find(base::Bind(&SaveConnection, &connection)); | 121 connection_finder.Find(base::Bind(&SaveConnection, &connection)); |
| 122 EXPECT_TRUE(connection); | 122 EXPECT_TRUE(connection); |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace proximity_auth | 125 } // namespace proximity_auth |
| OLD | NEW |