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

Side by Side Diff: components/proximity_auth/ble/bluetooth_low_energy_connection_unittest.cc

Issue 1144333007: Adding unit tests for BLE connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h"
6
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin der.h"
11 #include "components/proximity_auth/connection_finder.h"
12 #include "components/proximity_auth/remote_device.h"
13 #include "components/proximity_auth/wire_message.h"
14 #include "device/bluetooth/bluetooth_adapter_factory.h"
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
16 #include "device/bluetooth/bluetooth_uuid.h"
17 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
18 #include "device/bluetooth/test/mock_bluetooth_device.h"
19 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h"
20 #include "device/bluetooth/test/mock_bluetooth_gatt_characteristic.h"
21 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h"
22 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h"
23 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 using testing::_;
27 using testing::AtLeast;
28 using testing::NiceMock;
29 using testing::Return;
30 using testing::StrictMock;
31 using testing::SaveArg;
32
33 namespace proximity_auth {
34 namespace {
35
36 const char kDeviceName[] = "Device name";
37 const char kBluetoothAddress[] = "11:22:33:44:55:66";
38
39 const char kServiceUUID[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEEF";
40 const char kToPeripheralCharUUID[] = "FBAE09F2-0482-11E5-8418-1697F925EC7B";
41 const char kFromPeripheralCharUUID[] = "5539ED10-0483-11E5-8418-1697F925EC7B";
42
43 const char kServiceID[] = "service id";
44 const char kToPeripheralCharID[] = "to peripheral char id";
45 const char kFromPeripheralCharID[] = "from peripheral char id";
46
47 const device::BluetoothGattCharacteristic::Properties
48 kCharacteristicProperties =
49 device::BluetoothGattCharacteristic::PROPERTY_BROADCAST |
50 device::BluetoothGattCharacteristic::PROPERTY_READ |
51 device::BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE |
52 device::BluetoothGattCharacteristic::PROPERTY_INDICATE;
53
54 const int kMaxNumberOfTries = 3;
55
56 class MockBluetoothLowEnergyCharacteristicsFinder
57 : public BluetoothLowEnergyCharacteristicsFinder {
58 public:
59 MockBluetoothLowEnergyCharacteristicsFinder() {}
60 ~MockBluetoothLowEnergyCharacteristicsFinder() override {}
61 };
62
63 class MockBluetoothLowEnergyConnection : public BluetoothLowEnergyConnection {
64 public:
65 using BluetoothLowEnergyConnection::BluetoothLowEnergyConnection;
66 ~MockBluetoothLowEnergyConnection() override {}
67
68 MOCK_METHOD2(
69 CreateCharacteristicsFinder,
70 BluetoothLowEnergyCharacteristicsFinder*(
71 const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback&
72 success,
73 const BluetoothLowEnergyCharacteristicsFinder::ErrorCallback& error));
74
75 MOCK_METHOD2(OnDidSendMessage,
76 void(const WireMessage& message, bool success));
77
msarda 2015/06/05 09:40:19 // Exposing inherited protected methods for testin
sacomoto 2015/06/05 11:04:04 Done.
78 using BluetoothLowEnergyConnection::GattCharacteristicValueChanged;
79
msarda 2015/06/05 09:40:19 // Exposing inherited protected fields for testing
sacomoto 2015/06/05 11:04:04 Done.
80 using BluetoothLowEnergyConnection::status;
81 using BluetoothLowEnergyConnection::SubStatus;
82 using BluetoothLowEnergyConnection::sub_status;
83 };
84
85 } // namespace
86
87 class ProximityAuthBluetoothLowEnergyConnectionTest : public testing::Test {
88 public:
89 ProximityAuthBluetoothLowEnergyConnectionTest()
msarda 2015/06/05 09:40:19 This may be a personal preference, but I prefer ha
sacomoto 2015/06/05 11:04:04 Done.
90 : adapter_(new NiceMock<device::MockBluetoothAdapter>),
91 remote_device_({kDeviceName, kBluetoothAddress}),
92 service_uuid_(device::BluetoothUUID(kServiceUUID)),
93 to_peripheral_char_uuid_(device::BluetoothUUID(kToPeripheralCharUUID)),
94 from_peripheral_char_uuid_(
95 device::BluetoothUUID(kFromPeripheralCharUUID)),
96 gatt_connection_(new NiceMock<device::MockBluetoothGattConnection>(
97 kBluetoothAddress)),
98 gatt_connection_alias_(gatt_connection_.get()),
99 device_(new NiceMock<device::MockBluetoothDevice>(adapter_.get(),
100 0,
101 kDeviceName,
102 kBluetoothAddress,
103 false,
104 false)),
105 service_(new NiceMock<device::MockBluetoothGattService>(device_.get(),
106 kServiceID,
107 service_uuid_,
108 true,
109 false)),
110 to_peripheral_char_(
111 new NiceMock<device::MockBluetoothGattCharacteristic>(
112 service_.get(),
113 kToPeripheralCharID,
114 to_peripheral_char_uuid_,
115 false,
116 kCharacteristicProperties,
117 device::BluetoothGattCharacteristic::PERMISSION_NONE)),
118 from_peripheral_char_(
119 new NiceMock<device::MockBluetoothGattCharacteristic>(
120 service_.get(),
121 kFromPeripheralCharID,
122 from_peripheral_char_uuid_,
123 false,
124 kCharacteristicProperties,
125 device::BluetoothGattCharacteristic::PERMISSION_NONE)),
126 notify_session_alias_(NULL) {
127 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_);
128
129 ON_CALL(*adapter_, GetDevice(kBluetoothAddress))
130 .WillByDefault(Return(device_.get()));
131 ON_CALL(*device_, GetGattService(kServiceID))
132 .WillByDefault(Return(service_.get()));
133 ON_CALL(*service_, GetCharacteristic(kFromPeripheralCharID))
134 .WillByDefault(Return(from_peripheral_char_.get()));
135 ON_CALL(*service_, GetCharacteristic(kToPeripheralCharID))
136 .WillByDefault(Return(to_peripheral_char_.get()));
137 }
138
139 // Creates a BluetoothLowEnergyConnection and verifies it's in DISCONNECTED
140 // state.
141 scoped_ptr<MockBluetoothLowEnergyConnection> CreateConnection() {
142 EXPECT_CALL(*adapter_, AddObserver(_));
143 EXPECT_CALL(*adapter_, RemoveObserver(_));
144
145 scoped_ptr<MockBluetoothLowEnergyConnection> connection(
146 new MockBluetoothLowEnergyConnection(
147 remote_device_, adapter_, service_uuid_, to_peripheral_char_uuid_,
148 from_peripheral_char_uuid_, gatt_connection_.Pass(),
149 kMaxNumberOfTries));
150
151 EXPECT_EQ(connection->sub_status(),
152 MockBluetoothLowEnergyConnection::SubStatus::DISCONNECTED);
153 EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
154
155 return connection.Pass();
156 }
157
158 // Transitions |connection| from DISCONNECTED to WAITING_CHARACTERISTICS
159 // state, using an existing GATT connection.
160 void ConnectWithExistingGattConnection(
161 MockBluetoothLowEnergyConnection* connection) {
162 EXPECT_CALL(*gatt_connection_alias_, IsConnected()).WillOnce(Return(true));
163 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _))
164 .WillOnce(
165 DoAll(SaveArg<0>(&characteristics_finder_success_callback_),
166 SaveArg<1>(&characteristics_finder_error_callback_),
167 Return(new MockBluetoothLowEnergyCharacteristicsFinder)));
168
169 connection->Connect();
170
171 EXPECT_EQ(
172 connection->sub_status(),
173 MockBluetoothLowEnergyConnection::SubStatus::WAITING_CHARACTERISTICS);
174 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
175 }
176
177 // Transitions |connection| from DISCONNECTED to WAITING_CHARACTERISTICS
178 // state, without an existing GATT connection.
179 void ConnectWithoutExistingGattConnection(
180 MockBluetoothLowEnergyConnection* connection) {
181 // Preparing |connection| for a CreateGattConnection call.
182 EXPECT_CALL(*gatt_connection_alias_, IsConnected()).WillOnce(Return(false));
183 EXPECT_CALL(*device_, CreateGattConnection(_, _))
184 .WillOnce(DoAll(SaveArg<0>(&create_gatt_connection_success_callback_),
185 SaveArg<1>(&create_gatt_connection_error_callback_)));
186
187 connection->Connect();
188
189 EXPECT_EQ(
190 connection->sub_status(),
191 MockBluetoothLowEnergyConnection::SubStatus::WAITING_GATT_CONNECTION);
192 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
193
194 // Preparing |connection| to run |create_gatt_connection_success_callback_|.
195 EXPECT_FALSE(create_gatt_connection_error_callback_.is_null());
196 ASSERT_FALSE(create_gatt_connection_success_callback_.is_null());
197 EXPECT_CALL(*connection, CreateCharacteristicsFinder(_, _))
198 .WillOnce(DoAll(
199 SaveArg<0>(&characteristics_finder_success_callback_),
200 SaveArg<1>(&characteristics_finder_error_callback_),
201 Return(new NiceMock<MockBluetoothLowEnergyCharacteristicsFinder>)));
202
203 create_gatt_connection_success_callback_.Run(make_scoped_ptr(
204 new NiceMock<device::MockBluetoothGattConnection>(kBluetoothAddress)));
205
206 EXPECT_EQ(
207 connection->sub_status(),
208 MockBluetoothLowEnergyConnection::SubStatus::WAITING_CHARACTERISTICS);
209 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
210 }
211
212 // Transitions |connection| from WAITING_CHARACTERISTICS to
213 // WAITING_NOTIFY_SESSION state.
214 void CharacteristicsFound(MockBluetoothLowEnergyConnection* connection) {
215 EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _))
216 .WillOnce(DoAll(SaveArg<0>(&notify_session_success_callback_),
217 SaveArg<1>(&notify_session_error_callback_)));
218 EXPECT_FALSE(characteristics_finder_error_callback_.is_null());
219 ASSERT_FALSE(characteristics_finder_success_callback_.is_null());
220
221 characteristics_finder_success_callback_.Run(
222 {service_uuid_, kServiceID},
223 {to_peripheral_char_uuid_, kToPeripheralCharID},
224 {from_peripheral_char_uuid_, kFromPeripheralCharID});
225
226 EXPECT_EQ(
227 connection->sub_status(),
228 MockBluetoothLowEnergyConnection::SubStatus::WAITING_NOTIFY_SESSION);
229 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
230 }
231
232 // Transitions |connection| from WAITING_NOTIFY_SESSION to
233 // WAITING_RESPONSE_SIGNAL state.
234 void NotifySessionStarted(MockBluetoothLowEnergyConnection* connection) {
235 EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _))
236 .WillOnce(
237 DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_),
238 SaveArg<1>(&write_remote_characteristic_success_callback_),
239 SaveArg<2>(&write_remote_characteristic_error_callback_)));
240 EXPECT_FALSE(notify_session_error_callback_.is_null());
241 ASSERT_FALSE(notify_session_success_callback_.is_null());
242
243 // Store an alias for the notify session passed |connection|.
244 scoped_ptr<device::MockBluetoothGattNotifySession> notify_session(
245 new NiceMock<device::MockBluetoothGattNotifySession>(
246 kToPeripheralCharID));
247 notify_session_alias_ = notify_session.get();
248 notify_session_success_callback_.Run(notify_session.Pass());
249
250 EXPECT_EQ(
251 connection->sub_status(),
252 MockBluetoothLowEnergyConnection::SubStatus::WAITING_RESPONSE_SIGNAL);
253 EXPECT_EQ(connection->status(), Connection::IN_PROGRESS);
254 }
255
256 // Transitions |connection| from WAITING_RESPONSE_SIGNAL to CONNECTED state.
257 void ResponseSignalReceived(MockBluetoothLowEnergyConnection* connection) {
258 // Written value contains only the
259 // BluetoothLowEneryConnection::ControlSignal::kSendSignal.
260 const std::vector<uint8> kSendSignal = {0, 0, 0, 0};
261 EXPECT_EQ(last_value_written_on_to_peripheral_char_, kSendSignal);
262
263 EXPECT_CALL(*connection, OnDidSendMessage(_, _)).Times(0);
264 EXPECT_FALSE(write_remote_characteristic_error_callback_.is_null());
265 ASSERT_FALSE(write_remote_characteristic_success_callback_.is_null());
266 write_remote_characteristic_success_callback_.Run();
267
268 // Received the
269 // BluetoothLowEneryConnection::ControlSignal::kInvitationResponseSignal.
270 const std::vector<uint8> kInvitationResponseSignal = {1, 0, 0, 0};
271 connection->GattCharacteristicValueChanged(
272 adapter_.get(), from_peripheral_char_.get(), kInvitationResponseSignal);
273
274 EXPECT_EQ(connection->sub_status(),
275 MockBluetoothLowEnergyConnection::SubStatus::CONNECTED);
276 EXPECT_EQ(connection->status(), Connection::CONNECTED);
277 }
278
279 // Transitions |connection| to a DISCONNECTED state regardless of its initial
280 // state.
281 void Disconnect(MockBluetoothLowEnergyConnection* connection) {
282 // A notify session was previously set.
283 if (notify_session_alias_)
284 EXPECT_CALL(*notify_session_alias_, Stop(_));
285
286 connection->Disconnect();
287
288 EXPECT_EQ(connection->sub_status(),
289 MockBluetoothLowEnergyConnection::SubStatus::DISCONNECTED);
290 EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
291 }
292
293 protected:
294 scoped_refptr<device::MockBluetoothAdapter> adapter_;
295 RemoteDevice remote_device_;
296 device::BluetoothUUID service_uuid_;
297 device::BluetoothUUID to_peripheral_char_uuid_;
298 device::BluetoothUUID from_peripheral_char_uuid_;
299 scoped_ptr<device::MockBluetoothGattConnection> gatt_connection_;
300 device::MockBluetoothGattConnection* gatt_connection_alias_;
msarda 2015/06/05 09:40:19 I think this is useless (only used twice). Please
sacomoto 2015/06/05 11:04:04 We cannot remove it. We pass the ownership of |gat
301 scoped_ptr<device::MockBluetoothDevice> device_;
302 scoped_ptr<device::MockBluetoothGattService> service_;
303 scoped_ptr<device::MockBluetoothGattCharacteristic> to_peripheral_char_;
304 scoped_ptr<device::MockBluetoothGattCharacteristic> from_peripheral_char_;
305 std::vector<uint8> last_value_written_on_to_peripheral_char_;
306 device::MockBluetoothGattNotifySession* notify_session_alias_;
307
308 // Callbacks
309 device::BluetoothDevice::GattConnectionCallback
310 create_gatt_connection_success_callback_;
311 device::BluetoothDevice::ConnectErrorCallback
312 create_gatt_connection_error_callback_;
313
314 BluetoothLowEnergyCharacteristicsFinder::SuccessCallback
315 characteristics_finder_success_callback_;
316 BluetoothLowEnergyCharacteristicsFinder::ErrorCallback
317 characteristics_finder_error_callback_;
318
319 device::BluetoothGattCharacteristic::NotifySessionCallback
320 notify_session_success_callback_;
321 device::BluetoothGattCharacteristic::ErrorCallback
322 notify_session_error_callback_;
323
324 base::Closure write_remote_characteristic_success_callback_;
325 device::BluetoothGattCharacteristic::ErrorCallback
326 write_remote_characteristic_error_callback_;
327 };
328
329 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
330 CreateAndDestroyWithouthConnectCallDoesntCrash) {
331 BluetoothLowEnergyConnection connection(
332 remote_device_, adapter_, service_uuid_, to_peripheral_char_uuid_,
333 from_peripheral_char_uuid_, gatt_connection_.Pass(), kMaxNumberOfTries);
334 }
335
336 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
337 Disconect_WithoutConnectDoesntCrash) {
338 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
339 Disconnect(connection.get());
340 }
341
342 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
343 Connect_Success_WithGattConnection) {
344 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
345 ConnectWithExistingGattConnection(connection.get());
346 CharacteristicsFound(connection.get());
347 NotifySessionStarted(connection.get());
348 ResponseSignalReceived(connection.get());
349 }
350
351 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
352 Connect_Success_WithoutGattConnection) {
353 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
354 ConnectWithoutExistingGattConnection(connection.get());
355 CharacteristicsFound(connection.get());
356 NotifySessionStarted(connection.get());
357 ResponseSignalReceived(connection.get());
358 }
359
360 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
361 Connect_Success_Disconnect) {
362 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
363 ConnectWithExistingGattConnection(connection.get());
364 CharacteristicsFound(connection.get());
365 NotifySessionStarted(connection.get());
366 ResponseSignalReceived(connection.get());
367 Disconnect(connection.get());
368 }
369
370 TEST_F(
371 ProximityAuthBluetoothLowEnergyConnectionTest,
372 Connect_Incomplete_Disconnect_FromWaitingCharacteristicsStateWithoutExisting GattConnection) {
373 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
374 ConnectWithoutExistingGattConnection(connection.get());
375 Disconnect(connection.get());
376 }
377
378 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
379 Connect_Incomplete_Disconnect_FromWaitingCharacteristicsState) {
380 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
381 ConnectWithExistingGattConnection(connection.get());
382 Disconnect(connection.get());
383 }
384
385 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
386 Connect_Incomplete_Disconnect_FromWaitingNotifySessionState) {
387 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
388 ConnectWithExistingGattConnection(connection.get());
389 CharacteristicsFound(connection.get());
390 Disconnect(connection.get());
391 }
392
393 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
394 Connect_Incomplete_Disconnect_FromWaitingResponseSignalState) {
395 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
396 ConnectWithExistingGattConnection(connection.get());
397 CharacteristicsFound(connection.get());
398 NotifySessionStarted(connection.get());
399 Disconnect(connection.get());
400 }
401
402 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
403 Connect_Fails_CharacteristicsNotFound) {
404 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
405 ConnectWithExistingGattConnection(connection.get());
406
407 EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)).Times(0);
408 EXPECT_FALSE(characteristics_finder_success_callback_.is_null());
409 ASSERT_FALSE(characteristics_finder_error_callback_.is_null());
410
411 characteristics_finder_error_callback_.Run(
412 {to_peripheral_char_uuid_, kToPeripheralCharID},
413 {from_peripheral_char_uuid_, kFromPeripheralCharID});
414
415 EXPECT_EQ(connection->sub_status(),
416 MockBluetoothLowEnergyConnection::SubStatus::DISCONNECTED);
417 EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
418 }
419
420 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
421 Connect_Fails_NotifySessionError) {
422 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
423 ConnectWithExistingGattConnection(connection.get());
424 CharacteristicsFound(connection.get());
425
426 EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _))
427 .Times(0);
428 EXPECT_FALSE(notify_session_success_callback_.is_null());
429 ASSERT_FALSE(notify_session_error_callback_.is_null());
430
431 notify_session_error_callback_.Run(
432 device::BluetoothGattService::GATT_ERROR_UNKNOWN);
433
434 EXPECT_EQ(connection->sub_status(),
435 MockBluetoothLowEnergyConnection::SubStatus::DISCONNECTED);
436 EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
437 }
438
439 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
440 Connect_Fails_ErrorSendingInviteToConnectSignal) {
441 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
442 ConnectWithExistingGattConnection(connection.get());
443 CharacteristicsFound(connection.get());
444 NotifySessionStarted(connection.get());
445
446 // |connection| will call WriteRemoteCharacteristics(_,_) to try to send the
447 // message |kMaxNumberOfTries| times. There is alredy one EXPECTA_CALL for
448 // WriteRemoteCharacteristic(_,_,_) in NotifySessionStated, that's why we use
449 // |kMaxNumberOfTries-1| in the EXPECT_CALL statement.
450 EXPECT_CALL(*connection, OnDidSendMessage(_, _)).Times(0);
451 EXPECT_CALL(*to_peripheral_char_, WriteRemoteCharacteristic(_, _, _))
452 .Times(kMaxNumberOfTries - 1)
453 .WillRepeatedly(
454 DoAll(SaveArg<0>(&last_value_written_on_to_peripheral_char_),
455 SaveArg<1>(&write_remote_characteristic_success_callback_),
456 SaveArg<2>(&write_remote_characteristic_error_callback_)));
457
458 for (int i = 0; i < kMaxNumberOfTries; i++) {
459 const std::vector<uint8> kSendSignal = {0, 0, 0, 0};
460 EXPECT_EQ(last_value_written_on_to_peripheral_char_, kSendSignal);
461 ASSERT_FALSE(write_remote_characteristic_error_callback_.is_null());
462 EXPECT_FALSE(write_remote_characteristic_success_callback_.is_null());
463 write_remote_characteristic_error_callback_.Run(
464 device::BluetoothGattService::GATT_ERROR_UNKNOWN);
465 }
466
467 EXPECT_EQ(connection->sub_status(),
468 MockBluetoothLowEnergyConnection::SubStatus::DISCONNECTED);
469 EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
470 }
471
472 TEST_F(ProximityAuthBluetoothLowEnergyConnectionTest,
473 Connect_Fails_CharacteristicsNotFound_WithoutExistingGattConnection) {
474 scoped_ptr<MockBluetoothLowEnergyConnection> connection(CreateConnection());
475 ConnectWithoutExistingGattConnection(connection.get());
476
477 EXPECT_CALL(*from_peripheral_char_, StartNotifySession(_, _)).Times(0);
478 EXPECT_FALSE(characteristics_finder_success_callback_.is_null());
479 ASSERT_FALSE(characteristics_finder_error_callback_.is_null());
480
481 characteristics_finder_error_callback_.Run(
482 {to_peripheral_char_uuid_, kToPeripheralCharID},
483 {from_peripheral_char_uuid_, kFromPeripheralCharID});
484
485 EXPECT_EQ(connection->sub_status(),
486 MockBluetoothLowEnergyConnection::SubStatus::DISCONNECTED);
487 EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
488 }
489
490 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698