• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.hardware.input.InputSettings;
23 import android.os.UserHandle;
24 import android.provider.Settings;
25 
26 import androidx.test.core.app.ApplicationProvider;
27 
28 import com.android.settings.core.BasePreferenceController;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.robolectric.RobolectricTestRunner;
34 
35 /** Tests for {@link TrackpadPointerSpeedPreferenceController} */
36 @RunWith(RobolectricTestRunner.class)
37 public class TrackpadPointerSpeedPreferenceControllerTest {
38 
39     private static final String PREFERENCE_KEY = "trackpad_pointer_speed";
40     private static final String SETTING_KEY = Settings.System.TOUCHPAD_POINTER_SPEED;
41 
42     private Context mContext;
43     private TrackpadPointerSpeedPreferenceController mController;
44     private int mDefaultSpeed;
45 
46     @Before
setUp()47     public void setUp() {
48         mContext = ApplicationProvider.getApplicationContext();
49         mController = new TrackpadPointerSpeedPreferenceController(mContext, PREFERENCE_KEY);
50         mDefaultSpeed = Settings.System.getIntForUser(
51                 mContext.getContentResolver(),
52                 SETTING_KEY,
53                 InputSettings.DEFAULT_POINTER_SPEED,
54                 UserHandle.USER_CURRENT);
55     }
56 
57     @Test
getAvailabilityStatus_expected()58     public void getAvailabilityStatus_expected() {
59         assertThat(mController.getAvailabilityStatus())
60                 .isEqualTo(BasePreferenceController.AVAILABLE);
61     }
62 
63     @Test
getMin_expected()64     public void getMin_expected() {
65         assertThat(mController.getMin()).isEqualTo(InputSettings.MIN_POINTER_SPEED);
66     }
67 
68     @Test
getMax_expected()69     public void getMax_expected() {
70         assertThat(mController.getMax()).isEqualTo(InputSettings.MAX_POINTER_SPEED);
71     }
72 
73     @Test
getSliderPosition_defaultSpeed_return0()74     public void getSliderPosition_defaultSpeed_return0() {
75         int result = mController.getSliderPosition();
76 
77         assertThat(result).isEqualTo(0);
78     }
79 
80     @Test
setSliderPosition_speedValue1_shouldReturnTrue()81     public void setSliderPosition_speedValue1_shouldReturnTrue() {
82         int inputSpeed = 1;
83 
84         boolean result = mController.setSliderPosition(inputSpeed);
85 
86         assertThat(result).isTrue();
87         assertThat(mController.getSliderPosition()).isEqualTo(inputSpeed);
88     }
89 
90     @Test
setSliderPosition_speedValueOverMaxValue_shouldReturnFalse()91     public void setSliderPosition_speedValueOverMaxValue_shouldReturnFalse() {
92         int inputSpeed = InputSettings.MAX_POINTER_SPEED + 1;
93 
94         boolean result = mController.setSliderPosition(inputSpeed);
95 
96         assertThat(result).isFalse();
97         assertThat(mController.getSliderPosition()).isEqualTo(mDefaultSpeed);
98     }
99 
100     @Test
setSliderPosition_speedValueOverMinValue_shouldReturnFalse()101     public void setSliderPosition_speedValueOverMinValue_shouldReturnFalse() {
102         int inputSpeed = InputSettings.MIN_POINTER_SPEED - 1;
103 
104         boolean result = mController.setSliderPosition(inputSpeed);
105 
106         assertThat(result).isFalse();
107         assertThat(mController.getSliderPosition()).isEqualTo(mDefaultSpeed);
108     }
109 }
110