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

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

Issue 2438963002: bluetooth: Add tests for when frame reconnects during readValue (Closed)
Patch Set: Clean up Created 4 years, 2 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 observer.GattServicesDiscovered(adapter, device); 140 observer.GattServicesDiscovered(adapter, device);
141 } 141 }
142 142
143 // Notifies the adapter's observers that a device has changed. 143 // Notifies the adapter's observers that a device has changed.
144 void NotifyDeviceChanged(MockBluetoothAdapter* adapter, 144 void NotifyDeviceChanged(MockBluetoothAdapter* adapter,
145 MockBluetoothDevice* device) { 145 MockBluetoothDevice* device) {
146 for (auto& observer : adapter->GetObservers()) 146 for (auto& observer : adapter->GetObservers())
147 observer.DeviceChanged(adapter, device); 147 observer.DeviceChanged(adapter, device);
148 } 148 }
149 149
150 void PerformReadValue(
151 MockBluetoothAdapter* adapter,
152 MockBluetoothGattCharacteristic* characteristic,
153 const BluetoothRemoteGattCharacteristic::ValueCallback& callback,
154 const std::vector<uint8_t>& value) {
155 for (auto& observer : adapter->GetObservers()) {
156 observer.GattCharacteristicValueChanged(adapter, characteristic, value);
157 }
158 callback.Run(value);
159 }
160
150 } // namespace 161 } // namespace
151 162
152 namespace content { 163 namespace content {
153 164
154 // static 165 // static
155 scoped_refptr<BluetoothAdapter> 166 scoped_refptr<BluetoothAdapter>
156 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( 167 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter(
157 const std::string& fake_adapter_name) { 168 const std::string& fake_adapter_name) {
158 if (fake_adapter_name == "BaseAdapter") 169 if (fake_adapter_name == "BaseAdapter")
159 return GetBaseAdapter(); 170 return GetBaseAdapter();
(...skipping 25 matching lines...) Expand all
185 return GetTwoHeartRateServicesAdapter(); 196 return GetTwoHeartRateServicesAdapter();
186 if (fake_adapter_name == "DisconnectingHeartRateAdapter") 197 if (fake_adapter_name == "DisconnectingHeartRateAdapter")
187 return GetDisconnectingHeartRateAdapter(); 198 return GetDisconnectingHeartRateAdapter();
188 if (fake_adapter_name == "DisconnectingHealthThermometerAdapter") 199 if (fake_adapter_name == "DisconnectingHealthThermometerAdapter")
189 return GetDisconnectingHealthThermometer(); 200 return GetDisconnectingHealthThermometer();
190 if (fake_adapter_name == "DisconnectingDuringServiceRetrievalAdapter") 201 if (fake_adapter_name == "DisconnectingDuringServiceRetrievalAdapter")
191 return GetServicesDiscoveredAfterReconnectionAdapter(true /* disconnect */); 202 return GetServicesDiscoveredAfterReconnectionAdapter(true /* disconnect */);
192 if (fake_adapter_name == "ServicesDiscoveredAfterReconnectionAdapter") 203 if (fake_adapter_name == "ServicesDiscoveredAfterReconnectionAdapter")
193 return GetServicesDiscoveredAfterReconnectionAdapter( 204 return GetServicesDiscoveredAfterReconnectionAdapter(
194 false /* disconnect */); 205 false /* disconnect */);
206 if (fake_adapter_name == "DisconnectingDuringSuccessGATTOperationAdapter") {
207 return GetGATTOperationFinishesAfterReconnectionAdapter(
208 true /* disconnect */, true /* succeeds */);
209 }
210 if (fake_adapter_name == "DisconnectingDuringFailureGATTOperationAdapter") {
211 return GetGATTOperationFinishesAfterReconnectionAdapter(
212 true /* disconnect */, false /* succeeds */);
213 }
214 if (fake_adapter_name == "GATTOperationSucceedsAfterReconnectionAdapter") {
215 return GetGATTOperationFinishesAfterReconnectionAdapter(
216 false /* disconnect */, true /* succeeds */);
217 }
218 if (fake_adapter_name == "GATTOperationFailsAfterReconnectionAdapter") {
219 return GetGATTOperationFinishesAfterReconnectionAdapter(
220 false /* disconnect */, false /* succeeds */);
221 }
195 if (fake_adapter_name == "BlacklistTestAdapter") 222 if (fake_adapter_name == "BlacklistTestAdapter")
196 return GetBlacklistTestAdapter(); 223 return GetBlacklistTestAdapter();
197 if (fake_adapter_name == "FailingConnectionsAdapter") 224 if (fake_adapter_name == "FailingConnectionsAdapter")
198 return GetFailingConnectionsAdapter(); 225 return GetFailingConnectionsAdapter();
199 if (fake_adapter_name == "FailingGATTOperationsAdapter") 226 if (fake_adapter_name == "FailingGATTOperationsAdapter")
200 return GetFailingGATTOperationsAdapter(); 227 return GetFailingGATTOperationsAdapter();
201 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") 228 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter")
202 return GetSecondDiscoveryFindsHeartRateAdapter(); 229 return GetSecondDiscoveryFindsHeartRateAdapter();
203 if (fake_adapter_name == "DeviceEventAdapter") 230 if (fake_adapter_name == "DeviceEventAdapter")
204 return GetDeviceEventAdapter(); 231 return GetDeviceEventAdapter();
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 863 }
837 864
838 return true; 865 return true;
839 })); 866 }));
840 adapter->AddMockDevice(std::move(device)); 867 adapter->AddMockDevice(std::move(device));
841 868
842 return adapter; 869 return adapter;
843 } 870 }
844 871
845 // static 872 // static
873 scoped_refptr<NiceMockBluetoothAdapter> LayoutTestBluetoothAdapterProvider::
874 GetGATTOperationFinishesAfterReconnectionAdapter(bool disconnect,
875 bool succeeds) {
876 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
877 NiceMockBluetoothAdapter* adapter_ptr = adapter.get();
878
879 std::unique_ptr<NiceMockBluetoothDevice> device(GetConnectableDevice(
880 adapter_ptr, "GATT Operation finishes after reconnection Device",
881 BluetoothDevice::UUIDList({BluetoothUUID(kGenericAccessServiceUUID),
882 BluetoothUUID(kHealthThermometerUUID)})));
883 NiceMockBluetoothDevice* device_ptr = device.get();
884
885 ON_CALL(*device, CreateGattConnection(_, _))
886 .WillByDefault(Invoke([adapter_ptr, device_ptr](
887 const BluetoothDevice::GattConnectionCallback& callback,
888 const BluetoothDevice::ConnectErrorCallback& error_callback) {
889 callback.Run(base::MakeUnique<NiceMockBluetoothGattConnection>(
890 adapter_ptr, device_ptr->GetAddress()));
891 while (device_ptr->HasPendingCallback()) {
892 device_ptr->PopPendingCallback().Run();
893 }
894 }));
895
896 device->AddMockService(GetGenericAccessService(device.get()));
897
898 std::unique_ptr<NiceMockBluetoothGattService> health_thermometer(
899 GetBaseGATTService("Health Thermometer", device.get(),
900 kHealthThermometerUUID));
901
902 // Measurement Interval
903 std::unique_ptr<NiceMockBluetoothGattCharacteristic> measurement_interval(
904 GetBaseGATTCharacteristic(
905 "Measurement Interval", health_thermometer.get(),
906 kMeasurementIntervalUUID,
907 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
908 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE |
Jeffrey Yasskin 2016/10/22 01:02:06 Since the characteristic only actually handles rea
ortuno 2016/10/24 01:52:33 Done.
909 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY));
910 NiceMockBluetoothGattCharacteristic* measurement_ptr =
911 measurement_interval.get();
912
913 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _))
914 .WillByDefault(Invoke([adapter_ptr, device_ptr, measurement_ptr,
915 disconnect, succeeds](
916 const BluetoothRemoteGattCharacteristic::ValueCallback& callback,
917 const BluetoothRemoteGattCharacteristic::ErrorCallback&
918 error_callback) {
919 base::Closure pending;
920 if (succeeds) {
921 pending =
922 base::Bind(&PerformReadValue, base::RetainedRef(adapter_ptr),
923 measurement_ptr, callback, std::vector<uint8_t>({1}));
924 } else {
925 pending = base::Bind(error_callback,
926 BluetoothRemoteGattService::GATT_ERROR_FAILED);
927 }
928 device_ptr->PushPendingCallback(pending);
929 if (disconnect) {
930 device_ptr->SetConnected(false);
931 base::ThreadTaskRunnerHandle::Get()->PostTask(
932 FROM_HERE,
933 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
934 device_ptr));
935 }
936 }));
937
938 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
939 device->AddMockService(std::move(health_thermometer));
940 adapter->AddMockDevice(std::move(device));
941
942 return adapter;
943 }
944
945 // static
846 scoped_refptr<NiceMockBluetoothAdapter> 946 scoped_refptr<NiceMockBluetoothAdapter>
847 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { 947 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() {
848 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); 948 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter());
849 949
850 BluetoothDevice::UUIDList uuids; 950 BluetoothDevice::UUIDList uuids;
851 uuids.push_back(BluetoothUUID(kBlacklistTestServiceUUID)); 951 uuids.push_back(BluetoothUUID(kBlacklistTestServiceUUID));
852 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID)); 952 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID));
853 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); 953 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID));
854 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); 954 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID));
855 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); 955 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID));
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 return BluetoothUUID(); 1536 return BluetoothUUID();
1437 } 1537 }
1438 1538
1439 // static 1539 // static
1440 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1540 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1441 return BluetoothDevice::CanonicalizeAddress( 1541 return BluetoothDevice::CanonicalizeAddress(
1442 base::StringPrintf("%012" PRIx64, addr)); 1542 base::StringPrintf("%012" PRIx64, addr));
1443 } 1543 }
1444 1544
1445 } // namespace content 1545 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698