Merge "Improve GlobalActionsImeTest reliability" into rvc-dev am: a307a28a7a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11887441 Change-Id: I3eeb968ded157a3ff57efe6cdd8b5e040bd7c7dd
This commit is contained in:
@@ -60,8 +60,13 @@ public class GlobalActionsImeTest extends SysuiTestCase {
|
|||||||
public void testGlobalActions_doesntStealImeControl() throws Exception {
|
public void testGlobalActions_doesntStealImeControl() throws Exception {
|
||||||
turnScreenOn();
|
turnScreenOn();
|
||||||
final TestActivity activity = mActivityTestRule.launchActivity(null);
|
final TestActivity activity = mActivityTestRule.launchActivity(null);
|
||||||
|
boolean isImeVisible = waitUntil(activity::isImeVisible);
|
||||||
waitUntil("Ime is visible", activity::isImeVisible);
|
if (!isImeVisible) {
|
||||||
|
// Sometimes the keyboard is dismissed when run with other tests. Bringing it up again
|
||||||
|
// should improve test reliability
|
||||||
|
activity.showIme();
|
||||||
|
waitUntil("Ime is not visible", activity::isImeVisible);
|
||||||
|
}
|
||||||
|
|
||||||
executeShellCommand("input keyevent --longpress POWER");
|
executeShellCommand("input keyevent --longpress POWER");
|
||||||
|
|
||||||
@@ -91,17 +96,23 @@ public class GlobalActionsImeTest extends SysuiTestCase {
|
|||||||
|
|
||||||
private static void waitUntil(String message, BooleanSupplier predicate)
|
private static void waitUntil(String message, BooleanSupplier predicate)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
if (!waitUntil(predicate)) {
|
||||||
|
fail(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean waitUntil(BooleanSupplier predicate) throws Exception {
|
||||||
int sleep = 125;
|
int sleep = 125;
|
||||||
final long timeout = SystemClock.uptimeMillis() + 10_000; // 10 second timeout
|
final long timeout = SystemClock.uptimeMillis() + 10_000; // 10 second timeout
|
||||||
while (SystemClock.uptimeMillis() < timeout) {
|
while (SystemClock.uptimeMillis() < timeout) {
|
||||||
if (predicate.getAsBoolean()) {
|
if (predicate.getAsBoolean()) {
|
||||||
return; // okay
|
return true;
|
||||||
}
|
}
|
||||||
Thread.sleep(sleep);
|
Thread.sleep(sleep);
|
||||||
sleep *= 5;
|
sleep *= 5;
|
||||||
sleep = Math.min(2000, sleep);
|
sleep = Math.min(2000, sleep);
|
||||||
}
|
}
|
||||||
fail(message);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void executeShellCommand(String cmd) {
|
private static void executeShellCommand(String cmd) {
|
||||||
@@ -130,6 +141,7 @@ public class GlobalActionsImeTest extends SysuiTestCase {
|
|||||||
WindowInsetsController.OnControllableInsetsChangedListener,
|
WindowInsetsController.OnControllableInsetsChangedListener,
|
||||||
View.OnApplyWindowInsetsListener {
|
View.OnApplyWindowInsetsListener {
|
||||||
|
|
||||||
|
private EditText mEditText;
|
||||||
boolean mHasFocus;
|
boolean mHasFocus;
|
||||||
boolean mControlsIme;
|
boolean mControlsIme;
|
||||||
boolean mImeVisible;
|
boolean mImeVisible;
|
||||||
@@ -137,14 +149,16 @@ public class GlobalActionsImeTest extends SysuiTestCase {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
mEditText = new EditText(this);
|
||||||
|
mEditText.setCursorVisible(false); // Otherwise, main thread doesn't go idle.
|
||||||
|
setContentView(mEditText);
|
||||||
|
showIme();
|
||||||
|
}
|
||||||
|
|
||||||
EditText content = new EditText(this);
|
private void showIme() {
|
||||||
content.setCursorVisible(false); // Otherwise, main thread doesn't go idle.
|
mEditText.requestFocus();
|
||||||
setContentView(content);
|
|
||||||
content.requestFocus();
|
|
||||||
|
|
||||||
getWindow().getDecorView().setOnApplyWindowInsetsListener(this);
|
getWindow().getDecorView().setOnApplyWindowInsetsListener(this);
|
||||||
WindowInsetsController wic = content.getWindowInsetsController();
|
WindowInsetsController wic = mEditText.getWindowInsetsController();
|
||||||
wic.addOnControllableInsetsChangedListener(this);
|
wic.addOnControllableInsetsChangedListener(this);
|
||||||
wic.show(ime());
|
wic.show(ime());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user