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 "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 using device::BluetoothDevice; | 23 using device::BluetoothDevice; |
24 using testing::_; | 24 using testing::_; |
25 using testing::NiceMock; | 25 using testing::NiceMock; |
26 using testing::Return; | 26 using testing::Return; |
27 using testing::SaveArg; | 27 using testing::SaveArg; |
28 | 28 |
29 namespace proximity_auth { | 29 namespace proximity_auth { |
30 namespace { | 30 namespace { |
31 | 31 |
| 32 const char kRemoteDeviceUserId[] = "example@gmail.com"; |
32 const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; | 33 const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; |
33 const char kRemoteDevicePublicKey[] = "Remote Public Key"; | 34 const char kRemoteDevicePublicKey[] = "Remote Public Key"; |
34 const char kRemoteDeviceName[] = "LGE Nexus 5"; | 35 const char kRemoteDeviceName[] = "LGE Nexus 5"; |
35 const char kPersistentSymmetricKey[] = "PSK"; | 36 const char kPersistentSymmetricKey[] = "PSK"; |
36 | 37 |
37 class TestProximityMonitorImpl : public ProximityMonitorImpl { | 38 class TestProximityMonitorImpl : public ProximityMonitorImpl { |
38 public: | 39 public: |
39 explicit TestProximityMonitorImpl(const RemoteDevice& remote_device, | 40 explicit TestProximityMonitorImpl(const RemoteDevice& remote_device, |
40 scoped_ptr<base::TickClock> clock, | 41 scoped_ptr<base::TickClock> clock, |
41 ProximityMonitorObserver* observer) | 42 ProximityMonitorObserver* observer) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 public: | 76 public: |
76 ProximityAuthProximityMonitorImplTest() | 77 ProximityAuthProximityMonitorImplTest() |
77 : clock_(new base::SimpleTestTickClock()), | 78 : clock_(new base::SimpleTestTickClock()), |
78 bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()), | 79 bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()), |
79 remote_bluetooth_device_(&*bluetooth_adapter_, | 80 remote_bluetooth_device_(&*bluetooth_adapter_, |
80 0, | 81 0, |
81 kRemoteDeviceName, | 82 kRemoteDeviceName, |
82 kBluetoothAddress, | 83 kBluetoothAddress, |
83 false /* paired */, | 84 false /* paired */, |
84 true /* connected */), | 85 true /* connected */), |
85 monitor_(RemoteDevice(kRemoteDeviceName, | 86 monitor_(RemoteDevice(kRemoteDeviceUserId, |
| 87 kRemoteDeviceName, |
86 kRemoteDevicePublicKey, | 88 kRemoteDevicePublicKey, |
| 89 RemoteDevice::BLUETOOTH_CLASSIC, |
87 kBluetoothAddress, | 90 kBluetoothAddress, |
88 kPersistentSymmetricKey), | 91 kPersistentSymmetricKey, |
| 92 std::string()), |
89 make_scoped_ptr(clock_), | 93 make_scoped_ptr(clock_), |
90 &observer_), | 94 &observer_), |
91 task_runner_(new base::TestSimpleTaskRunner()), | 95 task_runner_(new base::TestSimpleTaskRunner()), |
92 thread_task_runner_handle_(task_runner_) { | 96 thread_task_runner_handle_(task_runner_) { |
93 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress)) | 97 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress)) |
94 .WillByDefault(Return(&remote_bluetooth_device_)); | 98 .WillByDefault(Return(&remote_bluetooth_device_)); |
95 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_)) | 99 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_)) |
96 .WillByDefault(SaveArg<0>(&connection_info_callback_)); | 100 .WillByDefault(SaveArg<0>(&connection_info_callback_)); |
97 } | 101 } |
98 ~ProximityAuthProximityMonitorImplTest() override {} | 102 ~ProximityAuthProximityMonitorImplTest() override {} |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", | 531 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
528 -100, 1); | 532 -100, 1); |
529 histogram_tester.ExpectUniqueSample( | 533 histogram_tester.ExpectUniqueSample( |
530 "EasyUnlock.AuthProximity.TransmitPowerDelta", 50, 1); | 534 "EasyUnlock.AuthProximity.TransmitPowerDelta", 50, 1); |
531 } | 535 } |
532 | 536 |
533 TEST_F(ProximityAuthProximityMonitorImplTest, | 537 TEST_F(ProximityAuthProximityMonitorImplTest, |
534 RecordProximityMetricsOnAuthSuccess_UnknownValues) { | 538 RecordProximityMetricsOnAuthSuccess_UnknownValues) { |
535 // Note: A device without a recorded name will have its Bluetooth address as | 539 // Note: A device without a recorded name will have its Bluetooth address as |
536 // its name. | 540 // its name. |
537 RemoteDevice unnamed_remote_device(kBluetoothAddress, kRemoteDevicePublicKey, | 541 RemoteDevice unnamed_remote_device( |
538 kBluetoothAddress, | 542 kRemoteDeviceUserId, kBluetoothAddress, kRemoteDevicePublicKey, |
539 kPersistentSymmetricKey); | 543 RemoteDevice::BLUETOOTH_CLASSIC, kBluetoothAddress, |
| 544 kPersistentSymmetricKey, std::string()); |
540 | 545 |
541 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); | 546 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); |
542 ProximityMonitorImpl monitor(unnamed_remote_device, clock.Pass(), &observer_); | 547 ProximityMonitorImpl monitor(unnamed_remote_device, clock.Pass(), &observer_); |
543 monitor.Start(); | 548 monitor.Start(); |
544 ProvideConnectionInfo({127, 127, 127}); | 549 ProvideConnectionInfo({127, 127, 127}); |
545 | 550 |
546 base::HistogramTester histogram_tester; | 551 base::HistogramTester histogram_tester; |
547 monitor.RecordProximityMetricsOnAuthSuccess(); | 552 monitor.RecordProximityMetricsOnAuthSuccess(); |
548 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", | 553 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
549 127, 1); | 554 127, 1); |
550 histogram_tester.ExpectUniqueSample( | 555 histogram_tester.ExpectUniqueSample( |
551 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); | 556 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); |
552 histogram_tester.ExpectUniqueSample( | 557 histogram_tester.ExpectUniqueSample( |
553 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", | 558 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", |
554 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); | 559 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); |
555 histogram_tester.ExpectUniqueSample( | 560 histogram_tester.ExpectUniqueSample( |
556 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", | 561 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", |
557 -1808066424 /* hash of "Unknown" */, 1); | 562 -1808066424 /* hash of "Unknown" */, 1); |
558 } | 563 } |
559 | 564 |
560 } // namespace proximity_auth | 565 } // namespace proximity_auth |
OLD | NEW |