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

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

Issue 2466223002: Implement WebBluetooth getDescriptor[s] (Closed)
Patch Set: Updating cross-origin-objects-exceptions.html 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[] = "bad0";
87 99
88 // Invokes Run() on the k-th argument of the function with no arguments. 100 // Invokes Run() on the k-th argument of the function with no arguments.
89 ACTION_TEMPLATE(RunCallback, 101 ACTION_TEMPLATE(RunCallback,
90 HAS_1_TEMPLATE_PARAMS(int, k), 102 HAS_1_TEMPLATE_PARAMS(int, k),
91 AND_0_VALUE_PARAMS()) { 103 AND_0_VALUE_PARAMS()) {
92 return ::testing::get<k>(args).Run(); 104 return ::testing::get<k>(args).Run();
93 } 105 }
94 106
95 // Invokes Run() on the k-th argument of the function with 1 argument. 107 // Invokes Run() on the k-th argument of the function with 1 argument.
96 ACTION_TEMPLATE(RunCallback, 108 ACTION_TEMPLATE(RunCallback,
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { 659 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
648 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 660 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
649 std::unique_ptr<NiceMockBluetoothDevice> device( 661 std::unique_ptr<NiceMockBluetoothDevice> device(
650 GetHeartRateDevice(adapter.get())); 662 GetHeartRateDevice(adapter.get()));
651 663
652 // TODO(ortuno): Implement the rest of the service's characteristics 664 // TODO(ortuno): Implement the rest of the service's characteristics
653 // See: http://crbug.com/529975 665 // See: http://crbug.com/529975
654 666
655 device->AddMockService(GetGenericAccessService(device.get())); 667 device->AddMockService(GetGenericAccessService(device.get()));
656 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); 668 device->AddMockService(GetHeartRateService(adapter.get(), device.get()));
669 adapter->AddMockDevice(std::move(device));
670 return adapter;
671 }
672 // static
673 void LayoutTestBluetoothAdapterProvider::AddDescriptorsToCharacteristic(
674 device::MockBluetoothGattCharacteristic* characteristic) {
675 std::unique_ptr<NiceMockBluetoothGattDescriptor> user_description(
676 new NiceMockBluetoothGattDescriptor(
677 characteristic, "gatt.characteristic_user_description",
678 BluetoothUUID(kUserDescriptionUUID), false,
679 device::BluetoothGattCharacteristic::Permission::PERMISSION_READ));
657 680
658 adapter->AddMockDevice(std::move(device)); 681 std::unique_ptr<NiceMockBluetoothGattDescriptor> client_config(
682 new NiceMockBluetoothGattDescriptor(
683 characteristic, "gatt.client_characteristic_configuration",
684 BluetoothUUID(kClientConfigUUID), false,
685 device::BluetoothGattCharacteristic::Permission::PERMISSION_WRITE));
659 686
660 return adapter; 687 // add it here with full permission as the blocklist should prevent us from
ortuno 2016/12/07 08:05:12 nit: s/add/Add/ Also this should DCHECK to match o
dougt 2016/12/07 19:48:57 You mean reading and writing to it, correct? We h
dougt 2016/12/07 22:21:43 In any case, in this CL, we don't read or write ye
ortuno 2016/12/08 05:42:51 For future reference. The intent is to make sure w
688 // accessing this descriptor
689 std::unique_ptr<NiceMockBluetoothGattDescriptor> blocklisted_descriptor(
690 new NiceMockBluetoothGattDescriptor(
691 characteristic, "bad0", BluetoothUUID(kBlocklistedDescriptorUUID),
692 false,
693 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ |
694 device::BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
695
696 characteristic->AddMockDescriptor(std::move(user_description));
697 characteristic->AddMockDescriptor(std::move(client_config));
661 } 698 }
662 699
663 // static 700 // static
664 scoped_refptr<NiceMockBluetoothAdapter> 701 scoped_refptr<NiceMockBluetoothAdapter>
665 LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() { 702 LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() {
666 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 703 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
667 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); 704 NiceMockBluetoothAdapter* adapter_ptr = adapter.get();
668 705
669 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice( 706 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice(
670 adapter_ptr, "Disconnecting Health Thermometer", 707 adapter_ptr, "Disconnecting Health Thermometer",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 739
703 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _)) 740 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _))
704 .WillByDefault(RunCallback<1 /* success_callback */>()); 741 .WillByDefault(RunCallback<1 /* success_callback */>());
705 742
706 ON_CALL(*measurement_interval, StartNotifySession(_, _)) 743 ON_CALL(*measurement_interval, StartNotifySession(_, _))
707 .WillByDefault( 744 .WillByDefault(
708 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() { 745 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() {
709 return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr()); 746 return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr());
710 })); 747 }));
711 748
749 AddDescriptorsToCharacteristic(measurement_interval.get());
750
712 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 751 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
713 device->AddMockService(std::move(health_thermometer)); 752 device->AddMockService(std::move(health_thermometer));
714 753
715 adapter->AddMockDevice(std::move(device)); 754 adapter->AddMockDevice(std::move(device));
716 755
717 return adapter; 756 return adapter;
718 } 757 }
719 758
720 // static 759 // static
721 scoped_refptr<NiceMockBluetoothAdapter> 760 scoped_refptr<NiceMockBluetoothAdapter>
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 // Write response. 1620 // Write response.
1582 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) 1621 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _))
1583 .WillByDefault( 1622 .WillByDefault(
1584 RunCallback<2>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); 1623 RunCallback<2>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED));
1585 1624
1586 // StartNotifySession response 1625 // StartNotifySession response
1587 ON_CALL(*characteristic, StartNotifySession(_, _)) 1626 ON_CALL(*characteristic, StartNotifySession(_, _))
1588 .WillByDefault( 1627 .WillByDefault(
1589 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED)); 1628 RunCallback<1>(BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED));
1590 1629
1630 // getDescriptors response
ortuno 2016/12/07 08:05:12 nit: I don't think the comment is necessary.
dougt 2016/12/07 19:48:57 I agree. I will also remove the three other comme
1631 ON_CALL(*characteristic, GetDescriptors())
1632 .WillByDefault(
1633 Invoke(characteristic.get(),
1634 &MockBluetoothGattCharacteristic::GetMockDescriptors));
1635
1636 // getDescriptor response
1637 ON_CALL(*characteristic, GetDescriptor(_))
1638 .WillByDefault(
1639 Invoke(characteristic.get(),
1640 &MockBluetoothGattCharacteristic::GetMockDescriptor));
1641
1591 return characteristic; 1642 return characteristic;
1592 } 1643 }
1593 1644
1594 // static 1645 // static
1595 std::unique_ptr<NiceMockBluetoothGattCharacteristic> 1646 std::unique_ptr<NiceMockBluetoothGattCharacteristic>
1596 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( 1647 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic(
1597 MockBluetoothGattService* service, 1648 MockBluetoothGattService* service,
1598 BluetoothRemoteGattService::GattErrorCode error_code) { 1649 BluetoothRemoteGattService::GattErrorCode error_code) {
1599 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. 1650 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1.
1600 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( 1651 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 return BluetoothUUID(); 1743 return BluetoothUUID();
1693 } 1744 }
1694 1745
1695 // static 1746 // static
1696 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1747 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1697 return BluetoothDevice::CanonicalizeAddress( 1748 return BluetoothDevice::CanonicalizeAddress(
1698 base::StringPrintf("%012" PRIx64, addr)); 1749 base::StringPrintf("%012" PRIx64, addr));
1699 } 1750 }
1700 1751
1701 } // namespace content 1752 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698