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

Unified Diff: components/proximity_auth/proximity_monitor_impl_unittest.cc

Issue 2973243002: Adding pref to store the user-selected proximity threshold. (Closed)
Patch Set: Fixing tests Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
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 24fac5c34c23254219e8e4b262eff0f7134bed3b..f8037cdc2050f8a1ce65c6c5d0783bb536862eea 100644
--- a/components/proximity_auth/proximity_monitor_impl_unittest.cc
+++ b/components/proximity_auth/proximity_monitor_impl_unittest.cc
@@ -17,7 +17,9 @@
#include "base/time/time.h"
#include "components/cryptauth/fake_connection.h"
#include "components/cryptauth/remote_device.h"
+#include "components/prefs/testing_pref_service.h"
#include "components/proximity_auth/logging/logging.h"
+#include "components/proximity_auth/proximity_auth_pref_manager.h"
#include "components/proximity_auth/proximity_monitor_observer.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
@@ -38,6 +40,9 @@ const char kRemoteDevicePublicKey[] = "Remote Public Key";
const char kRemoteDeviceName[] = "LGE Nexus 5";
const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF";
const char kPersistentSymmetricKey[] = "PSK";
+
+// The proximity threshold corresponds to a RSSI of -70.
+const int kProximityThreshold = 2;
Tim Song 2017/07/10 19:27:56 nit: rename to kProximityThresholdPrefValue
sacomoto 2017/07/11 09:56:06 Done.
const int kRssiThreshold = -70;
class MockProximityMonitorObserver : public ProximityMonitorObserver {
@@ -51,6 +56,17 @@ class MockProximityMonitorObserver : public ProximityMonitorObserver {
DISALLOW_COPY_AND_ASSIGN(MockProximityMonitorObserver);
};
+class MockProximityAuthPrefManager : public ProximityAuthPrefManager {
+ public:
+ MockProximityAuthPrefManager() : ProximityAuthPrefManager(nullptr) {}
+ ~MockProximityAuthPrefManager() override {}
+
+ MOCK_CONST_METHOD0(GetProximityThreshold, int(void));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockProximityAuthPrefManager);
+};
+
// Creates a mock Bluetooth adapter and sets it as the global adapter for
// testing.
scoped_refptr<device::MockBluetoothAdapter>
@@ -81,7 +97,10 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
kPersistentSymmetricKey,
std::string()),
connection_(remote_device_),
- monitor_(&connection_, base::WrapUnique(clock_)),
+ pref_manager_(new NiceMock<MockProximityAuthPrefManager>()),
+ monitor_(&connection_,
+ base::WrapUnique(clock_),
+ base::WrapUnique(pref_manager_)),
task_runner_(new base::TestSimpleTaskRunner()),
thread_task_runner_handle_(task_runner_) {
ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress))
@@ -89,6 +108,8 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_))
.WillByDefault(SaveArg<0>(&connection_info_callback_));
monitor_.AddObserver(&observer_);
+ ON_CALL(*pref_manager_, GetProximityThreshold())
+ .WillByDefault(Return(kProximityThreshold));
}
~ProximityAuthProximityMonitorImplTest() override {}
@@ -118,6 +139,9 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
cryptauth::RemoteDevice remote_device_;
cryptauth::FakeConnection connection_;
+ // ProximityAuthPrefManager mock.
+ NiceMock<MockProximityAuthPrefManager>* pref_manager_;
+
// The proximity monitor under test.
ProximityMonitorImpl monitor_;
@@ -341,8 +365,13 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
kBluetoothAddress, kPersistentSymmetricKey, std::string());
cryptauth::FakeConnection connection(unnamed_remote_device);
+ NiceMock<MockProximityAuthPrefManager>* pref_manager =
+ new NiceMock<MockProximityAuthPrefManager>();
std::unique_ptr<base::TickClock> clock(new base::SimpleTestTickClock());
- ProximityMonitorImpl monitor(&connection, std::move(clock));
+ ProximityMonitorImpl monitor(&connection, std::move(clock),
+ base::WrapUnique(pref_manager));
+ ON_CALL(*pref_manager, GetProximityThreshold())
+ .WillByDefault(Return(kProximityThreshold));
monitor.AddObserver(&observer_);
monitor.Start();
ProvideConnectionInfo({127, 127, 127});

Powered by Google App Engine
This is Rietveld 408576698