Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: components/proximity_auth/bluetooth_low_energy_connection_finder_unittest.cc

Issue 2847233003: [EasyUnlock] Move DataWithTimestamp out of ForegroundEidGenerator so it can be shared. (Closed)
Patch Set: fixes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/proximity_auth/bluetooth_low_energy_connection_finder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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; // 15 minutes.
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::DataWithTimestamp> 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
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::DataWithTimestamp> FakeEidGenerator::GenerateNearestEids(
135 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const { 136 const std::vector<cryptauth::BeaconSeed>& beacon_seed) const {
136 return connection_finder_->nearest_eids(); 137 std::vector<std::string> nearest_eids = connection_finder_->nearest_eids();
138
139 std::vector<cryptauth::DataWithTimestamp> eid_data_with_timestamps;
140 int64_t start_of_period_ms = 0;
141 for (const std::string& eid : nearest_eids) {
142 eid_data_with_timestamps.push_back(cryptauth::DataWithTimestamp(
143 eid, start_of_period_ms, start_of_period_ms + kEidPeriodMs));
144 start_of_period_ms += kEidPeriodMs;
145 }
146
147 return eid_data_with_timestamps;
137 } 148 }
138 149
139 } // namespace 150 } // namespace
140 151
141 class ProximityAuthBluetoothLowEnergyConnectionFinderTest 152 class ProximityAuthBluetoothLowEnergyConnectionFinderTest
142 : public testing::Test { 153 : public testing::Test {
143 protected: 154 protected:
144 ProximityAuthBluetoothLowEnergyConnectionFinderTest() 155 ProximityAuthBluetoothLowEnergyConnectionFinderTest()
145 : adapter_(new NiceMock<device::MockBluetoothAdapter>), 156 : adapter_(new NiceMock<device::MockBluetoothAdapter>),
146 connection_callback_( 157 connection_callback_(
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « components/proximity_auth/bluetooth_low_energy_connection_finder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698