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

Side by Side Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 2654403002: Implement WebBluetooth descriptor.writeValue() (Closed)
Patch Set: Inital Created 3 years, 10 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
OLDNEW
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
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(_, _, _))
ortuno 2017/01/28 00:22:51 Please update the docs in the header to reflect th
dougt 2017/01/31 00:31:25 Done.
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 ON_CALL(*client_config, WriteRemoteDescriptor(_, _, _))
ortuno 2017/01/28 00:22:51 nit for consistency: // Crash if WriteRemoteDe
dougt 2017/01/31 00:31:25 Done.
772 .WillByDefault(
773 Invoke([](const std::vector<uint8_t>&, const base::Closure&,
774 const BluetoothRemoteGattDescriptor::ErrorCallback&) {
775 NOTREACHED();
776 }));
777
768 auto no_read_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>( 778 auto no_read_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>(
769 measurement_interval.get(), kBlocklistedReadDescriptorUUID, 779 measurement_interval.get(), kBlocklistedReadDescriptorUUID,
770 BluetoothUUID(kBlocklistedReadDescriptorUUID), false, 780 BluetoothUUID(kBlocklistedReadDescriptorUUID), false,
771 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | 781 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ |
772 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE); 782 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE);
773 783
774 std::vector<uint8_t> value(1);
775 value[0] = false;
776
777 // Crash if ReadRemoteDescriptor called. Not using GoogleMock's Expect 784 // Crash if ReadRemoteDescriptor called. Not using GoogleMock's Expect
778 // because this is used in layout tests that may not report a mock 785 // because this is used in layout tests that may not report a mock
779 // expectation 786 // expectation
780 // error correctly as a layout test failure. 787 // error correctly as a layout test failure.
781 ON_CALL(*no_read_descriptor, ReadRemoteDescriptor(_, _)) 788 ON_CALL(*no_read_descriptor, ReadRemoteDescriptor(_, _))
782 .WillByDefault( 789 .WillByDefault(
783 Invoke([](const BluetoothRemoteGattDescriptor::ValueCallback&, 790 Invoke([](const BluetoothRemoteGattDescriptor::ValueCallback&,
784 const BluetoothRemoteGattDescriptor::ErrorCallback&) { 791 const BluetoothRemoteGattDescriptor::ErrorCallback&) {
785 NOTREACHED(); 792 NOTREACHED();
786 })); 793 }));
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 device_ptr->PushPendingCallback(pending); 1132 device_ptr->PushPendingCallback(pending);
1126 if (disconnect) { 1133 if (disconnect) {
1127 device_ptr->SetConnected(false); 1134 device_ptr->SetConnected(false);
1128 base::ThreadTaskRunnerHandle::Get()->PostTask( 1135 base::ThreadTaskRunnerHandle::Get()->PostTask(
1129 FROM_HERE, 1136 FROM_HERE,
1130 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), 1137 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
1131 device_ptr)); 1138 device_ptr));
1132 } 1139 }
1133 })); 1140 }));
1134 1141
1142 ON_CALL(*user_descriptor, WriteRemoteDescriptor(_, _, _))
1143 .WillByDefault(Invoke([adapter_ptr, device_ptr, user_descriptor_ptr,
1144 disconnect, succeeds](
1145 const std::vector<uint8_t>& value, const base::Closure& callback,
1146 const BluetoothRemoteGattDescriptor::ErrorCallback& error_callback) {
1147 base::Closure pending;
1148 if (succeeds) {
1149 pending = callback;
1150 } else {
1151 pending = base::Bind(error_callback,
1152 BluetoothRemoteGattService::GATT_ERROR_FAILED);
1153 }
1154 device_ptr->PushPendingCallback(pending);
1155 if (disconnect) {
1156 device_ptr->SetConnected(false);
1157 base::ThreadTaskRunnerHandle::Get()->PostTask(
1158 FROM_HERE,
1159 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
1160 device_ptr));
1161 }
1162 }));
1163
1135 measurement_interval->AddMockDescriptor(std::move(user_descriptor)); 1164 measurement_interval->AddMockDescriptor(std::move(user_descriptor));
1136 1165
1137 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 1166 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
1138 device->AddMockService(std::move(health_thermometer)); 1167 device->AddMockService(std::move(health_thermometer));
1139 adapter->AddMockDevice(std::move(device)); 1168 adapter->AddMockDevice(std::move(device));
1140 return adapter; 1169 return adapter;
1141 } 1170 }
1142 1171
1143 // static 1172 // static
1144 scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider:: 1173 scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider::
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 1753
1725 // Add error descriptor to |characteristic| 1754 // Add error descriptor to |characteristic|
1726 auto error_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>( 1755 auto error_descriptor = base::MakeUnique<NiceMockBluetoothGattDescriptor>(
1727 characteristic.get(), kCharacteristicUserDescription, 1756 characteristic.get(), kCharacteristicUserDescription,
1728 BluetoothUUID(kUserDescriptionUUID), false, 1757 BluetoothUUID(kUserDescriptionUUID), false,
1729 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ); 1758 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ);
1730 1759
1731 ON_CALL(*error_descriptor, ReadRemoteDescriptor(_, _)) 1760 ON_CALL(*error_descriptor, ReadRemoteDescriptor(_, _))
1732 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); 1761 .WillByDefault(RunCallback<1 /* error_callback */>(error_code));
1733 1762
1763 ON_CALL(*error_descriptor, WriteRemoteDescriptor(_, _, _))
1764 .WillByDefault(RunCallback<2 /* error_callback */>(error_code));
1765
1734 characteristic->AddMockDescriptor(std::move(error_descriptor)); 1766 characteristic->AddMockDescriptor(std::move(error_descriptor));
1735 1767
1736 return characteristic; 1768 return characteristic;
1737 } 1769 }
1738 1770
1739 // Notify sessions 1771 // Notify sessions
1740 1772
1741 // static 1773 // static
1742 std::unique_ptr<NiceMockBluetoothGattNotifySession> 1774 std::unique_ptr<NiceMockBluetoothGattNotifySession>
1743 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession( 1775 LayoutTestBluetoothAdapterProvider::GetBaseGATTNotifySession(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 return BluetoothUUID(); 1839 return BluetoothUUID();
1808 } 1840 }
1809 1841
1810 // static 1842 // static
1811 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1843 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1812 return BluetoothDevice::CanonicalizeAddress( 1844 return BluetoothDevice::CanonicalizeAddress(
1813 base::StringPrintf("%012" PRIx64, addr)); 1845 base::StringPrintf("%012" PRIx64, addr));
1814 } 1846 }
1815 1847
1816 } // namespace content 1848 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698