Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: components/proximity_auth/proximity_monitor_impl_unittest.cc

Issue 1372283002: Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: fix msan tests Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 29 matching lines...) Expand all
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 RemoteDevice::BLUETOOTH_CLASSIC, 88 RemoteDevice::BLUETOOTH_CLASSIC,
90 kBluetoothAddress, 89 kBluetoothAddress,
91 kPersistentSymmetricKey, 90 kPersistentSymmetricKey,
92 std::string()), 91 std::string()),
93 make_scoped_ptr(clock_), 92 make_scoped_ptr(clock_)),
94 &observer_),
95 task_runner_(new base::TestSimpleTaskRunner()), 93 task_runner_(new base::TestSimpleTaskRunner()),
96 thread_task_runner_handle_(task_runner_) { 94 thread_task_runner_handle_(task_runner_) {
97 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress)) 95 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress))
98 .WillByDefault(Return(&remote_bluetooth_device_)); 96 .WillByDefault(Return(&remote_bluetooth_device_));
99 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_)) 97 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_))
100 .WillByDefault(SaveArg<0>(&connection_info_callback_)); 98 .WillByDefault(SaveArg<0>(&connection_info_callback_));
99 monitor_.AddObserver(&observer_);
101 } 100 }
102 ~ProximityAuthProximityMonitorImplTest() override {} 101 ~ProximityAuthProximityMonitorImplTest() override {}
103 102
104 void RunPendingTasks() { task_runner_->RunPendingTasks(); } 103 void RunPendingTasks() { task_runner_->RunPendingTasks(); }
105 104
106 void ProvideConnectionInfo( 105 void ProvideConnectionInfo(
107 const BluetoothDevice::ConnectionInfo& connection_info) { 106 const BluetoothDevice::ConnectionInfo& connection_info) {
108 RunPendingTasks(); 107 RunPendingTasks();
109 connection_info_callback_.Run(connection_info); 108 connection_info_callback_.Run(connection_info);
110 109
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 TEST_F(ProximityAuthProximityMonitorImplTest, 536 TEST_F(ProximityAuthProximityMonitorImplTest,
538 RecordProximityMetricsOnAuthSuccess_UnknownValues) { 537 RecordProximityMetricsOnAuthSuccess_UnknownValues) {
539 // Note: A device without a recorded name will have its Bluetooth address as 538 // Note: A device without a recorded name will have its Bluetooth address as
540 // its name. 539 // its name.
541 RemoteDevice unnamed_remote_device( 540 RemoteDevice unnamed_remote_device(
542 kRemoteDeviceUserId, kBluetoothAddress, kRemoteDevicePublicKey, 541 kRemoteDeviceUserId, kBluetoothAddress, kRemoteDevicePublicKey,
543 RemoteDevice::BLUETOOTH_CLASSIC, kBluetoothAddress, 542 RemoteDevice::BLUETOOTH_CLASSIC, kBluetoothAddress,
544 kPersistentSymmetricKey, std::string()); 543 kPersistentSymmetricKey, std::string());
545 544
546 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); 545 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock());
547 ProximityMonitorImpl monitor(unnamed_remote_device, clock.Pass(), &observer_); 546 ProximityMonitorImpl monitor(unnamed_remote_device, clock.Pass());
547 monitor.AddObserver(&observer_);
548 monitor.Start(); 548 monitor.Start();
549 ProvideConnectionInfo({127, 127, 127}); 549 ProvideConnectionInfo({127, 127, 127});
550 550
551 base::HistogramTester histogram_tester; 551 base::HistogramTester histogram_tester;
552 monitor.RecordProximityMetricsOnAuthSuccess(); 552 monitor.RecordProximityMetricsOnAuthSuccess();
553 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", 553 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi",
554 127, 1); 554 127, 1);
555 histogram_tester.ExpectUniqueSample( 555 histogram_tester.ExpectUniqueSample(
556 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); 556 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1);
557 histogram_tester.ExpectUniqueSample( 557 histogram_tester.ExpectUniqueSample(
558 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", 558 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi",
559 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); 559 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1);
560 histogram_tester.ExpectUniqueSample( 560 histogram_tester.ExpectUniqueSample(
561 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", 561 "EasyUnlock.AuthProximity.RemoteDeviceModelHash",
562 -1808066424 /* hash of "Unknown" */, 1); 562 -1808066424 /* hash of "Unknown" */, 1);
563 } 563 }
564 564
565 } // namespace proximity_auth 565 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698