summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/test
diff options
context:
space:
mode:
Diffstat (limited to 'device/bluetooth/test')
-rw-r--r--device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java72
-rw-r--r--device/bluetooth/test/bluetooth_test.cc1
-rw-r--r--device/bluetooth/test/bluetooth_test.h36
-rw-r--r--device/bluetooth/test/bluetooth_test_android.cc87
-rw-r--r--device/bluetooth/test/bluetooth_test_android.h24
5 files changed, 215 insertions, 5 deletions
diff --git a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
index 46f9c66..f3d98a7 100644
--- a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
+++ b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
@@ -368,6 +368,7 @@ class Fakes {
boolean mReadCharacteristicWillFailSynchronouslyOnce = false;
boolean mSetCharacteristicNotificationWillFailSynchronouslyOnce = false;
boolean mWriteCharacteristicWillFailSynchronouslyOnce = false;
+ boolean mReadDescriptorWillFailSynchronouslyOnce = false;
boolean mWriteDescriptorWillFailSynchronouslyOnce = false;
public FakeBluetoothGatt(FakeBluetoothDevice device) {
@@ -431,6 +432,16 @@ class Fakes {
}
@Override
+ boolean readDescriptor(Wrappers.BluetoothGattDescriptorWrapper descriptor) {
+ if (mReadDescriptorWillFailSynchronouslyOnce) {
+ mReadDescriptorWillFailSynchronouslyOnce = false;
+ return false;
+ }
+ nativeOnFakeBluetoothGattReadDescriptor(mDevice.mAdapter.mNativeBluetoothTestAndroid);
+ return true;
+ }
+
+ @Override
boolean writeDescriptor(Wrappers.BluetoothGattDescriptorWrapper descriptor) {
if (mWriteDescriptorWillFailSynchronouslyOnce) {
mWriteDescriptorWillFailSynchronouslyOnce = false;
@@ -686,15 +697,65 @@ class Fakes {
final FakeBluetoothGattCharacteristic mCharacteristic;
final UUID mUuid;
byte[] mValue;
+ static FakeBluetoothGattDescriptor sRememberedDescriptor;
public FakeBluetoothGattDescriptor(
FakeBluetoothGattCharacteristic characteristic, UUID uuid) {
- super(null);
+ super(null, null);
mCharacteristic = characteristic;
mUuid = uuid;
mValue = new byte[0];
}
+ // Implements BluetoothTestAndroid::RememberDescriptorForSubsequentAction.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void rememberDescriptorForSubsequentAction(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor) {
+ sRememberedDescriptor = (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+ }
+
+ // Simulate a value being read from a descriptor.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void valueRead(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status, byte[] value) {
+ if (chromeDescriptor == null && sRememberedDescriptor == null)
+ throw new IllegalArgumentException("rememberDescriptor wasn't called previously.");
+
+ FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == null)
+ ? sRememberedDescriptor
+ : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+
+ fakeDescriptor.mValue = value;
+ fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDescriptorRead(
+ fakeDescriptor, status);
+ }
+
+ // Simulate a value being written to a descriptor.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void valueWrite(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status) {
+ if (chromeDescriptor == null && sRememberedDescriptor == null)
+ throw new IllegalArgumentException("rememberDescriptor wasn't called previously.");
+
+ FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == null)
+ ? sRememberedDescriptor
+ : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+
+ fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDescriptorWrite(
+ fakeDescriptor, status);
+ }
+
+ // Cause subsequent value read of a descriptor to fail synchronously.
+ @CalledByNative("FakeBluetoothGattDescriptor")
+ private static void setReadDescriptorWillFailSynchronouslyOnce(
+ ChromeBluetoothRemoteGattDescriptor chromeDescriptor) {
+ FakeBluetoothGattDescriptor fakeDescriptor =
+ (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
+
+ fakeDescriptor.mCharacteristic.mService.mDevice.mGatt
+ .mReadDescriptorWillFailSynchronouslyOnce = true;
+ }
+
// Cause subsequent value write of a descriptor to fail synchronously.
@CalledByNative("FakeBluetoothGattDescriptor")
private static void setWriteDescriptorWillFailSynchronouslyOnce(
@@ -710,6 +771,11 @@ class Fakes {
// Wrappers.BluetoothGattDescriptorWrapper overrides:
@Override
+ public Wrappers.BluetoothGattCharacteristicWrapper getCharacteristic() {
+ return mCharacteristic;
+ }
+
+ @Override
public UUID getUuid() {
return mUuid;
}
@@ -759,6 +825,10 @@ class Fakes {
private static native void nativeOnFakeBluetoothGattWriteCharacteristic(
long nativeBluetoothTestAndroid, byte[] value);
+ // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor.
+ private static native void nativeOnFakeBluetoothGattReadDescriptor(
+ long nativeBluetoothTestAndroid);
+
// Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor.
private static native void nativeOnFakeBluetoothGattWriteDescriptor(
long nativeBluetoothTestAndroid, byte[] value);
diff --git a/device/bluetooth/test/bluetooth_test.cc b/device/bluetooth/test/bluetooth_test.cc
index 5feec01..77ecddc 100644
--- a/device/bluetooth/test/bluetooth_test.cc
+++ b/device/bluetooth/test/bluetooth_test.cc
@@ -231,6 +231,7 @@ void BluetoothTestBase::ResetEventCounts() {
gatt_notify_characteristic_attempts_ = 0;
gatt_read_characteristic_attempts_ = 0;
gatt_write_characteristic_attempts_ = 0;
+ gatt_read_descriptor_attempts_ = 0;
gatt_write_descriptor_attempts_ = 0;
}
diff --git a/device/bluetooth/test/bluetooth_test.h b/device/bluetooth/test/bluetooth_test.h
index 5570ca1..c840935 100644
--- a/device/bluetooth/test/bluetooth_test.h
+++ b/device/bluetooth/test/bluetooth_test.h
@@ -189,6 +189,41 @@ class BluetoothTestBase : public testing::Test {
BluetoothGattCharacteristic* characteristic,
const std::string& uuid) {}
+ // Remembers |descriptor|'s platform specific object to be used in a
+ // subsequent call to methods such as SimulateGattDescriptorRead that
+ // accept a nullptr value to select this remembered descriptor. This
+ // enables tests where the platform attempts to reference descriptor
+ // objects after the Chrome objects have been deleted, e.g. with DeleteDevice.
+ virtual void RememberDescriptorForSubsequentAction(
+ BluetoothGattDescriptor* descriptor) {}
+
+ // Simulates a Descriptor Read operation succeeding, returning |value|.
+ // If |descriptor| is null, acts upon the descriptor provided to
+ // RememberDescriptorForSubsequentAction.
+ virtual void SimulateGattDescriptorRead(BluetoothGattDescriptor* descriptor,
+ const std::vector<uint8_t>& value) {}
+
+ // Simulates a Descriptor Read operation failing with a GattErrorCode.
+ virtual void SimulateGattDescriptorReadError(
+ BluetoothGattDescriptor* descriptor,
+ BluetoothGattService::GattErrorCode) {}
+
+ // Simulates a Descriptor Read operation failing synchronously once for an
+ // unknown reason.
+ virtual void SimulateGattDescriptorReadWillFailSynchronouslyOnce(
+ BluetoothGattDescriptor* descriptor) {}
+
+ // Simulates a Descriptor Write operation succeeding, returning |value|.
+ // If |descriptor| is null, acts upon the descriptor provided to
+ // RememberDescriptorForSubsequentAction.
+ virtual void SimulateGattDescriptorWrite(
+ BluetoothGattDescriptor* descriptor) {}
+
+ // Simulates a Descriptor Write operation failing with a GattErrorCode.
+ virtual void SimulateGattDescriptorWriteError(
+ BluetoothGattDescriptor* descriptor,
+ BluetoothGattService::GattErrorCode) {}
+
// Simulates a Descriptor Write operation failing synchronously once for
// an unknown reason.
virtual void SimulateGattDescriptorWriteWillFailSynchronouslyOnce(
@@ -250,6 +285,7 @@ class BluetoothTestBase : public testing::Test {
int gatt_notify_characteristic_attempts_ = 0;
int gatt_read_characteristic_attempts_ = 0;
int gatt_write_characteristic_attempts_ = 0;
+ int gatt_read_descriptor_attempts_ = 0;
int gatt_write_descriptor_attempts_ = 0;
// The following values are used to make sure the correct callbacks
diff --git a/device/bluetooth/test/bluetooth_test_android.cc b/device/bluetooth/test/bluetooth_test_android.cc
index 522cd61..b1cd357 100644
--- a/device/bluetooth/test/bluetooth_test_android.cc
+++ b/device/bluetooth/test/bluetooth_test_android.cc
@@ -176,10 +176,14 @@ void BluetoothTestAndroid::RememberCharacteristicForSubsequentAction(
void BluetoothTestAndroid::SimulateGattNotifySessionStarted(
BluetoothGattCharacteristic* characteristic) {
- // Android doesn't provide any sort of callback for when notifications have
- // been enabled. So, just run the message loop to process the success
- // callback.
- base::RunLoop().RunUntilIdle();
+ BluetoothGattDescriptor* descriptor = characteristic->GetDescriptorForUUID(
+ BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid());
+ BluetoothRemoteGattDescriptorAndroid* descriptor_android =
+ static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
+ Java_FakeBluetoothGattDescriptor_valueWrite(
+ base::android::AttachCurrentThread(),
+ descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr,
+ 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS
}
void BluetoothTestAndroid::
@@ -291,6 +295,75 @@ void BluetoothTestAndroid::SimulateGattDescriptor(
base::android::ConvertUTF8ToJavaString(env, uuid).obj());
}
+void BluetoothTestAndroid::RememberDescriptorForSubsequentAction(
+ BluetoothGattDescriptor* descriptor) {
+ BluetoothRemoteGattDescriptorAndroid* descriptor_android =
+ static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
+
+ Java_FakeBluetoothGattDescriptor_rememberDescriptorForSubsequentAction(
+ base::android::AttachCurrentThread(),
+ descriptor_android->GetJavaObject().obj());
+}
+
+void BluetoothTestAndroid::SimulateGattDescriptorRead(
+ BluetoothGattDescriptor* descriptor,
+ const std::vector<uint8_t>& value) {
+ BluetoothRemoteGattDescriptorAndroid* descriptor_android =
+ static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
+ JNIEnv* env = base::android::AttachCurrentThread();
+
+ Java_FakeBluetoothGattDescriptor_valueRead(
+ env,
+ descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr,
+ 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS
+ base::android::ToJavaByteArray(env, value).obj());
+}
+
+void BluetoothTestAndroid::SimulateGattDescriptorReadError(
+ BluetoothGattDescriptor* descriptor,
+ BluetoothGattService::GattErrorCode error_code) {
+ BluetoothRemoteGattDescriptorAndroid* descriptor_android =
+ static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
+ JNIEnv* env = base::android::AttachCurrentThread();
+ std::vector<uint8_t> empty_value;
+
+ Java_FakeBluetoothGattDescriptor_valueRead(
+ env, descriptor_android->GetJavaObject().obj(),
+ BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code),
+ base::android::ToJavaByteArray(env, empty_value).obj());
+}
+
+void BluetoothTestAndroid::SimulateGattDescriptorReadWillFailSynchronouslyOnce(
+ BluetoothGattDescriptor* descriptor) {
+ BluetoothRemoteGattDescriptorAndroid* descriptor_android =
+ static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
+ JNIEnv* env = base::android::AttachCurrentThread();
+
+ Java_FakeBluetoothGattDescriptor_setReadDescriptorWillFailSynchronouslyOnce(
+ env, descriptor_android->GetJavaObject().obj());
+}
+
+void BluetoothTestAndroid::SimulateGattDescriptorWrite(
+ BluetoothGattDescriptor* descriptor) {
+ BluetoothRemoteGattDescriptorAndroid* descriptor_android =
+ static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
+ Java_FakeBluetoothGattDescriptor_valueWrite(
+ base::android::AttachCurrentThread(),
+ descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr,
+ 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS
+}
+
+void BluetoothTestAndroid::SimulateGattDescriptorWriteError(
+ BluetoothGattDescriptor* descriptor,
+ BluetoothGattService::GattErrorCode error_code) {
+ BluetoothRemoteGattDescriptorAndroid* descriptor_android =
+ static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
+ Java_FakeBluetoothGattDescriptor_valueWrite(
+ base::android::AttachCurrentThread(),
+ descriptor_android->GetJavaObject().obj(),
+ BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code));
+}
+
void BluetoothTestAndroid::SimulateGattDescriptorWriteWillFailSynchronouslyOnce(
BluetoothGattDescriptor* descriptor) {
BluetoothRemoteGattDescriptorAndroid* descriptor_android =
@@ -348,6 +421,12 @@ void BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic(
base::android::JavaByteArrayToByteVector(env, value, &last_write_value_);
}
+void BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor(
+ JNIEnv* env,
+ const JavaParamRef<jobject>& caller) {
+ gatt_read_descriptor_attempts_++;
+}
+
void BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor(
JNIEnv* env,
const JavaParamRef<jobject>& caller,
diff --git a/device/bluetooth/test/bluetooth_test_android.h b/device/bluetooth/test/bluetooth_test_android.h
index b855eca..8fbf61c 100644
--- a/device/bluetooth/test/bluetooth_test_android.h
+++ b/device/bluetooth/test/bluetooth_test_android.h
@@ -51,6 +51,7 @@ class BluetoothTestAndroid : public BluetoothTestBase {
void SimulateGattCharacteristicChanged(
BluetoothGattCharacteristic* characteristic,
const std::vector<uint8_t>& value) override;
+
void SimulateGattCharacteristicRead(
BluetoothGattCharacteristic* characteristic,
const std::vector<uint8_t>& value) override;
@@ -59,6 +60,7 @@ class BluetoothTestAndroid : public BluetoothTestBase {
BluetoothGattService::GattErrorCode) override;
void SimulateGattCharacteristicReadWillFailSynchronouslyOnce(
BluetoothGattCharacteristic* characteristic) override;
+
void SimulateGattCharacteristicWrite(
BluetoothGattCharacteristic* characteristic) override;
void SimulateGattCharacteristicWriteError(
@@ -66,8 +68,25 @@ class BluetoothTestAndroid : public BluetoothTestBase {
BluetoothGattService::GattErrorCode) override;
void SimulateGattCharacteristicWriteWillFailSynchronouslyOnce(
BluetoothGattCharacteristic* characteristic) override;
+
void SimulateGattDescriptor(BluetoothGattCharacteristic* characteristic,
const std::string& uuid) override;
+ void RememberDescriptorForSubsequentAction(
+ BluetoothGattDescriptor* descriptor) override;
+
+ void SimulateGattDescriptorRead(BluetoothGattDescriptor* descriptor,
+ const std::vector<uint8_t>& value) override;
+ void SimulateGattDescriptorReadError(
+ BluetoothGattDescriptor* descriptor,
+ BluetoothGattService::GattErrorCode) override;
+ void SimulateGattDescriptorReadWillFailSynchronouslyOnce(
+ BluetoothGattDescriptor* descriptor) override;
+
+ void SimulateGattDescriptorWrite(
+ BluetoothGattDescriptor* descriptor) override;
+ void SimulateGattDescriptorWriteError(
+ BluetoothGattDescriptor* descriptor,
+ BluetoothGattService::GattErrorCode) override;
void SimulateGattDescriptorWriteWillFailSynchronouslyOnce(
BluetoothGattDescriptor* descriptor) override;
@@ -112,6 +131,11 @@ class BluetoothTestAndroid : public BluetoothTestBase {
const base::android::JavaParamRef<jobject>& caller,
const base::android::JavaParamRef<jbyteArray>& value);
+ // Records that Java FakeBluetoothGatt readDescriptor was called.
+ void OnFakeBluetoothGattReadDescriptor(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& caller);
+
// Records that Java FakeBluetoothGatt writeDescriptor was called.
void OnFakeBluetoothGattWriteDescriptor(
JNIEnv* env,