Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: content/shell/browser/layout_test/layout_test_bluetooth_adapter_provider.cc

Issue 1723723002: bluetooth: Implement Service.getCharacteristics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Merge with ToT Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 717
718 // static 718 // static
719 scoped_ptr<NiceMockBluetoothGattService> 719 scoped_ptr<NiceMockBluetoothGattService>
720 LayoutTestBluetoothAdapterProvider::GetBlacklistTestService( 720 LayoutTestBluetoothAdapterProvider::GetBlacklistTestService(
721 device::MockBluetoothDevice* device) { 721 device::MockBluetoothDevice* device) {
722 scoped_ptr<NiceMockBluetoothGattService> blacklist_test_service( 722 scoped_ptr<NiceMockBluetoothGattService> blacklist_test_service(
723 GetBaseGATTService(device, kBlacklistTestServiceUUID)); 723 GetBaseGATTService(device, kBlacklistTestServiceUUID));
724 724
725 scoped_ptr<NiceMockBluetoothGattCharacteristic> 725 scoped_ptr<NiceMockBluetoothGattCharacteristic>
726 blacklist_exclude_reads_characteristic(GetBaseGATTCharacteristic( 726 blacklist_exclude_reads_characteristic(GetBaseGATTCharacteristic(
727 blacklist_test_service.get(), 727 "Excluded Reads Characteristic", blacklist_test_service.get(),
728 kBlacklistExcludeReadsCharacteristicUUID, 728 kBlacklistExcludeReadsCharacteristicUUID,
729 BluetoothGattCharacteristic::PROPERTY_READ | 729 BluetoothGattCharacteristic::PROPERTY_READ |
730 BluetoothGattCharacteristic::PROPERTY_WRITE)); 730 BluetoothGattCharacteristic::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(
(...skipping 14 matching lines...) Expand all
752 } 752 }
753 753
754 // static 754 // static
755 scoped_ptr<NiceMockBluetoothGattService> 755 scoped_ptr<NiceMockBluetoothGattService>
756 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService( 756 LayoutTestBluetoothAdapterProvider::GetDeviceInformationService(
757 device::MockBluetoothDevice* device) { 757 device::MockBluetoothDevice* device) {
758 scoped_ptr<NiceMockBluetoothGattService> device_information( 758 scoped_ptr<NiceMockBluetoothGattService> device_information(
759 GetBaseGATTService(device, kDeviceInformationServiceUUID)); 759 GetBaseGATTService(device, kDeviceInformationServiceUUID));
760 760
761 scoped_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string( 761 scoped_ptr<NiceMockBluetoothGattCharacteristic> serial_number_string(
762 GetBaseGATTCharacteristic(device_information.get(), 762 GetBaseGATTCharacteristic(
763 kSerialNumberStringUUID, 763 "Serial Number String", device_information.get(),
764 BluetoothGattCharacteristic::PROPERTY_READ)); 764 kSerialNumberStringUUID, BluetoothGattCharacteristic::PROPERTY_READ));
765 765
766 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect 766 // Crash if ReadRemoteCharacteristic called. Not using GoogleMock's Expect
767 // because this is used in layout tests that may not report a mock expectation 767 // because this is used in layout tests that may not report a mock expectation
768 // error correctly as a layout test failure. 768 // error correctly as a layout test failure.
769 ON_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _)) 769 ON_CALL(*serial_number_string, ReadRemoteCharacteristic(_, _))
770 .WillByDefault( 770 .WillByDefault(
771 Invoke([](const BluetoothGattCharacteristic::ValueCallback&, 771 Invoke([](const BluetoothGattCharacteristic::ValueCallback&,
772 const BluetoothGattCharacteristic::ErrorCallback&) { 772 const BluetoothGattCharacteristic::ErrorCallback&) {
773 NOTREACHED(); 773 NOTREACHED();
774 })); 774 }));
775 775
776 device_information->AddMockCharacteristic(std::move(serial_number_string)); 776 device_information->AddMockCharacteristic(std::move(serial_number_string));
777 777
778 return device_information; 778 return device_information;
779 } 779 }
780 780
781 // static 781 // static
782 scoped_ptr<NiceMockBluetoothGattService> 782 scoped_ptr<NiceMockBluetoothGattService>
783 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( 783 LayoutTestBluetoothAdapterProvider::GetGenericAccessService(
784 device::MockBluetoothDevice* device) { 784 device::MockBluetoothDevice* device) {
785 scoped_ptr<NiceMockBluetoothGattService> generic_access( 785 scoped_ptr<NiceMockBluetoothGattService> generic_access(
786 GetBaseGATTService(device, kGenericAccessServiceUUID)); 786 GetBaseGATTService(device, kGenericAccessServiceUUID));
787 787
788 { // Device Name: 788 { // Device Name:
789 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( 789 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name(
790 GetBaseGATTCharacteristic( 790 GetBaseGATTCharacteristic(
791 generic_access.get(), kDeviceNameUUID, 791 "Device Name", generic_access.get(), kDeviceNameUUID,
792 BluetoothGattCharacteristic::PROPERTY_READ | 792 BluetoothGattCharacteristic::PROPERTY_READ |
793 BluetoothGattCharacteristic::PROPERTY_WRITE)); 793 BluetoothGattCharacteristic::PROPERTY_WRITE));
794 794
795 // Read response. 795 // Read response.
796 std::string device_name_str = device->GetDeviceName(); 796 std::string device_name_str = device->GetDeviceName();
797 std::vector<uint8_t> device_name_value(device_name_str.begin(), 797 std::vector<uint8_t> device_name_value(device_name_str.begin(),
798 device_name_str.end()); 798 device_name_str.end());
799 799
800 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) 800 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _))
801 .WillByDefault(RunCallback<0>(device_name_value)); 801 .WillByDefault(RunCallback<0>(device_name_value));
802 802
803 // Write response. 803 // Write response.
804 ON_CALL(*device_name, WriteRemoteCharacteristic(_, _, _)) 804 ON_CALL(*device_name, WriteRemoteCharacteristic(_, _, _))
805 .WillByDefault(RunCallback<1 /* success callback */>()); 805 .WillByDefault(RunCallback<1 /* success callback */>());
806 806
807 generic_access->AddMockCharacteristic(std::move(device_name)); 807 generic_access->AddMockCharacteristic(std::move(device_name));
808 } 808 }
809 809
810 { // Peripheral Privacy Flag: 810 { // Peripheral Privacy Flag:
811 scoped_ptr<NiceMockBluetoothGattCharacteristic> peripheral_privacy_flag( 811 scoped_ptr<NiceMockBluetoothGattCharacteristic> peripheral_privacy_flag(
812 GetBaseGATTCharacteristic( 812 GetBaseGATTCharacteristic(
813 generic_access.get(), kPeripheralPrivacyFlagUUID, 813 "Peripheral Privacy Flag", generic_access.get(),
814 kPeripheralPrivacyFlagUUID,
814 BluetoothGattCharacteristic::PROPERTY_READ | 815 BluetoothGattCharacteristic::PROPERTY_READ |
815 BluetoothGattCharacteristic::PROPERTY_WRITE)); 816 BluetoothGattCharacteristic::PROPERTY_WRITE));
816 817
817 // Read response. 818 // Read response.
818 std::vector<uint8_t> value(1); 819 std::vector<uint8_t> value(1);
819 value[0] = false; 820 value[0] = false;
820 821
821 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _)) 822 ON_CALL(*peripheral_privacy_flag, ReadRemoteCharacteristic(_, _))
822 .WillByDefault(RunCallback<0>(value)); 823 .WillByDefault(RunCallback<0>(value));
823 824
(...skipping 16 matching lines...) Expand all
840 // static 841 // static
841 scoped_ptr<NiceMockBluetoothGattService> 842 scoped_ptr<NiceMockBluetoothGattService>
842 LayoutTestBluetoothAdapterProvider::GetHeartRateService( 843 LayoutTestBluetoothAdapterProvider::GetHeartRateService(
843 MockBluetoothAdapter* adapter, 844 MockBluetoothAdapter* adapter,
844 MockBluetoothDevice* device) { 845 MockBluetoothDevice* device) {
845 scoped_ptr<NiceMockBluetoothGattService> heart_rate( 846 scoped_ptr<NiceMockBluetoothGattService> heart_rate(
846 GetBaseGATTService(device, kHeartRateServiceUUID)); 847 GetBaseGATTService(device, kHeartRateServiceUUID));
847 848
848 // Heart Rate Measurement 849 // Heart Rate Measurement
849 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( 850 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement(
850 GetBaseGATTCharacteristic(heart_rate.get(), kHeartRateMeasurementUUID, 851 GetBaseGATTCharacteristic("Heart Rate Measurement", heart_rate.get(),
852 kHeartRateMeasurementUUID,
851 BluetoothGattCharacteristic::PROPERTY_NOTIFY)); 853 BluetoothGattCharacteristic::PROPERTY_NOTIFY));
852 NiceMockBluetoothGattCharacteristic* measurement_ptr = 854 NiceMockBluetoothGattCharacteristic* measurement_ptr =
853 heart_rate_measurement.get(); 855 heart_rate_measurement.get();
854 856
855 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) 857 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _))
856 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 858 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
857 [adapter, measurement_ptr]() { 859 [adapter, measurement_ptr]() {
858 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session( 860 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session(
859 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); 861 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier()));
860 862
861 std::vector<uint8_t> rate(1 /* size */); 863 std::vector<uint8_t> rate(1 /* size */);
862 rate[0] = 60; 864 rate[0] = 60;
863 865
864 notify_session->StartTestNotifications(adapter, measurement_ptr, 866 notify_session->StartTestNotifications(adapter, measurement_ptr,
865 rate); 867 rate);
866 868
867 return notify_session; 869 return notify_session;
868 })); 870 }));
869 871
870 // Body Sensor Location Characteristic 872 // Body Sensor Location Characteristic (Chest)
871 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location( 873 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location_chest(
872 GetBaseGATTCharacteristic(heart_rate.get(), kBodySensorLocation, 874 GetBaseGATTCharacteristic("Body Sensor Location Chest", heart_rate.get(),
875 kBodySensorLocation,
873 BluetoothGattCharacteristic::PROPERTY_READ)); 876 BluetoothGattCharacteristic::PROPERTY_READ));
874 BluetoothGattCharacteristic* location_ptr = body_sensor_location.get(); 877 BluetoothGattCharacteristic* location_chest_ptr =
878 body_sensor_location_chest.get();
875 879
876 ON_CALL(*body_sensor_location, ReadRemoteCharacteristic(_, _)) 880 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _))
877 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 881 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
878 [adapter, location_ptr]() { 882 [adapter, location_chest_ptr]() {
879 std::vector<uint8_t> location(1 /* size */); 883 std::vector<uint8_t> location(1 /* size */);
880 location[0] = 1; // Chest 884 location[0] = 1; // Chest
881 // Read a characteristic has a side effect of 885 // Read a characteristic has a side effect of
882 // GattCharacteristicValueChanged being called. 886 // GattCharacteristicValueChanged being called.
883 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 887 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
884 adapter->GetObservers(), 888 adapter->GetObservers(),
885 GattCharacteristicValueChanged( 889 GattCharacteristicValueChanged(
886 adapter, location_ptr, location)); 890 adapter, location_chest_ptr, location));
891 return location;
892 }));
893
894 // Body Sensor Location Characteristic (Wrist)
895 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location_wrist(
896 GetBaseGATTCharacteristic("Body Sensor Location Wrist", heart_rate.get(),
897 kBodySensorLocation,
898 BluetoothGattCharacteristic::PROPERTY_READ));
899 BluetoothGattCharacteristic* location_wrist_ptr =
900 body_sensor_location_wrist.get();
901
902 ON_CALL(*body_sensor_location_wrist, ReadRemoteCharacteristic(_, _))
903 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
904 [adapter, location_wrist_ptr]() {
905 std::vector<uint8_t> location(1 /* size */);
906 location[0] = 2; // Wrist
907 // Read a characteristic has a side effect of
908 // GattCharacteristicValueChanged being called.
909 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
910 adapter->GetObservers(),
911 GattCharacteristicValueChanged(
912 adapter, location_wrist_ptr, location));
887 return location; 913 return location;
888 })); 914 }));
889 915
890 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement)); 916 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement));
891 heart_rate->AddMockCharacteristic(std::move(body_sensor_location)); 917 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest));
918 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist));
892 919
893 return heart_rate; 920 return heart_rate;
894 } 921 }
895 922
896 // Characteristics 923 // Characteristics
897 924
898 // static 925 // static
899 scoped_ptr<NiceMockBluetoothGattCharacteristic> 926 scoped_ptr<NiceMockBluetoothGattCharacteristic>
900 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( 927 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic(
928 const std::string& identifier,
901 MockBluetoothGattService* service, 929 MockBluetoothGattService* service,
902 const std::string& uuid, 930 const std::string& uuid,
903 BluetoothGattCharacteristic::Properties properties) { 931 BluetoothGattCharacteristic::Properties properties) {
904 return make_scoped_ptr(new NiceMockBluetoothGattCharacteristic( 932 return make_scoped_ptr(new NiceMockBluetoothGattCharacteristic(
905 service, uuid + " Identifier", BluetoothUUID(uuid), false /* is_local */, 933 service, identifier, BluetoothUUID(uuid), false /* is_local */,
906 properties, NULL /* permissions */)); 934 properties, NULL /* permissions */));
907 } 935 }
908 936
909 // static 937 // static
910 scoped_ptr<NiceMockBluetoothGattCharacteristic> 938 scoped_ptr<NiceMockBluetoothGattCharacteristic>
911 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( 939 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic(
912 MockBluetoothGattService* service, 940 MockBluetoothGattService* service,
913 BluetoothGattService::GattErrorCode error_code) { 941 BluetoothGattService::GattErrorCode error_code) {
914 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. 942 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1.
915 scoped_ptr<NiceMockBluetoothGattCharacteristic> characteristic( 943 scoped_ptr<NiceMockBluetoothGattCharacteristic> characteristic(
916 GetBaseGATTCharacteristic( 944 GetBaseGATTCharacteristic(
917 service, 945 // Use the UUID to generate unique identifiers.
946 "Error Characteristic " + errorUUID(error_alias), service,
918 errorUUID(error_alias), 947 errorUUID(error_alias),
919 BluetoothGattCharacteristic::PROPERTY_READ | 948 BluetoothGattCharacteristic::PROPERTY_READ |
920 BluetoothGattCharacteristic::PROPERTY_WRITE | 949 BluetoothGattCharacteristic::PROPERTY_WRITE |
921 BluetoothGattCharacteristic::PROPERTY_INDICATE)); 950 BluetoothGattCharacteristic::PROPERTY_INDICATE));
922
923 951
924 // Read response. 952 // Read response.
925 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) 953 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _))
926 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); 954 .WillByDefault(RunCallback<1 /* error_callback */>(error_code));
927 955
928 // Write response. 956 // Write response.
929 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) 957 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _))
930 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); 958 .WillByDefault(RunCallback<2 /* error_callback */>(error_code));
931 959
932 // StartNotifySession response 960 // StartNotifySession response
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 return BluetoothUUID(); 1035 return BluetoothUUID();
1008 } 1036 }
1009 1037
1010 // static 1038 // static
1011 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1039 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1012 return BluetoothDevice::CanonicalizeAddress( 1040 return BluetoothDevice::CanonicalizeAddress(
1013 base::StringPrintf("%012" PRIx64, addr)); 1041 base::StringPrintf("%012" PRIx64, addr));
1014 } 1042 }
1015 1043
1016 } // namespace content 1044 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698