| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.inputmethod.stresstest; |
| 18 |
|
| 19 |
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 20 |
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
| 21 |
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 22 |
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED; |
| 23 |
|
| 24 |
import static com.android.inputmethod.stresstest.ImeStressTestUtil.waitOnMainUntil; |
| 25 |
import static com.android.inputmethod.stresstest.ImeStressTestUtil.waitOnMainUntilImeIsShown; |
| 26 |
|
| 27 |
import android.app.Activity; |
| 28 |
import android.app.Instrumentation; |
| 29 |
import android.content.Intent; |
| 30 |
import android.os.Bundle; |
| 31 |
import android.platform.test.annotations.RootPermissionTest; |
| 32 |
import android.platform.test.rule.UnlockScreenRule; |
| 33 |
import android.widget.EditText; |
| 34 |
import android.widget.LinearLayout; |
| 35 |
|
| 36 |
import androidx.annotation.Nullable; |
| 37 |
import androidx.test.ext.junit.runners.AndroidJUnit4; |
| 38 |
import androidx.test.platform.app.InstrumentationRegistry; |
| 39 |
|
| 40 |
import org.junit.Rule; |
| 41 |
import org.junit.Test; |
| 42 |
import org.junit.runner.RunWith; |
| 43 |
|
| 44 |
@RootPermissionTest |
| 45 |
@RunWith(AndroidJUnit4.class) |
| 46 |
public final class AutoShowTest { |
| 47 |
|
| 48 |
@Rule |
| 49 |
public UnlockScreenRule mUnlockScreenRule = new UnlockScreenRule(); |
| 50 |
|
| 51 |
@Rule |
| 52 |
public ScreenCaptureRule mScreenCaptureRule = |
| 53 |
new ScreenCaptureRule("/sdcard/InputMethodStressTest"); |
| 54 |
|
| 55 |
@Test |
| 56 |
public void autoShow() { |
| 57 |
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); |
| 58 |
Intent intent = new Intent() |
| 59 |
.setAction(Intent.ACTION_MAIN) |
| 60 |
.setClass(instrumentation.getContext(), TestActivity.class) |
| 61 |
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| 62 |
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 63 |
TestActivity activity = (TestActivity) instrumentation.startActivitySync(intent); |
| 64 |
EditText editText = activity.getEditText(); |
| 65 |
waitOnMainUntil("activity should gain focus", editText::hasWindowFocus); |
| 66 |
waitOnMainUntilImeIsShown(editText); |
| 67 |
} |
| 68 |
|
| 69 |
public static class TestActivity extends Activity { |
| 70 |
private EditText mEditText; |
| 71 |
|
| 72 |
@Override |
| 73 |
protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 74 |
super.onCreate(savedInstanceState); |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
getWindow().setSoftInputMode(SOFT_INPUT_STATE_UNSPECIFIED | SOFT_INPUT_ADJUST_RESIZE); |
| 79 |
LinearLayout rootView = new LinearLayout(this); |
| 80 |
rootView.setOrientation(LinearLayout.VERTICAL); |
| 81 |
mEditText = new EditText(this); |
| 82 |
rootView.addView(mEditText, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)); |
| 83 |
setContentView(rootView); |
| 84 |
|
| 85 |
mEditText.requestFocus(); |
| 86 |
} |
| 87 |
|
| 88 |
public EditText getEditText() { |
| 89 |
return mEditText; |
| 90 |
} |
| 91 |
} |
| 92 |
} |