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 20 matching lines...) Expand all Loading... |
31 | 31 |
32 const char kRemoteDeviceUserId[] = "example@gmail.com"; | 32 const char kRemoteDeviceUserId[] = "example@gmail.com"; |
33 const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; | 33 const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; |
34 const char kRemoteDevicePublicKey[] = "Remote Public Key"; | 34 const char kRemoteDevicePublicKey[] = "Remote Public Key"; |
35 const char kRemoteDeviceName[] = "LGE Nexus 5"; | 35 const char kRemoteDeviceName[] = "LGE Nexus 5"; |
36 const char kPersistentSymmetricKey[] = "PSK"; | 36 const char kPersistentSymmetricKey[] = "PSK"; |
37 | 37 |
38 class TestProximityMonitorImpl : public ProximityMonitorImpl { | 38 class TestProximityMonitorImpl : public ProximityMonitorImpl { |
39 public: | 39 public: |
40 explicit TestProximityMonitorImpl(const RemoteDevice& remote_device, | 40 explicit TestProximityMonitorImpl(const RemoteDevice& remote_device, |
41 scoped_ptr<base::TickClock> clock, | 41 scoped_ptr<base::TickClock> clock) |
42 ProximityMonitorObserver* observer) | 42 : ProximityMonitorImpl(remote_device, clock.Pass()) {} |
43 : ProximityMonitorImpl(remote_device, clock.Pass(), observer) {} | |
44 ~TestProximityMonitorImpl() override {} | 43 ~TestProximityMonitorImpl() override {} |
45 | 44 |
46 using ProximityMonitorImpl::SetStrategy; | 45 using ProximityMonitorImpl::SetStrategy; |
47 | 46 |
48 private: | 47 private: |
49 DISALLOW_COPY_AND_ASSIGN(TestProximityMonitorImpl); | 48 DISALLOW_COPY_AND_ASSIGN(TestProximityMonitorImpl); |
50 }; | 49 }; |
51 | 50 |
52 class MockProximityMonitorObserver : public ProximityMonitorObserver { | 51 class MockProximityMonitorObserver : public ProximityMonitorObserver { |
53 public: | 52 public: |
(...skipping 27 matching lines...) Expand all Loading... |
81 0, | 80 0, |
82 kRemoteDeviceName, | 81 kRemoteDeviceName, |
83 kBluetoothAddress, | 82 kBluetoothAddress, |
84 false /* paired */, | 83 false /* paired */, |
85 true /* connected */), | 84 true /* connected */), |
86 monitor_(RemoteDevice(kRemoteDeviceUserId, | 85 monitor_(RemoteDevice(kRemoteDeviceUserId, |
87 kRemoteDeviceName, | 86 kRemoteDeviceName, |
88 kRemoteDevicePublicKey, | 87 kRemoteDevicePublicKey, |
89 kBluetoothAddress, | 88 kBluetoothAddress, |
90 kPersistentSymmetricKey), | 89 kPersistentSymmetricKey), |
91 make_scoped_ptr(clock_), | 90 make_scoped_ptr(clock_)), |
92 &observer_), | |
93 task_runner_(new base::TestSimpleTaskRunner()), | 91 task_runner_(new base::TestSimpleTaskRunner()), |
94 thread_task_runner_handle_(task_runner_) { | 92 thread_task_runner_handle_(task_runner_) { |
95 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress)) | 93 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress)) |
96 .WillByDefault(Return(&remote_bluetooth_device_)); | 94 .WillByDefault(Return(&remote_bluetooth_device_)); |
97 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_)) | 95 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_)) |
98 .WillByDefault(SaveArg<0>(&connection_info_callback_)); | 96 .WillByDefault(SaveArg<0>(&connection_info_callback_)); |
| 97 monitor_.AddObserver(&observer_); |
99 } | 98 } |
100 ~ProximityAuthProximityMonitorImplTest() override {} | 99 ~ProximityAuthProximityMonitorImplTest() override {} |
101 | 100 |
102 void RunPendingTasks() { task_runner_->RunPendingTasks(); } | 101 void RunPendingTasks() { task_runner_->RunPendingTasks(); } |
103 | 102 |
104 void ProvideConnectionInfo( | 103 void ProvideConnectionInfo( |
105 const BluetoothDevice::ConnectionInfo& connection_info) { | 104 const BluetoothDevice::ConnectionInfo& connection_info) { |
106 RunPendingTasks(); | 105 RunPendingTasks(); |
107 connection_info_callback_.Run(connection_info); | 106 connection_info_callback_.Run(connection_info); |
108 | 107 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 533 |
535 TEST_F(ProximityAuthProximityMonitorImplTest, | 534 TEST_F(ProximityAuthProximityMonitorImplTest, |
536 RecordProximityMetricsOnAuthSuccess_UnknownValues) { | 535 RecordProximityMetricsOnAuthSuccess_UnknownValues) { |
537 // Note: A device without a recorded name will have its Bluetooth address as | 536 // Note: A device without a recorded name will have its Bluetooth address as |
538 // its name. | 537 // its name. |
539 RemoteDevice unnamed_remote_device(kRemoteDeviceUserId, kBluetoothAddress, | 538 RemoteDevice unnamed_remote_device(kRemoteDeviceUserId, kBluetoothAddress, |
540 kRemoteDevicePublicKey, kBluetoothAddress, | 539 kRemoteDevicePublicKey, kBluetoothAddress, |
541 kPersistentSymmetricKey); | 540 kPersistentSymmetricKey); |
542 | 541 |
543 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); | 542 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); |
544 ProximityMonitorImpl monitor(unnamed_remote_device, clock.Pass(), &observer_); | 543 ProximityMonitorImpl monitor(unnamed_remote_device, clock.Pass()); |
| 544 monitor.AddObserver(&observer_); |
545 monitor.Start(); | 545 monitor.Start(); |
546 ProvideConnectionInfo({127, 127, 127}); | 546 ProvideConnectionInfo({127, 127, 127}); |
547 | 547 |
548 base::HistogramTester histogram_tester; | 548 base::HistogramTester histogram_tester; |
549 monitor.RecordProximityMetricsOnAuthSuccess(); | 549 monitor.RecordProximityMetricsOnAuthSuccess(); |
550 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", | 550 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
551 127, 1); | 551 127, 1); |
552 histogram_tester.ExpectUniqueSample( | 552 histogram_tester.ExpectUniqueSample( |
553 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); | 553 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); |
554 histogram_tester.ExpectUniqueSample( | 554 histogram_tester.ExpectUniqueSample( |
555 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", | 555 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", |
556 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); | 556 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); |
557 histogram_tester.ExpectUniqueSample( | 557 histogram_tester.ExpectUniqueSample( |
558 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", | 558 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", |
559 -1808066424 /* hash of "Unknown" */, 1); | 559 -1808066424 /* hash of "Unknown" */, 1); |
560 } | 560 } |
561 | 561 |
562 } // namespace proximity_auth | 562 } // namespace proximity_auth |
OLD | NEW |