• 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.os.UserHandle;
23 import android.provider.Settings;
24 
25 import androidx.test.core.app.ApplicationProvider;
26 
27 import com.android.settings.R;
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 TrackpadBottomPreferenceController} */
36 @RunWith(RobolectricTestRunner.class)
37 public class TrackpadBottomPreferenceControllerTest {
38 
39     private static final String PREFERENCE_KEY = "trackpad_bottom_right_tap";
40     private static final String SETTING_KEY = Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE;
41 
42     private Context mContext;
43     private TrackpadBottomPreferenceController mController;
44 
45     @Before
setUp()46     public void setUp() {
47         mContext = ApplicationProvider.getApplicationContext();
48         mController = new TrackpadBottomPreferenceController(mContext, PREFERENCE_KEY);
49     }
50 
51     @Test
getAvailabilityStatus_expected()52     public void getAvailabilityStatus_expected() {
53         assertThat(mController.getAvailabilityStatus())
54                 .isEqualTo(BasePreferenceController.AVAILABLE);
55     }
56 
57     @Test
getSliceHighlightMenuRes_expected()58     public void getSliceHighlightMenuRes_expected() {
59         assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system);
60     }
61 
62     @Test
setChecked_true_shouldReturn1()63     public void setChecked_true_shouldReturn1() {
64         mController.setChecked(true);
65 
66         int result = Settings.System.getIntForUser(
67                 mContext.getContentResolver(),
68                 SETTING_KEY,
69                 0,
70                 UserHandle.USER_CURRENT);
71 
72         assertThat(result).isEqualTo(1);
73     }
74 
75     @Test
setChecked_false_shouldReturn0()76     public void setChecked_false_shouldReturn0() {
77         mController.setChecked(false);
78 
79         int result = Settings.System.getIntForUser(
80                 mContext.getContentResolver(),
81                 SETTING_KEY,
82                 0,
83                 UserHandle.USER_CURRENT);
84 
85         assertThat(result).isEqualTo(0);
86     }
87 
88     @Test
isChecked_providerPutInt1_returnTrue()89     public void isChecked_providerPutInt1_returnTrue() {
90         Settings.System.putIntForUser(
91                 mContext.getContentResolver(),
92                 SETTING_KEY,
93                 1,
94                 UserHandle.USER_CURRENT);
95 
96         boolean result = mController.isChecked();
97 
98         assertThat(result).isTrue();
99     }
100 
101     @Test
isChecked_providerPutInt0_returnFalse()102     public void isChecked_providerPutInt0_returnFalse() {
103         Settings.System.putIntForUser(
104                 mContext.getContentResolver(),
105                 SETTING_KEY,
106                 0,
107                 UserHandle.USER_CURRENT);
108 
109         boolean result = mController.isChecked();
110 
111         assertThat(result).isFalse();
112     }
113 }
114