Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 namespace proximity_auth { | 44 namespace proximity_auth { |
| 45 namespace { | 45 namespace { |
| 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; | |
|
Kyle Horimoto
2017/04/28 22:19:17
nit: Use a constant kEidPeriodMinutes = 15 and use
Tim Song
2017/04/29 01:07:50
It seems cleaner to use milliseconds directly as I
Kyle Horimoto
2017/04/30 03:17:42
Alright, can you add a "15 minutes" comment then?
Tim Song
2017/05/01 22:23:38
Done.
| |
| 54 | 55 |
| 55 std::vector<cryptauth::BeaconSeed> CreateBeaconSeeds() { | 56 std::vector<cryptauth::BeaconSeed> CreateBeaconSeeds() { |
| 56 std::vector<cryptauth::BeaconSeed> beacon_seeds; | 57 std::vector<cryptauth::BeaconSeed> beacon_seeds; |
| 57 cryptauth::BeaconSeed seed; | 58 cryptauth::BeaconSeed seed; |
| 58 seed.set_data("\xab\xcd"); | 59 seed.set_data("\xab\xcd"); |
| 59 seed.set_start_time_millis(0); | 60 seed.set_start_time_millis(0); |
| 60 seed.set_end_time_millis(10000000); | 61 seed.set_end_time_millis(10000000); |
| 61 beacon_seeds.push_back(seed); | 62 beacon_seeds.push_back(seed); |
| 62 return beacon_seeds; | 63 return beacon_seeds; |
| 63 } | 64 } |
| 64 | 65 |
| 65 class MockBluetoothLowEnergyConnectionFinder; | 66 class MockBluetoothLowEnergyConnectionFinder; |
| 66 class FakeEidGenerator : public cryptauth::BackgroundEidGenerator { | 67 class FakeEidGenerator : public cryptauth::BackgroundEidGenerator { |
| 67 public: | 68 public: |
| 68 FakeEidGenerator(MockBluetoothLowEnergyConnectionFinder* connection_finder) | 69 FakeEidGenerator(MockBluetoothLowEnergyConnectionFinder* connection_finder) |
| 69 : connection_finder_(connection_finder) {} | 70 : connection_finder_(connection_finder) {} |
| 70 ~FakeEidGenerator() override {} | 71 ~FakeEidGenerator() override {} |
| 71 | 72 |
| 72 std::vector<std::string> GenerateNearestEids( | 73 std::vector<cryptauth::EidDataWithTimestamp> GenerateNearestEids( |
| 73 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const override; | 74 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const override; |
| 74 | 75 |
| 75 private: | 76 private: |
| 76 MockBluetoothLowEnergyConnectionFinder* connection_finder_; | 77 MockBluetoothLowEnergyConnectionFinder* connection_finder_; |
| 77 | 78 |
| 78 DISALLOW_COPY_AND_ASSIGN(FakeEidGenerator); | 79 DISALLOW_COPY_AND_ASSIGN(FakeEidGenerator); |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 class MockBluetoothLowEnergyConnectionFinder | 82 class MockBluetoothLowEnergyConnectionFinder |
| 82 : public BluetoothLowEnergyConnectionFinder { | 83 : public BluetoothLowEnergyConnectionFinder { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 } | 125 } |
| 125 | 126 |
| 126 private: | 127 private: |
| 127 std::vector<std::string> nearest_eids_; | 128 std::vector<std::string> nearest_eids_; |
| 128 | 129 |
| 129 DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyConnectionFinder); | 130 DISALLOW_COPY_AND_ASSIGN(MockBluetoothLowEnergyConnectionFinder); |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 // Not declared in-line due to dependency on | 133 // Not declared in-line due to dependency on |
| 133 // MockBluetoothLowEnergyConnectionFinder. | 134 // MockBluetoothLowEnergyConnectionFinder. |
| 134 std::vector<std::string> FakeEidGenerator::GenerateNearestEids( | 135 std::vector<cryptauth::EidDataWithTimestamp> |
| 136 FakeEidGenerator::GenerateNearestEids( | |
| 135 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const { | 137 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const { |
| 136 return connection_finder_->nearest_eids(); | 138 std::vector<std::string> nearest_eids = connection_finder_->nearest_eids(); |
| 139 | |
| 140 std::vector<cryptauth::EidDataWithTimestamp> eid_data_with_timestamps; | |
| 141 int64_t start_of_period_ms = 0; | |
| 142 for (const std::string& eid : nearest_eids) { | |
| 143 eid_data_with_timestamps.push_back(cryptauth::EidDataWithTimestamp( | |
| 144 eid, start_of_period_ms, start_of_period_ms + kEidPeriodMs)); | |
| 145 start_of_period_ms += kEidPeriodMs; | |
| 146 } | |
| 147 | |
| 148 return eid_data_with_timestamps; | |
| 137 } | 149 } |
| 138 | 150 |
| 139 } // namespace | 151 } // namespace |
| 140 | 152 |
| 141 class ProximityAuthBluetoothLowEnergyConnectionFinderTest | 153 class ProximityAuthBluetoothLowEnergyConnectionFinderTest |
| 142 : public testing::Test { | 154 : public testing::Test { |
| 143 protected: | 155 protected: |
| 144 ProximityAuthBluetoothLowEnergyConnectionFinderTest() | 156 ProximityAuthBluetoothLowEnergyConnectionFinderTest() |
| 145 : adapter_(new NiceMock<device::MockBluetoothAdapter>), | 157 : adapter_(new NiceMock<device::MockBluetoothAdapter>), |
| 146 connection_callback_( | 158 connection_callback_( |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 // Completing the connection. | 439 // Completing the connection. |
| 428 base::RunLoop run_loop; | 440 base::RunLoop run_loop; |
| 429 ASSERT_FALSE(last_found_connection_); | 441 ASSERT_FALSE(last_found_connection_); |
| 430 connection->SetStatus(cryptauth::Connection::IN_PROGRESS); | 442 connection->SetStatus(cryptauth::Connection::IN_PROGRESS); |
| 431 connection->SetStatus(cryptauth::Connection::CONNECTED); | 443 connection->SetStatus(cryptauth::Connection::CONNECTED); |
| 432 run_loop.RunUntilIdle(); | 444 run_loop.RunUntilIdle(); |
| 433 EXPECT_TRUE(last_found_connection_); | 445 EXPECT_TRUE(last_found_connection_); |
| 434 } | 446 } |
| 435 | 447 |
| 436 } // namespace proximity_auth | 448 } // namespace proximity_auth |
| OLD | NEW |