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

Unified Diff: device/vibration/android/java/src/org/chromium/device/vibration/VibrationManagerImpl.java

Issue 2774783003: [DeviceService] Add service tests for VibrationManager. (Closed)
Patch Set: Address comments from blundell@ Created 3 years, 8 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/vibration/android/BUILD.gn ('k') | device/vibration/vibration_manager_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/vibration/android/java/src/org/chromium/device/vibration/VibrationManagerImpl.java
diff --git a/device/vibration/android/java/src/org/chromium/device/vibration/VibrationManagerImpl.java b/device/vibration/android/java/src/org/chromium/device/vibration/VibrationManagerImpl.java
index 98c24ec1501c13b7269b380224e192465e3a260b..e781f71df9e193761e93209c435258d5fbbf2b0f 100644
--- a/device/vibration/android/java/src/org/chromium/device/vibration/VibrationManagerImpl.java
+++ b/device/vibration/android/java/src/org/chromium/device/vibration/VibrationManagerImpl.java
@@ -10,7 +10,8 @@ import android.media.AudioManager;
import android.os.Vibrator;
import android.util.Log;
-import org.chromium.base.VisibleForTesting;
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
import org.chromium.device.mojom.VibrationManager;
import org.chromium.mojo.system.MojoException;
import org.chromium.services.service_manager.InterfaceFactory;
@@ -19,6 +20,7 @@ import org.chromium.services.service_manager.InterfaceFactory;
* Android implementation of the vibration manager service defined in
* device/vibration/vibration_manager.mojom.
*/
+@JNINamespace("device")
public class VibrationManagerImpl implements VibrationManager {
private static final String TAG = "VibrationManagerImpl";
@@ -29,35 +31,12 @@ public class VibrationManagerImpl implements VibrationManager {
private final Vibrator mVibrator;
private final boolean mHasVibratePermission;
- private static AndroidVibratorWrapper sVibratorWrapper;
-
- /**
- * Android Vibrator wrapper class provided to test code to extend.
- */
- @VisibleForTesting
- public static class AndroidVibratorWrapper {
- protected AndroidVibratorWrapper() {}
-
- public void vibrate(Vibrator vibrator, long milliseconds) {
- vibrator.vibrate(milliseconds);
- }
-
- public void cancel(Vibrator vibrator) {
- vibrator.cancel();
- }
- }
-
- // Test code can use this function to inject other wrapper for testing.
- public static void setVibratorWrapperForTesting(AndroidVibratorWrapper wrapper) {
- sVibratorWrapper = wrapper;
- }
+ private static long sVibrateMilliSecondsForTesting = -1;
+ private static boolean sVibrateCancelledForTesting = false;
public VibrationManagerImpl(Context context) {
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
- if (sVibratorWrapper == null) {
- sVibratorWrapper = new AndroidVibratorWrapper();
- }
// TODO(mvanouwerkerk): What happens if permission is revoked? Handle this better.
mHasVibratePermission =
context.checkCallingOrSelfPermission(android.Manifest.permission.VIBRATE)
@@ -82,14 +61,18 @@ public class VibrationManagerImpl implements VibrationManager {
if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT
&& mHasVibratePermission) {
- sVibratorWrapper.vibrate(mVibrator, sanitizedMilliseconds);
+ mVibrator.vibrate(sanitizedMilliseconds);
}
+ setVibrateMilliSecondsForTesting(sanitizedMilliseconds);
callback.call();
}
@Override
public void cancel(CancelResponse callback) {
- if (mHasVibratePermission) sVibratorWrapper.cancel(mVibrator);
+ if (mHasVibratePermission) {
+ mVibrator.cancel();
+ }
+ setVibrateCancelledForTesting(true);
callback.call();
}
@@ -107,4 +90,22 @@ public class VibrationManagerImpl implements VibrationManager {
return new VibrationManagerImpl(mContext);
}
}
+
+ static void setVibrateMilliSecondsForTesting(long milliseconds) {
+ sVibrateMilliSecondsForTesting = milliseconds;
+ }
+
+ static void setVibrateCancelledForTesting(boolean cancelled) {
+ sVibrateCancelledForTesting = cancelled;
+ }
+
+ @CalledByNative
+ static long getVibrateMilliSecondsForTesting() {
+ return sVibrateMilliSecondsForTesting;
+ }
+
+ @CalledByNative
+ static boolean getVibrateCancelledForTesting() {
+ return sVibrateCancelledForTesting;
+ }
}
« no previous file with comments | « device/vibration/android/BUILD.gn ('k') | device/vibration/vibration_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698