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

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

Issue 2445633002: bluetooth: Require frame to be connected for writValue to succeed. (Closed)
Patch Set: Fix documentation Created 4 years, 1 month 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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 663
664 std::unique_ptr<NiceMockBluetoothGattService> health_thermometer( 664 std::unique_ptr<NiceMockBluetoothGattService> health_thermometer(
665 GetBaseGATTService("Health Thermometer", device.get(), 665 GetBaseGATTService("Health Thermometer", device.get(),
666 kHealthThermometerUUID)); 666 kHealthThermometerUUID));
667 667
668 // Measurement Interval 668 // Measurement Interval
669 std::unique_ptr<NiceMockBluetoothGattCharacteristic> measurement_interval( 669 std::unique_ptr<NiceMockBluetoothGattCharacteristic> measurement_interval(
670 GetBaseGATTCharacteristic( 670 GetBaseGATTCharacteristic(
671 "Measurement Interval", health_thermometer.get(), 671 "Measurement Interval", health_thermometer.get(),
672 kMeasurementIntervalUUID, 672 kMeasurementIntervalUUID,
673 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 673 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
674 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
674 NiceMockBluetoothGattCharacteristic* measurement_ptr = 675 NiceMockBluetoothGattCharacteristic* measurement_ptr =
675 measurement_interval.get(); 676 measurement_interval.get();
676 677
677 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _)) 678 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _))
678 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 679 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
679 [adapter_ptr, measurement_ptr]() { 680 [adapter_ptr, measurement_ptr]() {
680 std::vector<uint8_t> interval({1}); 681 std::vector<uint8_t> interval({1});
681 for (auto& observer : adapter_ptr->GetObservers()) { 682 for (auto& observer : adapter_ptr->GetObservers()) {
682 observer.GattCharacteristicValueChanged( 683 observer.GattCharacteristicValueChanged(
683 adapter_ptr, measurement_ptr, interval); 684 adapter_ptr, measurement_ptr, interval);
684 } 685 }
685 return interval; 686 return interval;
686 })); 687 }));
687 // TODO(crbug.com/608538): Mock Write and StartNotifySession. 688
689 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _))
690 .WillByDefault(RunCallback<1 /* success callback */>());
691
692 // TODO(crbug.com/608538): Mock StartNotifySession.
688 693
689 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 694 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
690 device->AddMockService(std::move(health_thermometer)); 695 device->AddMockService(std::move(health_thermometer));
691 696
692 adapter->AddMockDevice(std::move(device)); 697 adapter->AddMockDevice(std::move(device));
693 698
694 return adapter; 699 return adapter;
695 } 700 }
696 701
697 // static 702 // static
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 900
896 std::unique_ptr<NiceMockBluetoothGattService> health_thermometer( 901 std::unique_ptr<NiceMockBluetoothGattService> health_thermometer(
897 GetBaseGATTService("Health Thermometer", device.get(), 902 GetBaseGATTService("Health Thermometer", device.get(),
898 kHealthThermometerUUID)); 903 kHealthThermometerUUID));
899 904
900 // Measurement Interval 905 // Measurement Interval
901 std::unique_ptr<NiceMockBluetoothGattCharacteristic> measurement_interval( 906 std::unique_ptr<NiceMockBluetoothGattCharacteristic> measurement_interval(
902 GetBaseGATTCharacteristic( 907 GetBaseGATTCharacteristic(
903 "Measurement Interval", health_thermometer.get(), 908 "Measurement Interval", health_thermometer.get(),
904 kMeasurementIntervalUUID, 909 kMeasurementIntervalUUID,
905 BluetoothRemoteGattCharacteristic::PROPERTY_READ)); 910 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
911 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));
906 NiceMockBluetoothGattCharacteristic* measurement_ptr = 912 NiceMockBluetoothGattCharacteristic* measurement_ptr =
907 measurement_interval.get(); 913 measurement_interval.get();
908 914
909 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _)) 915 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _))
910 .WillByDefault(Invoke([adapter_ptr, device_ptr, measurement_ptr, 916 .WillByDefault(Invoke([adapter_ptr, device_ptr, measurement_ptr,
911 disconnect, succeeds]( 917 disconnect, succeeds](
912 const BluetoothRemoteGattCharacteristic::ValueCallback& callback, 918 const BluetoothRemoteGattCharacteristic::ValueCallback& callback,
913 const BluetoothRemoteGattCharacteristic::ErrorCallback& 919 const BluetoothRemoteGattCharacteristic::ErrorCallback&
914 error_callback) { 920 error_callback) {
915 base::Closure pending; 921 base::Closure pending;
916 if (succeeds) { 922 if (succeeds) {
917 pending = 923 pending =
918 base::Bind(&PerformReadValue, base::RetainedRef(adapter_ptr), 924 base::Bind(&PerformReadValue, base::RetainedRef(adapter_ptr),
919 measurement_ptr, callback, std::vector<uint8_t>({1})); 925 measurement_ptr, callback, std::vector<uint8_t>({1}));
920 } else { 926 } else {
921 pending = base::Bind(error_callback, 927 pending = base::Bind(error_callback,
922 BluetoothRemoteGattService::GATT_ERROR_FAILED); 928 BluetoothRemoteGattService::GATT_ERROR_FAILED);
923 } 929 }
924 device_ptr->PushPendingCallback(pending); 930 device_ptr->PushPendingCallback(pending);
925 if (disconnect) { 931 if (disconnect) {
926 device_ptr->SetConnected(false); 932 device_ptr->SetConnected(false);
927 base::ThreadTaskRunnerHandle::Get()->PostTask( 933 base::ThreadTaskRunnerHandle::Get()->PostTask(
928 FROM_HERE, 934 FROM_HERE,
929 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), 935 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
930 device_ptr)); 936 device_ptr));
931 } 937 }
932 })); 938 }));
933 939
940 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _))
941 .WillByDefault(Invoke([adapter_ptr, device_ptr, disconnect, succeeds](
942 const std::vector<uint8_t>& value, const base::Closure& callback,
943 const BluetoothRemoteGattCharacteristic::ErrorCallback&
944 error_callback) {
945 base::Closure pending;
946 if (succeeds) {
947 pending = callback;
948 } else {
949 pending = base::Bind(error_callback,
950 BluetoothRemoteGattService::GATT_ERROR_FAILED);
951 }
952 device_ptr->PushPendingCallback(pending);
953 if (disconnect) {
954 device_ptr->SetConnected(false);
955 base::ThreadTaskRunnerHandle::Get()->PostTask(
956 FROM_HERE,
957 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
958 device_ptr));
959 }
960 }));
934 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 961 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
935 device->AddMockService(std::move(health_thermometer)); 962 device->AddMockService(std::move(health_thermometer));
936 adapter->AddMockDevice(std::move(device)); 963 adapter->AddMockDevice(std::move(device));
937 964
938 return adapter; 965 return adapter;
939 } 966 }
940 967
941 // static 968 // static
942 scoped_refptr<NiceMockBluetoothAdapter> 969 scoped_refptr<NiceMockBluetoothAdapter>
943 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { 970 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() {
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 return BluetoothUUID(); 1559 return BluetoothUUID();
1533 } 1560 }
1534 1561
1535 // static 1562 // static
1536 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1563 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1537 return BluetoothDevice::CanonicalizeAddress( 1564 return BluetoothDevice::CanonicalizeAddress(
1538 base::StringPrintf("%012" PRIx64, addr)); 1565 base::StringPrintf("%012" PRIx64, addr));
1539 } 1566 }
1540 1567
1541 } // namespace content 1568 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698