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 <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
13 #include "base/test/simple_test_tick_clock.h" | 14 #include "base/test/simple_test_tick_clock.h" |
14 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "components/proximity_auth/logging/logging.h" | 18 #include "components/proximity_auth/logging/logging.h" |
18 #include "components/proximity_auth/proximity_monitor_observer.h" | 19 #include "components/proximity_auth/proximity_monitor_observer.h" |
19 #include "components/proximity_auth/remote_device.h" | 20 #include "components/proximity_auth/remote_device.h" |
20 #include "device/bluetooth/bluetooth_adapter_factory.h" | 21 #include "device/bluetooth/bluetooth_adapter_factory.h" |
21 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 22 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
(...skipping 11 matching lines...) Expand all Loading... |
33 | 34 |
34 const char kRemoteDeviceUserId[] = "example@gmail.com"; | 35 const char kRemoteDeviceUserId[] = "example@gmail.com"; |
35 const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; | 36 const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; |
36 const char kRemoteDevicePublicKey[] = "Remote Public Key"; | 37 const char kRemoteDevicePublicKey[] = "Remote Public Key"; |
37 const char kRemoteDeviceName[] = "LGE Nexus 5"; | 38 const char kRemoteDeviceName[] = "LGE Nexus 5"; |
38 const char kPersistentSymmetricKey[] = "PSK"; | 39 const char kPersistentSymmetricKey[] = "PSK"; |
39 | 40 |
40 class TestProximityMonitorImpl : public ProximityMonitorImpl { | 41 class TestProximityMonitorImpl : public ProximityMonitorImpl { |
41 public: | 42 public: |
42 explicit TestProximityMonitorImpl(const RemoteDevice& remote_device, | 43 explicit TestProximityMonitorImpl(const RemoteDevice& remote_device, |
43 scoped_ptr<base::TickClock> clock) | 44 std::unique_ptr<base::TickClock> clock) |
44 : ProximityMonitorImpl(remote_device, std::move(clock)) {} | 45 : ProximityMonitorImpl(remote_device, std::move(clock)) {} |
45 ~TestProximityMonitorImpl() override {} | 46 ~TestProximityMonitorImpl() override {} |
46 | 47 |
47 using ProximityMonitorImpl::SetStrategy; | 48 using ProximityMonitorImpl::SetStrategy; |
48 | 49 |
49 private: | 50 private: |
50 DISALLOW_COPY_AND_ASSIGN(TestProximityMonitorImpl); | 51 DISALLOW_COPY_AND_ASSIGN(TestProximityMonitorImpl); |
51 }; | 52 }; |
52 | 53 |
53 class MockProximityMonitorObserver : public ProximityMonitorObserver { | 54 class MockProximityMonitorObserver : public ProximityMonitorObserver { |
(...skipping 30 matching lines...) Expand all Loading... |
84 kBluetoothAddress, | 85 kBluetoothAddress, |
85 false /* paired */, | 86 false /* paired */, |
86 true /* connected */), | 87 true /* connected */), |
87 monitor_(RemoteDevice(kRemoteDeviceUserId, | 88 monitor_(RemoteDevice(kRemoteDeviceUserId, |
88 kRemoteDeviceName, | 89 kRemoteDeviceName, |
89 kRemoteDevicePublicKey, | 90 kRemoteDevicePublicKey, |
90 RemoteDevice::BLUETOOTH_CLASSIC, | 91 RemoteDevice::BLUETOOTH_CLASSIC, |
91 kBluetoothAddress, | 92 kBluetoothAddress, |
92 kPersistentSymmetricKey, | 93 kPersistentSymmetricKey, |
93 std::string()), | 94 std::string()), |
94 make_scoped_ptr(clock_)), | 95 base::WrapUnique(clock_)), |
95 task_runner_(new base::TestSimpleTaskRunner()), | 96 task_runner_(new base::TestSimpleTaskRunner()), |
96 thread_task_runner_handle_(task_runner_) { | 97 thread_task_runner_handle_(task_runner_) { |
97 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress)) | 98 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress)) |
98 .WillByDefault(Return(&remote_bluetooth_device_)); | 99 .WillByDefault(Return(&remote_bluetooth_device_)); |
99 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_)) | 100 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_)) |
100 .WillByDefault(SaveArg<0>(&connection_info_callback_)); | 101 .WillByDefault(SaveArg<0>(&connection_info_callback_)); |
101 monitor_.AddObserver(&observer_); | 102 monitor_.AddObserver(&observer_); |
102 } | 103 } |
103 ~ProximityAuthProximityMonitorImplTest() override {} | 104 ~ProximityAuthProximityMonitorImplTest() override {} |
104 | 105 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 | 538 |
538 TEST_F(ProximityAuthProximityMonitorImplTest, | 539 TEST_F(ProximityAuthProximityMonitorImplTest, |
539 RecordProximityMetricsOnAuthSuccess_UnknownValues) { | 540 RecordProximityMetricsOnAuthSuccess_UnknownValues) { |
540 // Note: A device without a recorded name will have its Bluetooth address as | 541 // Note: A device without a recorded name will have its Bluetooth address as |
541 // its name. | 542 // its name. |
542 RemoteDevice unnamed_remote_device( | 543 RemoteDevice unnamed_remote_device( |
543 kRemoteDeviceUserId, kBluetoothAddress, kRemoteDevicePublicKey, | 544 kRemoteDeviceUserId, kBluetoothAddress, kRemoteDevicePublicKey, |
544 RemoteDevice::BLUETOOTH_CLASSIC, kBluetoothAddress, | 545 RemoteDevice::BLUETOOTH_CLASSIC, kBluetoothAddress, |
545 kPersistentSymmetricKey, std::string()); | 546 kPersistentSymmetricKey, std::string()); |
546 | 547 |
547 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); | 548 std::unique_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); |
548 ProximityMonitorImpl monitor(unnamed_remote_device, std::move(clock)); | 549 ProximityMonitorImpl monitor(unnamed_remote_device, std::move(clock)); |
549 monitor.AddObserver(&observer_); | 550 monitor.AddObserver(&observer_); |
550 monitor.Start(); | 551 monitor.Start(); |
551 ProvideConnectionInfo({127, 127, 127}); | 552 ProvideConnectionInfo({127, 127, 127}); |
552 | 553 |
553 base::HistogramTester histogram_tester; | 554 base::HistogramTester histogram_tester; |
554 monitor.RecordProximityMetricsOnAuthSuccess(); | 555 monitor.RecordProximityMetricsOnAuthSuccess(); |
555 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", | 556 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
556 127, 1); | 557 127, 1); |
557 histogram_tester.ExpectUniqueSample( | 558 histogram_tester.ExpectUniqueSample( |
558 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); | 559 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); |
559 histogram_tester.ExpectUniqueSample( | 560 histogram_tester.ExpectUniqueSample( |
560 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", | 561 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", |
561 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); | 562 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); |
562 histogram_tester.ExpectUniqueSample( | 563 histogram_tester.ExpectUniqueSample( |
563 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", | 564 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", |
564 -1808066424 /* hash of "Unknown" */, 1); | 565 -1808066424 /* hash of "Unknown" */, 1); |
565 } | 566 } |
566 | 567 |
567 } // namespace proximity_auth | 568 } // namespace proximity_auth |
OLD | NEW |