diff --git a/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/AutoShowTest.java b/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/AutoShowTest.java index 9b0f952133aa0..0c7e452e49d30 100644 --- a/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/AutoShowTest.java +++ b/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/AutoShowTest.java @@ -60,12 +60,15 @@ import java.util.List; @RunWith(Parameterized.class) public final class AutoShowTest { - @Rule public UnlockScreenRule mUnlockScreenRule = new UnlockScreenRule(); - @Rule public ScreenCaptureRule mScreenCaptureRule = - new ScreenCaptureRule("/sdcard/InputMethodStressTest"); - @Rule public DisableLockScreenRule mDisableLockScreenRule = new DisableLockScreenRule(); - @Rule public ScreenOrientationRule mScreenOrientationRule = + @Rule(order = 0) public DisableLockScreenRule mDisableLockScreenRule = + new DisableLockScreenRule(); + @Rule(order = 1) public UnlockScreenRule mUnlockScreenRule = new UnlockScreenRule(); + @Rule(order = 2) public ScreenOrientationRule mScreenOrientationRule = new ScreenOrientationRule(true /* isPortrait */); + @Rule(order = 3) public PressHomeBeforeTestRule mPressHomeBeforeTestRule = + new PressHomeBeforeTestRule(); + @Rule(order = 4) public ScreenCaptureRule mScreenCaptureRule = + new ScreenCaptureRule("/sdcard/InputMethodStressTest"); // TODO(b/240359838): add test case {@code Configuration.SCREENLAYOUT_SIZE_LARGE}. @Parameterized.Parameters( diff --git a/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/ImeOpenCloseStressTest.java b/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/ImeOpenCloseStressTest.java index a6131ce45c8bc..f432caec37056 100644 --- a/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/ImeOpenCloseStressTest.java +++ b/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/ImeOpenCloseStressTest.java @@ -66,12 +66,15 @@ public final class ImeOpenCloseStressTest { private static final String TAG = "ImeOpenCloseStressTest"; private static final int NUM_TEST_ITERATIONS = 10; - @Rule public UnlockScreenRule mUnlockScreenRule = new UnlockScreenRule(); - @Rule public ScreenCaptureRule mScreenCaptureRule = - new ScreenCaptureRule("/sdcard/InputMethodStressTest"); - @Rule public DisableLockScreenRule mDisableLockScreenRule = new DisableLockScreenRule(); - @Rule public ScreenOrientationRule mScreenOrientationRule = + @Rule(order = 0) public DisableLockScreenRule mDisableLockScreenRule = + new DisableLockScreenRule(); + @Rule(order = 1) public UnlockScreenRule mUnlockScreenRule = new UnlockScreenRule(); + @Rule(order = 2) public ScreenOrientationRule mScreenOrientationRule = new ScreenOrientationRule(true /* isPortrait */); + @Rule(order = 3) public PressHomeBeforeTestRule mPressHomeBeforeTestRule = + new PressHomeBeforeTestRule(); + @Rule(order = 4) public ScreenCaptureRule mScreenCaptureRule = + new ScreenCaptureRule("/sdcard/InputMethodStressTest"); private final Instrumentation mInstrumentation; private final int mSoftInputFlags; diff --git a/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/PressHomeBeforeTestRule.java b/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/PressHomeBeforeTestRule.java new file mode 100644 index 0000000000000..6586f630fae4c --- /dev/null +++ b/tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/PressHomeBeforeTestRule.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.inputmethod.stresstest; + +import android.support.test.uiautomator.UiDevice; + +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +/** This rule will press home before a test case. */ +public class PressHomeBeforeTestRule extends TestWatcher { + private final UiDevice mUiDevice = + UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + + @Override + protected void starting(Description description) { + mUiDevice.pressHome(); + } +}