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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Services: |
| 64 const char kBatteryServiceUUID[] = "180f"; | 64 const char kBatteryServiceUUID[] = "180f"; |
| 65 const char kBlacklistTestServiceUUID[] = "611c954a-263b-4f4a-aab6-01ddb953f985"; | |
| 65 const char kDeviceInformationServiceUUID[] = "180a"; | 66 const char kDeviceInformationServiceUUID[] = "180a"; |
| 66 const char kGenericAccessServiceUUID[] = "1800"; | 67 const char kGenericAccessServiceUUID[] = "1800"; |
| 67 const char kGlucoseServiceUUID[] = "1808"; | 68 const char kGlucoseServiceUUID[] = "1808"; |
| 68 const char kHeartRateServiceUUID[] = "180d"; | 69 const char kHeartRateServiceUUID[] = "180d"; |
| 69 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; | 70 const char kHumanInterfaceDeviceServiceUUID[] = "1812"; |
| 70 const char kTxPowerServiceUUID[] = "1804"; | 71 const char kTxPowerServiceUUID[] = "1804"; |
| 71 // Characteristics: | 72 // Characteristics: |
| 73 const char kBlacklistExcludeReadsCharacteristicUUID[] = | |
| 74 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135"; | |
| 72 const char kBodySensorLocation[] = "2a38"; | 75 const char kBodySensorLocation[] = "2a38"; |
| 73 const char kDeviceNameUUID[] = "2a00"; | 76 const char kDeviceNameUUID[] = "2a00"; |
| 74 const char kHeartRateMeasurementUUID[] = "2a37"; | 77 const char kHeartRateMeasurementUUID[] = "2a37"; |
| 75 const char kSerialNumberStringUUID[] = "2a25"; | 78 const char kSerialNumberStringUUID[] = "2a25"; |
| 79 const char kPeripheralPrivacyFlagUUID[] = "2A02"; | |
|
ortuno
2016/02/26 00:07:11
lower case: 2a02
scheib
2016/02/26 00:49:49
Done.
| |
| 76 | 80 |
| 77 const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW. | 81 const int kDefaultTxPower = -10; // TxPower of a device broadcasting at 0.1mW. |
| 78 const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at | 82 const int kDefaultRssi = -51; // RSSI at 1m from a device broadcasting at |
| 79 // 0.1mW. | 83 // 0.1mW. |
| 80 | 84 |
| 81 // Invokes Run() on the k-th argument of the function with no arguments. | 85 // Invokes Run() on the k-th argument of the function with no arguments. |
| 82 ACTION_TEMPLATE(RunCallback, | 86 ACTION_TEMPLATE(RunCallback, |
| 83 HAS_1_TEMPLATE_PARAMS(int, k), | 87 HAS_1_TEMPLATE_PARAMS(int, k), |
| 84 AND_0_VALUE_PARAMS()) { | 88 AND_0_VALUE_PARAMS()) { |
| 85 return ::testing::get<k>(args).Run(); | 89 return ::testing::get<k>(args).Run(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 if (fake_adapter_name == "GlucoseHeartRateAdapter") | 153 if (fake_adapter_name == "GlucoseHeartRateAdapter") |
| 150 return GetGlucoseHeartRateAdapter(); | 154 return GetGlucoseHeartRateAdapter(); |
| 151 if (fake_adapter_name == "UnicodeDeviceAdapter") | 155 if (fake_adapter_name == "UnicodeDeviceAdapter") |
| 152 return GetUnicodeDeviceAdapter(); | 156 return GetUnicodeDeviceAdapter(); |
| 153 if (fake_adapter_name == "MissingServiceHeartRateAdapter") | 157 if (fake_adapter_name == "MissingServiceHeartRateAdapter") |
| 154 return GetMissingServiceHeartRateAdapter(); | 158 return GetMissingServiceHeartRateAdapter(); |
| 155 if (fake_adapter_name == "MissingCharacteristicHeartRateAdapter") | 159 if (fake_adapter_name == "MissingCharacteristicHeartRateAdapter") |
| 156 return GetMissingCharacteristicHeartRateAdapter(); | 160 return GetMissingCharacteristicHeartRateAdapter(); |
| 157 if (fake_adapter_name == "HeartRateAdapter") | 161 if (fake_adapter_name == "HeartRateAdapter") |
| 158 return GetHeartRateAdapter(); | 162 return GetHeartRateAdapter(); |
| 159 if (fake_adapter_name == "HeartRateAndHIDAdapter") | 163 if (fake_adapter_name == "BlacklistTestAdapter") |
| 160 return GetHeartRateAndHIDAdapter(); | 164 return GetBlacklistTestAdapter(); |
| 161 if (fake_adapter_name == "FailingConnectionsAdapter") | 165 if (fake_adapter_name == "FailingConnectionsAdapter") |
| 162 return GetFailingConnectionsAdapter(); | 166 return GetFailingConnectionsAdapter(); |
| 163 if (fake_adapter_name == "FailingGATTOperationsAdapter") | 167 if (fake_adapter_name == "FailingGATTOperationsAdapter") |
| 164 return GetFailingGATTOperationsAdapter(); | 168 return GetFailingGATTOperationsAdapter(); |
| 165 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") | 169 if (fake_adapter_name == "SecondDiscoveryFindsHeartRateAdapter") |
| 166 return GetSecondDiscoveryFindsHeartRateAdapter(); | 170 return GetSecondDiscoveryFindsHeartRateAdapter(); |
| 167 if (fake_adapter_name == "DelayedServicesDiscoveryAdapter") | 171 if (fake_adapter_name == "DelayedServicesDiscoveryAdapter") |
| 168 return GetDelayedServicesDiscoveryAdapter(); | 172 return GetDelayedServicesDiscoveryAdapter(); |
| 169 if (fake_adapter_name.empty()) | 173 if (fake_adapter_name.empty()) |
| 170 return nullptr; | 174 return nullptr; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 | 490 |
| 487 device->AddMockService(GetGenericAccessService(device.get())); | 491 device->AddMockService(GetGenericAccessService(device.get())); |
| 488 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 492 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
| 489 adapter->AddMockDevice(std::move(device)); | 493 adapter->AddMockDevice(std::move(device)); |
| 490 | 494 |
| 491 return adapter; | 495 return adapter; |
| 492 } | 496 } |
| 493 | 497 |
| 494 // static | 498 // static |
| 495 scoped_refptr<NiceMockBluetoothAdapter> | 499 scoped_refptr<NiceMockBluetoothAdapter> |
| 496 LayoutTestBluetoothAdapterProvider::GetHeartRateAndHIDAdapter() { | 500 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { |
| 497 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); | 501 scoped_refptr<NiceMockBluetoothAdapter> adapter(GetEmptyAdapter()); |
| 498 | 502 |
| 499 BluetoothDevice::UUIDList uuids; | 503 BluetoothDevice::UUIDList uuids; |
| 504 uuids.push_back(BluetoothUUID(kBlacklistTestServiceUUID)); | |
| 500 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID)); | 505 uuids.push_back(BluetoothUUID(kDeviceInformationServiceUUID)); |
| 501 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); | 506 uuids.push_back(BluetoothUUID(kGenericAccessServiceUUID)); |
| 502 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); | 507 uuids.push_back(BluetoothUUID(kHeartRateServiceUUID)); |
| 503 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); | 508 uuids.push_back(BluetoothUUID(kHumanInterfaceDeviceServiceUUID)); |
| 504 | 509 |
| 505 scoped_ptr<NiceMockBluetoothDevice> device( | 510 scoped_ptr<NiceMockBluetoothDevice> device( |
| 506 GetConnectableDevice(adapter.get(), "Heart Rate And HID Device", uuids)); | 511 GetConnectableDevice(adapter.get(), "Blacklist Test Device", uuids)); |
| 507 | 512 |
| 513 device->AddMockService(GetBlacklistTestService(device.get())); | |
| 508 device->AddMockService(GetDeviceInformationService(device.get())); | 514 device->AddMockService(GetDeviceInformationService(device.get())); |
| 509 device->AddMockService(GetGenericAccessService(device.get())); | 515 device->AddMockService(GetGenericAccessService(device.get())); |
| 510 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); | 516 device->AddMockService(GetHeartRateService(adapter.get(), device.get())); |
| 511 device->AddMockService( | 517 device->AddMockService( |
| 512 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); | 518 GetBaseGATTService(device.get(), kHumanInterfaceDeviceServiceUUID)); |
| 513 adapter->AddMockDevice(std::move(device)); | 519 adapter->AddMockDevice(std::move(device)); |
| 514 | 520 |
| 515 return adapter; | 521 return adapter; |
| 516 } | 522 } |
| 517 | 523 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 | 710 |
| 705 ON_CALL(*service, GetCharacteristic(_)) | 711 ON_CALL(*service, GetCharacteristic(_)) |
| 706 .WillByDefault(Invoke(service.get(), | 712 .WillByDefault(Invoke(service.get(), |
| 707 &MockBluetoothGattService::GetMockCharacteristic)); | 713 &MockBluetoothGattService::GetMockCharacteristic)); |
| 708 | 714 |
| 709 return service; | 715 return service; |
| 710 } | 716 } |
| 711 | 717 |
| 712 // static | 718 // static |
| 713 scoped_ptr<NiceMockBluetoothGattService> | 719 scoped_ptr<NiceMockBluetoothGattService> |
| 720 LayoutTestBluetoothAdapterProvider::GetBlacklistTestService( | |
| 721 device::MockBluetoothDevice* device) { | |
| 722 scoped_ptr<NiceMockBluetoothGattService> blacklist_test_service( | |
| 723 GetBaseGATTService(device, kBlacklistTestServiceUUID)); | |
| 724 | |
| 725 scoped_ptr<NiceMockBluetoothGattCharacteristic> | |
| 726 blacklist_exclude_reads_characteristic(GetBaseGATTCharacteristic( | |
| 727 blacklist_test_service.get(), | |
| 728 kBlacklistExcludeReadsCharacteristicUUID, | |
| 729 BluetoothGattCharacteristic::PROPERTY_READ | | |
| 730 BluetoothGattCharacteristic::PROPERTY_WRITE)); | |
| 731 | |
| 732 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect | |
| 733 // because this is used in layout tests that may not report a mock expectation | |
| 734 // error correctly as a layout test failure. | |
| 735 ON_CALL(*blacklist_exclude_reads_characteristic, | |
| 736 ReadRemoteCharacteristic(_, _)) | |
| 737 .WillByDefault( | |
| 738 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, | |
| 739 const BluetoothGattCharacteristic::ErrorCallback&) { | |
| 740 NOTREACHED(); | |
| 741 })); | |
| 742 | |
| 743 // Write response. | |
| 744 ON_CALL(*blacklist_exclude_reads_characteristic, | |
| 745 WriteRemoteCharacteristic(_, _, _)) | |
| 746 .WillByDefault(RunCallback<1 /* success callback */>()); | |
| 747 | |
| 748 blacklist_test_service->AddMockCharacteristic( | |
| 749 std::move(blacklist_exclude_reads_characteristic)); | |
| 750 | |
| 751 return blacklist_test_service; | |
| 752 } | |
| 753 | |
| 754 // static | |
| 755 scoped_ptr<NiceMockBluetoothGattService> | |
| 714 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( | 756 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( |
| 715 device::MockBluetoothDevice* device) { | 757 device::MockBluetoothDevice* device) { |
| 716 scoped_ptr<NiceMockBluetoothGattService> device_information( | 758 scoped_ptr<NiceMockBluetoothGattService> device_information( |
| 717 GetBaseGATTService(device, kDeviceInformationServiceUUID)); | 759 GetBaseGATTService(device, kDeviceInformationServiceUUID)); |
| 718 | 760 |
| 719 scoped_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( | 761 scoped_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( |
| 720 GetBaseGATTCharacteristic(device_information.get(), | 762 GetBaseGATTCharacteristic(device_information.get(), |
| 721 kSerialNumberStringUUID, | 763 kSerialNumberStringUUID, |
| 722 BluetoothGattCharacteristic::PROPERTY_READ)); | 764 BluetoothGattCharacteristic::PROPERTY_READ)); |
| 723 | 765 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 736 return device_information; | 778 return device_information; |
| 737 } | 779 } |
| 738 | 780 |
| 739 // static | 781 // static |
| 740 scoped_ptr<NiceMockBluetoothGattService> | 782 scoped_ptr<NiceMockBluetoothGattService> |
| 741 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( | 783 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( |
| 742 device::MockBluetoothDevice* device) { | 784 device::MockBluetoothDevice* device) { |
| 743 scoped_ptr<NiceMockBluetoothGattService> generic_access( | 785 scoped_ptr<NiceMockBluetoothGattService> generic_access( |
| 744 GetBaseGATTService(device, kGenericAccessServiceUUID)); | 786 GetBaseGATTService(device, kGenericAccessServiceUUID)); |
| 745 | 787 |
| 746 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( | 788 { // Device Name: |
|
ortuno
2016/02/26 00:07:11
Why add the scope here? None of the other function
scheib
2016/02/26 00:49:49
Mainly to visually group the related code blocks.
| |
| 747 GetBaseGATTCharacteristic( | 789 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( |
| 748 generic_access.get(), kDeviceNameUUID, | 790 GetBaseGATTCharacteristic( |
| 749 BluetoothGattCharacteristic::PROPERTY_READ | | 791 generic_access.get(), kDeviceNameUUID, |
| 750 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 792 BluetoothGattCharacteristic::PROPERTY_READ | |
| 793 BluetoothGattCharacteristic::PROPERTY_WRITE)); | |
| 751 | 794 |
| 752 // Read response. | 795 // Read response. |
| 753 std::string device_name_str = device->GetDeviceName(); | 796 std::string device_name_str = device->GetDeviceName(); |
| 754 std::vector<uint8_t> device_name_value(device_name_str.begin(), | 797 std::vector<uint8_t> device_name_value(device_name_str.begin(), |
| 755 device_name_str.end()); | 798 device_name_str.end()); |
| 756 | 799 |
| 757 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) | 800 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) |
| 758 .WillByDefault(RunCallback<0>(device_name_value)); | 801 .WillByDefault(RunCallback<0>(device_name_value)); |
| 759 | 802 |
| 760 // Write response. | 803 // Write response. |
| 761 ON_CALL(*device_name, WriteRemoteCharacteristic(_, _, _)) | 804 ON_CALL(*device_name, WriteRemoteCharacteristic(_, _, _)) |
| 762 .WillByDefault(RunCallback<1 /* success callback */>()); | 805 .WillByDefault(RunCallback<1 /* success callback */>()); |
| 763 | 806 |
| 764 generic_access->AddMockCharacteristic(std::move(device_name)); | 807 generic_access->AddMockCharacteristic(std::move(device_name)); |
| 808 } | |
| 809 | |
| 810 { // Peripheral Privacy Flag: | |
| 811 scoped_ptr<NiceMockBluetoothGattCharacteristic> peripheral_privacy_flag( | |
| 812 GetBaseGATTCharacteristic( | |
| 813 generic_access.get(), kPeripheralPrivacyFlagUUID, | |
| 814 BluetoothGattCharacteristic::PROPERTY_READ | | |
| 815 BluetoothGattCharacteristic::PROPERTY_WRITE)); | |
| 816 | |
| 817 // Read response. | |
| 818 std::vector<uint8_t> value(1); | |
| 819 value[0] = false; | |
| 820 | |
| 821 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _)) | |
| 822 .WillByDefault(RunCallback<0>(value)); | |
| 823 | |
| 824 // Crash if WriteRemoteCharacteristic called. Not using GoogleMock's Expect | |
| 825 // because this is used in layout tests that may not report a mock | |
| 826 // expectation error correctly as a layout test failure. | |
| 827 ON_CALL(*peripheral_privacy_flag, WriteRemoteCharacteristic(_, _, _)) | |
| 828 .WillByDefault( | |
| 829 Invoke([](const std::vector<uint8_t>&, const base::Closure&, | |
| 830 const BluetoothGattCharacteristic::ErrorCallback&) { | |
| 831 NOTREACHED(); | |
| 832 })); | |
| 833 | |
| 834 generic_access->AddMockCharacteristic(std::move(peripheral_privacy_flag)); | |
| 835 } | |
| 765 | 836 |
| 766 return generic_access; | 837 return generic_access; |
| 767 } | 838 } |
| 768 | 839 |
| 769 // static | 840 // static |
| 770 scoped_ptr<NiceMockBluetoothGattService> | 841 scoped_ptr<NiceMockBluetoothGattService> |
| 771 LayoutTestBluetoothAdapterProvider::GetHeartRateService( | 842 LayoutTestBluetoothAdapterProvider::GetHeartRateService( |
| 772 MockBluetoothAdapter* adapter, | 843 MockBluetoothAdapter* adapter, |
| 773 MockBluetoothDevice* device) { | 844 MockBluetoothDevice* device) { |
| 774 scoped_ptr<NiceMockBluetoothGattService> heart_rate( | 845 scoped_ptr<NiceMockBluetoothGattService> heart_rate( |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 return BluetoothUUID(); | 1007 return BluetoothUUID(); |
| 937 } | 1008 } |
| 938 | 1009 |
| 939 // static | 1010 // static |
| 940 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1011 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
| 941 return BluetoothDevice::CanonicalizeAddress( | 1012 return BluetoothDevice::CanonicalizeAddress( |
| 942 base::StringPrintf("%012" PRIx64, addr)); | 1013 base::StringPrintf("%012" PRIx64, addr)); |
| 943 } | 1014 } |
| 944 | 1015 |
| 945 } // namespace content | 1016 } // namespace content |
| OLD | NEW |