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

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: Clean up Created 4 years, 10 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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 // static 703 // static
704 scoped_ptr<NiceMockBluetoothGattService> 704 scoped_ptr<NiceMockBluetoothGattService>
705 LayoutTestBluetoothAdapterProvider::GetGenericAccessService( 705 LayoutTestBluetoothAdapterProvider::GetGenericAccessService(
706 MockBluetoothAdapter* adapter, 706 MockBluetoothAdapter* adapter,
707 MockBluetoothDevice* device) { 707 MockBluetoothDevice* device) {
708 scoped_ptr<NiceMockBluetoothGattService> generic_access( 708 scoped_ptr<NiceMockBluetoothGattService> generic_access(
709 GetBaseGATTService(device, kGenericAccessServiceUUID)); 709 GetBaseGATTService(device, kGenericAccessServiceUUID));
710 710
711 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name( 711 scoped_ptr<NiceMockBluetoothGattCharacteristic> device_name(
712 GetBaseGATTCharacteristic( 712 GetBaseGATTCharacteristic(
713 generic_access.get(), kDeviceNameUUID, 713 "Device Name Characteristic", generic_access.get(), kDeviceNameUUID,
714 BluetoothGattCharacteristic::PROPERTY_READ | 714 BluetoothGattCharacteristic::PROPERTY_READ |
715 BluetoothGattCharacteristic::PROPERTY_WRITE)); 715 BluetoothGattCharacteristic::PROPERTY_WRITE));
716 716
717 // Read response. 717 // Read response.
718 std::string device_name_str = device->GetDeviceName(); 718 std::string device_name_str = device->GetDeviceName();
719 std::vector<uint8_t> device_name_value(device_name_str.begin(), 719 std::vector<uint8_t> device_name_value(device_name_str.begin(),
720 device_name_str.end()); 720 device_name_str.end());
721 721
722 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _)) 722 ON_CALL(*device_name, ReadRemoteCharacteristic(_, _))
723 .WillByDefault(RunCallback<0>(device_name_value)); 723 .WillByDefault(RunCallback<0>(device_name_value));
(...skipping 10 matching lines...) Expand all
734 // static 734 // static
735 scoped_ptr<NiceMockBluetoothGattService> 735 scoped_ptr<NiceMockBluetoothGattService>
736 LayoutTestBluetoothAdapterProvider::GetHeartRateService( 736 LayoutTestBluetoothAdapterProvider::GetHeartRateService(
737 MockBluetoothAdapter* adapter, 737 MockBluetoothAdapter* adapter,
738 MockBluetoothDevice* device) { 738 MockBluetoothDevice* device) {
739 scoped_ptr<NiceMockBluetoothGattService> heart_rate( 739 scoped_ptr<NiceMockBluetoothGattService> heart_rate(
740 GetBaseGATTService(device, kHeartRateServiceUUID)); 740 GetBaseGATTService(device, kHeartRateServiceUUID));
741 741
742 // Heart Rate Measurement 742 // Heart Rate Measurement
743 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement( 743 scoped_ptr<NiceMockBluetoothGattCharacteristic> heart_rate_measurement(
744 GetBaseGATTCharacteristic(heart_rate.get(), kHeartRateMeasurementUUID, 744 GetBaseGATTCharacteristic("Heart Rate Measurement", heart_rate.get(),
745 kHeartRateMeasurementUUID,
745 BluetoothGattCharacteristic::PROPERTY_NOTIFY)); 746 BluetoothGattCharacteristic::PROPERTY_NOTIFY));
746 NiceMockBluetoothGattCharacteristic* measurement_ptr = 747 NiceMockBluetoothGattCharacteristic* measurement_ptr =
747 heart_rate_measurement.get(); 748 heart_rate_measurement.get();
748 749
749 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _)) 750 ON_CALL(*heart_rate_measurement, StartNotifySession(_, _))
750 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 751 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
751 [adapter, measurement_ptr]() { 752 [adapter, measurement_ptr]() {
752 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session( 753 scoped_ptr<NiceMockBluetoothGattNotifySession> notify_session(
753 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier())); 754 GetBaseGATTNotifySession(measurement_ptr->GetIdentifier()));
754 755
755 std::vector<uint8_t> rate(1 /* size */); 756 std::vector<uint8_t> rate(1 /* size */);
756 rate[0] = 60; 757 rate[0] = 60;
757 758
758 notify_session->StartTestNotifications(adapter, measurement_ptr, 759 notify_session->StartTestNotifications(adapter, measurement_ptr,
759 rate); 760 rate);
760 761
761 return notify_session; 762 return notify_session;
762 })); 763 }));
763 764
764 // Body Sensor Location Characteristic 765 // Body Sensor Location Characteristic (Chest)
765 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location( 766 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location_chest(
766 GetBaseGATTCharacteristic(heart_rate.get(), kBodySensorLocation, 767 GetBaseGATTCharacteristic("Body Sensor Location Chest", heart_rate.get(),
768 kBodySensorLocation,
767 BluetoothGattCharacteristic::PROPERTY_READ)); 769 BluetoothGattCharacteristic::PROPERTY_READ));
768 BluetoothGattCharacteristic* location_ptr = body_sensor_location.get(); 770 BluetoothGattCharacteristic* location_chest_ptr =
771 body_sensor_location_chest.get();
769 772
770 ON_CALL(*body_sensor_location, ReadRemoteCharacteristic(_, _)) 773 ON_CALL(*body_sensor_location_chest, ReadRemoteCharacteristic(_, _))
771 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 774 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
772 [adapter, location_ptr]() { 775 [adapter, location_chest_ptr]() {
773 std::vector<uint8_t> location(1 /* size */); 776 std::vector<uint8_t> location(1 /* size */);
774 location[0] = 1; // Chest 777 location[0] = 1; // Chest
775 // Read a characteristic has a side effect of 778 // Read a characteristic has a side effect of
776 // GattCharacteristicValueChanged being called. 779 // GattCharacteristicValueChanged being called.
777 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, 780 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
778 adapter->GetObservers(), 781 adapter->GetObservers(),
779 GattCharacteristicValueChanged( 782 GattCharacteristicValueChanged(
780 adapter, location_ptr, location)); 783 adapter, location_chest_ptr, location));
784 return location;
785 }));
786
787 // Body Sensor Location Characteristic (Wrist)
788 scoped_ptr<NiceMockBluetoothGattCharacteristic> body_sensor_location_wrist(
789 GetBaseGATTCharacteristic("Body Sensor Location Wrist", heart_rate.get(),
790 kBodySensorLocation,
791 BluetoothGattCharacteristic::PROPERTY_READ));
792 BluetoothGattCharacteristic* location_wrist_ptr =
793 body_sensor_location_wrist.get();
794
795 ON_CALL(*body_sensor_location_wrist, ReadRemoteCharacteristic(_, _))
796 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
797 [adapter, location_wrist_ptr]() {
798 std::vector<uint8_t> location(1 /* size */);
799 location[0] = 2; // Wrist
800 // Read a characteristic has a side effect of
801 // GattCharacteristicValueChanged being called.
802 FOR_EACH_OBSERVER(BluetoothAdapter::Observer,
803 adapter->GetObservers(),
804 GattCharacteristicValueChanged(
805 adapter, location_wrist_ptr, location));
781 return location; 806 return location;
782 })); 807 }));
783 808
784 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement)); 809 heart_rate->AddMockCharacteristic(std::move(heart_rate_measurement));
785 heart_rate->AddMockCharacteristic(std::move(body_sensor_location)); 810 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_chest));
811 heart_rate->AddMockCharacteristic(std::move(body_sensor_location_wrist));
786 812
787 return heart_rate; 813 return heart_rate;
788 } 814 }
789 815
790 // Characteristics 816 // Characteristics
791 817
792 // static 818 // static
793 scoped_ptr<NiceMockBluetoothGattCharacteristic> 819 scoped_ptr<NiceMockBluetoothGattCharacteristic>
794 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic( 820 LayoutTestBluetoothAdapterProvider::GetBaseGATTCharacteristic(
821 const std::string& identifier,
795 MockBluetoothGattService* service, 822 MockBluetoothGattService* service,
796 const std::string& uuid, 823 const std::string& uuid,
797 BluetoothGattCharacteristic::Properties properties) { 824 BluetoothGattCharacteristic::Properties properties) {
798 return make_scoped_ptr(new NiceMockBluetoothGattCharacteristic( 825 return make_scoped_ptr(new NiceMockBluetoothGattCharacteristic(
799 service, uuid + " Identifier", BluetoothUUID(uuid), false /* is_local */, 826 service, identifier, BluetoothUUID(uuid), false /* is_local */,
800 properties, NULL /* permissions */)); 827 properties, NULL /* permissions */));
801 } 828 }
802 829
803 // static 830 // static
804 scoped_ptr<NiceMockBluetoothGattCharacteristic> 831 scoped_ptr<NiceMockBluetoothGattCharacteristic>
805 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic( 832 LayoutTestBluetoothAdapterProvider::GetErrorCharacteristic(
806 MockBluetoothGattService* service, 833 MockBluetoothGattService* service,
807 BluetoothGattService::GattErrorCode error_code) { 834 BluetoothGattService::GattErrorCode error_code) {
808 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1. 835 uint32_t error_alias = error_code + 0xA1; // Error UUIDs start at 0xA1.
809 scoped_ptr<NiceMockBluetoothGattCharacteristic> characteristic( 836 scoped_ptr<NiceMockBluetoothGattCharacteristic> characteristic(
810 GetBaseGATTCharacteristic( 837 GetBaseGATTCharacteristic(
811 service, 838 // Use the UUID to generate unique identifiers.
839 "Error Characteristic " + errorUUID(error_alias), service,
812 errorUUID(error_alias), 840 errorUUID(error_alias),
813 BluetoothGattCharacteristic::PROPERTY_READ | 841 BluetoothGattCharacteristic::PROPERTY_READ |
814 BluetoothGattCharacteristic::PROPERTY_WRITE | 842 BluetoothGattCharacteristic::PROPERTY_WRITE |
815 BluetoothGattCharacteristic::PROPERTY_INDICATE)); 843 BluetoothGattCharacteristic::PROPERTY_INDICATE));
816
817 844
818 // Read response. 845 // Read response.
819 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _)) 846 ON_CALL(*characteristic, ReadRemoteCharacteristic(_, _))
820 .WillByDefault(RunCallback<1 /* error_callback */>(error_code)); 847 .WillByDefault(RunCallback<1 /* error_callback */>(error_code));
821 848
822 // Write response. 849 // Write response.
823 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _)) 850 ON_CALL(*characteristic, WriteRemoteCharacteristic(_, _, _))
824 .WillByDefault(RunCallback<2 /* error_callback */>(error_code)); 851 .WillByDefault(RunCallback<2 /* error_callback */>(error_code));
825 852
826 // StartNotifySession response 853 // StartNotifySession response
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 return BluetoothUUID(); 928 return BluetoothUUID();
902 } 929 }
903 930
904 // static 931 // static
905 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 932 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
906 return BluetoothDevice::CanonicalizeAddress( 933 return BluetoothDevice::CanonicalizeAddress(
907 base::StringPrintf("%012" PRIx64, addr)); 934 base::StringPrintf("%012" PRIx64, addr));
908 } 935 }
909 936
910 } // namespace content 937 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698