From 6007a4bc0c6fe47205fc4c91e81e298c2f2cb896 Mon Sep 17 00:00:00 2001 From: danielwbhuang Date: Tue, 31 Jan 2023 23:46:45 +0800 Subject: [PATCH] Add Trackpad settings tests 1. TrackpadBottomPreferenceControllerTest 2. TrackpadPointerSpeedPreferenceControllerTest 3. TrackpadReverseScrollingPreferenceControllerTest 4. TrackpadTapToClickPreferenceControllerTest Bug: 247080509 Test: manual, make RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.inputmethod.*" Change-Id: I61d6dd9bb807ec636e4103efc5b9ccc28d5bc2c1 --- .../TrackpadGestureDialogFragment.java | 4 +- ...rackpadBottomPreferenceControllerTest.java | 113 +++++++++++++++++ ...dPointerSpeedPreferenceControllerTest.java | 109 +++++++++++++++++ ...erseScrollingPreferenceControllerTest.java | 114 ++++++++++++++++++ ...padTapToClickPreferenceControllerTest.java | 113 +++++++++++++++++ 5 files changed, 450 insertions(+), 3 deletions(-) create mode 100644 tests/robotests/src/com/android/settings/inputmethod/TrackpadBottomPreferenceControllerTest.java create mode 100644 tests/robotests/src/com/android/settings/inputmethod/TrackpadPointerSpeedPreferenceControllerTest.java create mode 100644 tests/robotests/src/com/android/settings/inputmethod/TrackpadReverseScrollingPreferenceControllerTest.java create mode 100644 tests/robotests/src/com/android/settings/inputmethod/TrackpadTapToClickPreferenceControllerTest.java diff --git a/src/com/android/settings/inputmethod/TrackpadGestureDialogFragment.java b/src/com/android/settings/inputmethod/TrackpadGestureDialogFragment.java index 0e9cb12e77a..b644eb1ca28 100644 --- a/src/com/android/settings/inputmethod/TrackpadGestureDialogFragment.java +++ b/src/com/android/settings/inputmethod/TrackpadGestureDialogFragment.java @@ -16,7 +16,6 @@ package com.android.settings.inputmethod; -import static android.content.Context.LAYOUT_INFLATER_SERVICE; import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; import android.app.Activity; @@ -97,8 +96,7 @@ public class TrackpadGestureDialogFragment extends BottomSheetDialogFragment { @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); - mInflater = (LayoutInflater) mContext.getSystemService( - LAYOUT_INFLATER_SERVICE); + mInflater = mContext.getSystemService(LayoutInflater.class); View gestureEducationView = mInflater.inflate(R.layout.trackpad_gesture_preview, null); addViewPager(gestureEducationView); diff --git a/tests/robotests/src/com/android/settings/inputmethod/TrackpadBottomPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/TrackpadBottomPreferenceControllerTest.java new file mode 100644 index 00000000000..1b061ec8d74 --- /dev/null +++ b/tests/robotests/src/com/android/settings/inputmethod/TrackpadBottomPreferenceControllerTest.java @@ -0,0 +1,113 @@ +/* + * 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.settings.inputmethod; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.os.UserHandle; +import android.provider.Settings; + +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +/** Tests for {@link TrackpadBottomPreferenceController} */ +@RunWith(RobolectricTestRunner.class) +public class TrackpadBottomPreferenceControllerTest { + + private static final String PREFERENCE_KEY = "trackpad_bottom_right_tap"; + private static final String SETTING_KEY = Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE; + + private Context mContext; + private TrackpadBottomPreferenceController mController; + + @Before + public void setUp() { + mContext = ApplicationProvider.getApplicationContext(); + mController = new TrackpadBottomPreferenceController(mContext, PREFERENCE_KEY); + } + + @Test + public void getAvailabilityStatus_expected() { + assertThat(mController.getAvailabilityStatus()) + .isEqualTo(BasePreferenceController.AVAILABLE); + } + + @Test + public void getSliceHighlightMenuRes_expected() { + assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system); + } + + @Test + public void setChecked_true_shouldReturn1() { + mController.setChecked(true); + + int result = Settings.System.getIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + assertThat(result).isEqualTo(1); + } + + @Test + public void setChecked_false_shouldReturn0() { + mController.setChecked(false); + + int result = Settings.System.getIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + assertThat(result).isEqualTo(0); + } + + @Test + public void isChecked_providerPutInt1_returnTrue() { + Settings.System.putIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 1, + UserHandle.USER_CURRENT); + + boolean result = mController.isChecked(); + + assertThat(result).isTrue(); + } + + @Test + public void isChecked_providerPutInt0_returnFalse() { + Settings.System.putIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + boolean result = mController.isChecked(); + + assertThat(result).isFalse(); + } +} diff --git a/tests/robotests/src/com/android/settings/inputmethod/TrackpadPointerSpeedPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/TrackpadPointerSpeedPreferenceControllerTest.java new file mode 100644 index 00000000000..5c708771df5 --- /dev/null +++ b/tests/robotests/src/com/android/settings/inputmethod/TrackpadPointerSpeedPreferenceControllerTest.java @@ -0,0 +1,109 @@ +/* + * 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.settings.inputmethod; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.hardware.input.InputManager; +import android.os.UserHandle; +import android.provider.Settings; + +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.core.BasePreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +/** Tests for {@link TrackpadPointerSpeedPreferenceController} */ +@RunWith(RobolectricTestRunner.class) +public class TrackpadPointerSpeedPreferenceControllerTest { + + private static final String PREFERENCE_KEY = "trackpad_pointer_speed"; + private static final String SETTING_KEY = Settings.System.TOUCHPAD_POINTER_SPEED; + + private Context mContext; + private TrackpadPointerSpeedPreferenceController mController; + private int mDefaultSpeed; + + @Before + public void setUp() { + mContext = ApplicationProvider.getApplicationContext(); + mController = new TrackpadPointerSpeedPreferenceController(mContext, PREFERENCE_KEY); + mDefaultSpeed = Settings.System.getIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + InputManager.DEFAULT_POINTER_SPEED, + UserHandle.USER_CURRENT); + } + + @Test + public void getAvailabilityStatus_expected() { + assertThat(mController.getAvailabilityStatus()) + .isEqualTo(BasePreferenceController.AVAILABLE); + } + + @Test + public void getMin_expected() { + assertThat(mController.getMin()).isEqualTo(InputManager.MIN_POINTER_SPEED); + } + + @Test + public void getMax_expected() { + assertThat(mController.getMax()).isEqualTo(InputManager.MAX_POINTER_SPEED); + } + + @Test + public void getSliderPosition_defaultSpeed_return0() { + int result = mController.getSliderPosition(); + + assertThat(result).isEqualTo(0); + } + + @Test + public void setSliderPosition_speedValue1_shouldReturnTrue() { + int inputSpeed = 1; + + boolean result = mController.setSliderPosition(inputSpeed); + + assertThat(result).isTrue(); + assertThat(mController.getSliderPosition()).isEqualTo(inputSpeed); + } + + @Test + public void setSliderPosition_speedValueOverMaxValue_shouldReturnFalse() { + int inputSpeed = InputManager.MAX_POINTER_SPEED + 1; + + boolean result = mController.setSliderPosition(inputSpeed); + + assertThat(result).isFalse(); + assertThat(mController.getSliderPosition()).isEqualTo(mDefaultSpeed); + } + + @Test + public void setSliderPosition_speedValueOverMinValue_shouldReturnFalse() { + int inputSpeed = InputManager.MIN_POINTER_SPEED - 1; + + boolean result = mController.setSliderPosition(inputSpeed); + + assertThat(result).isFalse(); + assertThat(mController.getSliderPosition()).isEqualTo(mDefaultSpeed); + } +} diff --git a/tests/robotests/src/com/android/settings/inputmethod/TrackpadReverseScrollingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/TrackpadReverseScrollingPreferenceControllerTest.java new file mode 100644 index 00000000000..b4cb862e6c6 --- /dev/null +++ b/tests/robotests/src/com/android/settings/inputmethod/TrackpadReverseScrollingPreferenceControllerTest.java @@ -0,0 +1,114 @@ +/* + * 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.settings.inputmethod; + + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.os.UserHandle; +import android.provider.Settings; + +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +/** Tests for {@link TrackpadReverseScrollingPreferenceController} */ +@RunWith(RobolectricTestRunner.class) +public class TrackpadReverseScrollingPreferenceControllerTest { + + private static final String PREFERENCE_KEY = "trackpad_reverse_scrolling"; + private static final String SETTING_KEY = Settings.System.TOUCHPAD_NATURAL_SCROLLING; + + private Context mContext; + private TrackpadReverseScrollingPreferenceController mController; + + @Before + public void setUp() { + mContext = ApplicationProvider.getApplicationContext(); + mController = new TrackpadReverseScrollingPreferenceController(mContext, PREFERENCE_KEY); + } + + @Test + public void getAvailabilityStatus_expected() { + assertThat(mController.getAvailabilityStatus()) + .isEqualTo(BasePreferenceController.AVAILABLE); + } + + @Test + public void getSliceHighlightMenuRes_expected() { + assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system); + } + + @Test + public void setChecked_true_shouldReturn1() { + mController.setChecked(true); + + int result = Settings.System.getIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + assertThat(result).isEqualTo(1); + } + + @Test + public void setChecked_false_shouldReturn0() { + mController.setChecked(false); + + int result = Settings.System.getIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + assertThat(result).isEqualTo(0); + } + + @Test + public void isChecked_providerPutInt1_returnTrue() { + Settings.System.putIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 1, + UserHandle.USER_CURRENT); + + boolean result = mController.isChecked(); + + assertThat(result).isTrue(); + } + + @Test + public void isChecked_providerPutInt0_returnFalse() { + Settings.System.putIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + boolean result = mController.isChecked(); + + assertThat(result).isFalse(); + } +} diff --git a/tests/robotests/src/com/android/settings/inputmethod/TrackpadTapToClickPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/TrackpadTapToClickPreferenceControllerTest.java new file mode 100644 index 00000000000..b4b8921a050 --- /dev/null +++ b/tests/robotests/src/com/android/settings/inputmethod/TrackpadTapToClickPreferenceControllerTest.java @@ -0,0 +1,113 @@ +/* + * 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.settings.inputmethod; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.os.UserHandle; +import android.provider.Settings; + +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settings.core.BasePreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +/** Tests for {@link TrackpadTapToClickPreferenceController} */ +@RunWith(RobolectricTestRunner.class) +public class TrackpadTapToClickPreferenceControllerTest { + + private static final String PREFERENCE_KEY = "trackpad_tap_to_click"; + private static final String SETTING_KEY = Settings.System.TOUCHPAD_TAP_TO_CLICK; + + private Context mContext; + private TrackpadTapToClickPreferenceController mController; + + @Before + public void setUp() { + mContext = ApplicationProvider.getApplicationContext(); + mController = new TrackpadTapToClickPreferenceController(mContext, PREFERENCE_KEY); + } + + @Test + public void getAvailabilityStatus_expected() { + assertThat(mController.getAvailabilityStatus()) + .isEqualTo(BasePreferenceController.AVAILABLE); + } + + @Test + public void getSliceHighlightMenuRes_expected() { + assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system); + } + + @Test + public void setChecked_true_shouldReturn1() { + mController.setChecked(true); + + int result = Settings.System.getIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + assertThat(result).isEqualTo(1); + } + + @Test + public void setChecked_false_shouldReturn0() { + mController.setChecked(false); + + int result = Settings.System.getIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + assertThat(result).isEqualTo(0); + } + + @Test + public void isChecked_providerPutInt1_returnTrue() { + Settings.System.putIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 1, + UserHandle.USER_CURRENT); + + boolean result = mController.isChecked(); + + assertThat(result).isTrue(); + } + + @Test + public void isChecked_providerPutInt0_returnFalse() { + Settings.System.putIntForUser( + mContext.getContentResolver(), + SETTING_KEY, + 0, + UserHandle.USER_CURRENT); + + boolean result = mController.isChecked(); + + assertThat(result).isFalse(); + } +}