Index: content/public/android/junit/src/org/chromium/content/browser/input/GamepadMappingsTest.java |
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/input/GamepadMappingsTest.java b/content/public/android/junit/src/org/chromium/content/browser/input/GamepadMappingsTest.java |
similarity index 52% |
copy from content/public/android/javatests/src/org/chromium/content/browser/input/GamepadMappingsTest.java |
copy to content/public/android/junit/src/org/chromium/content/browser/input/GamepadMappingsTest.java |
index 5ae486d5c7be4b0d20456068387dda08c6140406..58e16e7eb6d2ee511f37607e80a48d86732eb0d7 100644 |
--- a/content/public/android/javatests/src/org/chromium/content/browser/input/GamepadMappingsTest.java |
+++ b/content/public/android/junit/src/org/chromium/content/browser/input/GamepadMappingsTest.java |
@@ -4,12 +4,18 @@ |
package org.chromium.content.browser.input; |
-import android.test.InstrumentationTestCase; |
-import android.test.suitebuilder.annotation.SmallTest; |
import android.view.KeyEvent; |
import android.view.MotionEvent; |
import org.chromium.base.test.util.Feature; |
+import org.chromium.testing.local.LocalRobolectricTestRunner; |
+ |
+import org.junit.Assert; |
+import org.junit.Before; |
+import org.junit.Test; |
+import org.junit.runner.RunWith; |
+ |
+import org.robolectric.annotation.Config; |
import java.util.Arrays; |
import java.util.BitSet; |
@@ -17,7 +23,10 @@ import java.util.BitSet; |
/** |
* Verify no regressions in gamepad mappings. |
*/ |
-public class GamepadMappingsTest extends InstrumentationTestCase { |
+@RunWith(LocalRobolectricTestRunner.class) |
+@Config(manifest = Config.NONE) |
+public class GamepadMappingsTest { |
+ private static final float ERROR_TOLERANCE = 0.000001f; |
/** |
* Set bits indicate that we don't expect the button at mMappedButtons[index] to be mapped. |
*/ |
@@ -31,9 +40,8 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
private float[] mRawButtons = new float[GamepadDevice.MAX_RAW_BUTTON_VALUES]; |
private float[] mRawAxes = new float[GamepadDevice.MAX_RAW_AXIS_VALUES]; |
- @Override |
- protected void setUp() throws Exception { |
- super.setUp(); |
+ @Before |
+ public void setUp() throws Exception { |
// By default, we expect every button and axis to be mapped. |
mUnmappedButtons.clear(); |
@@ -52,7 +60,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
} |
} |
- @SmallTest |
+ @Test |
@Feature({"Gamepad"}) |
public void testShieldGamepadMappings() throws Exception { |
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
@@ -61,7 +69,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
assertShieldGamepadMappings(); |
} |
- @SmallTest |
+ @Test |
@Feature({"Gamepad"}) |
public void testXBox360GamepadMappings() throws Exception { |
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
@@ -70,20 +78,20 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
assertShieldGamepadMappings(); |
} |
- @SmallTest |
+ @Test |
@Feature({"Gamepad"}) |
public void testPS3SixAxisGamepadMappings() throws Exception { |
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
GamepadMappings.PS3_SIXAXIS_DEVICE_NAME); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_X]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_Y]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_A]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_B]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_X], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_Y], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_A], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_B], ERROR_TOLERANCE); |
assertMappedCommonTriggerButtons(); |
assertMappedCommonThumbstickButtons(); |
@@ -96,7 +104,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
assertMapping(); |
} |
- @SmallTest |
+ @Test |
@Feature({"Gamepad"}) |
public void testSamsungEIGP20GamepadMappings() throws Exception { |
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
@@ -114,7 +122,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
assertMapping(); |
} |
- @SmallTest |
+ @Test |
@Feature({"Gamepad"}) |
public void testAmazonFireGamepadMappings() throws Exception { |
GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
@@ -132,7 +140,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
assertMapping(); |
} |
- @SmallTest |
+ @Test |
@Feature({"Gamepad"}) |
public void testUnknownGamepadMappings() throws Exception { |
GamepadMappings.mapToStandardGamepad( |
@@ -174,121 +182,128 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
public void assertMapping() { |
for (int i = 0; i < mMappedAxes.length; i++) { |
if (mUnmappedAxes.get(i)) { |
- assertTrue( |
+ Assert.assertTrue( |
"An unexpected axis was mapped at index " + i, Float.isNaN(mMappedAxes[i])); |
} else { |
- assertFalse("An axis was not mapped at index " + i, Float.isNaN(mMappedAxes[i])); |
+ Assert.assertFalse( |
+ "An axis was not mapped at index " + i, Float.isNaN(mMappedAxes[i])); |
} |
} |
for (int i = 0; i < mMappedButtons.length; i++) { |
if (mUnmappedButtons.get(i)) { |
- assertTrue("An unexpected button was mapped at index " + i, |
+ Assert.assertTrue("An unexpected button was mapped at index " + i, |
Float.isNaN(mMappedButtons[i])); |
} else { |
- assertFalse( |
+ Assert.assertFalse( |
"A button was not mapped at index " + i, Float.isNaN(mMappedButtons[i])); |
} |
} |
} |
private void assertMappedCommonTriggerButtons() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_L1]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_R1]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_L1], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_R1], ERROR_TOLERANCE); |
} |
private void assertMappedCommonDpadButtons() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_DOWN], |
- mRawButtons[KeyEvent.KEYCODE_DPAD_DOWN]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_UP], |
- mRawButtons[KeyEvent.KEYCODE_DPAD_UP]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_LEFT], |
- mRawButtons[KeyEvent.KEYCODE_DPAD_LEFT]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_RIGHT], |
- mRawButtons[KeyEvent.KEYCODE_DPAD_RIGHT]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_DOWN], |
+ mRawButtons[KeyEvent.KEYCODE_DPAD_DOWN], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_UP], |
+ mRawButtons[KeyEvent.KEYCODE_DPAD_UP], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_LEFT], |
+ mRawButtons[KeyEvent.KEYCODE_DPAD_LEFT], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_RIGHT], |
+ mRawButtons[KeyEvent.KEYCODE_DPAD_RIGHT], ERROR_TOLERANCE); |
} |
private void assertMappedTriggerAxexToShoulderButtons() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER], |
- mRawAxes[MotionEvent.AXIS_LTRIGGER]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER], |
- mRawAxes[MotionEvent.AXIS_RTRIGGER]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER], |
+ mRawAxes[MotionEvent.AXIS_LTRIGGER], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER], |
+ mRawAxes[MotionEvent.AXIS_RTRIGGER], ERROR_TOLERANCE); |
} |
private void assertMappedTriggerButtonsToTopShoulder() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_L1]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_R1]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_L1], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_R1], ERROR_TOLERANCE); |
} |
private void assertMappedCommonXYABButtons() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_A]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_B]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_X]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_Y]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_A], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_B], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_X], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_Y], ERROR_TOLERANCE); |
} |
private void assertMappedCommonThumbstickButtons() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_THUMBSTICK], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_THUMBSTICK], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_THUMBSTICK], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_THUMBSTICK], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR], ERROR_TOLERANCE); |
} |
private void assertMappedCommonStartSelectMetaButtons() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.START], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_START]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.BACK_SELECT], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_SELECT]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.META], |
- mRawButtons[KeyEvent.KEYCODE_BUTTON_MODE]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.START], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_START], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.BACK_SELECT], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_SELECT], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.META], |
+ mRawButtons[KeyEvent.KEYCODE_BUTTON_MODE], ERROR_TOLERANCE); |
} |
private void assertMappedPedalAxesToBottomShoulder() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
- mRawAxes[MotionEvent.AXIS_BRAKE]); |
- assertEquals( |
- mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], mRawAxes[MotionEvent.AXIS_GAS]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
+ mRawAxes[MotionEvent.AXIS_BRAKE], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], |
+ mRawAxes[MotionEvent.AXIS_GAS], ERROR_TOLERANCE); |
} |
private void assertMappedTriggerAxesToBottomShoulder() { |
- assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
- mRawAxes[MotionEvent.AXIS_LTRIGGER]); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], |
- mRawAxes[MotionEvent.AXIS_RTRIGGER]); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
+ mRawAxes[MotionEvent.AXIS_LTRIGGER], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], |
+ mRawAxes[MotionEvent.AXIS_RTRIGGER], ERROR_TOLERANCE); |
} |
private void assertMappedHatAxisToDpadButtons() { |
float hatX = mRawAxes[MotionEvent.AXIS_HAT_X]; |
float hatY = mRawAxes[MotionEvent.AXIS_HAT_Y]; |
- assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_LEFT], |
- GamepadMappings.negativeAxisValueAsButton(hatX)); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_RIGHT], |
- GamepadMappings.positiveAxisValueAsButton(hatX)); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_UP], |
- GamepadMappings.negativeAxisValueAsButton(hatY)); |
- assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_DOWN], |
- GamepadMappings.positiveAxisValueAsButton(hatY)); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_LEFT], |
+ GamepadMappings.negativeAxisValueAsButton(hatX), ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_RIGHT], |
+ GamepadMappings.positiveAxisValueAsButton(hatX), ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_UP], |
+ GamepadMappings.negativeAxisValueAsButton(hatY), ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_DOWN], |
+ GamepadMappings.positiveAxisValueAsButton(hatY), ERROR_TOLERANCE); |
} |
private void assertMappedXYAxes() { |
- assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_X], mRawAxes[MotionEvent.AXIS_X]); |
- assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_Y], mRawAxes[MotionEvent.AXIS_Y]); |
+ Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_X], |
+ mRawAxes[MotionEvent.AXIS_X], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_Y], |
+ mRawAxes[MotionEvent.AXIS_Y], ERROR_TOLERANCE); |
} |
private void assertMappedRXAndRYAxesToRightStick() { |
- assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X], mRawAxes[MotionEvent.AXIS_RX]); |
- assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y], mRawAxes[MotionEvent.AXIS_RY]); |
+ Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X], |
+ mRawAxes[MotionEvent.AXIS_RX], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y], |
+ mRawAxes[MotionEvent.AXIS_RY], ERROR_TOLERANCE); |
} |
private void assertMappedZAndRZAxesToRightStick() { |
- assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X], mRawAxes[MotionEvent.AXIS_Z]); |
- assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y], mRawAxes[MotionEvent.AXIS_RZ]); |
+ Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X], |
+ mRawAxes[MotionEvent.AXIS_Z], ERROR_TOLERANCE); |
+ Assert.assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y], |
+ mRawAxes[MotionEvent.AXIS_RZ], ERROR_TOLERANCE); |
} |
} |