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

Unified Diff: device/bluetooth/test/bluetooth_test_android.cc

Issue 1256313002: bluetooth: android: Implement & test CreateGattConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split tests up into smaller tests Created 5 years, 3 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
« no previous file with comments | « device/bluetooth/test/bluetooth_test_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/test/bluetooth_test_android.cc
diff --git a/device/bluetooth/test/bluetooth_test_android.cc b/device/bluetooth/test/bluetooth_test_android.cc
index 1be588d51643d5559b18d5462e5313ab4ad5ba27..36b5c28d292ab2045d79d72a9660bdfd05af0c73 100644
--- a/device/bluetooth/test/bluetooth_test_android.cc
+++ b/device/bluetooth/test/bluetooth_test_android.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "device/bluetooth/android/wrappers.h"
#include "device/bluetooth/bluetooth_adapter_android.h"
+#include "device/bluetooth/bluetooth_device_android.h"
#include "jni/Fakes_jni.h"
using base::android::AttachCurrentThread;
@@ -40,8 +41,8 @@ void BluetoothTestAndroid::InitWithoutDefaultAdapter() {
}
void BluetoothTestAndroid::InitWithFakeAdapter() {
- j_fake_bluetooth_adapter_.Reset(
- Java_FakeBluetoothAdapter_create(AttachCurrentThread()));
+ j_fake_bluetooth_adapter_.Reset(Java_FakeBluetoothAdapter_create(
+ AttachCurrentThread(), reinterpret_cast<intptr_t>(this)));
adapter_ =
BluetoothAdapterAndroid::Create(j_fake_bluetooth_adapter_.obj()).get();
@@ -52,4 +53,65 @@ void BluetoothTestAndroid::DiscoverLowEnergyDevice(int device_ordinal) {
AttachCurrentThread(), j_fake_bluetooth_adapter_.obj(), device_ordinal);
}
+void BluetoothTestAndroid::CompleteGattConnection(BluetoothDevice* device) {
+ BluetoothDeviceAndroid* device_android =
+ static_cast<BluetoothDeviceAndroid*>(device);
+
+ Java_FakeBluetoothDevice_connectionStateChange(
+ AttachCurrentThread(), device_android->GetJavaObject().obj(),
+ 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS
+ true); // connected
+}
+
+void BluetoothTestAndroid::FailGattConnection(
+ BluetoothDevice* device,
+ BluetoothDevice::ConnectErrorCode error) {
+ int android_error_value = 0;
+ switch (error) { // Constants are from android.bluetooth.BluetoothGatt.
+ case BluetoothDevice::ERROR_FAILED:
+ android_error_value = 0x00000101; // GATT_FAILURE
+ break;
+ case BluetoothDevice::ERROR_AUTH_FAILED:
+ android_error_value = 0x00000005; // GATT_INSUFFICIENT_AUTHENTICATION
+ break;
+ case BluetoothDevice::ERROR_UNKNOWN:
+ case BluetoothDevice::ERROR_INPROGRESS:
+ case BluetoothDevice::ERROR_AUTH_CANCELED:
+ case BluetoothDevice::ERROR_AUTH_REJECTED:
+ case BluetoothDevice::ERROR_AUTH_TIMEOUT:
+ case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE:
+ NOTREACHED() << "No translation for error code: " << error;
+ }
+
+ BluetoothDeviceAndroid* device_android =
+ static_cast<BluetoothDeviceAndroid*>(device);
+
+ Java_FakeBluetoothDevice_connectionStateChange(
+ AttachCurrentThread(), device_android->GetJavaObject().obj(),
+ android_error_value,
+ false); // connected
+}
+
+void BluetoothTestAndroid::CompleteGattDisconnection(BluetoothDevice* device) {
+ BluetoothDeviceAndroid* device_android =
+ static_cast<BluetoothDeviceAndroid*>(device);
+
+ Java_FakeBluetoothDevice_connectionStateChange(
+ AttachCurrentThread(), device_android->GetJavaObject().obj(),
+ 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS
+ false); // disconnected
+}
+
+// Records that Java FakeBluetoothDevice connectGatt was called.
+void BluetoothTestAndroid::OnBluetoothDeviceConnectGattCalled(JNIEnv* env,
+ jobject caller) {
+ gatt_connection_attempt_count_++;
+}
+
+// Records that Java FakeBluetoothGatt disconnect was called.
+void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect(JNIEnv* env,
+ jobject caller) {
+ gatt_disconnection_attempt_count_++;
+}
+
} // namespace device
« no previous file with comments | « device/bluetooth/test/bluetooth_test_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698