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

Unified Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc

Issue 2085293002: bluetooth: Call GattCharacteristicValueChanged after a read succeeds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Use a lambda to check that GattCharacteristicValueChanged has been called Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
diff --git a/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc b/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
index cc2186403f75d4fa8947fbfdec457d925a7a5e7c..37f205f6c8c8095b011244ae1b6863ad2bf7898d 100644
--- a/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_characteristic_unittest.cc
@@ -5,6 +5,7 @@
#include <stdint.h>
#include <utility>
+#include "base/bind.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "build/build_config.h"
@@ -383,8 +384,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) {
GetReadValueCallback(Call::EXPECTED),
GetGattErrorCallback(Call::NOT_EXPECTED));
- uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
- std::vector<uint8_t> test_vector(values, values + arraysize(values));
+ std::vector<uint8_t> test_vector = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
SimulateGattCharacteristicRead(characteristic1_, test_vector);
// Duplicate read reported from OS shouldn't cause a problem:
@@ -398,6 +398,46 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, ReadRemoteCharacteristic) {
#endif // defined(OS_ANDROID) || defined(OS_WIN)
#if defined(OS_ANDROID) || defined(OS_WIN)
+// Tests that ReadRemoteCharacteristic results in a
+// GattCharacteristicValueChanged call.
+TEST_F(BluetoothRemoteGattCharacteristicTest,
+ ReadRemoteCharacteristic_GattCharacteristicValueChanged) {
+ ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(
+ BluetoothRemoteGattCharacteristic::PROPERTY_READ));
+
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ // Callback that make sure GattCharacteristicValueChanged has been called
+ // before the callback runs.
+ auto test_callback = [](
+ BluetoothRemoteGattCharacteristic::ValueCallback callback,
+ const TestBluetoothAdapterObserver& callback_observer,
+ const std::vector<uint8_t>& value) {
+ EXPECT_EQ(1, callback_observer.gatt_characteristic_value_changed_count());
+ callback.Run(value);
+ };
+
+ characteristic1_->ReadRemoteCharacteristic(
+ base::Bind((void (*)(BluetoothRemoteGattCharacteristic::ValueCallback,
+ const TestBluetoothAdapterObserver&,
+ const std::vector<uint8_t>&))test_callback,
+ GetReadValueCallback(Call::EXPECTED),
+ base::ConstRef(observer)),
+ GetGattErrorCallback(Call::NOT_EXPECTED));
+
+ std::vector<uint8_t> test_vector = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
+ SimulateGattCharacteristicRead(characteristic1_, test_vector);
+
+ EXPECT_EQ(1, observer.gatt_characteristic_value_changed_count());
+ EXPECT_EQ(characteristic1_->GetIdentifier(),
+ observer.last_gatt_characteristic_id());
+ EXPECT_EQ(characteristic1_->GetUUID(),
+ observer.last_gatt_characteristic_uuid());
+ EXPECT_EQ(test_vector, observer.last_changed_characteristic_value());
+}
+#endif // defined(OS_ANDROID) || defined(OS_WIN)
+
+#if defined(OS_ANDROID) || defined(OS_WIN)
// Tests WriteRemoteCharacteristic with non-empty value buffer.
TEST_F(BluetoothRemoteGattCharacteristicTest, WriteRemoteCharacteristic) {
ASSERT_NO_FATAL_FAILURE(FakeCharacteristicBoilerplate(

Powered by Google App Engine
This is Rietveld 408576698