| 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" |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 752 |
| 753 ON_CALL(*user_description, ReadRemoteDescriptor(_, _)) | 753 ON_CALL(*user_description, ReadRemoteDescriptor(_, _)) |
| 754 .WillByDefault(Invoke([descriptorName]( | 754 .WillByDefault(Invoke([descriptorName]( |
| 755 const BluetoothRemoteGattDescriptor::ValueCallback& callback, | 755 const BluetoothRemoteGattDescriptor::ValueCallback& callback, |
| 756 const BluetoothRemoteGattDescriptor::ErrorCallback&) { | 756 const BluetoothRemoteGattDescriptor::ErrorCallback&) { |
| 757 std::vector<uint8_t> value(descriptorName.begin(), | 757 std::vector<uint8_t> value(descriptorName.begin(), |
| 758 descriptorName.end()); | 758 descriptorName.end()); |
| 759 callback.Run(value); | 759 callback.Run(value); |
| 760 })); | 760 })); |
| 761 | 761 |
| 762 ON_CALL(*user_description, WriteRemoteDescriptor(_, _, _)) |
| 763 .WillByDefault(RunCallback<1 /* success_callback */>()); |
| 764 |
| 762 auto client_config = base::MakeUnique<NiceMockBluetoothGattDescriptor>( | 765 auto client_config = base::MakeUnique<NiceMockBluetoothGattDescriptor>( |
| 763 measurement_interval.get(), "gatt.client_characteristic_configuration", | 766 measurement_interval.get(), "gatt.client_characteristic_configuration", |
| 764 BluetoothUUID(kClientConfigUUID), false /* is_local */, | 767 BluetoothUUID(kClientConfigUUID), false /* is_local */, |
| 765 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | | 768 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | |
| 766 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE); | 769 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE); |
| 767 | 770 |
| 771 // Crash if WriteRemoteDescriptor called. Not using GoogleMock's Expect |
| 772 // because this is used in layout tests that may not report a mock |
| 773 // expectation. |
| 774 ON_CALL(*client_config, WriteRemoteDescriptor(_, _, _)) |
| 775 .WillByDefault( |
| 776 Invoke([](const std::vector<uint8_t>&, const base::Closure&, |
| 777 const BluetoothRemoteGattDescriptor::ErrorCallback&) { |
| 778 NOTREACHED(); |
| 779 })); |
| 780 |
| 768 auto no_read_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>( | 781 auto no_read_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>( |
| 769 measurement_interval.get(), kBlocklistedReadDescriptorUUID, | 782 measurement_interval.get(), kBlocklistedReadDescriptorUUID, |
| 770 BluetoothUUID(kBlocklistedReadDescriptorUUID), false, | 783 BluetoothUUID(kBlocklistedReadDescriptorUUID), false, |
| 771 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | | 784 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | |
| 772 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE); | 785 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE); |
| 773 | 786 |
| 774 std::vector<uint8_t> value(1); | |
| 775 value[0] = false; | |
| 776 | |
| 777 // Crash if ReadRemoteDescriptor called. Not using GoogleMock's Expect | 787 // Crash if ReadRemoteDescriptor called. Not using GoogleMock's Expect |
| 778 // because this is used in layout tests that may not report a mock | 788 // because this is used in layout tests that may not report a mock |
| 779 // expectation | 789 // expectation |
| 780 // error correctly as a layout test failure. | 790 // error correctly as a layout test failure. |
| 781 ON_CALL(*no_read_descriptor, ReadRemoteDescriptor(_, _)) | 791 ON_CALL(*no_read_descriptor, ReadRemoteDescriptor(_, _)) |
| 782 .WillByDefault( | 792 .WillByDefault( |
| 783 Invoke([](const BluetoothRemoteGattDescriptor::ValueCallback&, | 793 Invoke([](const BluetoothRemoteGattDescriptor::ValueCallback&, |
| 784 const BluetoothRemoteGattDescriptor::ErrorCallback&) { | 794 const BluetoothRemoteGattDescriptor::ErrorCallback&) { |
| 785 NOTREACHED(); | 795 NOTREACHED(); |
| 786 })); | 796 })); |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 device_ptr->PushPendingCallback(pending); | 1135 device_ptr->PushPendingCallback(pending); |
| 1126 if (disconnect) { | 1136 if (disconnect) { |
| 1127 device_ptr->SetConnected(false); | 1137 device_ptr->SetConnected(false); |
| 1128 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1138 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1129 FROM_HERE, | 1139 FROM_HERE, |
| 1130 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), | 1140 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), |
| 1131 device_ptr)); | 1141 device_ptr)); |
| 1132 } | 1142 } |
| 1133 })); | 1143 })); |
| 1134 | 1144 |
| 1145 ON_CALL(*user_descriptor, WriteRemoteDescriptor(_, _, _)) |
| 1146 .WillByDefault(Invoke([adapter_ptr, device_ptr, user_descriptor_ptr, |
| 1147 disconnect, succeeds]( |
| 1148 const std::vector<uint8_t>& value, const base::Closure& callback, |
| 1149 const BluetoothRemoteGattDescriptor::ErrorCallback& error_callback) { |
| 1150 base::Closure pending; |
| 1151 if (succeeds) { |
| 1152 pending = callback; |
| 1153 } else { |
| 1154 pending = base::Bind(error_callback, |
| 1155 BluetoothRemoteGattService::GATT_ERROR_FAILED); |
| 1156 } |
| 1157 device_ptr->PushPendingCallback(pending); |
| 1158 if (disconnect) { |
| 1159 device_ptr->SetConnected(false); |
| 1160 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1161 FROM_HERE, |
| 1162 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), |
| 1163 device_ptr)); |
| 1164 } |
| 1165 })); |
| 1166 |
| 1135 measurement_interval->AddMockDescriptor(std::move(user_descriptor)); | 1167 measurement_interval->AddMockDescriptor(std::move(user_descriptor)); |
| 1136 | 1168 |
| 1137 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); | 1169 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); |
| 1138 device->AddMockService(std::move(health_thermometer)); | 1170 device->AddMockService(std::move(health_thermometer)); |
| 1139 adapter->AddMockDevice(std::move(device)); | 1171 adapter->AddMockDevice(std::move(device)); |
| 1140 return adapter; | 1172 return adapter; |
| 1141 } | 1173 } |
| 1142 | 1174 |
| 1143 // static | 1175 // static |
| 1144 scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider:: | 1176 scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider:: |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 | 1756 |
| 1725 // Add error descriptor to |characteristic| | 1757 // Add error descriptor to |characteristic| |
| 1726 auto error_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>( | 1758 auto error_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>( |
| 1727 characteristic.get(), kCharacteristicUserDescription, | 1759 characteristic.get(), kCharacteristicUserDescription, |
| 1728 BluetoothUUID(kUserDescriptionUUID), false, | 1760 BluetoothUUID(kUserDescriptionUUID), false, |
| 1729 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ); | 1761 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ); |
| 1730 | 1762 |
| 1731 ON_CALL(*error_descriptor, ReadRemoteDescriptor(_, _)) | 1763 ON_CALL(*error_descriptor, ReadRemoteDescriptor(_, _)) |
| 1732 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 1764 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
| 1733 | 1765 |
| 1766 ON_CALL(*error_descriptor, WriteRemoteDescriptor(_, _, _)) |
| 1767 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); |
| 1768 |
| 1734 characteristic->AddMockDescriptor(std::move(error_descriptor)); | 1769 characteristic->AddMockDescriptor(std::move(error_descriptor)); |
| 1735 | 1770 |
| 1736 return characteristic; | 1771 return characteristic; |
| 1737 } | 1772 } |
| 1738 | 1773 |
| 1739 // Notify sessions | 1774 // Notify sessions |
| 1740 | 1775 |
| 1741 // static | 1776 // static |
| 1742 std::unique_ptr<NiceMockBluetoothGattNotifySession> | 1777 std::unique_ptr<NiceMockBluetoothGattNotifySession> |
| 1743 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( | 1778 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1807 return BluetoothUUID(); | 1842 return BluetoothUUID(); |
| 1808 } | 1843 } |
| 1809 | 1844 |
| 1810 // static | 1845 // static |
| 1811 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1846 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
| 1812 return BluetoothDevice::CanonicalizeAddress( | 1847 return BluetoothDevice::CanonicalizeAddress( |
| 1813 base::StringPrintf("%012" PRIx64, addr)); | 1848 base::StringPrintf("%012" PRIx64, addr)); |
| 1814 } | 1849 } |
| 1815 | 1850 |
| 1816 } // namespace content | 1851 } // namespace content |
| OLD | NEW |