Add rule to press home before ImeOpenCloseStressTest and AutoShowTest

Add PressHomeBeforeTestRule to press home before tests, which avoids
test failures when notification page is shown before tests.

Bug: 261775358
Test: atest com.android.inputmethod.stresstest.AutoShowTest
Test: atest com.android.inputmethod.stresstest.ImeOpenCloseStressTest
Change-Id: I55d8f8423429c6a6410722daa613b92e8da20ff5
This commit is contained in:
czq
2023-01-11 15:57:13 +08:00
parent 26af2c72fe
commit 5cb3ec18eb
3 changed files with 50 additions and 10 deletions

View File

@@ -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(

View File

@@ -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;

View File

@@ -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();
}
}