Loading tests/InputMethodStressTest/AndroidManifest.xml +1 −2 Original line number Original line Diff line number Diff line Loading @@ -19,8 +19,7 @@ package="com.android.inputmethod.stresstest"> package="com.android.inputmethod.stresstest"> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <application> <application> <activity android:name=".ImeStressTestUtil$TestActivity" <activity android:name=".ImeStressTestUtil$TestActivity"/> android:configChanges="orientation|screenSize"/> </application> </application> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" Loading tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/ImeOpenCloseStressTest.java +35 −2 Original line number Original line Diff line number Diff line Loading @@ -493,6 +493,7 @@ public final class ImeOpenCloseStressTest { verifyShowBehavior(activity); verifyShowBehavior(activity); } } // TODO: Add tests for activities that don't handle the rotation. @Test @Test public void testRotateScreenWithKeyboardOn() throws Exception { public void testRotateScreenWithKeyboardOn() throws Exception { Intent intent = Intent intent = Loading @@ -514,14 +515,14 @@ public final class ImeOpenCloseStressTest { Thread.sleep(1000); Thread.sleep(1000); Log.i(TAG, "Rotate screen right"); Log.i(TAG, "Rotate screen right"); assertThat(uiDevice.isNaturalOrientation()).isFalse(); assertThat(uiDevice.isNaturalOrientation()).isFalse(); verifyShowBehavior(activity); verifyRotateBehavior(activity); uiDevice.setOrientationLeft(); uiDevice.setOrientationLeft(); uiDevice.waitForIdle(); uiDevice.waitForIdle(); Thread.sleep(1000); Thread.sleep(1000); Log.i(TAG, "Rotate screen left"); Log.i(TAG, "Rotate screen left"); assertThat(uiDevice.isNaturalOrientation()).isFalse(); assertThat(uiDevice.isNaturalOrientation()).isFalse(); verifyShowBehavior(activity); verifyRotateBehavior(activity); uiDevice.setOrientationNatural(); uiDevice.setOrientationNatural(); uiDevice.waitForIdle(); uiDevice.waitForIdle(); Loading Loading @@ -569,4 +570,36 @@ public final class ImeOpenCloseStressTest { waitOnMainUntilImeIsShown(editText); waitOnMainUntilImeIsShown(editText); } } } } private static void verifyRotateBehavior(TestActivity activity) { // Get the new TestActivity after recreation. TestActivity newActivity = TestActivity.getLastCreatedInstance(); assertThat(newActivity).isNotNull(); assertThat(newActivity).isNotEqualTo(activity); EditText newEditText = newActivity.getEditText(); int softInputMode = newActivity.getWindow().getAttributes().softInputMode; int softInputVisibility = softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE; if (hasUnfocusableWindowFlags(newActivity)) { verifyImeAlwaysHiddenWithWindowFlagSet(newActivity); return; } if (softInputVisibility == WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) { // After rotation, the keyboard would be hidden only when the flag is // SOFT_INPUT_STATE_ALWAYS_HIDDEN. However, SOFT_INPUT_STATE_HIDDEN is different because // it requires appending SOFT_INPUT_IS_FORWARD_NAVIGATION flag, which won't be added // when rotating the devices (rotating doesn't navigate forward to the next app window.) verifyWindowAndViewFocus(newEditText, /*expectWindowFocus*/ true, /*expectViewFocus*/ true); waitOnMainUntilImeIsHidden(newEditText); } else { // Other cases, keyboard would be shown. verifyWindowAndViewFocus(newEditText, /*expectWindowFocus*/ true, /*expectViewFocus*/ true); waitOnMainUntilImeIsShown(newEditText); } } } } tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/ImeStressTestUtil.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.compatibility.common.util.ThrowingRunnable; import com.android.compatibility.common.util.ThrowingRunnable; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.ArrayList; import java.util.List; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.Callable; Loading Loading @@ -296,6 +297,8 @@ public final class ImeStressTestUtil { private static final String TAG = "ImeStressTestUtil.TestActivity"; private static final String TAG = "ImeStressTestUtil.TestActivity"; private EditText mEditText; private EditText mEditText; private boolean mIsAnimating; private boolean mIsAnimating; private static WeakReference<TestActivity> sLastCreatedInstance = new WeakReference<>(null); private final WindowInsetsAnimation.Callback mWindowInsetsAnimationCallback = private final WindowInsetsAnimation.Callback mWindowInsetsAnimationCallback = new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) { new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) { Loading Loading @@ -336,6 +339,7 @@ public final class ImeStressTestUtil { protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); Log.i(TAG, "onCreate()"); Log.i(TAG, "onCreate()"); sLastCreatedInstance = new WeakReference<>(this); boolean isUnfocusableView = getIntent().getBooleanExtra(UNFOCUSABLE_VIEW, false); boolean isUnfocusableView = getIntent().getBooleanExtra(UNFOCUSABLE_VIEW, false); boolean requestFocus = getIntent().getBooleanExtra(REQUEST_FOCUS_ON_CREATE, false); boolean requestFocus = getIntent().getBooleanExtra(REQUEST_FOCUS_ON_CREATE, false); int softInputFlags = getIntent().getIntExtra(SOFT_INPUT_FLAGS, 0); int softInputFlags = getIntent().getIntExtra(SOFT_INPUT_FLAGS, 0); Loading Loading @@ -378,6 +382,12 @@ public final class ImeStressTestUtil { } } } } /** Get the last created TestActivity instance. */ @Nullable public static TestActivity getLastCreatedInstance() { return sLastCreatedInstance.get(); } /** Show IME with InputMethodManager. */ /** Show IME with InputMethodManager. */ public boolean showImeWithInputMethodManager() { public boolean showImeWithInputMethodManager() { boolean showResult = boolean showResult = Loading Loading
tests/InputMethodStressTest/AndroidManifest.xml +1 −2 Original line number Original line Diff line number Diff line Loading @@ -19,8 +19,7 @@ package="com.android.inputmethod.stresstest"> package="com.android.inputmethod.stresstest"> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <application> <application> <activity android:name=".ImeStressTestUtil$TestActivity" <activity android:name=".ImeStressTestUtil$TestActivity"/> android:configChanges="orientation|screenSize"/> </application> </application> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" Loading
tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/ImeOpenCloseStressTest.java +35 −2 Original line number Original line Diff line number Diff line Loading @@ -493,6 +493,7 @@ public final class ImeOpenCloseStressTest { verifyShowBehavior(activity); verifyShowBehavior(activity); } } // TODO: Add tests for activities that don't handle the rotation. @Test @Test public void testRotateScreenWithKeyboardOn() throws Exception { public void testRotateScreenWithKeyboardOn() throws Exception { Intent intent = Intent intent = Loading @@ -514,14 +515,14 @@ public final class ImeOpenCloseStressTest { Thread.sleep(1000); Thread.sleep(1000); Log.i(TAG, "Rotate screen right"); Log.i(TAG, "Rotate screen right"); assertThat(uiDevice.isNaturalOrientation()).isFalse(); assertThat(uiDevice.isNaturalOrientation()).isFalse(); verifyShowBehavior(activity); verifyRotateBehavior(activity); uiDevice.setOrientationLeft(); uiDevice.setOrientationLeft(); uiDevice.waitForIdle(); uiDevice.waitForIdle(); Thread.sleep(1000); Thread.sleep(1000); Log.i(TAG, "Rotate screen left"); Log.i(TAG, "Rotate screen left"); assertThat(uiDevice.isNaturalOrientation()).isFalse(); assertThat(uiDevice.isNaturalOrientation()).isFalse(); verifyShowBehavior(activity); verifyRotateBehavior(activity); uiDevice.setOrientationNatural(); uiDevice.setOrientationNatural(); uiDevice.waitForIdle(); uiDevice.waitForIdle(); Loading Loading @@ -569,4 +570,36 @@ public final class ImeOpenCloseStressTest { waitOnMainUntilImeIsShown(editText); waitOnMainUntilImeIsShown(editText); } } } } private static void verifyRotateBehavior(TestActivity activity) { // Get the new TestActivity after recreation. TestActivity newActivity = TestActivity.getLastCreatedInstance(); assertThat(newActivity).isNotNull(); assertThat(newActivity).isNotEqualTo(activity); EditText newEditText = newActivity.getEditText(); int softInputMode = newActivity.getWindow().getAttributes().softInputMode; int softInputVisibility = softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE; if (hasUnfocusableWindowFlags(newActivity)) { verifyImeAlwaysHiddenWithWindowFlagSet(newActivity); return; } if (softInputVisibility == WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) { // After rotation, the keyboard would be hidden only when the flag is // SOFT_INPUT_STATE_ALWAYS_HIDDEN. However, SOFT_INPUT_STATE_HIDDEN is different because // it requires appending SOFT_INPUT_IS_FORWARD_NAVIGATION flag, which won't be added // when rotating the devices (rotating doesn't navigate forward to the next app window.) verifyWindowAndViewFocus(newEditText, /*expectWindowFocus*/ true, /*expectViewFocus*/ true); waitOnMainUntilImeIsHidden(newEditText); } else { // Other cases, keyboard would be shown. verifyWindowAndViewFocus(newEditText, /*expectWindowFocus*/ true, /*expectViewFocus*/ true); waitOnMainUntilImeIsShown(newEditText); } } } }
tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/ImeStressTestUtil.java +10 −0 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.compatibility.common.util.ThrowingRunnable; import com.android.compatibility.common.util.ThrowingRunnable; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.ArrayList; import java.util.List; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.Callable; Loading Loading @@ -296,6 +297,8 @@ public final class ImeStressTestUtil { private static final String TAG = "ImeStressTestUtil.TestActivity"; private static final String TAG = "ImeStressTestUtil.TestActivity"; private EditText mEditText; private EditText mEditText; private boolean mIsAnimating; private boolean mIsAnimating; private static WeakReference<TestActivity> sLastCreatedInstance = new WeakReference<>(null); private final WindowInsetsAnimation.Callback mWindowInsetsAnimationCallback = private final WindowInsetsAnimation.Callback mWindowInsetsAnimationCallback = new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) { new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) { Loading Loading @@ -336,6 +339,7 @@ public final class ImeStressTestUtil { protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.onCreate(savedInstanceState); Log.i(TAG, "onCreate()"); Log.i(TAG, "onCreate()"); sLastCreatedInstance = new WeakReference<>(this); boolean isUnfocusableView = getIntent().getBooleanExtra(UNFOCUSABLE_VIEW, false); boolean isUnfocusableView = getIntent().getBooleanExtra(UNFOCUSABLE_VIEW, false); boolean requestFocus = getIntent().getBooleanExtra(REQUEST_FOCUS_ON_CREATE, false); boolean requestFocus = getIntent().getBooleanExtra(REQUEST_FOCUS_ON_CREATE, false); int softInputFlags = getIntent().getIntExtra(SOFT_INPUT_FLAGS, 0); int softInputFlags = getIntent().getIntExtra(SOFT_INPUT_FLAGS, 0); Loading Loading @@ -378,6 +382,12 @@ public final class ImeStressTestUtil { } } } } /** Get the last created TestActivity instance. */ @Nullable public static TestActivity getLastCreatedInstance() { return sLastCreatedInstance.get(); } /** Show IME with InputMethodManager. */ /** Show IME with InputMethodManager. */ public boolean showImeWithInputMethodManager() { public boolean showImeWithInputMethodManager() { boolean showResult = boolean showResult = Loading