Bug 1572728 - Sync Gecko's selection for sendKey test of testInputConnection. r=geckoview-reviewers,snorp

Actually, `assertTextAndSelectionAt` checks Java side text and selection only.
So even if `assertTextAndSelectionAt` is successful, Gecko's text and selection
aren't updated yet. Since `sendKeyEvent` test uses both Gecko's selection and
Java's selection, this has timing issue. Since `sendKeyEvent` uses Gecko's
selection for insertion point, we have to sync Java's selection with Gecko's
selection. But since there is no way to sync it, this sendKey test may be failure.

To sync both data, this test should always use key event to update both Gecko
side and Java side correctly. GV's test uses Gecko's selection, so this issue
is robocop test only.

Differential Revision: https://phabricator.services.mozilla.com/D42599

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Makoto Kato 2019-08-22 17:45:21 +00:00
parent bfbfab85eb
commit e0b2f3e09c

View File

@ -106,6 +106,14 @@ public class testInputConnection extends JavascriptBridgeTest {
mType = type;
}
private void pressKey(final InputConnection ic, int keycode) {
final long time = SystemClock.uptimeMillis();
final KeyEvent key = new KeyEvent(time, time, KeyEvent.ACTION_DOWN, keycode, 0);
ic.sendKeyEvent(key);
ic.sendKeyEvent(KeyEvent.changeAction(key, KeyEvent.ACTION_UP));
}
@Override
public void test(final InputConnection ic, EditorInfo info) {
waitFor("focus change", new Condition() {
@ -178,14 +186,23 @@ public class testInputConnection extends JavascriptBridgeTest {
ic.finishComposingText();
assertTextAndSelectionAt("Can finish composition", ic, "frabar", 6);
ic.deleteSurroundingText(6, 0);
assertTextAndSelectionAt("Can clear text", ic, "", 0);
// Test sendKeyEvent
pressKey(ic, KeyEvent.KEYCODE_F);
pressKey(ic, KeyEvent.KEYCODE_R);
pressKey(ic, KeyEvent.KEYCODE_A);
pressKey(ic, KeyEvent.KEYCODE_B);
pressKey(ic, KeyEvent.KEYCODE_A);
pressKey(ic, KeyEvent.KEYCODE_R);
assertTextAndSelectionAt("Can input text by keyboard", ic, "frabar", 6);
final long time = SystemClock.uptimeMillis();
final KeyEvent shiftKey = new KeyEvent(time, time, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0);
final KeyEvent leftKey = new KeyEvent(time, time, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_DPAD_LEFT, 0);
final KeyEvent tKey = new KeyEvent(time, time, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_T, 0);
ic.sendKeyEvent(shiftKey);
ic.sendKeyEvent(leftKey);
@ -193,8 +210,7 @@ public class testInputConnection extends JavascriptBridgeTest {
ic.sendKeyEvent(KeyEvent.changeAction(shiftKey, KeyEvent.ACTION_UP));
assertTextAndSelection("Can select using key event", ic, "frabar", 6, 5);
ic.sendKeyEvent(tKey);
ic.sendKeyEvent(KeyEvent.changeAction(tKey, KeyEvent.ACTION_UP));
pressKey(ic, KeyEvent.KEYCODE_T);
assertTextAndSelectionAt("Can type using event", ic, "frabat", 6);
ic.deleteSurroundingText(6, 0);