Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 typedef testing::NiceMock<MockBluetoothGattConnection> | 54 typedef testing::NiceMock<MockBluetoothGattConnection> |
| 55 NiceMockBluetoothGattConnection; | 55 NiceMockBluetoothGattConnection; |
| 56 typedef testing::NiceMock<MockBluetoothGattService> | 56 typedef testing::NiceMock<MockBluetoothGattService> |
| 57 NiceMockBluetoothGattService; | 57 NiceMockBluetoothGattService; |
| 58 typedef testing::NiceMock<MockBluetoothGattNotifySession> | 58 typedef testing::NiceMock<MockBluetoothGattNotifySession> |
| 59 NiceMockBluetoothGattNotifySession; | 59 NiceMockBluetoothGattNotifySession; |
| 60 | 60 |
| 61 namespace { | 61 namespace { |
| 62 // Bluetooth UUIDs suitable to pass to BluetoothUUID(). | 62 // Bluetooth UUIDs suitable to pass to BluetoothUUID(). |
| 63 const char kBatteryServiceUUID[] = "180f"; | 63 const char kBatteryServiceUUID[] = "180f"; |
| 64 const char kBodySensorLocation[] = "2a38"; | |
| 65 const char kDeviceInformationServiceUUID[] = "180A"; | |
|
ortuno
2016/02/23 22:37:58
Use lower-case i.e. 180a
scheib
2016/02/24 19:51:29
Done.
| |
| 66 const char kDeviceNameUUID[] = "2a00"; | |
| 64 const char kGenericAccessServiceUUID[] = "1800"; | 67 const char kGenericAccessServiceUUID[] = "1800"; |
| 65 const char kGlucoseServiceUUID[] = "1808"; | 68 const char kGlucoseServiceUUID[] = "1808"; |
| 69 const char kHeartRateMeasurementUUID[] = "2a37"; | |
| 66 const char kHeartRateServiceUUID[] = "180d"; | 70 const char kHeartRateServiceUUID[] = "180d"; |
| 67 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; | 71 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; |
| 72 const char kSerialNumberStringUUID[] = "2A25"; | |
|
ortuno
2016/02/23 22:37:59
Same here use lower-case. 2a25
scheib
2016/02/24 19:51:29
Done.
| |
| 68 const char kTxPowerServiceUUID[] = "1804"; | 73 const char kTxPowerServiceUUID[] = "1804"; |
| 69 const char kHeartRateMeasurementUUID[] = "2a37"; | |
|
ortuno
2016/02/23 22:37:58
Unsure if alphabetical is the right order. I think
scheib
2016/02/24 19:51:29
Splitting the Services and Characteristics SGTM.
| |
| 70 const char kBodySensorLocation[] = "2a38"; | |
| 71 const char kDeviceNameUUID[] = "2a00"; | |
| 72 | 74 |
| 73 const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW. | 75 const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW. |
| 74 const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at | 76 const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at |
| 75 // 0.1mW. | 77 // 0.1mW. |
| 76 | 78 |
| 77 // Invokes Run() on the k-th argument of the function with no arguments. | 79 // Invokes Run() on the k-th argument of the function with no arguments. |
| 78 ACTION_TEMPLATE(RunCallback, | 80 ACTION_TEMPLATE(RunCallback, |
| 79 HAS_1_TEMPLATE_PARAMS(int, k), | 81 HAS_1_TEMPLATE_PARAMS(int, k), |
| 80 AND_0_VALUE_PARAMS()) { | 82 AND_0_VALUE_PARAMS()) { |
| 81 return ::testing::get<k>(args).Run(); | 83 return ::testing::get<k>(args).Run(); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 | 475 |
| 474 // static | 476 // static |
| 475 scoped_refptr<NiceMockBluetoothAdapter> | 477 scoped_refptr<NiceMockBluetoothAdapter> |
| 476 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { | 478 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { |
| 477 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 479 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 478 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 480 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); |
| 479 | 481 |
| 480 // TODO(ortuno): Implement the rest of the service's characteristics | 482 // TODO(ortuno): Implement the rest of the service's characteristics |
| 481 // See: http://crbug.com/529975 | 483 // See: http://crbug.com/529975 |
| 482 | 484 |
| 483 device->AddMockService(GetGenericAccessService(adapter.get(), device.get())); | 485 device->AddMockService(GetGenericAccessService(device.get())); |
| 484 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 486 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
| 485 adapter->AddMockDevice(std::move(device)); | 487 adapter->AddMockDevice(std::move(device)); |
| 486 | 488 |
| 487 return adapter; | 489 return adapter; |
| 488 } | 490 } |
| 489 | 491 |
| 490 // static | 492 // static |
| 491 scoped_refptr<NiceMockBluetoothAdapter> | 493 scoped_refptr<NiceMockBluetoothAdapter> |
| 492 LayoutTestBluetoothAdapterProvider::GetHeartRateAndHIDAdapter() { | 494 LayoutTestBluetoothAdapterProvider::GetHeartRateAndHIDAdapter() { |
| 493 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 495 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 494 | 496 |
| 495 BluetoothDevice::UUIDList uuids; | 497 BluetoothDevice::UUIDList uuids; |
| 496 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); | 498 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); |
| 497 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); | 499 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); |
| 498 | 500 |
| 499 scoped_ptr<NiceMockBluetoothDevice> device( | 501 scoped_ptr<NiceMockBluetoothDevice> device( |
| 500 GetConnectableDevice(adapter.get(), "Heart Rate And HID Device", uuids)); | 502 GetConnectableDevice(adapter.get(), "Heart Rate And HID Device", uuids)); |
| 501 | 503 |
| 502 device->AddMockService(GetGenericAccessService(adapter.get(), device.get())); | 504 device->AddMockService(GetDeviceInformationService(device.get())); |
| 505 device->AddMockService(GetGenericAccessService(device.get())); | |
| 503 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 506 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
| 504 device->AddMockService( | 507 device->AddMockService( |
| 505 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); | 508 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); |
| 506 adapter->AddMockDevice(std::move(device)); | 509 adapter->AddMockDevice(std::move(device)); |
| 507 | 510 |
| 508 return adapter; | 511 return adapter; |
| 509 } | 512 } |
| 510 | 513 |
| 511 // static | 514 // static |
| 512 scoped_refptr<NiceMockBluetoothAdapter> | 515 scoped_refptr<NiceMockBluetoothAdapter> |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 | 698 |
| 696 ON_CALL(*service, GetCharacteristic(_)) | 699 ON_CALL(*service, GetCharacteristic(_)) |
| 697 .WillByDefault(Invoke(service.get(), | 700 .WillByDefault(Invoke(service.get(), |
| 698 &MockBluetoothGattService::GetMockCharacteristic)); | 701 &MockBluetoothGattService::GetMockCharacteristic)); |
| 699 | 702 |
| 700 return service; | 703 return service; |
| 701 } | 704 } |
| 702 | 705 |
| 703 // static | 706 // static |
| 704 scoped_ptr<NiceMockBluetoothGattService> | 707 scoped_ptr<NiceMockBluetoothGattService> |
| 708 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( | |
| 709 device::MockBluetoothDevice* device) { | |
| 710 scoped_ptr<NiceMockBluetoothGattService> device_information( | |
| 711 GetBaseGATTService(device, kDeviceInformationServiceUUID)); | |
| 712 | |
| 713 scoped_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( | |
| 714 GetBaseGATTCharacteristic(device_information.get(), | |
| 715 kSerialNumberStringUUID, | |
| 716 BluetoothGattCharacteristic::PROPERTY_READ)); | |
| 717 | |
| 718 EXPECT_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _)).Times(0); | |
| 719 | |
| 720 device_information->AddMockCharacteristic(std::move(serial_number_string)); | |
| 721 | |
| 722 return device_information; | |
| 723 } | |
| 724 | |
| 725 // static | |
| 726 scoped_ptr<NiceMockBluetoothGattService> | |
| 705 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( | 727 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( |
| 706 MockBluetoothAdapter* adapter, | 728 device::MockBluetoothDevice* device) { |
| 707 MockBluetoothDevice* device) { | |
| 708 scoped_ptr<NiceMockBluetoothGattService> generic_access( | 729 scoped_ptr<NiceMockBluetoothGattService> generic_access( |
| 709 GetBaseGATTService(device, kGenericAccessServiceUUID)); | 730 GetBaseGATTService(device, kGenericAccessServiceUUID)); |
| 710 | 731 |
| 711 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( | 732 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( |
| 712 GetBaseGATTCharacteristic( | 733 GetBaseGATTCharacteristic( |
| 713 generic_access.get(), kDeviceNameUUID, | 734 generic_access.get(), kDeviceNameUUID, |
| 714 BluetoothGattCharacteristic::PROPERTY_READ | | 735 BluetoothGattCharacteristic::PROPERTY_READ | |
| 715 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 736 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
| 716 | 737 |
| 717 // Read response. | 738 // Read response. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 return BluetoothUUID(); | 922 return BluetoothUUID(); |
| 902 } | 923 } |
| 903 | 924 |
| 904 // static | 925 // static |
| 905 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 926 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
| 906 return BluetoothDevice::CanonicalizeAddress( | 927 return BluetoothDevice::CanonicalizeAddress( |
| 907 base::StringPrintf("%012" PRIx64, addr)); | 928 base::StringPrintf("%012" PRIx64, addr)); |
| 908 } | 929 } |
| 909 | 930 |
| 910 } // namespace content | 931 } // namespace content |
| OLD | NEW |