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 11 matching lines...) Expand all Loading... |
22 #include "device/bluetooth/bluetooth_uuid.h" | 22 #include "device/bluetooth/bluetooth_uuid.h" |
23 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 23 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
24 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" | 24 #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" |
25 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 25 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
26 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" | 26 #include "device/bluetooth/test/mock_bluetooth_gatt_notify_session.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
28 | 28 |
29 using base::StringPiece; | 29 using base::StringPiece; |
30 using device::BluetoothAdapter; | 30 using device::BluetoothAdapter; |
31 using device::BluetoothDevice; | 31 using device::BluetoothDevice; |
32 using device::BluetoothGattCharacteristic; | 32 using device::BluetoothRemoteGattCharacteristic; |
33 using device::BluetoothGattService; | 33 using device::BluetoothRemoteGattService; |
34 using device::BluetoothUUID; | 34 using device::BluetoothUUID; |
35 using device::MockBluetoothAdapter; | 35 using device::MockBluetoothAdapter; |
36 using device::MockBluetoothDevice; | 36 using device::MockBluetoothDevice; |
37 using device::MockBluetoothDiscoverySession; | 37 using device::MockBluetoothDiscoverySession; |
38 using device::MockBluetoothGattCharacteristic; | 38 using device::MockBluetoothGattCharacteristic; |
39 using device::MockBluetoothGattConnection; | 39 using device::MockBluetoothGattConnection; |
40 using device::MockBluetoothGattNotifySession; | 40 using device::MockBluetoothGattNotifySession; |
41 using device::MockBluetoothGattService; | 41 using device::MockBluetoothGattService; |
42 using testing::ElementsAre; | 42 using testing::ElementsAre; |
43 using testing::Invoke; | 43 using testing::Invoke; |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 MockBluetoothAdapter* adapter_ptr = adapter.get(); | 446 MockBluetoothAdapter* adapter_ptr = adapter.get(); |
447 MockBluetoothDevice* device_ptr = device.get(); | 447 MockBluetoothDevice* device_ptr = device.get(); |
448 | 448 |
449 // Override the previous mock implementation of | 449 // Override the previous mock implementation of |
450 // IsGattServicesDiscoveryComplete so that the first time the function is | 450 // IsGattServicesDiscoveryComplete so that the first time the function is |
451 // called it returns false, adds a service and posts a task to notify | 451 // called it returns false, adds a service and posts a task to notify |
452 // the services have been discovered. Subsequent calls to the function | 452 // the services have been discovered. Subsequent calls to the function |
453 // will return true. | 453 // will return true. |
454 ON_CALL(*device, IsGattServicesDiscoveryComplete()) | 454 ON_CALL(*device, IsGattServicesDiscoveryComplete()) |
455 .WillByDefault(Invoke([adapter_ptr, device_ptr] { | 455 .WillByDefault(Invoke([adapter_ptr, device_ptr] { |
456 std::vector<BluetoothGattService*> services = | 456 std::vector<BluetoothRemoteGattService*> services = |
457 device_ptr->GetMockServices(); | 457 device_ptr->GetMockServices(); |
458 | 458 |
459 if (services.size() == 0) { | 459 if (services.size() == 0) { |
460 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( | 460 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( |
461 GetBaseGATTService(device_ptr, kHeartRateServiceUUID)); | 461 GetBaseGATTService(device_ptr, kHeartRateServiceUUID)); |
462 | 462 |
463 device_ptr->AddMockService(std::move(heart_rate)); | 463 device_ptr->AddMockService(std::move(heart_rate)); |
464 base::ThreadTaskRunnerHandle::Get()->PostTask( | 464 base::ThreadTaskRunnerHandle::Get()->PostTask( |
465 FROM_HERE, | 465 FROM_HERE, |
466 base::Bind(&NotifyServicesDiscovered, | 466 base::Bind(&NotifyServicesDiscovered, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 544 |
545 BluetoothDevice::UUIDList uuids; | 545 BluetoothDevice::UUIDList uuids; |
546 uuids.push_back(BluetoothUUID(errorsServiceUUID)); | 546 uuids.push_back(BluetoothUUID(errorsServiceUUID)); |
547 | 547 |
548 std::unique_ptr<NiceMockBluetoothDevice> device( | 548 std::unique_ptr<NiceMockBluetoothDevice> device( |
549 GetConnectableDevice(adapter.get(), "Errors Device", uuids)); | 549 GetConnectableDevice(adapter.get(), "Errors Device", uuids)); |
550 | 550 |
551 std::unique_ptr<NiceMockBluetoothGattService> service( | 551 std::unique_ptr<NiceMockBluetoothGattService> service( |
552 GetBaseGATTService(device.get(), errorsServiceUUID)); | 552 GetBaseGATTService(device.get(), errorsServiceUUID)); |
553 | 553 |
554 for (int error = BluetoothGattService::GATT_ERROR_UNKNOWN; | 554 for (int error = BluetoothRemoteGattService::GATT_ERROR_UNKNOWN; |
555 error <= BluetoothGattService::GATT_ERROR_NOT_SUPPORTED; error++) { | 555 error <= BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED; error++) { |
556 service->AddMockCharacteristic(GetErrorCharacteristic( | 556 service->AddMockCharacteristic(GetErrorCharacteristic( |
557 service.get(), | 557 service.get(), |
558 static_cast<BluetoothGattService::GattErrorCode>(error))); | 558 static_cast<BluetoothRemoteGattService::GattErrorCode>(error))); |
559 } | 559 } |
560 | 560 |
561 device->AddMockService(std::move(service)); | 561 device->AddMockService(std::move(service)); |
562 adapter->AddMockDevice(std::move(device)); | 562 adapter->AddMockDevice(std::move(device)); |
563 | 563 |
564 return adapter; | 564 return adapter; |
565 } | 565 } |
566 | 566 |
567 // Discovery Sessions | 567 // Discovery Sessions |
568 | 568 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 std::unique_ptr<NiceMockBluetoothGattService> | 719 std::unique_ptr<NiceMockBluetoothGattService> |
720 LayoutTestBluetoothAdapterProvider::GetBlacklistTestService( | 720 LayoutTestBluetoothAdapterProvider::GetBlacklistTestService( |
721 device::MockBluetoothDevice* device) { | 721 device::MockBluetoothDevice* device) { |
722 std::unique_ptr<NiceMockBluetoothGattService> blacklist_test_service( | 722 std::unique_ptr<NiceMockBluetoothGattService> blacklist_test_service( |
723 GetBaseGATTService(device, kBlacklistTestServiceUUID)); | 723 GetBaseGATTService(device, kBlacklistTestServiceUUID)); |
724 | 724 |
725 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 725 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
726 blacklist_exclude_reads_characteristic(GetBaseGATTCharacteristic( | 726 blacklist_exclude_reads_characteristic(GetBaseGATTCharacteristic( |
727 "Excluded Reads Characteristic", blacklist_test_service.get(), | 727 "Excluded Reads Characteristic", blacklist_test_service.get(), |
728 kBlacklistExcludeReadsCharacteristicUUID, | 728 kBlacklistExcludeReadsCharacteristicUUID, |
729 BluetoothGattCharacteristic::PROPERTY_READ | | 729 BluetoothRemoteGattCharacteristic::PROPERTY_READ | |
730 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 730 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
731 | 731 |
732 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect | 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 | 733 // because this is used in layout tests that may not report a mock expectation |
734 // error correctly as a layout test failure. | 734 // error correctly as a layout test failure. |
735 ON_CALL(*blacklist_exclude_reads_characteristic, | 735 ON_CALL(*blacklist_exclude_reads_characteristic, |
736 ReadRemoteCharacteristic(_, _)) | 736 ReadRemoteCharacteristic(_, _)) |
737 .WillByDefault( | 737 .WillByDefault( |
738 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, | 738 Invoke([](const BluetoothRemoteGattCharacteristic::ValueCallback&, |
739 const BluetoothGattCharacteristic::ErrorCallback&) { | 739 const BluetoothRemoteGattCharacteristic::ErrorCallback&) { |
740 NOTREACHED(); | 740 NOTREACHED(); |
741 })); | 741 })); |
742 | 742 |
743 // Write response. | 743 // Write response. |
744 ON_CALL(*blacklist_exclude_reads_characteristic, | 744 ON_CALL(*blacklist_exclude_reads_characteristic, |
745 WriteRemoteCharacteristic(_, _, _)) | 745 WriteRemoteCharacteristic(_, _, _)) |
746 .WillByDefault(RunCallback<1 /* success callback */>()); | 746 .WillByDefault(RunCallback<1 /* success callback */>()); |
747 | 747 |
748 blacklist_test_service->AddMockCharacteristic( | 748 blacklist_test_service->AddMockCharacteristic( |
749 std::move(blacklist_exclude_reads_characteristic)); | 749 std::move(blacklist_exclude_reads_characteristic)); |
750 | 750 |
751 return blacklist_test_service; | 751 return blacklist_test_service; |
752 } | 752 } |
753 | 753 |
754 // static | 754 // static |
755 std::unique_ptr<NiceMockBluetoothGattService> | 755 std::unique_ptr<NiceMockBluetoothGattService> |
756 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( | 756 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( |
757 device::MockBluetoothDevice* device) { | 757 device::MockBluetoothDevice* device) { |
758 std::unique_ptr<NiceMockBluetoothGattService> device_information( | 758 std::unique_ptr<NiceMockBluetoothGattService> device_information( |
759 GetBaseGATTService(device, kDeviceInformationServiceUUID)); | 759 GetBaseGATTService(device, kDeviceInformationServiceUUID)); |
760 | 760 |
761 std::unique_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( | 761 std::unique_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( |
762 GetBaseGATTCharacteristic( | 762 GetBaseGATTCharacteristic( |
763 "Serial Number String", device_information.get(), | 763 "Serial Number String", device_information.get(), |
764 kSerialNumberStringUUID, BluetoothGattCharacteristic::PROPERTY_READ)); | 764 kSerialNumberStringUUID, |
| 765 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
765 | 766 |
766 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect | 767 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect |
767 // because this is used in layout tests that may not report a mock expectation | 768 // because this is used in layout tests that may not report a mock expectation |
768 // error correctly as a layout test failure. | 769 // error correctly as a layout test failure. |
769 ON_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _)) | 770 ON_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _)) |
770 .WillByDefault( | 771 .WillByDefault( |
771 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, | 772 Invoke([](const BluetoothRemoteGattCharacteristic::ValueCallback&, |
772 const BluetoothGattCharacteristic::ErrorCallback&) { | 773 const BluetoothRemoteGattCharacteristic::ErrorCallback&) { |
773 NOTREACHED(); | 774 NOTREACHED(); |
774 })); | 775 })); |
775 | 776 |
776 device_information->AddMockCharacteristic(std::move(serial_number_string)); | 777 device_information->AddMockCharacteristic(std::move(serial_number_string)); |
777 | 778 |
778 return device_information; | 779 return device_information; |
779 } | 780 } |
780 | 781 |
781 // static | 782 // static |
782 std::unique_ptr<NiceMockBluetoothGattService> | 783 std::unique_ptr<NiceMockBluetoothGattService> |
783 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( | 784 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( |
784 device::MockBluetoothDevice* device) { | 785 device::MockBluetoothDevice* device) { |
785 std::unique_ptr<NiceMockBluetoothGattService> generic_access( | 786 std::unique_ptr<NiceMockBluetoothGattService> generic_access( |
786 GetBaseGATTService(device, kGenericAccessServiceUUID)); | 787 GetBaseGATTService(device, kGenericAccessServiceUUID)); |
787 | 788 |
788 { // Device Name: | 789 { // Device Name: |
789 std::unique_ptr<NiceMockBluetoothGattCharacteristic> device_name( | 790 std::unique_ptr<NiceMockBluetoothGattCharacteristic> device_name( |
790 GetBaseGATTCharacteristic( | 791 GetBaseGATTCharacteristic( |
791 "Device Name", generic_access.get(), kDeviceNameUUID, | 792 "Device Name", generic_access.get(), kDeviceNameUUID, |
792 BluetoothGattCharacteristic::PROPERTY_READ | | 793 BluetoothRemoteGattCharacteristic::PROPERTY_READ | |
793 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 794 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
794 | 795 |
795 // Read response. | 796 // Read response. |
796 std::string device_name_str = device->GetDeviceName(); | 797 std::string device_name_str = device->GetDeviceName(); |
797 std::vector<uint8_t> device_name_value(device_name_str.begin(), | 798 std::vector<uint8_t> device_name_value(device_name_str.begin(), |
798 device_name_str.end()); | 799 device_name_str.end()); |
799 | 800 |
800 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) | 801 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) |
801 .WillByDefault(RunCallback<0>(device_name_value)); | 802 .WillByDefault(RunCallback<0>(device_name_value)); |
802 | 803 |
803 // Write response. | 804 // Write response. |
804 ON_CALL(*device_name, WriteRemoteCharacteristic(_, _, _)) | 805 ON_CALL(*device_name, WriteRemoteCharacteristic(_, _, _)) |
805 .WillByDefault(RunCallback<1 /* success callback */>()); | 806 .WillByDefault(RunCallback<1 /* success callback */>()); |
806 | 807 |
807 generic_access->AddMockCharacteristic(std::move(device_name)); | 808 generic_access->AddMockCharacteristic(std::move(device_name)); |
808 } | 809 } |
809 | 810 |
810 { // Peripheral Privacy Flag: | 811 { // Peripheral Privacy Flag: |
811 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 812 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
812 peripheral_privacy_flag(GetBaseGATTCharacteristic( | 813 peripheral_privacy_flag(GetBaseGATTCharacteristic( |
813 "Peripheral Privacy Flag", generic_access.get(), | 814 "Peripheral Privacy Flag", generic_access.get(), |
814 kPeripheralPrivacyFlagUUID, | 815 kPeripheralPrivacyFlagUUID, |
815 BluetoothGattCharacteristic::PROPERTY_READ | | 816 BluetoothRemoteGattCharacteristic::PROPERTY_READ | |
816 BluetoothGattCharacteristic::PROPERTY_WRITE)); | 817 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); |
817 | 818 |
818 // Read response. | 819 // Read response. |
819 std::vector<uint8_t> value(1); | 820 std::vector<uint8_t> value(1); |
820 value[0] = false; | 821 value[0] = false; |
821 | 822 |
822 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _)) | 823 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _)) |
823 .WillByDefault(RunCallback<0>(value)); | 824 .WillByDefault(RunCallback<0>(value)); |
824 | 825 |
825 // Crash if WriteRemoteCharacteristic called. Not using GoogleMock's Expect | 826 // Crash if WriteRemoteCharacteristic called. Not using GoogleMock's Expect |
826 // because this is used in layout tests that may not report a mock | 827 // because this is used in layout tests that may not report a mock |
827 // expectation error correctly as a layout test failure. | 828 // expectation error correctly as a layout test failure. |
828 ON_CALL(*peripheral_privacy_flag, WriteRemoteCharacteristic(_, _, _)) | 829 ON_CALL(*peripheral_privacy_flag, WriteRemoteCharacteristic(_, _, _)) |
829 .WillByDefault( | 830 .WillByDefault( |
830 Invoke([](const std::vector<uint8_t>&, const base::Closure&, | 831 Invoke([](const std::vector<uint8_t>&, const base::Closure&, |
831 const BluetoothGattCharacteristic::ErrorCallback&) { | 832 const BluetoothRemoteGattCharacteristic::ErrorCallback&) { |
832 NOTREACHED(); | 833 NOTREACHED(); |
833 })); | 834 })); |
834 | 835 |
835 generic_access->AddMockCharacteristic(std::move(peripheral_privacy_flag)); | 836 generic_access->AddMockCharacteristic(std::move(peripheral_privacy_flag)); |
836 } | 837 } |
837 | 838 |
838 return generic_access; | 839 return generic_access; |
839 } | 840 } |
840 | 841 |
841 // static | 842 // static |
842 std::unique_ptr<NiceMockBluetoothGattService> | 843 std::unique_ptr<NiceMockBluetoothGattService> |
843 LayoutTestBluetoothAdapterProvider::GetHeartRateService( | 844 LayoutTestBluetoothAdapterProvider::GetHeartRateService( |
844 MockBluetoothAdapter* adapter, | 845 MockBluetoothAdapter* adapter, |
845 MockBluetoothDevice* device) { | 846 MockBluetoothDevice* device) { |
846 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( | 847 std::unique_ptr<NiceMockBluetoothGattService> heart_rate( |
847 GetBaseGATTService(device, kHeartRateServiceUUID)); | 848 GetBaseGATTService(device, kHeartRateServiceUUID)); |
848 | 849 |
849 // Heart Rate Measurement | 850 // Heart Rate Measurement |
850 std::unique_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( | 851 std::unique_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( |
851 GetBaseGATTCharacteristic("Heart Rate Measurement", heart_rate.get(), | 852 GetBaseGATTCharacteristic( |
852 kHeartRateMeasurementUUID, | 853 "Heart Rate Measurement", heart_rate.get(), kHeartRateMeasurementUUID, |
853 BluetoothGattCharacteristic::PROPERTY_NOTIFY)); | 854 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY)); |
854 NiceMockBluetoothGattCharacteristic* measurement_ptr = | 855 NiceMockBluetoothGattCharacteristic* measurement_ptr = |
855 heart_rate_measurement.get(); | 856 heart_rate_measurement.get(); |
856 | 857 |
857 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) | 858 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) |
858 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 859 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
859 [adapter, measurement_ptr]() { | 860 [adapter, measurement_ptr]() { |
860 std::unique_ptr<NiceMockBluetoothGattNotifySession> notify_session( | 861 std::unique_ptr<NiceMockBluetoothGattNotifySession> notify_session( |
861 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); | 862 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); |
862 | 863 |
863 std::vector<uint8_t> rate(1 /* size */); | 864 std::vector<uint8_t> rate(1 /* size */); |
864 rate[0] = 60; | 865 rate[0] = 60; |
865 | 866 |
866 notify_session->StartTestNotifications(adapter, measurement_ptr, | 867 notify_session->StartTestNotifications(adapter, measurement_ptr, |
867 rate); | 868 rate); |
868 | 869 |
869 return notify_session; | 870 return notify_session; |
870 })); | 871 })); |
871 | 872 |
872 // Body Sensor Location Characteristic (Chest) | 873 // Body Sensor Location Characteristic (Chest) |
873 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 874 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
874 body_sensor_location_chest(GetBaseGATTCharacteristic( | 875 body_sensor_location_chest(GetBaseGATTCharacteristic( |
875 "Body Sensor Location Chest", heart_rate.get(), kBodySensorLocation, | 876 "Body Sensor Location Chest", heart_rate.get(), kBodySensorLocation, |
876 BluetoothGattCharacteristic::PROPERTY_READ)); | 877 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
877 BluetoothGattCharacteristic* location_chest_ptr = | 878 BluetoothRemoteGattCharacteristic* location_chest_ptr = |
878 body_sensor_location_chest.get(); | 879 body_sensor_location_chest.get(); |
879 | 880 |
880 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _)) | 881 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _)) |
881 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 882 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
882 [adapter, location_chest_ptr]() { | 883 [adapter, location_chest_ptr]() { |
883 std::vector<uint8_t> location(1 /* size */); | 884 std::vector<uint8_t> location(1 /* size */); |
884 location[0] = 1; // Chest | 885 location[0] = 1; // Chest |
885 // Read a characteristic has a side effect of | 886 // Read a characteristic has a side effect of |
886 // GattCharacteristicValueChanged being called. | 887 // GattCharacteristicValueChanged being called. |
887 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 888 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
888 adapter->GetObservers(), | 889 adapter->GetObservers(), |
889 GattCharacteristicValueChanged( | 890 GattCharacteristicValueChanged( |
890 adapter, location_chest_ptr, location)); | 891 adapter, location_chest_ptr, location)); |
891 return location; | 892 return location; |
892 })); | 893 })); |
893 | 894 |
894 // Body Sensor Location Characteristic (Wrist) | 895 // Body Sensor Location Characteristic (Wrist) |
895 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 896 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
896 body_sensor_location_wrist(GetBaseGATTCharacteristic( | 897 body_sensor_location_wrist(GetBaseGATTCharacteristic( |
897 "Body Sensor Location Wrist", heart_rate.get(), kBodySensorLocation, | 898 "Body Sensor Location Wrist", heart_rate.get(), kBodySensorLocation, |
898 BluetoothGattCharacteristic::PROPERTY_READ)); | 899 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); |
899 BluetoothGattCharacteristic* location_wrist_ptr = | 900 BluetoothRemoteGattCharacteristic* location_wrist_ptr = |
900 body_sensor_location_wrist.get(); | 901 body_sensor_location_wrist.get(); |
901 | 902 |
902 ON_CALL(*body_sensor_location_wrist, ReadRemoteCharacteristic(_, _)) | 903 ON_CALL(*body_sensor_location_wrist, ReadRemoteCharacteristic(_, _)) |
903 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( | 904 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( |
904 [adapter, location_wrist_ptr]() { | 905 [adapter, location_wrist_ptr]() { |
905 std::vector<uint8_t> location(1 /* size */); | 906 std::vector<uint8_t> location(1 /* size */); |
906 location[0] = 2; // Wrist | 907 location[0] = 2; // Wrist |
907 // Read a characteristic has a side effect of | 908 // Read a characteristic has a side effect of |
908 // GattCharacteristicValueChanged being called. | 909 // GattCharacteristicValueChanged being called. |
909 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, | 910 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
(...skipping 11 matching lines...) Expand all Loading... |
921 } | 922 } |
922 | 923 |
923 // Characteristics | 924 // Characteristics |
924 | 925 |
925 // static | 926 // static |
926 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 927 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
927 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( | 928 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( |
928 const std::string& identifier, | 929 const std::string& identifier, |
929 MockBluetoothGattService* service, | 930 MockBluetoothGattService* service, |
930 const std::string& uuid, | 931 const std::string& uuid, |
931 BluetoothGattCharacteristic::Properties properties) { | 932 BluetoothRemoteGattCharacteristic::Properties properties) { |
932 return base::WrapUnique(new NiceMockBluetoothGattCharacteristic( | 933 return base::WrapUnique(new NiceMockBluetoothGattCharacteristic( |
933 service, identifier, BluetoothUUID(uuid), false /* is_local */, | 934 service, identifier, BluetoothUUID(uuid), false /* is_local */, |
934 properties, NULL /* permissions */)); | 935 properties, NULL /* permissions */)); |
935 } | 936 } |
936 | 937 |
937 // static | 938 // static |
938 std::unique_ptr<NiceMockBluetoothGattCharacteristic> | 939 std::unique_ptr<NiceMockBluetoothGattCharacteristic> |
939 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( | 940 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( |
940 MockBluetoothGattService* service, | 941 MockBluetoothGattService* service, |
941 BluetoothGattService::GattErrorCode error_code) { | 942 BluetoothRemoteGattService::GattErrorCode error_code) { |
942 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. | 943 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. |
943 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( | 944 std::unique_ptr<NiceMockBluetoothGattCharacteristic> characteristic( |
944 GetBaseGATTCharacteristic( | 945 GetBaseGATTCharacteristic( |
945 // Use the UUID to generate unique identifiers. | 946 // Use the UUID to generate unique identifiers. |
946 "Error Characteristic " + errorUUID(error_alias), service, | 947 "Error Characteristic " + errorUUID(error_alias), service, |
947 errorUUID(error_alias), | 948 errorUUID(error_alias), |
948 BluetoothGattCharacteristic::PROPERTY_READ | | 949 BluetoothRemoteGattCharacteristic::PROPERTY_READ | |
949 BluetoothGattCharacteristic::PROPERTY_WRITE | | 950 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE | |
950 BluetoothGattCharacteristic::PROPERTY_INDICATE)); | 951 BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE)); |
951 | 952 |
952 // Read response. | 953 // Read response. |
953 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) | 954 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) |
954 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); | 955 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); |
955 | 956 |
956 // Write response. | 957 // Write response. |
957 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) | 958 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) |
958 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); | 959 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); |
959 | 960 |
960 // StartNotifySession response | 961 // StartNotifySession response |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 return BluetoothUUID(); | 1036 return BluetoothUUID(); |
1036 } | 1037 } |
1037 | 1038 |
1038 // static | 1039 // static |
1039 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { | 1040 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { |
1040 return BluetoothDevice::CanonicalizeAddress( | 1041 return BluetoothDevice::CanonicalizeAddress( |
1041 base::StringPrintf("%012" PRIx64, addr)); | 1042 base::StringPrintf("%012" PRIx64, addr)); |
1042 } | 1043 } |
1043 | 1044 |
1044 } // namespace content | 1045 } // namespace content |
OLD | NEW |