Index: components/proximity_auth/proximity_monitor_impl_unittest.cc |
diff --git a/components/proximity_auth/proximity_monitor_impl_unittest.cc b/components/proximity_auth/proximity_monitor_impl_unittest.cc |
index 85def4bf236968ef2ed12731b2cdbd87939f7f5d..c87837c75a280e38f8aca51bf81e732afd1cdad0 100644 |
--- a/components/proximity_auth/proximity_monitor_impl_unittest.cc |
+++ b/components/proximity_auth/proximity_monitor_impl_unittest.cc |
@@ -10,6 +10,7 @@ |
#include "base/macros.h" |
#include "base/memory/ptr_util.h" |
#include "base/memory/ref_counted.h" |
+#include "base/optional.h" |
#include "base/test/histogram_tester.h" |
#include "base/test/simple_test_tick_clock.h" |
#include "base/test/test_simple_task_runner.h" |
@@ -236,7 +237,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
monitor_.Start(); |
ProvideConnectionInfo({0, 0, 4}); |
- ProvideConnectionInfo({BluetoothDevice::kUnknownPower, 0, 4}); |
+ ProvideConnectionInfo({base::nullopt, 0, 4}); |
EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
EXPECT_FALSE(monitor_.IsInRssiRange()); |
@@ -248,7 +249,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
monitor_.Start(); |
ProvideConnectionInfo({0, 0, 4}); |
- ProvideConnectionInfo({0, BluetoothDevice::kUnknownPower, 4}); |
+ ProvideConnectionInfo({0, base::nullopt, 4}); |
EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
EXPECT_FALSE(monitor_.IsInRssiRange()); |
@@ -260,7 +261,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
monitor_.Start(); |
ProvideConnectionInfo({0, 0, 4}); |
- ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownPower}); |
+ ProvideConnectionInfo({0, 0, base::nullopt}); |
EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
EXPECT_FALSE(monitor_.IsInRssiRange()); |
@@ -316,7 +317,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
monitor_.Start(); |
ProvideConnectionInfo({0, 0, 4}); |
- ProvideConnectionInfo({BluetoothDevice::kUnknownPower, 0, 4}); |
+ ProvideConnectionInfo({base::nullopt, 0, 4}); |
EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
EXPECT_FALSE(monitor_.IsInRssiRange()); |
@@ -328,7 +329,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
monitor_.Start(); |
ProvideConnectionInfo({0, 0, 4}); |
- ProvideConnectionInfo({0, BluetoothDevice::kUnknownPower, 4}); |
+ ProvideConnectionInfo({0, base::nullopt, 4}); |
EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
EXPECT_FALSE(monitor_.IsInRssiRange()); |
@@ -340,7 +341,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
monitor_.Start(); |
ProvideConnectionInfo({0, 0, 4}); |
- ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownPower}); |
+ ProvideConnectionInfo({0, 0, base::nullopt}); |
EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
EXPECT_FALSE(monitor_.IsInRssiRange()); |
@@ -524,15 +525,42 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
} |
TEST_F(ProximityAuthProximityMonitorImplTest, |
- RecordProximityMetricsOnAuthSuccess_ClampedValues) { |
+ RecordProximityMetricsOnAuthSuccess_ClampedValues_LowerThreshold) { |
+ // Tests that we clamp values lower than -100 before histograming. |
+ |
+ int8_t rssi = -128; |
+ int8_t tx_power = -128; |
+ int8_t max_tx_power = 0; |
+ // The resulting TransmitPowerDelta that we try to record is -128. |
+ |
monitor_.Start(); |
- ProvideConnectionInfo({-99999, 99999, 12345}); |
+ ProvideConnectionInfo({rssi, tx_power, max_tx_power}); |
base::HistogramTester histogram_tester; |
monitor_.RecordProximityMetricsOnAuthSuccess(); |
histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
-100, 1); |
histogram_tester.ExpectUniqueSample( |
+ "EasyUnlock.AuthProximity.TransmitPowerDelta", -100, 1); |
+} |
+ |
+TEST_F(ProximityAuthProximityMonitorImplTest, |
+ RecordProximityMetricsOnAuthSuccess_ClampedValues_UpperThreshold) { |
+ // Tests that we clamp values larger than 50 before histograming. |
+ |
+ int8_t rssi = 126; |
+ int8_t tx_power = 126; |
+ int8_t max_tx_power = 0; |
+ // The resulting TransmitPowerDelta that we try to record is 126. |
+ |
+ monitor_.Start(); |
+ ProvideConnectionInfo({rssi, tx_power, max_tx_power}); |
+ |
+ base::HistogramTester histogram_tester; |
+ monitor_.RecordProximityMetricsOnAuthSuccess(); |
+ histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
+ 50, 1); |
+ histogram_tester.ExpectUniqueSample( |
"EasyUnlock.AuthProximity.TransmitPowerDelta", 50, 1); |
} |
@@ -549,7 +577,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
ProximityMonitorImpl monitor(unnamed_remote_device, std::move(clock)); |
monitor.AddObserver(&observer_); |
monitor.Start(); |
- ProvideConnectionInfo({127, 127, 127}); |
+ ProvideConnectionInfo({base::nullopt, base::nullopt, base::nullopt}); |
base::HistogramTester histogram_tester; |
monitor.RecordProximityMetricsOnAuthSuccess(); |