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

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

Issue 2447593002: bluetooth: Require frame to be connected for startNotifications to succeed. (Closed)
Patch Set: Remove stopNotifications code 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 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE |
675 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY));
675 NiceMockBluetoothGattCharacteristic* measurement_ptr = 676 NiceMockBluetoothGattCharacteristic* measurement_ptr =
676 measurement_interval.get(); 677 measurement_interval.get();
677 678
678 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _)) 679 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _))
679 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>( 680 .WillByDefault(RunCallbackWithResult<0 /* success_callback */>(
680 [adapter_ptr, measurement_ptr]() { 681 [adapter_ptr, measurement_ptr]() {
681 std::vector<uint8_t> interval({1}); 682 std::vector<uint8_t> interval({1});
682 for (auto& observer : adapter_ptr->GetObservers()) { 683 for (auto& observer : adapter_ptr->GetObservers()) {
683 observer.GattCharacteristicValueChanged( 684 observer.GattCharacteristicValueChanged(
684 adapter_ptr, measurement_ptr, interval); 685 adapter_ptr, measurement_ptr, interval);
685 } 686 }
686 return interval; 687 return interval;
687 })); 688 }));
688 689
689 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _)) 690 ON_CALL(*measurement_interval, WriteRemoteCharacteristic(_, _, _))
690 .WillByDefault(RunCallback<1 /* success callback */>()); 691 .WillByDefault(RunCallback<1 /* success_callback */>());
691 692
692 // TODO(crbug.com/608538): Mock StartNotifySession. 693 ON_CALL(*measurement_interval, StartNotifySession(_, _))
694 .WillByDefault(
695 RunCallbackWithResult<0 /* success_callback */>([measurement_ptr]() {
696 return GetBaseGATTNotifySession(measurement_ptr->GetWeakPtr());
697 }));
693 698
694 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 699 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
695 device->AddMockService(std::move(health_thermometer)); 700 device->AddMockService(std::move(health_thermometer));
696 701
697 adapter->AddMockDevice(std::move(device)); 702 adapter->AddMockDevice(std::move(device));
698 703
699 return adapter; 704 return adapter;
700 } 705 }
701 706
702 // static 707 // static
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 std::unique_ptr<NiceMockBluetoothGattService> health_thermometer( 906 std::unique_ptr<NiceMockBluetoothGattService> health_thermometer(
902 GetBaseGATTService("Health Thermometer", device.get(), 907 GetBaseGATTService("Health Thermometer", device.get(),
903 kHealthThermometerUUID)); 908 kHealthThermometerUUID));
904 909
905 // Measurement Interval 910 // Measurement Interval
906 std::unique_ptr<NiceMockBluetoothGattCharacteristic> measurement_interval( 911 std::unique_ptr<NiceMockBluetoothGattCharacteristic> measurement_interval(
907 GetBaseGATTCharacteristic( 912 GetBaseGATTCharacteristic(
908 "Measurement Interval", health_thermometer.get(), 913 "Measurement Interval", health_thermometer.get(),
909 kMeasurementIntervalUUID, 914 kMeasurementIntervalUUID,
910 BluetoothRemoteGattCharacteristic::PROPERTY_READ | 915 BluetoothRemoteGattCharacteristic::PROPERTY_READ |
911 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE)); 916 BluetoothRemoteGattCharacteristic::PROPERTY_WRITE |
917 BluetoothRemoteGattCharacteristic::PROPERTY_NOTIFY));
912 NiceMockBluetoothGattCharacteristic* measurement_ptr = 918 NiceMockBluetoothGattCharacteristic* measurement_ptr =
913 measurement_interval.get(); 919 measurement_interval.get();
914 920
915 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _)) 921 ON_CALL(*measurement_interval, ReadRemoteCharacteristic(_, _))
916 .WillByDefault(Invoke([adapter_ptr, device_ptr, measurement_ptr, 922 .WillByDefault(Invoke([adapter_ptr, device_ptr, measurement_ptr,
917 disconnect, succeeds]( 923 disconnect, succeeds](
918 const BluetoothRemoteGattCharacteristic::ValueCallback& callback, 924 const BluetoothRemoteGattCharacteristic::ValueCallback& callback,
919 const BluetoothRemoteGattCharacteristic::ErrorCallback& 925 const BluetoothRemoteGattCharacteristic::ErrorCallback&
920 error_callback) { 926 error_callback) {
921 base::Closure pending; 927 base::Closure pending;
(...skipping 29 matching lines...) Expand all
951 } 957 }
952 device_ptr->PushPendingCallback(pending); 958 device_ptr->PushPendingCallback(pending);
953 if (disconnect) { 959 if (disconnect) {
954 device_ptr->SetConnected(false); 960 device_ptr->SetConnected(false);
955 base::ThreadTaskRunnerHandle::Get()->PostTask( 961 base::ThreadTaskRunnerHandle::Get()->PostTask(
956 FROM_HERE, 962 FROM_HERE,
957 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr), 963 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
958 device_ptr)); 964 device_ptr));
959 } 965 }
960 })); 966 }));
967
968 ON_CALL(*measurement_interval, StartNotifySession(_, _))
969 .WillByDefault(Invoke([adapter_ptr, device_ptr, measurement_ptr,
970 disconnect, succeeds](
971 const BluetoothRemoteGattCharacteristic::NotifySessionCallback&
972 callback,
973 const BluetoothRemoteGattCharacteristic::ErrorCallback&
974 error_callback) {
975 base::Closure pending;
976 if (succeeds) {
977 pending = base::Bind(callback, base::Passed(GetBaseGATTNotifySession(
978 measurement_ptr->GetWeakPtr())));
979 } else {
980 pending = base::Bind(error_callback,
981 BluetoothRemoteGattService::GATT_ERROR_FAILED);
982 }
983 device_ptr->PushPendingCallback(pending);
984 if (disconnect) {
985 device_ptr->SetConnected(false);
986 base::ThreadTaskRunnerHandle::Get()->PostTask(
987 FROM_HERE,
988 base::Bind(&NotifyDeviceChanged, base::RetainedRef(adapter_ptr),
989 device_ptr));
990 }
991 }));
992
961 health_thermometer->AddMockCharacteristic(std::move(measurement_interval)); 993 health_thermometer->AddMockCharacteristic(std::move(measurement_interval));
962 device->AddMockService(std::move(health_thermometer)); 994 device->AddMockService(std::move(health_thermometer));
963 adapter->AddMockDevice(std::move(device)); 995 adapter->AddMockDevice(std::move(device));
964 996
965 return adapter; 997 return adapter;
966 } 998 }
967 999
968 // static 1000 // static
969 scoped_refptr<NiceMockBluetoothAdapter> 1001 scoped_refptr<NiceMockBluetoothAdapter>
970 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() { 1002 LayoutTestBluetoothAdapterProvider::GetBlacklistTestAdapter() {
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 return BluetoothUUID(); 1591 return BluetoothUUID();
1560 } 1592 }
1561 1593
1562 // static 1594 // static
1563 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) { 1595 std::string LayoutTestBluetoothAdapterProvider::makeMACAddress(uint64_t addr) {
1564 return BluetoothDevice::CanonicalizeAddress( 1596 return BluetoothDevice::CanonicalizeAddress(
1565 base::StringPrintf("%012" PRIx64, addr)); 1597 base::StringPrintf("%012" PRIx64, addr));
1566 } 1598 }
1567 1599
1568 } // namespace content 1600 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698