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/proximity_monitor_impl.h" | 5 #include "components/proximity_auth/proximity_monitor_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 EXPECT_TRUE(monitor_.IsUnlockAllowed()); | 229 EXPECT_TRUE(monitor_.IsUnlockAllowed()); |
230 EXPECT_TRUE(monitor_.IsInRssiRange()); | 230 EXPECT_TRUE(monitor_.IsInRssiRange()); |
231 } | 231 } |
232 | 232 |
233 TEST_F(ProximityAuthProximityMonitorImplTest, | 233 TEST_F(ProximityAuthProximityMonitorImplTest, |
234 ProximityState_CheckRssi_UnknownRssi) { | 234 ProximityState_CheckRssi_UnknownRssi) { |
235 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI); | 235 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI); |
236 monitor_.Start(); | 236 monitor_.Start(); |
237 | 237 |
238 ProvideConnectionInfo({0, 0, 4}); | 238 ProvideConnectionInfo({0, 0, 4}); |
239 ProvideConnectionInfo({BluetoothDevice::kUnknownPower, 0, 4}); | 239 ProvideConnectionInfo({BluetoothDevice::kUnknownRSSI, 0, 4}); |
240 | 240 |
241 EXPECT_FALSE(monitor_.IsUnlockAllowed()); | 241 EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
242 EXPECT_FALSE(monitor_.IsInRssiRange()); | 242 EXPECT_FALSE(monitor_.IsInRssiRange()); |
243 } | 243 } |
244 | 244 |
245 TEST_F(ProximityAuthProximityMonitorImplTest, | 245 TEST_F(ProximityAuthProximityMonitorImplTest, |
246 ProximityState_CheckRssi_UnknownTxPower) { | 246 ProximityState_CheckRssi_UnknownTxPower) { |
247 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI); | 247 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI); |
248 monitor_.Start(); | 248 monitor_.Start(); |
249 | 249 |
250 ProvideConnectionInfo({0, 0, 4}); | 250 ProvideConnectionInfo({0, 0, 4}); |
251 ProvideConnectionInfo({0, BluetoothDevice::kUnknownPower, 4}); | 251 ProvideConnectionInfo({0, BluetoothDevice::kUnknownTxPower, 4}); |
252 | 252 |
253 EXPECT_FALSE(monitor_.IsUnlockAllowed()); | 253 EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
254 EXPECT_FALSE(monitor_.IsInRssiRange()); | 254 EXPECT_FALSE(monitor_.IsInRssiRange()); |
255 } | 255 } |
256 | 256 |
257 TEST_F(ProximityAuthProximityMonitorImplTest, | 257 TEST_F(ProximityAuthProximityMonitorImplTest, |
258 ProximityState_CheckRssi_UnknownMaxTxPower) { | 258 ProximityState_CheckRssi_UnknownMaxTxPower) { |
259 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI); | 259 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI); |
260 monitor_.Start(); | 260 monitor_.Start(); |
261 | 261 |
262 ProvideConnectionInfo({0, 0, 4}); | 262 ProvideConnectionInfo({0, 0, 4}); |
263 ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownPower}); | 263 ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownTxPower}); |
264 | 264 |
265 EXPECT_FALSE(monitor_.IsUnlockAllowed()); | 265 EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
266 EXPECT_FALSE(monitor_.IsInRssiRange()); | 266 EXPECT_FALSE(monitor_.IsInRssiRange()); |
267 } | 267 } |
268 | 268 |
269 TEST_F(ProximityAuthProximityMonitorImplTest, | 269 TEST_F(ProximityAuthProximityMonitorImplTest, |
270 ProximityState_CheckTxPower_RssiIndicatesProximity_TxPowerDoesNot) { | 270 ProximityState_CheckTxPower_RssiIndicatesProximity_TxPowerDoesNot) { |
271 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER); | 271 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER); |
272 monitor_.Start(); | 272 monitor_.Start(); |
273 | 273 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 EXPECT_TRUE(monitor_.IsUnlockAllowed()); | 309 EXPECT_TRUE(monitor_.IsUnlockAllowed()); |
310 EXPECT_TRUE(monitor_.IsInRssiRange()); | 310 EXPECT_TRUE(monitor_.IsInRssiRange()); |
311 } | 311 } |
312 | 312 |
313 TEST_F(ProximityAuthProximityMonitorImplTest, | 313 TEST_F(ProximityAuthProximityMonitorImplTest, |
314 ProximityState_CheckTxPower_UnknownRssi) { | 314 ProximityState_CheckTxPower_UnknownRssi) { |
315 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER); | 315 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER); |
316 monitor_.Start(); | 316 monitor_.Start(); |
317 | 317 |
318 ProvideConnectionInfo({0, 0, 4}); | 318 ProvideConnectionInfo({0, 0, 4}); |
319 ProvideConnectionInfo({BluetoothDevice::kUnknownPower, 0, 4}); | 319 ProvideConnectionInfo({BluetoothDevice::kUnknownRSSI, 0, 4}); |
320 | 320 |
321 EXPECT_FALSE(monitor_.IsUnlockAllowed()); | 321 EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
322 EXPECT_FALSE(monitor_.IsInRssiRange()); | 322 EXPECT_FALSE(monitor_.IsInRssiRange()); |
323 } | 323 } |
324 | 324 |
325 TEST_F(ProximityAuthProximityMonitorImplTest, | 325 TEST_F(ProximityAuthProximityMonitorImplTest, |
326 ProximityState_CheckTxPower_UnknownTxPower) { | 326 ProximityState_CheckTxPower_UnknownTxPower) { |
327 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER); | 327 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER); |
328 monitor_.Start(); | 328 monitor_.Start(); |
329 | 329 |
330 ProvideConnectionInfo({0, 0, 4}); | 330 ProvideConnectionInfo({0, 0, 4}); |
331 ProvideConnectionInfo({0, BluetoothDevice::kUnknownPower, 4}); | 331 ProvideConnectionInfo({0, BluetoothDevice::kUnknownTxPower, 4}); |
332 | 332 |
333 EXPECT_FALSE(monitor_.IsUnlockAllowed()); | 333 EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
334 EXPECT_FALSE(monitor_.IsInRssiRange()); | 334 EXPECT_FALSE(monitor_.IsInRssiRange()); |
335 } | 335 } |
336 | 336 |
337 TEST_F(ProximityAuthProximityMonitorImplTest, | 337 TEST_F(ProximityAuthProximityMonitorImplTest, |
338 ProximityState_CheckTxPower_UnknownMaxTxPower) { | 338 ProximityState_CheckTxPower_UnknownMaxTxPower) { |
339 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER); | 339 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_TRANSMIT_POWER); |
340 monitor_.Start(); | 340 monitor_.Start(); |
341 | 341 |
342 ProvideConnectionInfo({0, 0, 4}); | 342 ProvideConnectionInfo({0, 0, 4}); |
343 ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownPower}); | 343 ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownTxPower}); |
344 | 344 |
345 EXPECT_FALSE(monitor_.IsUnlockAllowed()); | 345 EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
346 EXPECT_FALSE(monitor_.IsInRssiRange()); | 346 EXPECT_FALSE(monitor_.IsInRssiRange()); |
347 } | 347 } |
348 | 348 |
349 TEST_F(ProximityAuthProximityMonitorImplTest, ProximityState_StartThenStop) { | 349 TEST_F(ProximityAuthProximityMonitorImplTest, ProximityState_StartThenStop) { |
350 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI); | 350 monitor_.SetStrategy(ProximityMonitor::Strategy::CHECK_RSSI); |
351 | 351 |
352 monitor_.Start(); | 352 monitor_.Start(); |
353 ProvideConnectionInfo({0, 0, 4}); | 353 ProvideConnectionInfo({0, 0, 4}); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 histogram_tester.ExpectUniqueSample( | 517 histogram_tester.ExpectUniqueSample( |
518 "EasyUnlock.AuthProximity.TransmitPowerDelta", -1, 1); | 518 "EasyUnlock.AuthProximity.TransmitPowerDelta", -1, 1); |
519 histogram_tester.ExpectUniqueSample( | 519 histogram_tester.ExpectUniqueSample( |
520 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", 304, 1); | 520 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", 304, 1); |
521 histogram_tester.ExpectUniqueSample( | 521 histogram_tester.ExpectUniqueSample( |
522 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", | 522 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", |
523 1881443083 /* hash of "LGE Nexus 5" */, 1); | 523 1881443083 /* hash of "LGE Nexus 5" */, 1); |
524 } | 524 } |
525 | 525 |
526 TEST_F(ProximityAuthProximityMonitorImplTest, | 526 TEST_F(ProximityAuthProximityMonitorImplTest, |
527 RecordProximityMetricsOnAuthSuccess_ClampedValues) { | 527 RecordProximityMetricsOnAuthSuccess_ClampedValues_LowerThreshold) { |
528 // Tests that we clamp values lower than -100 before histograming. | |
529 int8_t rssi = -128; | |
530 int8_t tx_power = -127; | |
531 int8_t max_tx_power = 0; | |
532 int8_t tx_power_delta = tx_power - max_tx_power; | |
533 | |
528 monitor_.Start(); | 534 monitor_.Start(); |
Ilya Sherman
2016/05/04 23:01:44
nit: I'd keep this line right above ProvideConnect
ortuno
2016/05/07 00:32:09
Done.
| |
529 ProvideConnectionInfo({-99999, 99999, 12345}); | 535 |
536 ASSERT_NE(BluetoothDevice::kUnknownRSSI, rssi); | |
537 ASSERT_NE(BluetoothDevice::kUnknownTxPower, tx_power); | |
538 ASSERT_NE(BluetoothDevice::kUnknownTxPower, max_tx_power); | |
539 ASSERT_NE(BluetoothDevice::kUnknownTxPower, tx_power_delta); | |
540 | |
541 ProvideConnectionInfo({rssi, tx_power, max_tx_power}); | |
530 | 542 |
531 base::HistogramTester histogram_tester; | 543 base::HistogramTester histogram_tester; |
532 monitor_.RecordProximityMetricsOnAuthSuccess(); | 544 monitor_.RecordProximityMetricsOnAuthSuccess(); |
533 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", | 545 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
534 -100, 1); | 546 -100, 1); |
535 histogram_tester.ExpectUniqueSample( | 547 histogram_tester.ExpectUniqueSample( |
548 "EasyUnlock.AuthProximity.TransmitPowerDelta", -100, 1); | |
549 } | |
550 | |
551 TEST_F(ProximityAuthProximityMonitorImplTest, | |
552 RecordProximityMetricsOnAuthSuccess_ClampedValues_UpperThreshold) { | |
553 // Tests that we clamp values larger than 50 before histograming. | |
554 int8_t rssi = 126; | |
555 int8_t tx_power = 127; | |
556 int8_t max_tx_power = 0; | |
557 int8_t tx_power_delta = tx_power - max_tx_power; | |
558 | |
559 monitor_.Start(); | |
560 | |
561 ASSERT_NE(BluetoothDevice::kUnknownRSSI, rssi); | |
562 ASSERT_NE(BluetoothDevice::kUnknownTxPower, tx_power); | |
563 ASSERT_NE(BluetoothDevice::kUnknownTxPower, max_tx_power); | |
564 ASSERT_NE(BluetoothDevice::kUnknownTxPower, tx_power_delta); | |
565 | |
566 ProvideConnectionInfo({rssi, tx_power, max_tx_power}); | |
567 | |
568 base::HistogramTester histogram_tester; | |
569 monitor_.RecordProximityMetricsOnAuthSuccess(); | |
570 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", | |
571 50, 1); | |
572 histogram_tester.ExpectUniqueSample( | |
536 "EasyUnlock.AuthProximity.TransmitPowerDelta", 50, 1); | 573 "EasyUnlock.AuthProximity.TransmitPowerDelta", 50, 1); |
537 } | 574 } |
538 | 575 |
539 TEST_F(ProximityAuthProximityMonitorImplTest, | 576 TEST_F(ProximityAuthProximityMonitorImplTest, |
540 RecordProximityMetricsOnAuthSuccess_UnknownValues) { | 577 RecordProximityMetricsOnAuthSuccess_UnknownValues) { |
541 // Note: A device without a recorded name will have its Bluetooth address as | 578 // Note: A device without a recorded name will have its Bluetooth address as |
542 // its name. | 579 // its name. |
543 RemoteDevice unnamed_remote_device( | 580 RemoteDevice unnamed_remote_device( |
544 kRemoteDeviceUserId, kBluetoothAddress, kRemoteDevicePublicKey, | 581 kRemoteDeviceUserId, kBluetoothAddress, kRemoteDevicePublicKey, |
545 RemoteDevice::BLUETOOTH_CLASSIC, kBluetoothAddress, | 582 RemoteDevice::BLUETOOTH_CLASSIC, kBluetoothAddress, |
546 kPersistentSymmetricKey, std::string()); | 583 kPersistentSymmetricKey, std::string()); |
547 | 584 |
548 std::unique_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); | 585 std::unique_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); |
549 ProximityMonitorImpl monitor(unnamed_remote_device, std::move(clock)); | 586 ProximityMonitorImpl monitor(unnamed_remote_device, std::move(clock)); |
550 monitor.AddObserver(&observer_); | 587 monitor.AddObserver(&observer_); |
551 monitor.Start(); | 588 monitor.Start(); |
552 ProvideConnectionInfo({127, 127, 127}); | 589 ProvideConnectionInfo({BluetoothDevice::kUnknownRSSI, |
590 BluetoothDevice::kUnknownTxPower, | |
591 BluetoothDevice::kUnknownTxPower}); | |
553 | 592 |
554 base::HistogramTester histogram_tester; | 593 base::HistogramTester histogram_tester; |
555 monitor.RecordProximityMetricsOnAuthSuccess(); | 594 monitor.RecordProximityMetricsOnAuthSuccess(); |
556 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", | 595 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
557 127, 1); | 596 BluetoothDevice::kUnknownRSSI, 1); |
Ilya Sherman
2016/05/04 23:01:44
Hmm, the reported RSSI shouldn't change, even if t
ortuno
2016/05/07 00:32:09
Ah. I misunderstood the purpose of the test. Fixed
| |
558 histogram_tester.ExpectUniqueSample( | 597 histogram_tester.ExpectUniqueSample( |
559 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); | 598 "EasyUnlock.AuthProximity.TransmitPowerDelta", |
599 BluetoothDevice::kUnknownTxPower, 1); | |
Ilya Sherman
2016/05/04 23:01:44
Ditto.
ortuno
2016/05/07 00:32:09
Done.
| |
560 histogram_tester.ExpectUniqueSample( | 600 histogram_tester.ExpectUniqueSample( |
561 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", | 601 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", |
562 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); | 602 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); |
563 histogram_tester.ExpectUniqueSample( | 603 histogram_tester.ExpectUniqueSample( |
564 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", | 604 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", |
565 -1808066424 /* hash of "Unknown" */, 1); | 605 -1808066424 /* hash of "Unknown" */, 1); |
566 } | 606 } |
567 | 607 |
568 } // namespace proximity_auth | 608 } // namespace proximity_auth |
OLD | NEW |