| 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_low_energy_connection_finder.h" | 5 #include "components/proximity_auth/bluetooth_low_energy_connection_finder.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 const char kBLEGattServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; | 47 const char kBLEGattServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; |
| 48 const char kAdvertisementUUID[] = "0000fe50-0000-1000-8000-00805f9b34fb"; | 48 const char kAdvertisementUUID[] = "0000fe50-0000-1000-8000-00805f9b34fb"; |
| 49 const int8_t kRssi = -30; | 49 const int8_t kRssi = -30; |
| 50 const char kEidForPreviousTimeQuantum[] = "\x12\x34"; | 50 const char kEidForPreviousTimeQuantum[] = "\x12\x34"; |
| 51 const char kEidForCurrentTimeQuantum[] = "\xab\xcd"; | 51 const char kEidForCurrentTimeQuantum[] = "\xab\xcd"; |
| 52 const char kEidForNextTimeQuantum[] = "\x56\x78"; | 52 const char kEidForNextTimeQuantum[] = "\x56\x78"; |
| 53 const char kWrongEid[] = "\xff\xff"; | 53 const char kWrongEid[] = "\xff\xff"; |
| 54 const int64_t kEidPeriodMs = 60 * 1000 * 15; // 15 minutes. | 54 const int64_t kEidPeriodMs = 60 * 1000 * 15; // 15 minutes. |
| 55 | 55 |
| 56 std::vector<cryptauth::BeaconSeed> CreateBeaconSeeds() { |
| 57 std::vector<cryptauth::BeaconSeed> beacon_seeds; |
| 58 cryptauth::BeaconSeed seed; |
| 59 seed.set_data("\xab\xcd"); |
| 60 seed.set_start_time_millis(0); |
| 61 seed.set_end_time_millis(10000000); |
| 62 beacon_seeds.push_back(seed); |
| 63 return beacon_seeds; |
| 64 } |
| 65 |
| 56 class MockBluetoothLowEnergyConnectionFinder; | 66 class MockBluetoothLowEnergyConnectionFinder; |
| 57 class FakeEidGenerator : public cryptauth::BackgroundEidGenerator { | 67 class FakeEidGenerator : public cryptauth::BackgroundEidGenerator { |
| 58 public: | 68 public: |
| 59 FakeEidGenerator(MockBluetoothLowEnergyConnectionFinder* connection_finder) | 69 FakeEidGenerator(MockBluetoothLowEnergyConnectionFinder* connection_finder) |
| 60 : connection_finder_(connection_finder) {} | 70 : connection_finder_(connection_finder) {} |
| 61 ~FakeEidGenerator() override {} | 71 ~FakeEidGenerator() override {} |
| 62 | 72 |
| 63 std::vector<cryptauth::DataWithTimestamp> GenerateNearestEids( | 73 std::vector<cryptauth::DataWithTimestamp> GenerateNearestEids( |
| 64 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const override; | 74 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const override; |
| 65 | 75 |
| 66 private: | 76 private: |
| 67 MockBluetoothLowEnergyConnectionFinder* connection_finder_; | 77 MockBluetoothLowEnergyConnectionFinder* connection_finder_; |
| 68 | 78 |
| 69 DISALLOW_COPY_AND_ASSIGN(FakeEidGenerator); | 79 DISALLOW_COPY_AND_ASSIGN(FakeEidGenerator); |
| 70 }; | 80 }; |
| 71 | 81 |
| 72 class MockBluetoothLowEnergyConnectionFinder | 82 class MockBluetoothLowEnergyConnectionFinder |
| 73 : public BluetoothLowEnergyConnectionFinder { | 83 : public BluetoothLowEnergyConnectionFinder { |
| 74 public: | 84 public: |
| 75 MockBluetoothLowEnergyConnectionFinder() | 85 MockBluetoothLowEnergyConnectionFinder() |
| 76 : BluetoothLowEnergyConnectionFinder( | 86 : BluetoothLowEnergyConnectionFinder( |
| 77 cryptauth::CreateLERemoteDeviceForTest(), | 87 cryptauth::CreateLERemoteDeviceForTest(), |
| 78 kBLEGattServiceUUID, | 88 kBLEGattServiceUUID, |
| 89 CreateBeaconSeeds(), |
| 79 base::MakeUnique<FakeEidGenerator>(this), | 90 base::MakeUnique<FakeEidGenerator>(this), |
| 80 nullptr) {} | 91 nullptr) {} |
| 81 | 92 |
| 82 ~MockBluetoothLowEnergyConnectionFinder() override {} | 93 ~MockBluetoothLowEnergyConnectionFinder() override {} |
| 83 | 94 |
| 84 // Mock methods don't support return type std::unique_ptr<>. This is a | 95 // Mock methods don't support return type std::unique_ptr<>. This is a |
| 85 // possible workaround: mock a proxy method to be called by the target | 96 // possible workaround: mock a proxy method to be called by the target |
| 86 // overridden method (CreateConnection). | 97 // overridden method (CreateConnection). |
| 87 MOCK_METHOD0(CreateConnectionProxy, cryptauth::Connection*()); | 98 MOCK_METHOD0(CreateConnectionProxy, cryptauth::Connection*()); |
| 88 | 99 |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // Completing the connection. | 438 // Completing the connection. |
| 428 base::RunLoop run_loop; | 439 base::RunLoop run_loop; |
| 429 ASSERT_FALSE(last_found_connection_); | 440 ASSERT_FALSE(last_found_connection_); |
| 430 connection->SetStatus(cryptauth::Connection::IN_PROGRESS); | 441 connection->SetStatus(cryptauth::Connection::IN_PROGRESS); |
| 431 connection->SetStatus(cryptauth::Connection::CONNECTED); | 442 connection->SetStatus(cryptauth::Connection::CONNECTED); |
| 432 run_loop.RunUntilIdle(); | 443 run_loop.RunUntilIdle(); |
| 433 EXPECT_TRUE(last_found_connection_); | 444 EXPECT_TRUE(last_found_connection_); |
| 434 } | 445 } |
| 435 | 446 |
| 436 } // namespace proximity_auth | 447 } // namespace proximity_auth |
| OLD | NEW |