| 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/remote_device.h" |
| 14 #include "components/proximity_auth/bluetooth_connection_finder.h" | 15 #include "components/proximity_auth/bluetooth_connection_finder.h" |
| 15 #include "components/proximity_auth/bluetooth_throttler.h" | 16 #include "components/proximity_auth/bluetooth_throttler.h" |
| 16 #include "components/proximity_auth/fake_connection.h" | 17 #include "components/proximity_auth/fake_connection.h" |
| 17 #include "components/proximity_auth/remote_device.h" | |
| 18 #include "components/proximity_auth/wire_message.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 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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 }; |
| 50 | 50 |
| 51 class FakeBluetoothConnectionFinder : public BluetoothConnectionFinder { | 51 class FakeBluetoothConnectionFinder : public BluetoothConnectionFinder { |
| 52 public: | 52 public: |
| 53 FakeBluetoothConnectionFinder() | 53 FakeBluetoothConnectionFinder() |
| 54 : BluetoothConnectionFinder( | 54 : BluetoothConnectionFinder( |
| 55 RemoteDevice(), | 55 cryptauth::RemoteDevice(), |
| 56 device::BluetoothUUID(kUuid), | 56 device::BluetoothUUID(kUuid), |
| 57 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)) {} | 57 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)) {} |
| 58 ~FakeBluetoothConnectionFinder() override {} | 58 ~FakeBluetoothConnectionFinder() override {} |
| 59 | 59 |
| 60 void Find(const ConnectionCallback& connection_callback) override { | 60 void Find(const ConnectionCallback& connection_callback) override { |
| 61 connection_callback.Run(base::MakeUnique<FakeConnection>(RemoteDevice())); | 61 connection_callback.Run( |
| 62 base::MakeUnique<FakeConnection>(cryptauth::RemoteDevice())); |
| 62 } | 63 } |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothConnectionFinder); | 66 DISALLOW_COPY_AND_ASSIGN(FakeBluetoothConnectionFinder); |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 } // namespace | 69 } // namespace |
| 69 | 70 |
| 70 class ProximityAuthThrottledBluetoothConnectionFinderTest | 71 class ProximityAuthThrottledBluetoothConnectionFinderTest |
| 71 : public testing::Test { | 72 : public testing::Test { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 ThrottledBluetoothConnectionFinder connection_finder( | 116 ThrottledBluetoothConnectionFinder connection_finder( |
| 116 base::WrapUnique(new FakeBluetoothConnectionFinder), task_runner_, | 117 base::WrapUnique(new FakeBluetoothConnectionFinder), task_runner_, |
| 117 &throttler_); | 118 &throttler_); |
| 118 std::unique_ptr<Connection> connection; | 119 std::unique_ptr<Connection> connection; |
| 119 EXPECT_CALL(throttler_, OnConnection(_)); | 120 EXPECT_CALL(throttler_, OnConnection(_)); |
| 120 connection_finder.Find(base::Bind(&SaveConnection, &connection)); | 121 connection_finder.Find(base::Bind(&SaveConnection, &connection)); |
| 121 EXPECT_TRUE(connection); | 122 EXPECT_TRUE(connection); |
| 122 } | 123 } |
| 123 | 124 |
| 124 } // namespace proximity_auth | 125 } // namespace proximity_auth |
| OLD | NEW |