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 "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" | 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_adapter_provid er.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
19 #include "device/bluetooth/bluetooth_adapter.h" | 19 #include "device/bluetooth/bluetooth_adapter.h" |
20 #include "device/bluetooth/bluetooth_device.h" | 20 #include "device/bluetooth/bluetooth_device.h" |
21 #include "device/bluetooth/bluetooth_discovery_session.h" | 21 #include "device/bluetooth/bluetooth_discovery_session.h" |
22 #include "device/bluetooth/bluetooth_uuid.h" | 22 #include "device/bluetooth/bluetooth_uuid.h" |
23 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 23 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
24 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | 24 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
25 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 25 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
26 #include "device/bluetooth/test/mock_bluetooth_gatt_descriptor.h" | |
26 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" | 27 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
28 | 29 |
29 using base::StringPiece; | 30 using base::StringPiece; |
30 using device::BluetoothAdapter; | 31 using device::BluetoothAdapter; |
31 using device::BluetoothDevice; | 32 using device::BluetoothDevice; |
33 using device::BluetoothGattCharacteristic; | |
32 using device::BluetoothRemoteGattCharacteristic; | 34 using device::BluetoothRemoteGattCharacteristic; |
35 using device::BluetoothRemoteGattDescriptor; | |
33 using device::BluetoothRemoteGattService; | 36 using device::BluetoothRemoteGattService; |
34 using device::BluetoothUUID; | 37 using device::BluetoothUUID; |
35 using device::MockBluetoothAdapter; | 38 using device::MockBluetoothAdapter; |
36 using device::MockBluetoothDevice; | 39 using device::MockBluetoothDevice; |
37 using device::MockBluetoothDiscoverySession; | 40 using device::MockBluetoothDiscoverySession; |
38 using device::MockBluetoothGattCharacteristic; | 41 using device::MockBluetoothGattCharacteristic; |
39 using device::MockBluetoothGattConnection; | 42 using device::MockBluetoothGattConnection; |
43 using device::MockBluetoothGattDescriptor; | |
40 using device::MockBluetoothGattNotifySession; | 44 using device::MockBluetoothGattNotifySession; |
41 using device::MockBluetoothGattService; | 45 using device::MockBluetoothGattService; |
42 using testing::ElementsAre; | 46 using testing::ElementsAre; |
43 using testing::Invoke; | 47 using testing::Invoke; |
44 using testing::InvokeWithoutArgs; | 48 using testing::InvokeWithoutArgs; |
45 using testing::ResultOf; | 49 using testing::ResultOf; |
46 using testing::Return; | 50 using testing::Return; |
47 using testing::_; | 51 using testing::_; |
48 | 52 |
49 typedef testing::NiceMock<MockBluetoothAdapter> NiceMockBluetoothAdapter; | 53 typedef testing::NiceMock<MockBluetoothAdapter> NiceMockBluetoothAdapter; |
50 typedef testing::NiceMock<MockBluetoothDevice> NiceMockBluetoothDevice; | 54 typedef testing::NiceMock<MockBluetoothDevice> NiceMockBluetoothDevice; |
51 typedef testing::NiceMock<MockBluetoothDiscoverySession> | 55 typedef testing::NiceMock<MockBluetoothDiscoverySession> |
52 NiceMockBluetoothDiscoverySession; | 56 NiceMockBluetoothDiscoverySession; |
57 typedef testing::NiceMock<MockBluetoothGattDescriptor> | |
58 NiceMockBluetoothGattDescriptor; | |
53 typedef testing::NiceMock<MockBluetoothGattCharacteristic> | 59 typedef testing::NiceMock<MockBluetoothGattCharacteristic> |
54 NiceMockBluetoothGattCharacteristic; | 60 NiceMockBluetoothGattCharacteristic; |
55 typedef testing::NiceMock<MockBluetoothGattConnection> | 61 typedef testing::NiceMock<MockBluetoothGattConnection> |
56 NiceMockBluetoothGattConnection; | 62 NiceMockBluetoothGattConnection; |
57 typedef testing::NiceMock<MockBluetoothGattService> | 63 typedef testing::NiceMock<MockBluetoothGattService> |
58 NiceMockBluetoothGattService; | 64 NiceMockBluetoothGattService; |
59 typedef testing::NiceMock<MockBluetoothGattNotifySession> | 65 typedef testing::NiceMock<MockBluetoothGattNotifySession> |
60 NiceMockBluetoothGattNotifySession; | 66 NiceMockBluetoothGattNotifySession; |
61 | 67 |
62 namespace { | 68 namespace { |
(...skipping 14 matching lines...) Expand all Loading... | |
77 const char kBlacklistExcludeReadsCharacteristicUUID[] = | 83 const char kBlacklistExcludeReadsCharacteristicUUID[] = |
78 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135"; | 84 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135"; |
79 const char kRequestDisconnectionCharacteristicUUID[] = | 85 const char kRequestDisconnectionCharacteristicUUID[] = |
80 "01d7d88a-7451-419f-aeb8-d65e7b9277af"; | 86 "01d7d88a-7451-419f-aeb8-d65e7b9277af"; |
81 const char kBodySensorLocation[] = "2a38"; | 87 const char kBodySensorLocation[] = "2a38"; |
82 const char kDeviceNameUUID[] = "2a00"; | 88 const char kDeviceNameUUID[] = "2a00"; |
83 const char kMeasurementIntervalUUID[] = "2a21"; | 89 const char kMeasurementIntervalUUID[] = "2a21"; |
84 const char kHeartRateMeasurementUUID[] = "2a37"; | 90 const char kHeartRateMeasurementUUID[] = "2a37"; |
85 const char kSerialNumberStringUUID[] = "2a25"; | 91 const char kSerialNumberStringUUID[] = "2a25"; |
86 const char kPeripheralPrivacyFlagUUID[] = "2a02"; | 92 const char kPeripheralPrivacyFlagUUID[] = "2a02"; |
93 // Descriptors: | |
94 const char kUserDescriptionUUID[] = "2901"; | |
95 // client config is in our blacklist. it must not be writable | |
ortuno
2016/11/21 03:34:08
s/client/Client/ and s/it/It/
dougt
2016/11/22 01:47:16
Acknowledged.
| |
96 const char kClientConfigUUID[] = "00002902-0000-1000-8000-00805f9b34fb"; | |
ortuno
2016/11/21 03:34:08
Since it's a standard service you don't need the s
dougt
2016/11/22 01:47:16
Acknowledged.
| |
87 | 97 |
88 // Invokes Run() on the k-th argument of the function with no arguments. | 98 // Invokes Run() on the k-th argument of the function with no arguments. |
89 ACTION_TEMPLATE(RunCallback, | 99 ACTION_TEMPLATE(RunCallback, |
90 HAS_1_TEMPLATE_PARAMS(int, k), | 100 HAS_1_TEMPLATE_PARAMS(int, k), |
91 AND_0_VALUE_PARAMS()) { | 101 AND_0_VALUE_PARAMS()) { |
92 return ::testing::get<k>(args).Run(); | 102 return ::testing::get<k>(args).Run(); |
93 } | 103 } |
94 | 104 |
95 // Invokes Run() on the k-th argument of the function with 1 argument. | 105 // Invokes Run() on the k-th argument of the function with 1 argument. |
96 ACTION_TEMPLATE(RunCallback, | 106 ACTION_TEMPLATE(RunCallback, |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { | 653 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { |
644 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 654 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
645 std::unique_ptr<NiceMockBluetoothDevice> device( | 655 std::unique_ptr<NiceMockBluetoothDevice> device( |
646 GetHeartRateDevice(adapter.get())); | 656 GetHeartRateDevice(adapter.get())); |
647 | 657 |
648 // TODO(ortuno): Implement the rest of the service's characteristics | 658 // TODO(ortuno): Implement the rest of the service's characteristics |
649 // See: http://crbug.com/529975 | 659 // See: http://crbug.com/529975 |
650 | 660 |
651 device->AddMockService(GetGenericAccessService(device.get())); | 661 device->AddMockService(GetGenericAccessService(device.get())); |
652 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 662 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
653 | |
654 adapter->AddMockDevice(std::move(device)); | 663 adapter->AddMockDevice(std::move(device)); |
655 | |
656 return adapter; | 664 return adapter; |
657 } | 665 } |
658 | 666 |
659 // static | 667 // static |
660 scoped_refptr<NiceMockBluetoothAdapter> | 668 scoped_refptr<NiceMockBluetoothAdapter> |
661 LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() { | 669 LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() { |
662 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 670 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
663 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); | 671 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); |
664 | 672 |
665 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice( | 673 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice( |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 error++) { | 1116 error++) { |
1109 adapter->AddMockDevice(GetUnconnectableDevice( | 1117 adapter->AddMockDevice(GetUnconnectableDevice( |
1110 adapter.get(), static_cast<BluetoothDevice::ConnectErrorCode>(error))); | 1118 adapter.get(), static_cast<BluetoothDevice::ConnectErrorCode>(error))); |
1111 } | 1119 } |
1112 | 1120 |
1113 return adapter; | 1121 return adapter; |
1114 } | 1122 } |
1115 | 1123 |
1116 // static | 1124 // static |
1117 scoped_refptr<NiceMockBluetoothAdapter> | 1125 scoped_refptr<NiceMockBluetoothAdapter> |
1118 LayoutTestBluetoothAdapterProvider::GetFailingGATTOperationsAdapter() { | 1126 LayoutTestBluetoothAdapterProvider::GetFailingGATTOperationsAdapter() { |
ortuno
2016/11/21 03:34:08
Also add descriptors to the device in this adapter
| |
1119 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 1127 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
1120 | 1128 |
1121 const std::string errorsServiceUUID = errorUUID(0xA0); | 1129 const std::string errorsServiceUUID = errorUUID(0xA0); |
1122 | 1130 |
1123 BluetoothDevice::UUIDList uuids; | 1131 BluetoothDevice::UUIDList uuids; |
1124 uuids.push_back(BluetoothUUID(errorsServiceUUID)); | 1132 uuids.push_back(BluetoothUUID(errorsServiceUUID)); |
1125 | 1133 |
1126 std::unique_ptr<NiceMockBluetoothDevice> device( | 1134 std::unique_ptr<NiceMockBluetoothDevice> device( |
1127 GetConnectableDevice(adapter.get(), "Errors Device", uuids)); | 1135 GetConnectableDevice(adapter.get(), "Errors Device", uuids)); |
1128 | 1136 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1445 | 1453 |
1446 std::vector<uint8_t> rate(1 /* size */); | 1454 std::vector<uint8_t> rate(1 /* size */); |
1447 rate[0] = 60; | 1455 rate[0] = 60; |
1448 | 1456 |
1449 notify_session->StartTestNotifications(adapter, measurement_ptr, | 1457 notify_session->StartTestNotifications(adapter, measurement_ptr, |
1450 rate); | 1458 rate); |
1451 | 1459 |
1452 return notify_session; | 1460 return notify_session; |
1453 })); | 1461 })); |
1454 | 1462 |
1463 // Enable descriptors on the heart_rate_measurement | |
1464 ON_CALL(*heart_rate_measurement, GetDescriptors()) | |
1465 .WillByDefault( | |
1466 Invoke(measurement_ptr, | |
1467 &MockBluetoothGattCharacteristic::GetMockDescriptors)); | |
1468 | |
1469 ON_CALL(*heart_rate_measurement, GetDescriptor(_)) | |
1470 .WillByDefault( | |
1471 Invoke(measurement_ptr, | |
1472 &MockBluetoothGattCharacteristic::GetMockDescriptor)); | |
1473 | |
1455 // Body Sensor Location Characteristic (Chest) | 1474 // Body Sensor Location Characteristic (Chest) |
1456 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 1475 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
1457 body_sensor_location_chest(GetBaseGATTCharacteristic( | 1476 body_sensor_location_chest(GetBaseGATTCharacteristic( |
1458 "Body Sensor Location Chest", heart_rate.get(), kBodySensorLocation, | 1477 "Body Sensor Location Chest", heart_rate.get(), kBodySensorLocation, |
1459 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); | 1478 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
1460 BluetoothRemoteGattCharacteristic* location_chest_ptr = | 1479 BluetoothRemoteGattCharacteristic* location_chest_ptr = |
1461 body_sensor_location_chest.get(); | 1480 body_sensor_location_chest.get(); |
1462 | 1481 |
1463 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _)) | 1482 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _)) |
1464 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 1483 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
(...skipping 24 matching lines...) Expand all Loading... | |
1489 location[0] = 2; // Wrist | 1508 location[0] = 2; // Wrist |
1490 // Read a characteristic has a side effect of | 1509 // Read a characteristic has a side effect of |
1491 // GattCharacteristicValueChanged being called. | 1510 // GattCharacteristicValueChanged being called. |
1492 for (auto& observer : adapter->GetObservers()) { | 1511 for (auto& observer : adapter->GetObservers()) { |
1493 observer.GattCharacteristicValueChanged( | 1512 observer.GattCharacteristicValueChanged( |
1494 adapter, location_wrist_ptr, location); | 1513 adapter, location_wrist_ptr, location); |
1495 } | 1514 } |
1496 return location; | 1515 return location; |
1497 })); | 1516 })); |
1498 | 1517 |
1518 // Add two descriptors on the heart rate. One for user description, and one | |
ortuno
2016/11/21 03:34:08
I would add these to DisconnectingHealthThermomete
dougt
2016/11/29 22:50:48
Done.
| |
1519 // for client configuration. Client configuration is blacklisted for writes. | |
1520 std::unique_ptr<NiceMockBluetoothGattDescriptor> user_description( | |
1521 new NiceMockBluetoothGattDescriptor( | |
1522 heart_rate_measurement.get(), "user_description", | |
1523 BluetoothUUID(kUserDescriptionUUID), false, | |
1524 device::BluetoothGattCharacteristic::Permission::PERMISSION_READ)); | |
1525 | |
1526 // this descriptor is not allowed to be written. | |
1527 std::unique_ptr<NiceMockBluetoothGattDescriptor> client_config( | |
1528 new NiceMockBluetoothGattDescriptor( | |
1529 heart_rate_measurement.get(), "client_characteristic_configuration", | |
1530 BluetoothUUID(kClientConfigUUID), false, | |
1531 device::BluetoothGattCharacteristic::Permission::PERMISSION_WRITE)); | |
1532 | |
1533 ON_CALL(*client_config, ReadRemoteDescriptor(_, _)) | |
1534 .WillByDefault(Invoke( | |
1535 [](const BluetoothRemoteGattDescriptor::ValueCallback& callback, | |
1536 const BluetoothRemoteGattDescriptor::ErrorCallback&) { | |
1537 std::vector<uint8_t> value({1}); | |
1538 callback.Run(value); | |
1539 })); | |
1540 | |
1541 // Default write that returns success. This is used to test blacklist | |
1542 // handling of writes. | |
1543 ON_CALL(*client_config, WriteRemoteDescriptor(_, _, _)) | |
1544 .WillByDefault(RunCallback<1 /* success callback */>()); | |
1545 | |
1546 heart_rate_measurement->AddMockDescriptor(std::move(user_description)); | |
1547 heart_rate_measurement->AddMockDescriptor(std::move(client_config)); | |
1548 | |
1499 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement)); | 1549 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement)); |
1500 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest)); | 1550 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest)); |
1501 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist)); | 1551 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist)); |
1502 | 1552 |
1503 return heart_rate; | 1553 return heart_rate; |
1504 } | 1554 } |
1505 | 1555 |
1506 // static | 1556 // static |
1507 std::unique_ptr<NiceMockBluetoothGattService> | 1557 std::unique_ptr<NiceMockBluetoothGattService> |
1508 LayoutTestBluetoothAdapterProvider::GetDisconnectingService( | 1558 LayoutTestBluetoothAdapterProvider::GetDisconnectingService( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1666 return BluetoothUUID(); | 1716 return BluetoothUUID(); |
1667 } | 1717 } |
1668 | 1718 |
1669 // static | 1719 // static |
1670 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1720 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
1671 return BluetoothDevice::CanonicalizeAddress( | 1721 return BluetoothDevice::CanonicalizeAddress( |
1672 base::StringPrintf("%012" PRIx64, addr)); | 1722 base::StringPrintf("%012" PRIx64, addr)); |
1673 } | 1723 } |
1674 | 1724 |
1675 } // namespace content | 1725 } // namespace content |
OLD | NEW |