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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 typedef testing::NiceMock<MockBluetoothGattCharacteristic> | 52 typedef testing::NiceMock<MockBluetoothGattCharacteristic> |
53 NiceMockBluetoothGattCharacteristic; | 53 NiceMockBluetoothGattCharacteristic; |
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 // Services: |
63 const char kBatteryServiceUUID[] = "180f"; | 64 const char kBatteryServiceUUID[] = "180f"; |
| 65 const char kDeviceInformationServiceUUID[] = "180a"; |
64 const char kGenericAccessServiceUUID[] = "1800"; | 66 const char kGenericAccessServiceUUID[] = "1800"; |
65 const char kGlucoseServiceUUID[] = "1808"; | 67 const char kGlucoseServiceUUID[] = "1808"; |
66 const char kHeartRateServiceUUID[] = "180d"; | 68 const char kHeartRateServiceUUID[] = "180d"; |
67 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; | 69 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; |
68 const char kTxPowerServiceUUID[] = "1804"; | 70 const char kTxPowerServiceUUID[] = "1804"; |
69 const char kHeartRateMeasurementUUID[] = "2a37"; | 71 // Characteristics: |
70 const char kBodySensorLocation[] = "2a38"; | 72 const char kBodySensorLocation[] = "2a38"; |
71 const char kDeviceNameUUID[] = "2a00"; | 73 const char kDeviceNameUUID[] = "2a00"; |
| 74 const char kHeartRateMeasurementUUID[] = "2a37"; |
| 75 const char kSerialNumberStringUUID[] = "2a25"; |
72 | 76 |
73 const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW. | 77 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 | 78 const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at |
75 // 0.1mW. | 79 // 0.1mW. |
76 | 80 |
77 // Invokes Run() on the k-th argument of the function with no arguments. | 81 // Invokes Run() on the k-th argument of the function with no arguments. |
78 ACTION_TEMPLATE(RunCallback, | 82 ACTION_TEMPLATE(RunCallback, |
79 HAS_1_TEMPLATE_PARAMS(int, k), | 83 HAS_1_TEMPLATE_PARAMS(int, k), |
80 AND_0_VALUE_PARAMS()) { | 84 AND_0_VALUE_PARAMS()) { |
81 return ::testing::get<k>(args).Run(); | 85 return ::testing::get<k>(args).Run(); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 477 |
474 // static | 478 // static |
475 scoped_refptr<NiceMockBluetoothAdapter> | 479 scoped_refptr<NiceMockBluetoothAdapter> |
476 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { | 480 LayoutTestBluetoothAdapterProvider::GetHeartRateAdapter() { |
477 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 481 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
478 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); | 482 scoped_ptr<NiceMockBluetoothDevice> device(GetHeartRateDevice(adapter.get())); |
479 | 483 |
480 // TODO(ortuno): Implement the rest of the service's characteristics | 484 // TODO(ortuno): Implement the rest of the service's characteristics |
481 // See: http://crbug.com/529975 | 485 // See: http://crbug.com/529975 |
482 | 486 |
483 device->AddMockService(GetGenericAccessService(adapter.get(), device.get())); | 487 device->AddMockService(GetGenericAccessService(device.get())); |
484 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 488 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
485 adapter->AddMockDevice(std::move(device)); | 489 adapter->AddMockDevice(std::move(device)); |
486 | 490 |
487 return adapter; | 491 return adapter; |
488 } | 492 } |
489 | 493 |
490 // static | 494 // static |
491 scoped_refptr<NiceMockBluetoothAdapter> | 495 scoped_refptr<NiceMockBluetoothAdapter> |
492 LayoutTestBluetoothAdapterProvider::GetHeartRateAndHIDAdapter() { | 496 LayoutTestBluetoothAdapterProvider::GetHeartRateAndHIDAdapter() { |
493 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 497 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
494 | 498 |
495 BluetoothDevice::UUIDList uuids; | 499 BluetoothDevice::UUIDList uuids; |
| 500 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID)); |
496 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); | 501 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); |
497 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); | 502 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); |
498 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); | 503 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); |
499 | 504 |
500 scoped_ptr<NiceMockBluetoothDevice> device( | 505 scoped_ptr<NiceMockBluetoothDevice> device( |
501 GetConnectableDevice(adapter.get(), "Heart Rate And HID Device", uuids)); | 506 GetConnectableDevice(adapter.get(), "Heart Rate And HID Device", uuids)); |
502 | 507 |
503 device->AddMockService(GetGenericAccessService(adapter.get(), device.get())); | 508 device->AddMockService(GetDeviceInformationService(device.get())); |
| 509 device->AddMockService(GetGenericAccessService(device.get())); |
504 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 510 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
505 device->AddMockService( | 511 device->AddMockService( |
506 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); | 512 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); |
507 adapter->AddMockDevice(std::move(device)); | 513 adapter->AddMockDevice(std::move(device)); |
508 | 514 |
509 return adapter; | 515 return adapter; |
510 } | 516 } |
511 | 517 |
512 // static | 518 // static |
513 scoped_refptr<NiceMockBluetoothAdapter> | 519 scoped_refptr<NiceMockBluetoothAdapter> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 | 619 |
614 return GetBaseDevice(adapter, "Battery Device", uuids, makeMACAddress(0x1)); | 620 return GetBaseDevice(adapter, "Battery Device", uuids, makeMACAddress(0x1)); |
615 } | 621 } |
616 | 622 |
617 // static | 623 // static |
618 scoped_ptr<NiceMockBluetoothDevice> | 624 scoped_ptr<NiceMockBluetoothDevice> |
619 LayoutTestBluetoothAdapterProvider::GetGlucoseDevice( | 625 LayoutTestBluetoothAdapterProvider::GetGlucoseDevice( |
620 MockBluetoothAdapter* adapter) { | 626 MockBluetoothAdapter* adapter) { |
621 BluetoothDevice::UUIDList uuids; | 627 BluetoothDevice::UUIDList uuids; |
622 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); | 628 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); |
| 629 uuids.push_back(BluetoothUUID(kGlucoseServiceUUID)); |
623 uuids.push_back(BluetoothUUID(kTxPowerServiceUUID)); | 630 uuids.push_back(BluetoothUUID(kTxPowerServiceUUID)); |
624 uuids.push_back(BluetoothUUID(kGlucoseServiceUUID)); | |
625 | 631 |
626 return GetBaseDevice(adapter, "Glucose Device", uuids, makeMACAddress(0x2)); | 632 return GetBaseDevice(adapter, "Glucose Device", uuids, makeMACAddress(0x2)); |
627 } | 633 } |
628 | 634 |
629 // static | 635 // static |
630 scoped_ptr<NiceMockBluetoothDevice> | 636 scoped_ptr<NiceMockBluetoothDevice> |
631 LayoutTestBluetoothAdapterProvider::GetConnectableDevice( | 637 LayoutTestBluetoothAdapterProvider::GetConnectableDevice( |
632 device::MockBluetoothAdapter* adapter, | 638 device::MockBluetoothAdapter* adapter, |
633 const std::string& device_name, | 639 const std::string& device_name, |
634 BluetoothDevice::UUIDList uuids, | 640 BluetoothDevice::UUIDList uuids, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 | 704 |
699 ON_CALL(*service, GetCharacteristic(_)) | 705 ON_CALL(*service, GetCharacteristic(_)) |
700 .WillByDefault(Invoke(service.get(), | 706 .WillByDefault(Invoke(service.get(), |
701 &MockBluetoothGattService::GetMockCharacteristic)); | 707 &MockBluetoothGattService::GetMockCharacteristic)); |
702 | 708 |
703 return service; | 709 return service; |
704 } | 710 } |
705 | 711 |
706 // static | 712 // static |
707 scoped_ptr<NiceMockBluetoothGattService> | 713 scoped_ptr<NiceMockBluetoothGattService> |
| 714 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( |
| 715 device::MockBluetoothDevice* device) { |
| 716 scoped_ptr<NiceMockBluetoothGattService> device_information( |
| 717 GetBaseGATTService(device, kDeviceInformationServiceUUID)); |
| 718 |
| 719 scoped_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( |
| 720 GetBaseGATTCharacteristic(device_information.get(), |
| 721 kSerialNumberStringUUID, |
| 722 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 723 |
| 724 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect |
| 725 // because this is used in layout tests that may not report a mock expectation |
| 726 // error correctly as a layout test failure. |
| 727 ON_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _)) |
| 728 .WillByDefault( |
| 729 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, |
| 730 const BluetoothGattCharacteristic::ErrorCallback&) { |
| 731 NOTREACHED(); |
| 732 })); |
| 733 |
| 734 device_information->AddMockCharacteristic(std::move(serial_number_string)); |
| 735 |
| 736 return device_information; |
| 737 } |
| 738 |
| 739 // static |
| 740 scoped_ptr<NiceMockBluetoothGattService> |
708 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( | 741 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( |
709 MockBluetoothAdapter* adapter, | 742 device::MockBluetoothDevice* device) { |
710 MockBluetoothDevice* device) { | |
711 scoped_ptr<NiceMockBluetoothGattService> generic_access( | 743 scoped_ptr<NiceMockBluetoothGattService> generic_access( |
712 GetBaseGATTService(device, kGenericAccessServiceUUID)); | 744 GetBaseGATTService(device, kGenericAccessServiceUUID)); |
713 | 745 |
714 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( | 746 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( |
715 GetBaseGATTCharacteristic( | 747 GetBaseGATTCharacteristic( |
716 generic_access.get(), kDeviceNameUUID, | 748 generic_access.get(), kDeviceNameUUID, |
717 BluetoothGattCharacteristic::PROPERTY_READ | | 749 BluetoothGattCharacteristic::PROPERTY_READ | |
718 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 750 BluetoothGattCharacteristic::PROPERTY_WRITE)); |
719 | 751 |
720 // Read response. | 752 // Read response. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 return BluetoothUUID(); | 936 return BluetoothUUID(); |
905 } | 937 } |
906 | 938 |
907 // static | 939 // static |
908 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 940 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
909 return BluetoothDevice::CanonicalizeAddress( | 941 return BluetoothDevice::CanonicalizeAddress( |
910 base::StringPrintf("%012" PRIx64, addr)); | 942 base::StringPrintf("%012" PRIx64, addr)); |
911 } | 943 } |
912 | 944 |
913 } // namespace content | 945 } // namespace content |
OLD | NEW |