Chromium Code Reviews| 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 76% |
| 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..47e73b6b42d38fca4a1e8017279529a05bda2b37 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,21 @@ |
| package org.chromium.content.browser.input; |
| -import android.test.InstrumentationTestCase; |
| -import android.test.suitebuilder.annotation.SmallTest; |
| +import static org.junit.Assert.assertEquals; |
|
jbudorick
2015/03/24 21:27:07
nix the import statics
mikecase (-- gone --)
2015/03/24 22:00:40
Done.
|
| +import static org.junit.Assert.assertFalse; |
| +import static org.junit.Assert.assertTrue; |
| + |
| import android.view.KeyEvent; |
| import android.view.MotionEvent; |
| import org.chromium.base.test.util.Feature; |
| +import org.chromium.testing.local.LocalRobolectricTestRunner; |
| + |
| +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 +26,9 @@ import java.util.BitSet; |
| /** |
| * Verify no regressions in gamepad mappings. |
| */ |
| -public class GamepadMappingsTest extends InstrumentationTestCase { |
| +@RunWith(LocalRobolectricTestRunner.class) |
|
jbudorick
2015/03/23 22:32:24
Converting these before we've got the bots set up
mikecase (-- gone --)
2015/03/24 21:14:46
Ok, will commit this CL, then make the bots run th
|
| +@Config(manifest = Config.NONE) |
| +public class GamepadMappingsTest { |
| /** |
| * Set bits indicate that we don't expect the button at mMappedButtons[index] to be mapped. |
| */ |
| @@ -31,9 +42,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 +62,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
| } |
| } |
| - @SmallTest |
| + @Test |
| @Feature({"Gamepad"}) |
| public void testShieldGamepadMappings() throws Exception { |
| GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
| @@ -61,7 +71,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
| assertShieldGamepadMappings(); |
| } |
| - @SmallTest |
| + @Test |
| @Feature({"Gamepad"}) |
| public void testXBox360GamepadMappings() throws Exception { |
| GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
| @@ -70,20 +80,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]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_X], 0.0f); |
|
jbudorick
2015/03/24 21:27:07
These values should be (very) small, but nonzero.
mikecase (-- gone --)
2015/03/24 22:00:40
Done. Set values to do "ERROR_TOLERANCE = 0.000001
|
| assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_Y]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_Y], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_A]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_A], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_B]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_B], 0.0f); |
| assertMappedCommonTriggerButtons(); |
| assertMappedCommonThumbstickButtons(); |
| @@ -96,7 +106,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
| assertMapping(); |
| } |
| - @SmallTest |
| + @Test |
| @Feature({"Gamepad"}) |
| public void testSamsungEIGP20GamepadMappings() throws Exception { |
| GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
| @@ -114,7 +124,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
| assertMapping(); |
| } |
| - @SmallTest |
| + @Test |
| @Feature({"Gamepad"}) |
| public void testAmazonFireGamepadMappings() throws Exception { |
| GamepadMappings.mapToStandardGamepad(mMappedAxes, mMappedButtons, mRawAxes, mRawButtons, |
| @@ -132,7 +142,7 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
| assertMapping(); |
| } |
| - @SmallTest |
| + @Test |
| @Feature({"Gamepad"}) |
| public void testUnknownGamepadMappings() throws Exception { |
| GamepadMappings.mapToStandardGamepad( |
| @@ -193,102 +203,108 @@ public class GamepadMappingsTest extends InstrumentationTestCase { |
| private void assertMappedCommonTriggerButtons() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_L1]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_L1], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_R1]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_R1], 0.0f); |
| } |
| private void assertMappedCommonDpadButtons() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_DOWN], |
| - mRawButtons[KeyEvent.KEYCODE_DPAD_DOWN]); |
| + mRawButtons[KeyEvent.KEYCODE_DPAD_DOWN], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_UP], |
| - mRawButtons[KeyEvent.KEYCODE_DPAD_UP]); |
| + mRawButtons[KeyEvent.KEYCODE_DPAD_UP], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_LEFT], |
| - mRawButtons[KeyEvent.KEYCODE_DPAD_LEFT]); |
| + mRawButtons[KeyEvent.KEYCODE_DPAD_LEFT], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_RIGHT], |
| - mRawButtons[KeyEvent.KEYCODE_DPAD_RIGHT]); |
| + mRawButtons[KeyEvent.KEYCODE_DPAD_RIGHT], 0.0f); |
| } |
| private void assertMappedTriggerAxexToShoulderButtons() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER], |
| - mRawAxes[MotionEvent.AXIS_LTRIGGER]); |
| + mRawAxes[MotionEvent.AXIS_LTRIGGER], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER], |
| - mRawAxes[MotionEvent.AXIS_RTRIGGER]); |
| + mRawAxes[MotionEvent.AXIS_RTRIGGER], 0.0f); |
| } |
| private void assertMappedTriggerButtonsToTopShoulder() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_SHOULDER], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_L1]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_L1], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_R1]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_R1], 0.0f); |
| } |
| private void assertMappedCommonXYABButtons() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.PRIMARY], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_A]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_A], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.SECONDARY], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_B]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_B], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.TERTIARY], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_X]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_X], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.QUATERNARY], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_Y]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_Y], 0.0f); |
| } |
| private void assertMappedCommonThumbstickButtons() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_THUMBSTICK], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_THUMBSTICK], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR], 0.0f); |
| } |
| private void assertMappedCommonStartSelectMetaButtons() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.START], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_START]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_START], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.BACK_SELECT], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_SELECT]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_SELECT], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.META], |
| - mRawButtons[KeyEvent.KEYCODE_BUTTON_MODE]); |
| + mRawButtons[KeyEvent.KEYCODE_BUTTON_MODE], 0.0f); |
| } |
| private void assertMappedPedalAxesToBottomShoulder() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
| - mRawAxes[MotionEvent.AXIS_BRAKE]); |
| - assertEquals( |
| - mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], mRawAxes[MotionEvent.AXIS_GAS]); |
| + mRawAxes[MotionEvent.AXIS_BRAKE], 0.0f); |
| + assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], |
| + mRawAxes[MotionEvent.AXIS_GAS], 0.0f); |
| } |
| private void assertMappedTriggerAxesToBottomShoulder() { |
| assertEquals(mMappedButtons[CanonicalButtonIndex.LEFT_TRIGGER], |
| - mRawAxes[MotionEvent.AXIS_LTRIGGER]); |
| + mRawAxes[MotionEvent.AXIS_LTRIGGER], 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER], |
| - mRawAxes[MotionEvent.AXIS_RTRIGGER]); |
| + mRawAxes[MotionEvent.AXIS_RTRIGGER], 0.0f); |
| } |
| 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)); |
| + GamepadMappings.negativeAxisValueAsButton(hatX), 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_RIGHT], |
| - GamepadMappings.positiveAxisValueAsButton(hatX)); |
| + GamepadMappings.positiveAxisValueAsButton(hatX), 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_UP], |
| - GamepadMappings.negativeAxisValueAsButton(hatY)); |
| + GamepadMappings.negativeAxisValueAsButton(hatY), 0.0f); |
| assertEquals(mMappedButtons[CanonicalButtonIndex.DPAD_DOWN], |
| - GamepadMappings.positiveAxisValueAsButton(hatY)); |
| + GamepadMappings.positiveAxisValueAsButton(hatY), 0.0f); |
| } |
| private void assertMappedXYAxes() { |
| - assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_X], mRawAxes[MotionEvent.AXIS_X]); |
| - assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_Y], mRawAxes[MotionEvent.AXIS_Y]); |
| + assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_X], |
| + mRawAxes[MotionEvent.AXIS_X], 0.0f); |
| + assertEquals(mMappedAxes[CanonicalAxisIndex.LEFT_STICK_Y], |
| + mRawAxes[MotionEvent.AXIS_Y], 0.0f); |
| } |
| private void assertMappedRXAndRYAxesToRightStick() { |
| - assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X], mRawAxes[MotionEvent.AXIS_RX]); |
| - assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y], mRawAxes[MotionEvent.AXIS_RY]); |
| + assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X], |
| + mRawAxes[MotionEvent.AXIS_RX], 0.0f); |
| + assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y], |
| + mRawAxes[MotionEvent.AXIS_RY], 0.0f); |
| } |
| private void assertMappedZAndRZAxesToRightStick() { |
| - assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X], mRawAxes[MotionEvent.AXIS_Z]); |
| - assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y], mRawAxes[MotionEvent.AXIS_RZ]); |
| + assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_X], |
| + mRawAxes[MotionEvent.AXIS_Z], 0.0f); |
| + assertEquals(mMappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y], |
| + mRawAxes[MotionEvent.AXIS_RZ], 0.0f); |
| } |
| } |