Chromium Code Reviews| 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..d06acfbc56cc49c6bf91152683dc58ba84ade58c 100644 |
| --- a/components/proximity_auth/proximity_monitor_impl_unittest.cc |
| +++ b/components/proximity_auth/proximity_monitor_impl_unittest.cc |
| @@ -236,7 +236,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
| monitor_.Start(); |
| ProvideConnectionInfo({0, 0, 4}); |
| - ProvideConnectionInfo({BluetoothDevice::kUnknownPower, 0, 4}); |
| + ProvideConnectionInfo({BluetoothDevice::kUnknownRSSI, 0, 4}); |
| EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
| EXPECT_FALSE(monitor_.IsInRssiRange()); |
| @@ -248,7 +248,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
| monitor_.Start(); |
| ProvideConnectionInfo({0, 0, 4}); |
| - ProvideConnectionInfo({0, BluetoothDevice::kUnknownPower, 4}); |
| + ProvideConnectionInfo({0, BluetoothDevice::kUnknownTxPower, 4}); |
| EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
| EXPECT_FALSE(monitor_.IsInRssiRange()); |
| @@ -260,7 +260,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
| monitor_.Start(); |
| ProvideConnectionInfo({0, 0, 4}); |
| - ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownPower}); |
| + ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownTxPower}); |
| EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
| EXPECT_FALSE(monitor_.IsInRssiRange()); |
| @@ -316,7 +316,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
| monitor_.Start(); |
| ProvideConnectionInfo({0, 0, 4}); |
| - ProvideConnectionInfo({BluetoothDevice::kUnknownPower, 0, 4}); |
| + ProvideConnectionInfo({BluetoothDevice::kUnknownRSSI, 0, 4}); |
| EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
| EXPECT_FALSE(monitor_.IsInRssiRange()); |
| @@ -328,7 +328,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
| monitor_.Start(); |
| ProvideConnectionInfo({0, 0, 4}); |
| - ProvideConnectionInfo({0, BluetoothDevice::kUnknownPower, 4}); |
| + ProvideConnectionInfo({0, BluetoothDevice::kUnknownTxPower, 4}); |
| EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
| EXPECT_FALSE(monitor_.IsInRssiRange()); |
| @@ -340,7 +340,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
| monitor_.Start(); |
| ProvideConnectionInfo({0, 0, 4}); |
| - ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownPower}); |
| + ProvideConnectionInfo({0, 0, BluetoothDevice::kUnknownTxPower}); |
| EXPECT_FALSE(monitor_.IsUnlockAllowed()); |
| EXPECT_FALSE(monitor_.IsInRssiRange()); |
| @@ -524,15 +524,52 @@ 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 = -127; |
| + int8_t max_tx_power = 0; |
| + int8_t tx_power_delta = tx_power - max_tx_power; |
| + |
| monitor_.Start(); |
|
Ilya Sherman
2016/05/04 23:01:44
nit: I'd keep this line right above ProvideConnect
ortuno
2016/05/07 00:32:09
Done.
|
| - ProvideConnectionInfo({-99999, 99999, 12345}); |
| + |
| + ASSERT_NE(BluetoothDevice::kUnknownRSSI, rssi); |
| + ASSERT_NE(BluetoothDevice::kUnknownTxPower, tx_power); |
| + ASSERT_NE(BluetoothDevice::kUnknownTxPower, max_tx_power); |
| + ASSERT_NE(BluetoothDevice::kUnknownTxPower, tx_power_delta); |
| + |
| + 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 = 127; |
| + int8_t max_tx_power = 0; |
| + int8_t tx_power_delta = tx_power - max_tx_power; |
| + |
| + monitor_.Start(); |
| + |
| + ASSERT_NE(BluetoothDevice::kUnknownRSSI, rssi); |
| + ASSERT_NE(BluetoothDevice::kUnknownTxPower, tx_power); |
| + ASSERT_NE(BluetoothDevice::kUnknownTxPower, max_tx_power); |
| + ASSERT_NE(BluetoothDevice::kUnknownTxPower, tx_power_delta); |
| + |
| + 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,14 +586,17 @@ TEST_F(ProximityAuthProximityMonitorImplTest, |
| ProximityMonitorImpl monitor(unnamed_remote_device, std::move(clock)); |
| monitor.AddObserver(&observer_); |
| monitor.Start(); |
| - ProvideConnectionInfo({127, 127, 127}); |
| + ProvideConnectionInfo({BluetoothDevice::kUnknownRSSI, |
| + BluetoothDevice::kUnknownTxPower, |
| + BluetoothDevice::kUnknownTxPower}); |
| base::HistogramTester histogram_tester; |
| monitor.RecordProximityMetricsOnAuthSuccess(); |
| histogram_tester.ExpectUniqueSample("EasyUnlock.AuthProximity.RollingRssi", |
| - 127, 1); |
| + BluetoothDevice::kUnknownRSSI, 1); |
|
Ilya Sherman
2016/05/04 23:01:44
Hmm, the reported RSSI shouldn't change, even if t
ortuno
2016/05/07 00:32:09
Ah. I misunderstood the purpose of the test. Fixed
|
| histogram_tester.ExpectUniqueSample( |
| - "EasyUnlock.AuthProximity.TransmitPowerDelta", 127, 1); |
| + "EasyUnlock.AuthProximity.TransmitPowerDelta", |
| + BluetoothDevice::kUnknownTxPower, 1); |
|
Ilya Sherman
2016/05/04 23:01:44
Ditto.
ortuno
2016/05/07 00:32:09
Done.
|
| histogram_tester.ExpectUniqueSample( |
| "EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", |
| base::TimeDelta::FromSeconds(10).InMilliseconds(), 1); |