summaryrefslogtreecommitdiffstats
path: root/components/proximity_auth/bluetooth_connection_finder_unittest.cc
diff options
context:
space:
mode:
authortengs <tengs@chromium.org>2015-09-28 12:18:21 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-28 19:19:39 +0000
commitb3163737b4390d4c438aa4d644dacb7257a89bf7 (patch)
tree1847c03cde748918de0e42a8483c6bca80a4c9da /components/proximity_auth/bluetooth_connection_finder_unittest.cc
parent4fa288fc5b41d03b84d2940cd51fee78f3259db9 (diff)
downloadchromium_src-b3163737b4390d4c438aa4d644dacb7257a89bf7.zip
chromium_src-b3163737b4390d4c438aa4d644dacb7257a89bf7.tar.gz
chromium_src-b3163737b4390d4c438aa4d644dacb7257a89bf7.tar.bz2
Add RemoteDeviceLoader to create RemoteDevice from CryptAuth data.
BUG=527558 TEST=unit test Review URL: https://codereview.chromium.org/1356943004 Cr-Commit-Position: refs/heads/master@{#351098}
Diffstat (limited to 'components/proximity_auth/bluetooth_connection_finder_unittest.cc')
-rw-r--r--components/proximity_auth/bluetooth_connection_finder_unittest.cc35
1 files changed, 14 insertions, 21 deletions
diff --git a/components/proximity_auth/bluetooth_connection_finder_unittest.cc b/components/proximity_auth/bluetooth_connection_finder_unittest.cc
index 393f734..0d38111 100644
--- a/components/proximity_auth/bluetooth_connection_finder_unittest.cc
+++ b/components/proximity_auth/bluetooth_connection_finder_unittest.cc
@@ -10,6 +10,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/time/time.h"
+#include "components/proximity_auth/proximity_auth_test_util.h"
#include "components/proximity_auth/remote_device.h"
#include "components/proximity_auth/wire_message.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
@@ -27,21 +28,13 @@ using testing::StrictMock;
namespace proximity_auth {
namespace {
-const char kDeviceName[] = "Device name";
-const char kPublicKey[] = "Public key";
-const char kBluetoothAddress[] = "11:22:33:44:55:66";
-const char kPersistentSymmetricKey[] = "PSK";
-
const char kUuid[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEF";
-RemoteDevice CreateRemoteDevice() {
- return RemoteDevice(kDeviceName, kPublicKey, kBluetoothAddress,
- kPersistentSymmetricKey);
-}
-
class MockConnection : public Connection {
public:
- MockConnection() : Connection(CreateRemoteDevice()), do_not_destroy_(false) {}
+ MockConnection()
+ : Connection(CreateClassicRemoteDeviceForTest()),
+ do_not_destroy_(false) {}
~MockConnection() override { EXPECT_FALSE(do_not_destroy_); }
MOCK_METHOD0(Connect, void());
@@ -68,7 +61,7 @@ class MockConnection : public Connection {
class MockBluetoothConnectionFinder : public BluetoothConnectionFinder {
public:
MockBluetoothConnectionFinder()
- : BluetoothConnectionFinder(CreateRemoteDevice(),
+ : BluetoothConnectionFinder(CreateClassicRemoteDeviceForTest(),
device::BluetoothUUID(kUuid),
base::TimeDelta()) {}
~MockBluetoothConnectionFinder() override {}
@@ -111,7 +104,7 @@ class MockBluetoothConnectionFinder : public BluetoothConnectionFinder {
const std::string& bluetooth_address,
const base::Closure& callback,
const bluetooth_util::ErrorCallback& error_callback) override {
- EXPECT_EQ(kBluetoothAddress, bluetooth_address);
+ EXPECT_EQ(kTestRemoteDeviceBluetoothAddress, bluetooth_address);
seek_callback_ = callback;
seek_error_callback_ = error_callback;
}
@@ -132,8 +125,8 @@ class ProximityAuthBluetoothConnectionFinderTest : public testing::Test {
bluetooth_device_(new NiceMock<device::MockBluetoothDevice>(
adapter_.get(),
device::BluetoothDevice::DEVICE_PHONE,
- kDeviceName,
- kBluetoothAddress,
+ kTestRemoteDeviceName,
+ kTestRemoteDeviceBluetoothAddress,
true,
false)),
connection_callback_(base::Bind(
@@ -148,7 +141,7 @@ class ProximityAuthBluetoothConnectionFinderTest : public testing::Test {
// By default, the remote device is known to |adapter_| so
// |SeekDeviceByAddress()| will not be called.
- ON_CALL(*adapter_, GetDevice(kBluetoothAddress))
+ ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress))
.WillByDefault(Return(bluetooth_device_.get()));
}
@@ -195,7 +188,7 @@ TEST_F(ProximityAuthBluetoothConnectionFinderTest,
// Destroying a BluetoothConnectionFinder for which Find() has not been called
// should not crash.
BluetoothConnectionFinder connection_finder(
- CreateRemoteDevice(), device::BluetoothUUID(kUuid),
+ CreateClassicRemoteDeviceForTest(), device::BluetoothUUID(kUuid),
base::TimeDelta::FromMilliseconds(1));
}
@@ -322,14 +315,14 @@ TEST_F(ProximityAuthBluetoothConnectionFinderTest,
Find_DeviceNotKnown_SeekDeviceSucceeds) {
// If the BluetoothDevice is not known by the adapter, |connection_finder|
// will call SeekDeviceByAddress() first to make it known.
- ON_CALL(*adapter_, GetDevice(kBluetoothAddress))
+ ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress))
.WillByDefault(Return(nullptr));
connection_finder_.Find(connection_callback_);
ASSERT_FALSE(connection_finder_.seek_callback().is_null());
EXPECT_FALSE(connection_finder_.seek_error_callback().is_null());
// After seeking is successful, the normal flow should resume.
- ON_CALL(*adapter_, GetDevice(kBluetoothAddress))
+ ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress))
.WillByDefault(Return(bluetooth_device_.get()));
MockConnection* connection = connection_finder_.ExpectCreateConnection();
connection_finder_.seek_callback().Run();
@@ -340,7 +333,7 @@ TEST_F(ProximityAuthBluetoothConnectionFinderTest,
Find_DeviceNotKnown_SeekDeviceFailThenSucceeds) {
// If the BluetoothDevice is not known by the adapter, |connection_finder|
// will call SeekDeviceByAddress() first to make it known.
- ON_CALL(*adapter_, GetDevice(kBluetoothAddress))
+ ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress))
.WillByDefault(Return(nullptr));
connection_finder_.Find(connection_callback_);
EXPECT_FALSE(connection_finder_.seek_callback().is_null());
@@ -360,7 +353,7 @@ TEST_F(ProximityAuthBluetoothConnectionFinderTest,
EXPECT_FALSE(connection_finder_.seek_error_callback().is_null());
// Successfully connect to the Bluetooth device.
- ON_CALL(*adapter_, GetDevice(kBluetoothAddress))
+ ON_CALL(*adapter_, GetDevice(kTestRemoteDeviceBluetoothAddress))
.WillByDefault(Return(bluetooth_device_.get()));
MockConnection* connection = connection_finder_.ExpectCreateConnection();
connection_finder_.seek_callback().Run();