| 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 | |
| 66 class MockBluetoothLowEnergyConnectionFinder; | 56 class MockBluetoothLowEnergyConnectionFinder; |
| 67 class FakeEidGenerator : public cryptauth::BackgroundEidGenerator { | 57 class FakeEidGenerator : public cryptauth::BackgroundEidGenerator { |
| 68 public: | 58 public: |
| 69 FakeEidGenerator(MockBluetoothLowEnergyConnectionFinder* connection_finder) | 59 FakeEidGenerator(MockBluetoothLowEnergyConnectionFinder* connection_finder) |
| 70 : connection_finder_(connection_finder) {} | 60 : connection_finder_(connection_finder) {} |
| 71 ~FakeEidGenerator() override {} | 61 ~FakeEidGenerator() override {} |
| 72 | 62 |
| 73 std::vector<cryptauth::DataWithTimestamp> GenerateNearestEids( | 63 std::vector<cryptauth::DataWithTimestamp> GenerateNearestEids( |
| 74 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const override; | 64 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const override; |
| 75 | 65 |
| 76 private: | 66 private: |
| 77 MockBluetoothLowEnergyConnectionFinder* connection_finder_; | 67 MockBluetoothLowEnergyConnectionFinder* connection_finder_; |
| 78 | 68 |
| 79 DISALLOW_COPY_AND_ASSIGN(FakeEidGenerator); | 69 DISALLOW_COPY_AND_ASSIGN(FakeEidGenerator); |
| 80 }; | 70 }; |
| 81 | 71 |
| 82 class MockBluetoothLowEnergyConnectionFinder | 72 class MockBluetoothLowEnergyConnectionFinder |
| 83 : public BluetoothLowEnergyConnectionFinder { | 73 : public BluetoothLowEnergyConnectionFinder { |
| 84 public: | 74 public: |
| 85 MockBluetoothLowEnergyConnectionFinder() | 75 MockBluetoothLowEnergyConnectionFinder() |
| 86 : BluetoothLowEnergyConnectionFinder( | 76 : BluetoothLowEnergyConnectionFinder( |
| 87 cryptauth::CreateLERemoteDeviceForTest(), | 77 cryptauth::CreateLERemoteDeviceForTest(), |
| 88 kBLEGattServiceUUID, | 78 kBLEGattServiceUUID, |
| 89 CreateBeaconSeeds(), | |
| 90 base::MakeUnique<FakeEidGenerator>(this), | 79 base::MakeUnique<FakeEidGenerator>(this), |
| 91 nullptr) {} | 80 nullptr) {} |
| 92 | 81 |
| 93 ~MockBluetoothLowEnergyConnectionFinder() override {} | 82 ~MockBluetoothLowEnergyConnectionFinder() override {} |
| 94 | 83 |
| 95 // Mock methods don't support return type std::unique_ptr<>. This is a | 84 // Mock methods don't support return type std::unique_ptr<>. This is a |
| 96 // possible workaround: mock a proxy method to be called by the target | 85 // possible workaround: mock a proxy method to be called by the target |
| 97 // overridden method (CreateConnection). | 86 // overridden method (CreateConnection). |
| 98 MOCK_METHOD0(CreateConnectionProxy, cryptauth::Connection*()); | 87 MOCK_METHOD0(CreateConnectionProxy, cryptauth::Connection*()); |
| 99 | 88 |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // Completing the connection. | 427 // Completing the connection. |
| 439 base::RunLoop run_loop; | 428 base::RunLoop run_loop; |
| 440 ASSERT_FALSE(last_found_connection_); | 429 ASSERT_FALSE(last_found_connection_); |
| 441 connection->SetStatus(cryptauth::Connection::IN_PROGRESS); | 430 connection->SetStatus(cryptauth::Connection::IN_PROGRESS); |
| 442 connection->SetStatus(cryptauth::Connection::CONNECTED); | 431 connection->SetStatus(cryptauth::Connection::CONNECTED); |
| 443 run_loop.RunUntilIdle(); | 432 run_loop.RunUntilIdle(); |
| 444 EXPECT_TRUE(last_found_connection_); | 433 EXPECT_TRUE(last_found_connection_); |
| 445 } | 434 } |
| 446 | 435 |
| 447 } // namespace proximity_auth | 436 } // namespace proximity_auth |
| OLD | NEW |