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

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

Issue 2466223002: Implement WebBluetooth getDescriptor[s] (Closed)
Patch Set: rebase to master Created 4 years 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"
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
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
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
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::BluetoothGattCharacteristic::Permission::PERMISSION_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::BluetoothGattCharacteristic::Permission::PERMISSION_WRITE));
ortuno 2016/12/08 05:42:51 I think this is Read and write: https://www.bluet
dougt 2016/12/08 08:35:58 Done. Note, I also converted calls sites here to
735
736 // Add it here with full permission as the blocklist should prevent us from
737 // accessing this descriptor
738 std::unique_ptr<NiceMockBluetoothGattDescriptor> blocklisted_descriptor(
739 new NiceMockBluetoothGattDescriptor(
740 measurement_interval.get(), "bad2ddcf-60db-45cd-bef9-fd72b153cf7c",
741 BluetoothUUID(kBlocklistedDescriptorUUID), false,
742 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ |
743 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
744
745 measurement_interval->AddMockDescriptor(std::move(user_description));
746 measurement_interval->AddMockDescriptor(std::move(client_config));
747
712 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 748 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
713 device->AddMockService(std::move(health_thermometer)); 749 device->AddMockService(std::move(health_thermometer));
714 750
715 adapter->AddMockDevice(std::move(device)); 751 adapter->AddMockDevice(std::move(device));
716 752
717 return adapter; 753 return adapter;
718 } 754 }
719 755
720 // static 756 // static
721 scoped_refptr<NiceMockBluetoothAdapter> 757 scoped_refptr<NiceMockBluetoothAdapter>
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( 1602 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic(
1567 const std::string& identifier, 1603 const std::string& identifier,
1568 MockBluetoothGattService* service, 1604 MockBluetoothGattService* service,
1569 const std::string& uuid, 1605 const std::string& uuid,
1570 BluetoothRemoteGattCharacteristic::Properties properties) { 1606 BluetoothRemoteGattCharacteristic::Properties properties) {
1571 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( 1607 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic(
1572 new NiceMockBluetoothGattCharacteristic( 1608 new NiceMockBluetoothGattCharacteristic(
1573 service, identifier, BluetoothUUID(uuid), false /* is_local */, 1609 service, identifier, BluetoothUUID(uuid), false /* is_local */,
1574 properties, NULL /* permissions */)); 1610 properties, NULL /* permissions */));
1575 1611
1576 // Read response.
1577 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) 1612 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _))
1578 .WillByDefault( 1613 .WillByDefault(
1579 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); 1614 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED));
1580 1615
1581 // Write response.
1582 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) 1616 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _))
1583 .WillByDefault( 1617 .WillByDefault(
1584 RunCallback<2>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); 1618 RunCallback<2>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED));
1585 1619
1586 // StartNotifySession response
1587 ON_CALL(*characteristic, StartNotifySession(_, _)) 1620 ON_CALL(*characteristic, StartNotifySession(_, _))
1588 .WillByDefault( 1621 .WillByDefault(
1589 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); 1622 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED));
1590 1623
1624 ON_CALL(*characteristic, GetDescriptors())
1625 .WillByDefault(
1626 Invoke(characteristic.get(),
1627 &MockBluetoothGattCharacteristic::GetMockDescriptors));
1628
1629 ON_CALL(*characteristic, GetDescriptor(_))
1630 .WillByDefault(
1631 Invoke(characteristic.get(),
1632 &MockBluetoothGattCharacteristic::GetMockDescriptor));
1633
1591 return characteristic; 1634 return characteristic;
1592 } 1635 }
1593 1636
1594 // static 1637 // static
1595 std::unique_ptr<NiceMockBluetoothGattCharacteristic> 1638 std::unique_ptr<NiceMockBluetoothGattCharacteristic>
1596 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( 1639 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic(
1597 MockBluetoothGattService* service, 1640 MockBluetoothGattService* service,
1598 BluetoothRemoteGattService::GattErrorCode error_code) { 1641 BluetoothRemoteGattService::GattErrorCode error_code) {
1599 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. 1642 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1.
1600 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( 1643 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 return BluetoothUUID(); 1735 return BluetoothUUID();
1693 } 1736 }
1694 1737
1695 // static 1738 // static
1696 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1739 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1697 return BluetoothDevice::CanonicalizeAddress( 1740 return BluetoothDevice::CanonicalizeAddress(
1698 base::StringPrintf("%012" PRIx64, addr)); 1741 base::StringPrintf("%012" PRIx64, addr));
1699 } 1742 }
1700 1743
1701 } // namespace content 1744 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698