1 /* 2 * Copyright 2025 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.settings.inputmethod; 18 19 import static com.android.settings.inputmethod.KeyboardAccessibilityKeysDialogFragment.EXTRA_SUBTITLE_RES; 20 import static com.android.settings.inputmethod.KeyboardAccessibilityKeysDialogFragment.EXTRA_TITLE_RES; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import android.app.AlertDialog; 25 import android.hardware.input.InputSettings; 26 import android.os.Bundle; 27 import android.widget.Button; 28 import android.widget.RadioGroup; 29 30 import androidx.fragment.app.testing.FragmentScenario; 31 import androidx.lifecycle.Lifecycle; 32 import androidx.test.core.app.ApplicationProvider; 33 34 import com.android.settings.R; 35 36 import org.junit.Before; 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 import org.robolectric.RobolectricTestRunner; 40 import org.robolectric.shadows.ShadowLooper; 41 42 @RunWith(RobolectricTestRunner.class) 43 public class KeyboardAccessibilitySlowKeysDialogFragmentTest { 44 private AlertDialog mAlertDialog; 45 46 @Before setUp()47 public void setUp() { 48 Bundle bundle = new Bundle(); 49 bundle.putInt(EXTRA_TITLE_RES, R.string.slow_keys); 50 bundle.putInt(EXTRA_SUBTITLE_RES, R.string.slow_keys_summary); 51 52 FragmentScenario<KeyboardAccessibilitySlowKeysDialogFragment> mFragmentScenario = 53 FragmentScenario.launch( 54 KeyboardAccessibilitySlowKeysDialogFragment.class, 55 bundle, 56 R.style.Theme_AlertDialog_SettingsLib, 57 Lifecycle.State.INITIALIZED); 58 mFragmentScenario.moveToState(Lifecycle.State.RESUMED); 59 60 mFragmentScenario.onFragment(fragment -> { 61 assertThat(fragment.getDialog()).isNotNull(); 62 assertThat(fragment.requireDialog().isShowing()).isTrue(); 63 assertThat(fragment.requireDialog()).isInstanceOf(AlertDialog.class); 64 mAlertDialog = (AlertDialog) fragment.requireDialog(); 65 }); 66 } 67 68 @Test handlePreferenceTreeClick_performClickOn200_updatesSlowKeysThreshold()69 public void handlePreferenceTreeClick_performClickOn200_updatesSlowKeysThreshold() { 70 assertThat(mAlertDialog.isShowing()).isTrue(); 71 RadioGroup radioGroup = mAlertDialog.findViewById(R.id.input_setting_keys_value_group); 72 radioGroup.check(R.id.input_setting_keys_value_200); 73 74 Button doneButton = mAlertDialog.findViewById(R.id.done_button); 75 doneButton.performClick(); 76 ShadowLooper.idleMainLooper(); 77 78 assertThat(mAlertDialog.isShowing()).isFalse(); 79 int threshold = InputSettings.getAccessibilitySlowKeysThreshold( 80 ApplicationProvider.getApplicationContext()); 81 assertThat(threshold).isEqualTo(200); 82 } 83 } 84