• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 static org.mockito.Mockito.when;
22 
23 import android.content.Context;
24 import android.platform.test.annotations.EnableFlags;
25 import android.platform.test.flag.junit.SetFlagsRule;
26 import android.view.InputDevice;
27 
28 import androidx.test.core.app.ApplicationProvider;
29 
30 import com.android.settings.core.BasePreferenceController;
31 import com.android.settings.keyboard.Flags;
32 import com.android.settings.testutils.shadow.ShadowInputDevice;
33 
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mock;
39 import org.mockito.junit.MockitoJUnit;
40 import org.mockito.junit.MockitoRule;
41 import org.robolectric.RobolectricTestRunner;
42 import org.robolectric.annotation.Config;
43 
44 /** Tests for {@link PhysicalKeyboardA11yPreferenceController} */
45 @RunWith(RobolectricTestRunner.class)
46 @Config(shadows = {
47         com.android.settings.testutils.shadow.ShadowInputDevice.class,
48 })
49 public class PhysicalKeyboardA11yPreferenceControllerTest {
50     @Rule
51     public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
52     @Rule
53     public MockitoRule rule = MockitoJUnit.rule();
54     private static final String PREFERENCE_KEY = "physical_keyboard_a11y";
55     private Context mContext;
56     private PhysicalKeyboardA11yPreferenceController mController;
57     @Mock
58     InputDevice mInputDevice;
59 
60     @Before
setUp()61     public void setUp() {
62         mContext = ApplicationProvider.getApplicationContext();
63         mController = new PhysicalKeyboardA11yPreferenceController(mContext, PREFERENCE_KEY);
64     }
65 
66     @Test
67     @EnableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
getAvailabilityStatus_expected()68     public void getAvailabilityStatus_expected() {
69         int deviceId = 1;
70         ShadowInputDevice.sDeviceIds = new int[]{deviceId};
71         when(mInputDevice.isVirtual()).thenReturn(false);
72         when(mInputDevice.isFullKeyboard()).thenReturn(true);
73 
74         ShadowInputDevice.addDevice(deviceId, mInputDevice);
75 
76         assertThat(InputDevice.getDeviceIds()).isNotEmpty();
77         assertThat(mController.getAvailabilityStatus())
78                 .isEqualTo(BasePreferenceController.AVAILABLE);
79 
80     }
81 
82     @Test
83     @EnableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
getAvailabilityStatus_deviceIsNotAsExpected_unavailable()84     public void getAvailabilityStatus_deviceIsNotAsExpected_unavailable() {
85         int deviceId = 1;
86         ShadowInputDevice.sDeviceIds = new int[]{deviceId};
87         when(mInputDevice.isVirtual()).thenReturn(true);
88         when(mInputDevice.isFullKeyboard()).thenReturn(false);
89 
90         ShadowInputDevice.addDevice(deviceId, mInputDevice);
91 
92         assertThat(InputDevice.getDeviceIds()).isNotEmpty();
93         assertThat(mController.getAvailabilityStatus())
94                 .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
95 
96     }
97 
98 }
99