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 kBlocklistExcludeReadsCharacteristicUUID[] = | 83 const char kBlocklistExcludeReadsCharacteristicUUID[] = |
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 blocklist. It must not be writable | |
96 const char kClientConfigUUID[] = "2902"; | |
97 // Blocklisted descriptor | |
98 const char kBlocklistedDescriptorUUID[] = | |
99 "bad2ddcf-60db-45cd-bef9-fd72b153cf7c"; | |
87 | 100 |
88 // Invokes Run() on the k-th argument of the function with no arguments. | 101 // Invokes Run() on the k-th argument of the function with no arguments. |
89 ACTION_TEMPLATE(RunCallback, | 102 ACTION_TEMPLATE(RunCallback, |
90 HAS_1_TEMPLATE_PARAMS(int, k), | 103 HAS_1_TEMPLATE_PARAMS(int, k), |
91 AND_0_VALUE_PARAMS()) { | 104 AND_0_VALUE_PARAMS()) { |
92 return ::testing::get<k>(args).Run(); | 105 return ::testing::get<k>(args).Run(); |
93 } | 106 } |
94 | 107 |
95 // Invokes Run() on the k-th argument of the function with 1 argument. | 108 // Invokes Run() on the k-th argument of the function with 1 argument. |
96 ACTION_TEMPLATE(RunCallback, | 109 ACTION_TEMPLATE(RunCallback, |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { | 660 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { |
648 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 661 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
649 std::unique_ptr<NiceMockBluetoothDevice> device( | 662 std::unique_ptr<NiceMockBluetoothDevice> device( |
650 GetHeartRateDevice(adapter.get())); | 663 GetHeartRateDevice(adapter.get())); |
651 | 664 |
652 // TODO(ortuno): Implement the rest of the service's characteristics | 665 // TODO(ortuno): Implement the rest of the service's characteristics |
653 // See: http://crbug.com/529975 | 666 // See: http://crbug.com/529975 |
654 | 667 |
655 device->AddMockService(GetGenericAccessService(device.get())); | 668 device->AddMockService(GetGenericAccessService(device.get())); |
656 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 669 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
657 | |
658 adapter->AddMockDevice(std::move(device)); | 670 adapter->AddMockDevice(std::move(device)); |
659 | |
660 return adapter; | 671 return adapter; |
661 } | 672 } |
662 | 673 |
663 // static | 674 // static |
664 scoped_refptr<NiceMockBluetoothAdapter> | 675 scoped_refptr<NiceMockBluetoothAdapter> |
665 LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() { | 676 LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() { |
666 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 677 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
667 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); | 678 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); |
668 | 679 |
669 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice( | 680 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 | 713 |
703 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _)) | 714 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _)) |
704 .WillByDefault(RunCallback<1 /* success_callback */>()); | 715 .WillByDefault(RunCallback<1 /* success_callback */>()); |
705 | 716 |
706 ON_CALL(*measurement_interval, StartNotifySession(_, _)) | 717 ON_CALL(*measurement_interval, StartNotifySession(_, _)) |
707 .WillByDefault( | 718 .WillByDefault( |
708 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() { | 719 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() { |
709 return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr()); | 720 return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr()); |
710 })); | 721 })); |
711 | 722 |
723 std::unique_ptr<NiceMockBluetoothGattDescriptor> user_description( | |
724 new NiceMockBluetoothGattDescriptor( | |
725 measurement_interval.get(), "gatt.characteristic_user_description", | |
726 BluetoothUUID(kUserDescriptionUUID), false, | |
727 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ)); | |
728 | |
729 std::unique_ptr<NiceMockBluetoothGattDescriptor> client_config( | |
730 new NiceMockBluetoothGattDescriptor( | |
731 measurement_interval.get(), | |
732 "gatt.client_characteristic_configuration", | |
733 BluetoothUUID(kClientConfigUUID), false, | |
734 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | | |
735 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); | |
736 | |
737 // Add it here with full permission as the blocklist should prevent us from | |
738 // accessing this descriptor | |
739 std::unique_ptr<NiceMockBluetoothGattDescriptor> blocklisted_descriptor( | |
740 new NiceMockBluetoothGattDescriptor( | |
741 measurement_interval.get(), "bad2ddcf-60db-45cd-bef9-fd72b153cf7c", | |
742 BluetoothUUID(kBlocklistedDescriptorUUID), false, | |
743 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | | |
744 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); | |
745 | |
746 measurement_interval->AddMockDescriptor(std::move(user_description)); | |
747 measurement_interval->AddMockDescriptor(std::move(client_config)); | |
scheib
2017/01/12 23:41:35
add blocklisted_descriptor?
dougt
2017/01/13 00:16:28
Yup! added.
| |
748 | |
712 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); | 749 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); |
713 device->AddMockService(std::move(health_thermometer)); | 750 device->AddMockService(std::move(health_thermometer)); |
714 | 751 |
715 adapter->AddMockDevice(std::move(device)); | 752 adapter->AddMockDevice(std::move(device)); |
716 | 753 |
717 return adapter; | 754 return adapter; |
718 } | 755 } |
719 | 756 |
720 // static | 757 // static |
721 scoped_refptr<NiceMockBluetoothAdapter> | 758 scoped_refptr<NiceMockBluetoothAdapter> |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1566 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( | 1603 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( |
1567 const std::string& identifier, | 1604 const std::string& identifier, |
1568 MockBluetoothGattService* service, | 1605 MockBluetoothGattService* service, |
1569 const std::string& uuid, | 1606 const std::string& uuid, |
1570 BluetoothRemoteGattCharacteristic::Properties properties) { | 1607 BluetoothRemoteGattCharacteristic::Properties properties) { |
1571 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( | 1608 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( |
1572 new NiceMockBluetoothGattCharacteristic( | 1609 new NiceMockBluetoothGattCharacteristic( |
1573 service, identifier, BluetoothUUID(uuid), false /* is_local */, | 1610 service, identifier, BluetoothUUID(uuid), false /* is_local */, |
1574 properties, NULL /* permissions */)); | 1611 properties, NULL /* permissions */)); |
1575 | 1612 |
1576 // Read response. | |
1577 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) | 1613 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) |
1578 .WillByDefault( | 1614 .WillByDefault( |
1579 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); | 1615 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
1580 | 1616 |
1581 // Write response. | |
1582 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) | 1617 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) |
1583 .WillByDefault( | 1618 .WillByDefault( |
1584 RunCallback<2>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); | 1619 RunCallback<2>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
1585 | 1620 |
1586 // StartNotifySession response | |
1587 ON_CALL(*characteristic, StartNotifySession(_, _)) | 1621 ON_CALL(*characteristic, StartNotifySession(_, _)) |
1588 .WillByDefault( | 1622 .WillByDefault( |
1589 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); | 1623 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); |
1590 | 1624 |
1625 ON_CALL(*characteristic, GetDescriptors()) | |
1626 .WillByDefault( | |
1627 Invoke(characteristic.get(), | |
1628 &MockBluetoothGattCharacteristic::GetMockDescriptors)); | |
1629 | |
1630 ON_CALL(*characteristic, GetDescriptor(_)) | |
1631 .WillByDefault( | |
1632 Invoke(characteristic.get(), | |
1633 &MockBluetoothGattCharacteristic::GetMockDescriptor)); | |
1634 | |
1591 return characteristic; | 1635 return characteristic; |
1592 } | 1636 } |
1593 | 1637 |
1594 // static | 1638 // static |
1595 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 1639 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
1596 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( | 1640 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( |
1597 MockBluetoothGattService* service, | 1641 MockBluetoothGattService* service, |
1598 BluetoothRemoteGattService::GattErrorCode error_code) { | 1642 BluetoothRemoteGattService::GattErrorCode error_code) { |
1599 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. | 1643 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. |
1600 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( | 1644 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1692 return BluetoothUUID(); | 1736 return BluetoothUUID(); |
1693 } | 1737 } |
1694 | 1738 |
1695 // static | 1739 // static |
1696 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1740 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
1697 return BluetoothDevice::CanonicalizeAddress( | 1741 return BluetoothDevice::CanonicalizeAddress( |
1698 base::StringPrintf("%012" PRIx64, addr)); | 1742 base::StringPrintf("%012" PRIx64, addr)); |
1699 } | 1743 } |
1700 | 1744 |
1701 } // namespace content | 1745 } // namespace content |
OLD | NEW |