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