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

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

Issue 2100313003: bluetooth: Remove Context from Wrappers and use LocationUtils directly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-location-utils
Patch Set: remove new line 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/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 ae1873581adce554331f4e26fee34bd6a2b9e362..856f4c373c9a6963be605a2548eb3a420e05afdf 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
@@ -16,9 +16,12 @@ import android.content.IntentFilter;
import android.os.Build;
import android.os.ParcelUuid;
+import android.test.mock.MockContext;
+
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
+import org.chromium.components.location.LocationUtils;
import java.util.ArrayList;
import java.util.HashMap;
@@ -39,6 +42,32 @@ class Fakes {
private static final String TAG = "cr.Bluetooth";
/**
+ * Sets the factory for LocationUtils to return an instance whose
+ * hasAndroidLocationPermission and isSystemLocationSettingEnabled return
+ * values depend on |hasPermission| and |isEnabled| respectively.
+ */
+ @CalledByNative
+ public static void setLocationServicesState(
+ final boolean hasPermission, final boolean isEnabled) {
+ LocationUtils.setFactory(new LocationUtils.Factory() {
+ @Override
+ public LocationUtils create() {
+ return new LocationUtils() {
+ @Override
+ public boolean hasAndroidLocationPermission(Context context) {
+ return hasPermission;
+ }
+
+ @Override
+ public boolean isSystemLocationSettingEnabled(Context context) {
+ return isEnabled;
+ }
+ };
+ }
+ });
+ }
+
+ /**
* Fakes android.bluetooth.BluetoothAdapter.
*/
static class FakeBluetoothAdapter extends Wrappers.BluetoothAdapterWrapper {
@@ -63,11 +92,6 @@ class Fakes {
mFakeScanner = new FakeBluetoothLeScanner();
}
- @CalledByNative("FakeBluetoothAdapter")
- public void denyPermission() {
- mFakeContext.mHasLocation = false;
- }
-
/**
* Creates and discovers a new device.
*/
@@ -188,18 +212,11 @@ class Fakes {
}
/**
- * Fakes android.content.Context.
+ * Fakes android.content.Context by extending MockContext.
*/
- static class FakeContext extends Wrappers.ContextWrapper {
- public boolean mHasLocation = true;
-
+ static class FakeContext extends MockContext {
public FakeContext() {
- super(null);
- }
-
- @Override
- public boolean hasAndroidLocationPermission() {
- return mHasLocation;
+ super();
}
@Override

Powered by Google App Engine
This is Rietveld 408576698