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

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 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 blacklist. It must not be writable
ortuno 2016/12/02 06:14:50 s/blacklist/blocklist/
dougt 2016/12/02 18:31:28 Done.
96 const char kClientConfigUUID[] = "2902";
87 97
88 // Invokes Run() on the k-th argument of the function with no arguments. 98 // Invokes Run() on the k-th argument of the function with no arguments.
89 ACTION_TEMPLATE(RunCallback, 99 ACTION_TEMPLATE(RunCallback,
90 HAS_1_TEMPLATE_PARAMS(int, k), 100 HAS_1_TEMPLATE_PARAMS(int, k),
91 AND_0_VALUE_PARAMS()) { 101 AND_0_VALUE_PARAMS()) {
92 return ::testing::get<k>(args).Run(); 102 return ::testing::get<k>(args).Run();
93 } 103 }
94 104
95 // Invokes Run() on the k-th argument of the function with 1 argument. 105 // Invokes Run() on the k-th argument of the function with 1 argument.
96 ACTION_TEMPLATE(RunCallback, 106 ACTION_TEMPLATE(RunCallback,
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { 653 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() {
644 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 654 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
645 std::unique_ptr<NiceMockBluetoothDevice> device( 655 std::unique_ptr<NiceMockBluetoothDevice> device(
646 GetHeartRateDevice(adapter.get())); 656 GetHeartRateDevice(adapter.get()));
647 657
648 // TODO(ortuno): Implement the rest of the service's characteristics 658 // TODO(ortuno): Implement the rest of the service's characteristics
649 // See: http://crbug.com/529975 659 // See: http://crbug.com/529975
650 660
651 device->AddMockService(GetGenericAccessService(device.get())); 661 device->AddMockService(GetGenericAccessService(device.get()));
652 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); 662 device->AddMockService(GetHeartRateService(adapter.get(), device.get()));
663 adapter->AddMockDevice(std::move(device));
664 return adapter;
665 }
666 // static
667 void LayoutTestBluetoothAdapterProvider::AddDescriptorsToCharacteristic(
ortuno 2016/12/02 06:14:50 Given that this will only be used in one place (se
dougt 2016/12/02 18:31:28 Acknowledged. I was thinking that it might be nee
ortuno 2016/12/07 08:05:12 hmm I can't see us using this but maybe I'm missin
668 device::MockBluetoothGattCharacteristic* characteristic) {
669 std::unique_ptr<NiceMockBluetoothGattDescriptor> user_description(
670 new NiceMockBluetoothGattDescriptor(
671 characteristic, "user_description",
672 BluetoothUUID(kUserDescriptionUUID), false,
673 device::BluetoothGattCharacteristic::Permission::PERMISSION_READ));
653 674
654 adapter->AddMockDevice(std::move(device)); 675 std::unique_ptr<NiceMockBluetoothGattDescriptor> client_config(
676 new NiceMockBluetoothGattDescriptor(
677 characteristic, "client_characteristic_configuration",
678 BluetoothUUID(kClientConfigUUID), false,
679 device::BluetoothGattCharacteristic::Permission::PERMISSION_WRITE));
655 680
656 return adapter; 681 ON_CALL(*client_config, ReadRemoteDescriptor(_, _))
ortuno 2016/12/02 06:14:50 No need for Write/Read yet.
dougt 2016/12/02 18:31:28 Done.
682 .WillByDefault(Invoke(
683 [](const BluetoothRemoteGattDescriptor::ValueCallback& callback,
684 const BluetoothRemoteGattDescriptor::ErrorCallback&) {
685 std::vector<uint8_t> value({1});
686 callback.Run(value);
687 }));
688
689 // Default write that returns success. This is used to test blacklist
690 // handling of writes.
691 ON_CALL(*client_config, WriteRemoteDescriptor(_, _, _))
ortuno 2016/12/02 06:14:50 Rather than succeeding this should DCHECK. See oth
dougt 2016/12/02 18:31:28 Acknowledged. Removing as we're not doing write i
692 .WillByDefault(RunCallback<1 /* success callback */>());
693
694 ON_CALL(*characteristic, GetDescriptors())
ortuno 2016/12/02 06:14:50 Add these to GetBaseGATTCharacteristic so that all
dougt 2016/12/02 18:31:28 Done.
695 .WillByDefault(
696 Invoke(characteristic,
697 &MockBluetoothGattCharacteristic::GetMockDescriptors));
698
699 ON_CALL(*characteristic, GetDescriptor(_))
700 .WillByDefault(Invoke(
701 characteristic, &MockBluetoothGattCharacteristic::GetMockDescriptor));
702
703 characteristic->AddMockDescriptor(std::move(user_description));
704 characteristic->AddMockDescriptor(std::move(client_config));
657 } 705 }
658 706
659 // static 707 // static
660 scoped_refptr<NiceMockBluetoothAdapter> 708 scoped_refptr<NiceMockBluetoothAdapter>
661 LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() { 709 LayoutTestBluetoothAdapterProvider::GetDisconnectingHealthThermometer() {
662 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 710 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
663 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); 711 NiceMockBluetoothAdapter* adapter_ptr = adapter.get();
664 712
665 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice( 713 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice(
666 adapter_ptr, "Disconnecting Health Thermometer", 714 adapter_ptr, "Disconnecting Health Thermometer",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 746
699 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _)) 747 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _))
700 .WillByDefault(RunCallback<1 /* success_callback */>()); 748 .WillByDefault(RunCallback<1 /* success_callback */>());
701 749
702 ON_CALL(*measurement_interval, StartNotifySession(_, _)) 750 ON_CALL(*measurement_interval, StartNotifySession(_, _))
703 .WillByDefault( 751 .WillByDefault(
704 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() { 752 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() {
705 return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr()); 753 return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr());
706 })); 754 }));
707 755
756 AddDescriptorsToCharacteristic(measurement_interval.get());
757
708 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 758 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
709 device->AddMockService(std::move(health_thermometer)); 759 device->AddMockService(std::move(health_thermometer));
710 760
711 adapter->AddMockDevice(std::move(device)); 761 adapter->AddMockDevice(std::move(device));
712 762
713 return adapter; 763 return adapter;
714 } 764 }
715 765
716 // static 766 // static
717 scoped_refptr<NiceMockBluetoothAdapter> 767 scoped_refptr<NiceMockBluetoothAdapter>
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 device_ptr->PushPendingCallback(pending); 1042 device_ptr->PushPendingCallback(pending);
993 if (disconnect) { 1043 if (disconnect) {
994 device_ptr->SetConnected(false); 1044 device_ptr->SetConnected(false);
995 base::ThreadTaskRunnerHandle::Get()->PostTask( 1045 base::ThreadTaskRunnerHandle::Get()->PostTask(
996 FROM_HERE, 1046 FROM_HERE,
997 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), 1047 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
998 device_ptr)); 1048 device_ptr));
999 } 1049 }
1000 })); 1050 }));
1001 1051
1052 AddDescriptorsToCharacteristic(measurement_interval.get());
ortuno 2016/12/02 06:14:50 I don't think this applies here. When you read/wri
dougt 2016/12/02 18:31:28 Done.
1053
1002 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 1054 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
1003 device->AddMockService(std::move(health_thermometer)); 1055 device->AddMockService(std::move(health_thermometer));
1004 adapter->AddMockDevice(std::move(device)); 1056 adapter->AddMockDevice(std::move(device));
1005 return adapter; 1057 return adapter;
1006 } 1058 }
1007 1059
1008 // static 1060 // static
1009 scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider:: 1061 scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider::
1010 GetStopNotifySessionFinishesAfterReconnectionAdapter(bool disconnect) { 1062 GetStopNotifySessionFinishesAfterReconnectionAdapter(bool disconnect) {
1011 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 1063 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 return BluetoothUUID(); 1718 return BluetoothUUID();
1667 } 1719 }
1668 1720
1669 // static 1721 // static
1670 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1722 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1671 return BluetoothDevice::CanonicalizeAddress( 1723 return BluetoothDevice::CanonicalizeAddress(
1672 base::StringPrintf("%012" PRIx64, addr)); 1724 base::StringPrintf("%012" PRIx64, addr));
1673 } 1725 }
1674 1726
1675 } // namespace content 1727 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698