• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 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.platform.test.annotations.DisableFlags;
23 import android.platform.test.annotations.EnableFlags;
24 import android.platform.test.flag.junit.SetFlagsRule;
25 import android.view.InputDevice;
26 
27 import androidx.test.core.app.ApplicationProvider;
28 
29 import com.android.settings.core.BasePreferenceController;
30 import com.android.settings.keyboard.Flags;
31 import com.android.settings.testutils.shadow.ShadowInputDevice;
32 
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.junit.MockitoJUnit;
38 import org.mockito.junit.MockitoRule;
39 import org.robolectric.RobolectricTestRunner;
40 import org.robolectric.annotation.Config;
41 
42 /** Tests for {@link TouchpadSettingsController} */
43 @RunWith(RobolectricTestRunner.class)
44 @Config(shadows = {
45         com.android.settings.testutils.shadow.ShadowSystemSettings.class,
46         ShadowInputDevice.class,
47 })
48 public class TouchpadSettingsControllerTest {
49     @Rule
50     public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
51     @Rule
52     public MockitoRule rule = MockitoJUnit.rule();
53 
54     private static final String PREFERENCE_KEY = "keyboard_touchpad_settings";
55 
56     private Context mContext;
57     private TouchpadSettingsController mController;
58 
59     @Before
setUp()60     public void setUp() {
61         mContext = ApplicationProvider.getApplicationContext();
62         mController = new TouchpadSettingsController(mContext, PREFERENCE_KEY);
63         ShadowInputDevice.reset();
64     }
65 
66     @Test
67     @DisableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
getAvailabilityStatus_flagIsDisable_returnsUnavailable()68     public void getAvailabilityStatus_flagIsDisable_returnsUnavailable() {
69         int deviceId = 1;
70         ShadowInputDevice.sDeviceIds = new int[]{deviceId};
71         ShadowInputDevice.addDevice(deviceId, ShadowInputDevice.makeInputDevicebyId(deviceId));
72         assertThat(mController.getAvailabilityStatus())
73                 .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
74     }
75 
76     @Test
77     @EnableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
getAvailabilityStatus_isTouchpad_returnsAvailable()78     public void getAvailabilityStatus_isTouchpad_returnsAvailable() {
79         int deviceId = 1;
80         ShadowInputDevice.sDeviceIds = new int[]{deviceId};
81         InputDevice device = ShadowInputDevice.makeInputDevicebyIdWithSources(deviceId,
82                 InputDevice.SOURCE_TOUCHPAD);
83         ShadowInputDevice.addDevice(deviceId, device);
84 
85         assertThat(mController.getAvailabilityStatus())
86                 .isEqualTo(BasePreferenceController.AVAILABLE);
87     }
88 }
89