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

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

Issue 1356943004: Add RemoteDeviceLoader to create RemoteDevice from CryptAuth data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webui
Patch Set: 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 11 matching lines...) Expand all
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
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,
87 kBluetoothAddress, 89 kBluetoothAddress,
88 kPersistentSymmetricKey), 90 kPersistentSymmetricKey),
89 make_scoped_ptr(clock_), 91 make_scoped_ptr(clock_),
90 &observer_), 92 &observer_),
91 task_runner_(new base::TestSimpleTaskRunner()), 93 task_runner_(new base::TestSimpleTaskRunner()),
92 thread_task_runner_handle_(task_runner_) { 94 thread_task_runner_handle_(task_runner_) {
93 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress)) 95 ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress))
94 .WillByDefault(Return(&remote_bluetooth_device_)); 96 .WillByDefault(Return(&remote_bluetooth_device_));
95 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_)) 97 ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_))
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", 529 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi",
528 -100, 1); 530 -100, 1);
529 histogram_tester.ExpectUniqueSample( 531 histogram_tester.ExpectUniqueSample(
530 "EasyUnlock.AuthProximity.TransmitPowerDelta", 50, 1); 532 "EasyUnlock.AuthProximity.TransmitPowerDelta", 50, 1);
531 } 533 }
532 534
533 TEST_F(ProximityAuthProximityMonitorImplTest, 535 TEST_F(ProximityAuthProximityMonitorImplTest,
534 RecordProximityMetricsOnAuthSuccess_UnknownValues) { 536 RecordProximityMetricsOnAuthSuccess_UnknownValues) {
535 // Note: A device without a recorded name will have its Bluetooth address as 537 // Note: A device without a recorded name will have its Bluetooth address as
536 // its name. 538 // its name.
537 RemoteDevice unnamed_remote_device(kBluetoothAddress, kRemoteDevicePublicKey, 539 RemoteDevice unnamed_remote_device(kRemoteDeviceUserId, kBluetoothAddress,
538 kBluetoothAddress, 540 kRemoteDevicePublicKey, kBluetoothAddress,
539 kPersistentSymmetricKey); 541 kPersistentSymmetricKey);
540 542
541 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock()); 543 scoped_ptr<base::TickClock> clock(new base::SimpleTestTickClock());
542 ProximityMonitorImpl monitor(unnamed_remote_device, clock.Pass(), &observer_); 544 ProximityMonitorImpl monitor(unnamed_remote_device, clock.Pass(), &observer_);
543 monitor.Start(); 545 monitor.Start();
544 ProvideConnectionInfo({127, 127, 127}); 546 ProvideConnectionInfo({127, 127, 127});
545 547
546 base::HistogramTester histogram_tester; 548 base::HistogramTester histogram_tester;
547 monitor.RecordProximityMetricsOnAuthSuccess(); 549 monitor.RecordProximityMetricsOnAuthSuccess();
548 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", 550 histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi",
549 127, 1); 551 127, 1);
550 histogram_tester.ExpectUniqueSample( 552 histogram_tester.ExpectUniqueSample(
551 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); 553 "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1);
552 histogram_tester.ExpectUniqueSample( 554 histogram_tester.ExpectUniqueSample(
553 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", 555 "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi",
554 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); 556 base::TimeDelta::FromSeconds(10).InMilliseconds(), 1);
555 histogram_tester.ExpectUniqueSample( 557 histogram_tester.ExpectUniqueSample(
556 "EasyUnlock.AuthProximity.RemoteDeviceModelHash", 558 "EasyUnlock.AuthProximity.RemoteDeviceModelHash",
557 -1808066424 /* hash of "Unknown" */, 1); 559 -1808066424 /* hash of "Unknown" */, 1);
558 } 560 }
559 561
560 } // namespace proximity_auth 562 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698