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

Unified Diff: device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java

Issue 2708513002: bluetooth: Post a task when sending GATT events to simulate another thread. (Closed)
Patch Set: Remove unnecessary if statement Created 3 years, 9 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/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
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 998450a3a49b79e304583e73de3cb9a86d215947..b4a1b34cec29c354145561c8b65211351de923cb 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
@@ -75,6 +75,34 @@ class Fakes {
}
/**
+ * Sets the factory for ThreadUtilsWrapper to always post a task to the UI thread
+ * rather than running the task immediately. This simulates events arriving on a separate
+ * thread on Android.
+ * runOnUiThread uses nativePostTaskFromJava. This allows java to post tasks to the
+ * message loop that the test is using rather than to the Java message loop which
+ * is not running during tests.
+ */
+ @CalledByNative
+ public static void initFakeThreadUtilsWrapper(final long nativeBluetoothTestAndroid) {
+ Wrappers.ThreadUtilsWrapper.setFactory(new Wrappers.ThreadUtilsWrapper.Factory() {
+ @Override
+ public Wrappers.ThreadUtilsWrapper create() {
+ return new Wrappers.ThreadUtilsWrapper() {
+ @Override
+ public void runOnUiThread(Runnable r) {
+ nativePostTaskFromJava(nativeBluetoothTestAndroid, r);
+ }
+ };
+ }
+ });
+ }
+
+ @CalledByNative
+ public static void runRunnable(Runnable r) {
+ r.run();
+ }
+
+ /**
* Fakes android.bluetooth.BluetoothAdapter.
*/
static class FakeBluetoothAdapter extends Wrappers.BluetoothAdapterWrapper {
@@ -114,8 +142,7 @@ class Fakes {
uuids.add(ParcelUuid.fromString("00001800-0000-1000-8000-00805f9b34fb"));
uuids.add(ParcelUuid.fromString("00001801-0000-1000-8000-00805f9b34fb"));
- mFakeScanner.mScanCallback.onScanResult(
- ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
+ mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(new FakeBluetoothDevice(this, "01:00:00:90:1E:BE",
"FakeBluetoothDevice"),
TestRSSI.LOWEST, uuids, TestTxPower.LOWEST));
@@ -126,8 +153,7 @@ class Fakes {
uuids.add(ParcelUuid.fromString("00001802-0000-1000-8000-00805f9b34fb"));
uuids.add(ParcelUuid.fromString("00001803-0000-1000-8000-00805f9b34fb"));
- mFakeScanner.mScanCallback.onScanResult(
- ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
+ mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(new FakeBluetoothDevice(this, "01:00:00:90:1E:BE",
"FakeBluetoothDevice"),
TestRSSI.LOWER, uuids, TestTxPower.LOWER));
@@ -135,8 +161,7 @@ class Fakes {
}
case 3: {
ArrayList<ParcelUuid> uuids = null;
- mFakeScanner.mScanCallback.onScanResult(
- ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
+ mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
new FakeBluetoothDevice(this, "01:00:00:90:1E:BE", ""),
TestRSSI.LOW, uuids, NO_TX_POWER));
@@ -145,8 +170,7 @@ class Fakes {
}
case 4: {
ArrayList<ParcelUuid> uuids = null;
- mFakeScanner.mScanCallback.onScanResult(
- ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
+ mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
new FakeBluetoothDevice(this, "02:00:00:8B:74:63", ""),
TestRSSI.MEDIUM, uuids, NO_TX_POWER));
@@ -155,8 +179,7 @@ class Fakes {
}
case 5: {
ArrayList<ParcelUuid> uuids = null;
- mFakeScanner.mScanCallback.onScanResult(
- ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
+ mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
new FakeBluetoothDevice(this, "01:00:00:90:1E:BE", null),
TestRSSI.HIGH, uuids, NO_TX_POWER));
@@ -838,6 +861,9 @@ class Fakes {
// ---------------------------------------------------------------------------------------------
// BluetoothTestAndroid C++ methods declared for access from java:
+ // Bind to BluetoothTestAndroid::PostTaskFromJava.
+ private static native void nativePostTaskFromJava(long nativeBluetoothTestAndroid, Runnable r);
+
// Binds to BluetoothTestAndroid::OnFakeAdapterStateChanged.
private static native void nativeOnFakeAdapterStateChanged(
long nativeBluetoothTestAndroid, boolean powered);
« no previous file with comments | « device/bluetooth/bluetooth_remote_gatt_service_unittest.cc ('k') | device/bluetooth/test/bluetooth_test_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698