OLD | NEW |
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 std::set<BluetoothUUID> GetUUIDs( | 119 std::set<BluetoothUUID> GetUUIDs( |
120 const device::BluetoothDiscoveryFilter* filter) { | 120 const device::BluetoothDiscoveryFilter* filter) { |
121 std::set<BluetoothUUID> result; | 121 std::set<BluetoothUUID> result; |
122 filter->GetUUIDs(result); | 122 filter->GetUUIDs(result); |
123 return result; | 123 return result; |
124 } | 124 } |
125 | 125 |
126 // Notifies the adapter's observers for each device id the adapter. | 126 // Notifies the adapter's observers for each device id the adapter. |
127 void NotifyDevicesAdded(MockBluetoothAdapter* adapter) { | 127 void NotifyDevicesAdded(MockBluetoothAdapter* adapter) { |
128 for (BluetoothDevice* device : adapter->GetMockDevices()) { | 128 for (BluetoothDevice* device : adapter->GetMockDevices()) { |
129 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), | 129 for (auto& observer : adapter->GetObservers()) |
130 DeviceAdded(adapter, device)); | 130 observer.DeviceAdded(adapter, device); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 // Notifies the adapter's observers that the services have been discovered. | 134 // Notifies the adapter's observers that the services have been discovered. |
135 void NotifyServicesDiscovered(MockBluetoothAdapter* adapter, | 135 void NotifyServicesDiscovered(MockBluetoothAdapter* adapter, |
136 MockBluetoothDevice* device) { | 136 MockBluetoothDevice* device) { |
137 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), | 137 for (auto& observer : adapter->GetObservers()) |
138 GattServicesDiscovered(adapter, device)); | 138 observer.GattServicesDiscovered(adapter, device); |
139 } | 139 } |
140 | 140 |
141 // Notifies the adapter's observers that a device has changed. | 141 // Notifies the adapter's observers that a device has changed. |
142 void NotifyDeviceChanged(MockBluetoothAdapter* adapter, | 142 void NotifyDeviceChanged(MockBluetoothAdapter* adapter, |
143 MockBluetoothDevice* device) { | 143 MockBluetoothDevice* device) { |
144 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), | 144 for (auto& observer : adapter->GetObservers()) |
145 DeviceChanged(adapter, device)); | 145 observer.DeviceChanged(adapter, device); |
146 } | 146 } |
147 | 147 |
148 } // namespace | 148 } // namespace |
149 | 149 |
150 namespace content { | 150 namespace content { |
151 | 151 |
152 // static | 152 // static |
153 scoped_refptr<BluetoothAdapter> | 153 scoped_refptr<BluetoothAdapter> |
154 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( | 154 LayoutTestBluetoothAdapterProvider::GetBluetoothAdapter( |
155 const std::string& fake_adapter_name) { | 155 const std::string& fake_adapter_name) { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 356 |
357 return adapter; | 357 return adapter; |
358 } | 358 } |
359 | 359 |
360 // Adds a device to |adapter| and notifies all observers about that new device. | 360 // Adds a device to |adapter| and notifies all observers about that new device. |
361 // Mocks can call this asynchronously to cause changes in the middle of a test. | 361 // Mocks can call this asynchronously to cause changes in the middle of a test. |
362 static void AddDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, | 362 static void AddDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, |
363 std::unique_ptr<NiceMockBluetoothDevice> new_device) { | 363 std::unique_ptr<NiceMockBluetoothDevice> new_device) { |
364 NiceMockBluetoothDevice* new_device_ptr = new_device.get(); | 364 NiceMockBluetoothDevice* new_device_ptr = new_device.get(); |
365 adapter->AddMockDevice(std::move(new_device)); | 365 adapter->AddMockDevice(std::move(new_device)); |
366 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), | 366 for (auto& observer : adapter->GetObservers()) |
367 DeviceAdded(adapter.get(), new_device_ptr)); | 367 observer.DeviceAdded(adapter.get(), new_device_ptr); |
368 } | 368 } |
369 | 369 |
370 static void RemoveDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, | 370 static void RemoveDevice(scoped_refptr<NiceMockBluetoothAdapter> adapter, |
371 const std::string& device_address) { | 371 const std::string& device_address) { |
372 std::unique_ptr<MockBluetoothDevice> removed_device = | 372 std::unique_ptr<MockBluetoothDevice> removed_device = |
373 adapter->RemoveMockDevice(device_address); | 373 adapter->RemoveMockDevice(device_address); |
374 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter->GetObservers(), | 374 for (auto& observer : adapter->GetObservers()) |
375 DeviceRemoved(adapter.get(), removed_device.get())); | 375 observer.DeviceRemoved(adapter.get(), removed_device.get()); |
376 } | 376 } |
377 // static | 377 // static |
378 scoped_refptr<NiceMockBluetoothAdapter> | 378 scoped_refptr<NiceMockBluetoothAdapter> |
379 LayoutTestBluetoothAdapterProvider::GetSecondDiscoveryFindsHeartRateAdapter() { | 379 LayoutTestBluetoothAdapterProvider::GetSecondDiscoveryFindsHeartRateAdapter() { |
380 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); | 380 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetPoweredAdapter()); |
381 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); | 381 NiceMockBluetoothAdapter* adapter_ptr = adapter.get(); |
382 | 382 |
383 EXPECT_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) | 383 EXPECT_CALL(*adapter, StartDiscoverySessionWithFilterRaw(_, _, _)) |
384 .WillOnce(RunCallbackWithResult<1 /* success_callback */>( | 384 .WillOnce(RunCallbackWithResult<1 /* success_callback */>( |
385 []() { return GetDiscoverySession(); })) | 385 []() { return GetDiscoverySession(); })) |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 729 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
730 disconnection_characteristic(GetBaseGATTCharacteristic( | 730 disconnection_characteristic(GetBaseGATTCharacteristic( |
731 "Disconnection Characteristic", disconnection_service.get(), | 731 "Disconnection Characteristic", disconnection_service.get(), |
732 kRequestDisconnectionCharacteristicUUID, | 732 kRequestDisconnectionCharacteristicUUID, |
733 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE)); | 733 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE)); |
734 ON_CALL(*disconnection_characteristic, WriteRemoteCharacteristic(_, _, _)) | 734 ON_CALL(*disconnection_characteristic, WriteRemoteCharacteristic(_, _, _)) |
735 .WillByDefault(Invoke([adapter_ptr, device_ptr]( | 735 .WillByDefault(Invoke([adapter_ptr, device_ptr]( |
736 const std::vector<uint8_t>& value, const base::Closure& success, | 736 const std::vector<uint8_t>& value, const base::Closure& success, |
737 const BluetoothRemoteGattCharacteristic::ErrorCallback& error) { | 737 const BluetoothRemoteGattCharacteristic::ErrorCallback& error) { |
738 device_ptr->SetConnected(false); | 738 device_ptr->SetConnected(false); |
739 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 739 for (auto& observer : adapter_ptr->GetObservers()) |
740 adapter_ptr->GetObservers(), | 740 observer.DeviceChanged(adapter_ptr, device_ptr); |
741 DeviceChanged(adapter_ptr, device_ptr)); | |
742 success.Run(); | 741 success.Run(); |
743 })); | 742 })); |
744 | 743 |
745 disconnection_service->AddMockCharacteristic( | 744 disconnection_service->AddMockCharacteristic( |
746 std::move(disconnection_characteristic)); | 745 std::move(disconnection_characteristic)); |
747 device->AddMockService(std::move(disconnection_service)); | 746 device->AddMockService(std::move(disconnection_service)); |
748 adapter->AddMockDevice(std::move(device)); | 747 adapter->AddMockDevice(std::move(device)); |
749 | 748 |
750 return adapter; | 749 return adapter; |
751 } | 750 } |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 BluetoothRemoteGattCharacteristic* location_chest_ptr = | 1201 BluetoothRemoteGattCharacteristic* location_chest_ptr = |
1203 body_sensor_location_chest.get(); | 1202 body_sensor_location_chest.get(); |
1204 | 1203 |
1205 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _)) | 1204 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _)) |
1206 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 1205 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
1207 [adapter, location_chest_ptr]() { | 1206 [adapter, location_chest_ptr]() { |
1208 std::vector<uint8_t> location(1 /* size */); | 1207 std::vector<uint8_t> location(1 /* size */); |
1209 location[0] = 1; // Chest | 1208 location[0] = 1; // Chest |
1210 // Read a characteristic has a side effect of | 1209 // Read a characteristic has a side effect of |
1211 // GattCharacteristicValueChanged being called. | 1210 // GattCharacteristicValueChanged being called. |
1212 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 1211 for (auto& observer : adapter->GetObservers()) { |
1213 adapter->GetObservers(), | 1212 observer.GattCharacteristicValueChanged( |
1214 GattCharacteristicValueChanged( | 1213 adapter, location_chest_ptr, location); |
1215 adapter, location_chest_ptr, location)); | 1214 } |
1216 return location; | 1215 return location; |
1217 })); | 1216 })); |
1218 | 1217 |
1219 // Body Sensor Location Characteristic (Wrist) | 1218 // Body Sensor Location Characteristic (Wrist) |
1220 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 1219 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
1221 body_sensor_location_wrist(GetBaseGATTCharacteristic( | 1220 body_sensor_location_wrist(GetBaseGATTCharacteristic( |
1222 "Body Sensor Location Wrist", heart_rate.get(), kBodySensorLocation, | 1221 "Body Sensor Location Wrist", heart_rate.get(), kBodySensorLocation, |
1223 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); | 1222 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
1224 BluetoothRemoteGattCharacteristic* location_wrist_ptr = | 1223 BluetoothRemoteGattCharacteristic* location_wrist_ptr = |
1225 body_sensor_location_wrist.get(); | 1224 body_sensor_location_wrist.get(); |
1226 | 1225 |
1227 ON_CALL(*body_sensor_location_wrist, ReadRemoteCharacteristic(_, _)) | 1226 ON_CALL(*body_sensor_location_wrist, ReadRemoteCharacteristic(_, _)) |
1228 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 1227 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
1229 [adapter, location_wrist_ptr]() { | 1228 [adapter, location_wrist_ptr]() { |
1230 std::vector<uint8_t> location(1 /* size */); | 1229 std::vector<uint8_t> location(1 /* size */); |
1231 location[0] = 2; // Wrist | 1230 location[0] = 2; // Wrist |
1232 // Read a characteristic has a side effect of | 1231 // Read a characteristic has a side effect of |
1233 // GattCharacteristicValueChanged being called. | 1232 // GattCharacteristicValueChanged being called. |
1234 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 1233 for (auto& observer : adapter->GetObservers()) { |
1235 adapter->GetObservers(), | 1234 observer.GattCharacteristicValueChanged( |
1236 GattCharacteristicValueChanged( | 1235 adapter, location_wrist_ptr, location); |
1237 adapter, location_wrist_ptr, location)); | 1236 } |
1238 return location; | 1237 return location; |
1239 })); | 1238 })); |
1240 | 1239 |
1241 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement)); | 1240 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement)); |
1242 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest)); | 1241 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest)); |
1243 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist)); | 1242 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist)); |
1244 | 1243 |
1245 return heart_rate; | 1244 return heart_rate; |
1246 } | 1245 } |
1247 | 1246 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 return BluetoothUUID(); | 1377 return BluetoothUUID(); |
1379 } | 1378 } |
1380 | 1379 |
1381 // static | 1380 // static |
1382 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1381 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
1383 return BluetoothDevice::CanonicalizeAddress( | 1382 return BluetoothDevice::CanonicalizeAddress( |
1384 base::StringPrintf("%012" PRIx64, addr)); | 1383 base::StringPrintf("%012" PRIx64, addr)); |
1385 } | 1384 } |
1386 | 1385 |
1387 } // namespace content | 1386 } // namespace content |
OLD | NEW |