| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/cryptauth/mock_foreground_eid_generator.h" | 5 #include "components/cryptauth/mock_foreground_eid_generator.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 | 8 |
| 9 namespace cryptauth { | 9 namespace cryptauth { |
| 10 | 10 |
| 11 MockForegroundEidGenerator::MockForegroundEidGenerator() | 11 MockForegroundEidGenerator::MockForegroundEidGenerator() |
| 12 : background_scan_filter_(nullptr), | 12 : background_scan_filter_(nullptr), |
| 13 advertisement_(nullptr), | 13 advertisement_(nullptr), |
| 14 possible_advertisements_(nullptr), | 14 possible_advertisements_(nullptr), |
| 15 identified_device_(nullptr), | 15 identified_device_(nullptr), |
| 16 num_identify_calls_(0) {} | 16 num_identify_calls_(0) {} |
| 17 | 17 |
| 18 MockForegroundEidGenerator::~MockForegroundEidGenerator() {} | 18 MockForegroundEidGenerator::~MockForegroundEidGenerator() {} |
| 19 | 19 |
| 20 std::unique_ptr<ForegroundEidGenerator::EidData> | 20 std::unique_ptr<ForegroundEidGenerator::EidData> |
| 21 MockForegroundEidGenerator::GenerateBackgroundScanFilter( | 21 MockForegroundEidGenerator::GenerateBackgroundScanFilter( |
| 22 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const { | 22 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const { |
| 23 if (!background_scan_filter_) { | 23 if (!background_scan_filter_) { |
| 24 return nullptr; | 24 return nullptr; |
| 25 } | 25 } |
| 26 | 26 |
| 27 std::unique_ptr<ForegroundEidGenerator::DataWithTimestamp> adjacent_data; | 27 std::unique_ptr<EidDataWithTimestamp> adjacent_data; |
| 28 if (background_scan_filter_->adjacent_data) { | 28 if (background_scan_filter_->adjacent_data) { |
| 29 adjacent_data = base::MakeUnique<DataWithTimestamp>( | 29 adjacent_data = base::MakeUnique<EidDataWithTimestamp>( |
| 30 background_scan_filter_->adjacent_data->data, | 30 background_scan_filter_->adjacent_data->data, |
| 31 background_scan_filter_->adjacent_data->start_timestamp_ms, | 31 background_scan_filter_->adjacent_data->start_timestamp_ms, |
| 32 background_scan_filter_->adjacent_data->end_timestamp_ms); | 32 background_scan_filter_->adjacent_data->end_timestamp_ms); |
| 33 } | 33 } |
| 34 | 34 |
| 35 return base::MakeUnique<EidData>(background_scan_filter_->current_data, | 35 return base::MakeUnique<EidData>(background_scan_filter_->current_data, |
| 36 std::move(adjacent_data)); | 36 std::move(adjacent_data)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 std::unique_ptr<ForegroundEidGenerator::DataWithTimestamp> | 39 std::unique_ptr<EidDataWithTimestamp> |
| 40 MockForegroundEidGenerator::GenerateAdvertisement( | 40 MockForegroundEidGenerator::GenerateAdvertisement( |
| 41 const std::string& advertising_device_public_key, | 41 const std::string& advertising_device_public_key, |
| 42 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const { | 42 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const { |
| 43 if (!advertisement_) { | 43 if (!advertisement_) { |
| 44 return nullptr; | 44 return nullptr; |
| 45 } | 45 } |
| 46 | 46 |
| 47 return base::MakeUnique<DataWithTimestamp>(advertisement_->data, | 47 return base::MakeUnique<EidDataWithTimestamp>( |
| 48 advertisement_->start_timestamp_ms, | 48 advertisement_->data, advertisement_->start_timestamp_ms, |
| 49 advertisement_->end_timestamp_ms); | 49 advertisement_->end_timestamp_ms); |
| 50 } | 50 } |
| 51 | 51 |
| 52 std::vector<std::string> | 52 std::vector<std::string> |
| 53 MockForegroundEidGenerator::GeneratePossibleAdvertisements( | 53 MockForegroundEidGenerator::GeneratePossibleAdvertisements( |
| 54 const std::string& advertising_device_public_key, | 54 const std::string& advertising_device_public_key, |
| 55 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const { | 55 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const { |
| 56 if (!possible_advertisements_) { | 56 if (!possible_advertisements_) { |
| 57 return std::vector<std::string>(); | 57 return std::vector<std::string>(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 return *possible_advertisements_; | 60 return *possible_advertisements_; |
| 61 } | 61 } |
| 62 | 62 |
| 63 RemoteDevice const* | 63 RemoteDevice const* |
| 64 MockForegroundEidGenerator::IdentifyRemoteDeviceByAdvertisement( | 64 MockForegroundEidGenerator::IdentifyRemoteDeviceByAdvertisement( |
| 65 const std::string& advertisement_service_data, | 65 const std::string& advertisement_service_data, |
| 66 const std::vector<RemoteDevice>& device_list, | 66 const std::vector<RemoteDevice>& device_list, |
| 67 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const { | 67 const std::vector<BeaconSeed>& scanning_device_beacon_seeds) const { |
| 68 // Increment num_identify_calls_. Since this overrides a const method, some | 68 // Increment num_identify_calls_. Since this overrides a const method, some |
| 69 // hacking is needed to modify the num_identify_calls_ instance variable. | 69 // hacking is needed to modify the num_identify_calls_ instance variable. |
| 70 int* num_identify_calls_ptr = const_cast<int*>(&num_identify_calls_); | 70 int* num_identify_calls_ptr = const_cast<int*>(&num_identify_calls_); |
| 71 *num_identify_calls_ptr = *num_identify_calls_ptr + 1; | 71 *num_identify_calls_ptr = *num_identify_calls_ptr + 1; |
| 72 | 72 |
| 73 return identified_device_; | 73 return identified_device_; |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace cryptauth | 76 } // namespace cryptauth |
| OLD | NEW |