OLD | NEW |
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/remote_device_loader.h" | 5 #include "components/proximity_auth/remote_device_loader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" | 13 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" |
13 #include "components/proximity_auth/proximity_auth_pref_manager.h" | 14 #include "components/proximity_auth/proximity_auth_pref_manager.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace proximity_auth { | 18 namespace proximity_auth { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 80 |
80 // Stores the bluetooth address for BLE devices. | 81 // Stores the bluetooth address for BLE devices. |
81 scoped_ptr<MockProximityAuthPrefManager> pref_manager_; | 82 scoped_ptr<MockProximityAuthPrefManager> pref_manager_; |
82 | 83 |
83 DISALLOW_COPY_AND_ASSIGN(ProximityAuthRemoteDeviceLoaderTest); | 84 DISALLOW_COPY_AND_ASSIGN(ProximityAuthRemoteDeviceLoaderTest); |
84 }; | 85 }; |
85 | 86 |
86 TEST_F(ProximityAuthRemoteDeviceLoaderTest, LoadZeroDevices) { | 87 TEST_F(ProximityAuthRemoteDeviceLoaderTest, LoadZeroDevices) { |
87 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys; | 88 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys; |
88 RemoteDeviceLoader loader(unlock_keys, user_private_key_, kUserId, | 89 RemoteDeviceLoader loader(unlock_keys, user_private_key_, kUserId, |
89 secure_message_delegate_.Pass(), | 90 std::move(secure_message_delegate_), |
90 pref_manager_.get()); | 91 pref_manager_.get()); |
91 | 92 |
92 std::vector<RemoteDevice> result; | 93 std::vector<RemoteDevice> result; |
93 EXPECT_CALL(*this, LoadCompleted()); | 94 EXPECT_CALL(*this, LoadCompleted()); |
94 loader.Load( | 95 loader.Load( |
95 base::Bind(&ProximityAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, | 96 base::Bind(&ProximityAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, |
96 base::Unretained(this))); | 97 base::Unretained(this))); |
97 | 98 |
98 EXPECT_EQ(0u, remote_devices_.size()); | 99 EXPECT_EQ(0u, remote_devices_.size()); |
99 } | 100 } |
100 | 101 |
101 TEST_F(ProximityAuthRemoteDeviceLoaderTest, LoadOneClassicRemoteDevice) { | 102 TEST_F(ProximityAuthRemoteDeviceLoaderTest, LoadOneClassicRemoteDevice) { |
102 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys(1, | 103 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys(1, |
103 CreateUnlockKey("1")); | 104 CreateUnlockKey("1")); |
104 RemoteDeviceLoader loader(unlock_keys, user_private_key_, kUserId, | 105 RemoteDeviceLoader loader(unlock_keys, user_private_key_, kUserId, |
105 secure_message_delegate_.Pass(), | 106 std::move(secure_message_delegate_), |
106 pref_manager_.get()); | 107 pref_manager_.get()); |
107 | 108 |
108 std::vector<RemoteDevice> result; | 109 std::vector<RemoteDevice> result; |
109 EXPECT_CALL(*this, LoadCompleted()); | 110 EXPECT_CALL(*this, LoadCompleted()); |
110 loader.Load( | 111 loader.Load( |
111 base::Bind(&ProximityAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, | 112 base::Bind(&ProximityAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, |
112 base::Unretained(this))); | 113 base::Unretained(this))); |
113 | 114 |
114 EXPECT_EQ(1u, remote_devices_.size()); | 115 EXPECT_EQ(1u, remote_devices_.size()); |
115 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty()); | 116 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty()); |
116 EXPECT_EQ(unlock_keys[0].friendly_device_name(), remote_devices_[0].name); | 117 EXPECT_EQ(unlock_keys[0].friendly_device_name(), remote_devices_[0].name); |
117 EXPECT_EQ(unlock_keys[0].public_key(), remote_devices_[0].public_key); | 118 EXPECT_EQ(unlock_keys[0].public_key(), remote_devices_[0].public_key); |
118 EXPECT_EQ(unlock_keys[0].bluetooth_address(), | 119 EXPECT_EQ(unlock_keys[0].bluetooth_address(), |
119 remote_devices_[0].bluetooth_address); | 120 remote_devices_[0].bluetooth_address); |
120 EXPECT_EQ(RemoteDevice::BLUETOOTH_CLASSIC, remote_devices_[0].bluetooth_type); | 121 EXPECT_EQ(RemoteDevice::BLUETOOTH_CLASSIC, remote_devices_[0].bluetooth_type); |
121 } | 122 } |
122 | 123 |
123 TEST_F(ProximityAuthRemoteDeviceLoaderTest, LoadOneBLERemoteDevice) { | 124 TEST_F(ProximityAuthRemoteDeviceLoaderTest, LoadOneBLERemoteDevice) { |
124 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys(1, | 125 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys(1, |
125 CreateUnlockKey("1")); | 126 CreateUnlockKey("1")); |
126 unlock_keys[0].set_bluetooth_address(std::string()); | 127 unlock_keys[0].set_bluetooth_address(std::string()); |
127 RemoteDeviceLoader loader(unlock_keys, user_private_key_, kUserId, | 128 RemoteDeviceLoader loader(unlock_keys, user_private_key_, kUserId, |
128 secure_message_delegate_.Pass(), | 129 std::move(secure_message_delegate_), |
129 pref_manager_.get()); | 130 pref_manager_.get()); |
130 | 131 |
131 std::string ble_address = "00:00:00:00:00:00"; | 132 std::string ble_address = "00:00:00:00:00:00"; |
132 EXPECT_CALL(*pref_manager_, GetDeviceAddress(testing::_)) | 133 EXPECT_CALL(*pref_manager_, GetDeviceAddress(testing::_)) |
133 .WillOnce(testing::Return(ble_address)); | 134 .WillOnce(testing::Return(ble_address)); |
134 | 135 |
135 std::vector<RemoteDevice> result; | 136 std::vector<RemoteDevice> result; |
136 EXPECT_CALL(*this, LoadCompleted()); | 137 EXPECT_CALL(*this, LoadCompleted()); |
137 loader.Load( | 138 loader.Load( |
138 base::Bind(&ProximityAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, | 139 base::Bind(&ProximityAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, |
139 base::Unretained(this))); | 140 base::Unretained(this))); |
140 | 141 |
141 EXPECT_EQ(1u, remote_devices_.size()); | 142 EXPECT_EQ(1u, remote_devices_.size()); |
142 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty()); | 143 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty()); |
143 EXPECT_EQ(unlock_keys[0].friendly_device_name(), remote_devices_[0].name); | 144 EXPECT_EQ(unlock_keys[0].friendly_device_name(), remote_devices_[0].name); |
144 EXPECT_EQ(unlock_keys[0].public_key(), remote_devices_[0].public_key); | 145 EXPECT_EQ(unlock_keys[0].public_key(), remote_devices_[0].public_key); |
145 EXPECT_EQ(ble_address, remote_devices_[0].bluetooth_address); | 146 EXPECT_EQ(ble_address, remote_devices_[0].bluetooth_address); |
146 EXPECT_EQ(RemoteDevice::BLUETOOTH_LE, remote_devices_[0].bluetooth_type); | 147 EXPECT_EQ(RemoteDevice::BLUETOOTH_LE, remote_devices_[0].bluetooth_type); |
147 } | 148 } |
148 | 149 |
149 TEST_F(ProximityAuthRemoteDeviceLoaderTest, LoadThreeRemoteDevice) { | 150 TEST_F(ProximityAuthRemoteDeviceLoaderTest, LoadThreeRemoteDevice) { |
150 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys; | 151 std::vector<cryptauth::ExternalDeviceInfo> unlock_keys; |
151 unlock_keys.push_back(CreateUnlockKey("1")); | 152 unlock_keys.push_back(CreateUnlockKey("1")); |
152 unlock_keys.push_back(CreateUnlockKey("2")); | 153 unlock_keys.push_back(CreateUnlockKey("2")); |
153 unlock_keys.push_back(CreateUnlockKey("3")); | 154 unlock_keys.push_back(CreateUnlockKey("3")); |
154 RemoteDeviceLoader loader(unlock_keys, user_private_key_, kUserId, | 155 RemoteDeviceLoader loader(unlock_keys, user_private_key_, kUserId, |
155 secure_message_delegate_.Pass(), | 156 std::move(secure_message_delegate_), |
156 pref_manager_.get()); | 157 pref_manager_.get()); |
157 | 158 |
158 std::vector<RemoteDevice> result; | 159 std::vector<RemoteDevice> result; |
159 EXPECT_CALL(*this, LoadCompleted()); | 160 EXPECT_CALL(*this, LoadCompleted()); |
160 loader.Load( | 161 loader.Load( |
161 base::Bind(&ProximityAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, | 162 base::Bind(&ProximityAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, |
162 base::Unretained(this))); | 163 base::Unretained(this))); |
163 | 164 |
164 EXPECT_EQ(3u, remote_devices_.size()); | 165 EXPECT_EQ(3u, remote_devices_.size()); |
165 for (size_t i = 0; i < 3; ++i) { | 166 for (size_t i = 0; i < 3; ++i) { |
166 EXPECT_FALSE(remote_devices_[i].persistent_symmetric_key.empty()); | 167 EXPECT_FALSE(remote_devices_[i].persistent_symmetric_key.empty()); |
167 EXPECT_EQ(unlock_keys[i].friendly_device_name(), remote_devices_[i].name); | 168 EXPECT_EQ(unlock_keys[i].friendly_device_name(), remote_devices_[i].name); |
168 EXPECT_EQ(unlock_keys[i].public_key(), remote_devices_[i].public_key); | 169 EXPECT_EQ(unlock_keys[i].public_key(), remote_devices_[i].public_key); |
169 EXPECT_EQ(unlock_keys[i].bluetooth_address(), | 170 EXPECT_EQ(unlock_keys[i].bluetooth_address(), |
170 remote_devices_[i].bluetooth_address); | 171 remote_devices_[i].bluetooth_address); |
171 } | 172 } |
172 } | 173 } |
173 | 174 |
174 } // namespace proximity_auth | 175 } // namespace proximity_auth |
OLD | NEW |