• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 android.car.builtin.input;
18 
19 import static org.mockito.Mockito.eq;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.when;
22 import static org.mockito.Mockito.verify;
23 
24 import android.hardware.input.InputManager;
25 import android.view.KeyEvent;
26 import android.view.View;
27 import android.view.ViewRootImpl;
28 
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.junit.MockitoJUnitRunner;
33 
34 @RunWith(MockitoJUnitRunner.class)
35 public final class InputManagerHelperTest {
36 
37     @Mock
38     private InputManager mMockInputManager;
39 
40     @Test
injectInputEvent_delegateInjectionInAsyncMode()41     public void injectInputEvent_delegateInjectionInAsyncMode() {
42         KeyEvent someEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0);
43 
44         InputManagerHelper.injectInputEvent(mMockInputManager, someEvent);
45 
46         verify(mMockInputManager).injectInputEvent(someEvent,
47                 InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
48     }
49 
50     @Test
testPilferPointers()51     public void testPilferPointers() {
52         View view = mock(View.class);
53         ViewRootImpl viewRootImpl = mock(ViewRootImpl.class);
54         when(view.getViewRootImpl()).thenReturn(viewRootImpl);
55 
56         InputManagerHelper.pilferPointers(mMockInputManager, view);
57 
58         verify(mMockInputManager).pilferPointers(viewRootImpl.getInputToken());
59     }
60 
61     @Test
testAddUniqueIdAssociationByDescriptor()62     public void testAddUniqueIdAssociationByDescriptor() {
63         String inputDeviceDescriptor = "descriptor";
64         String displayUniqueId = "uniqueId";
65 
66         InputManagerHelper.addUniqueIdAssociationByDescriptor(mMockInputManager,
67                 inputDeviceDescriptor, displayUniqueId);
68 
69         verify(mMockInputManager).addUniqueIdAssociationByDescriptor(eq(inputDeviceDescriptor),
70                 eq(displayUniqueId));
71     }
72 
73     @Test
testRemoveUniqueIdAssociationByDescriptor()74     public void testRemoveUniqueIdAssociationByDescriptor() {
75         String inputDeviceDescriptor = "descriptor";
76 
77         InputManagerHelper.removeUniqueIdAssociationByDescriptor(mMockInputManager,
78                 inputDeviceDescriptor);
79 
80         verify(mMockInputManager).removeUniqueIdAssociationByDescriptor(eq(inputDeviceDescriptor));
81     }
82 }
83