Merge "Modified text field arrow tests for different input devices" into oc-dev
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index 5fe73af..b40b2f1 100644
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -2808,12 +2808,18 @@
         mInstrumentation.waitForIdleSync();
         assertTrue(mTextView.isFocused());
 
-        // Arrows should not cause focus to leave the textfield
+        // Pure-keyboard arrows should not cause focus to leave the textfield
         CtsKeyEventUtil.sendKeyDownUp(mInstrumentation, mTextView, KeyEvent.KEYCODE_DPAD_UP);
         mInstrumentation.waitForIdleSync();
         assertTrue(mTextView.isFocused());
 
-        CtsKeyEventUtil.sendKeyDownUp(mInstrumentation, mTextView, KeyEvent.KEYCODE_DPAD_DOWN);
+        // Non-pure-keyboard arrows, however, should.
+        int dpadRemote = InputDevice.SOURCE_DPAD | InputDevice.SOURCE_KEYBOARD;
+        sendSourceKeyDownUp(mInstrumentation, mTextView, KeyEvent.KEYCODE_DPAD_UP, dpadRemote);
+        mInstrumentation.waitForIdleSync();
+        assertFalse(mTextView.isFocused());
+
+        sendSourceKeyDownUp(mInstrumentation, mTextView, KeyEvent.KEYCODE_DPAD_DOWN, dpadRemote);
         mInstrumentation.waitForIdleSync();
         assertTrue(mTextView.isFocused());
 
@@ -2823,6 +2829,16 @@
         assertFalse(mTextView.isFocused());
     }
 
+    private void sendSourceKeyDownUp(Instrumentation instrumentation, View targetView, int key,
+            int source) {
+        KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, key);
+        event.setSource(source);
+        CtsKeyEventUtil.sendKey(instrumentation, targetView, event);
+        event = new KeyEvent(KeyEvent.ACTION_UP, key);
+        event.setSource(source);
+        CtsKeyEventUtil.sendKey(instrumentation, targetView, event);
+    }
+
     @Test
     public void testSetIncludeFontPadding() throws Throwable {
         mTextView = findTextView(R.id.textview_text);