Debian Codegraph @

tests/InputMethodStressTest/src/com/android/inputmethod/stresstest/AutoShowTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 // IME will be auto-shown if the following conditions are met:
76 // 1. SoftInputMode state is SOFT_INPUT_STATE_UNSPECIFIED.
77 // 2. SoftInputMode adjust is SOFT_INPUT_ADJUST_RESIZE.
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 // 3. The focused view is a text editor (View#onCheckIsTextEditor() returns true).
85 mEditText.requestFocus();
86 }
87
88 public EditText getEditText() {
89 return mEditText;
90 }
91 }
92 }