Flutter Engine
The Flutter Engine
KeyChannelResponderTest.java
Go to the documentation of this file.
1package io.flutter.embedding.android;
2
3import static io.flutter.Build.API_LEVELS;
4import static junit.framework.TestCase.assertEquals;
5import static org.mockito.Mockito.any;
6import static org.mockito.Mockito.doAnswer;
7
8import android.annotation.TargetApi;
9import android.view.KeyEvent;
10import androidx.test.ext.junit.runners.AndroidJUnit4;
11import io.flutter.embedding.engine.systemchannels.KeyEventChannel;
12import io.flutter.embedding.engine.systemchannels.KeyEventChannel.EventResponseHandler;
13import io.flutter.embedding.engine.systemchannels.KeyEventChannel.FlutterKeyEvent;
14import org.junit.Before;
15import org.junit.Test;
16import org.junit.runner.RunWith;
17import org.mockito.Mock;
18import org.mockito.MockitoAnnotations;
19import org.robolectric.annotation.Config;
20
21@Config(manifest = Config.NONE)
22@RunWith(AndroidJUnit4.class)
23@TargetApi(API_LEVELS.API_28)
25
28
29 @Before
30 public void setUp() {
31 MockitoAnnotations.openMocks(this);
32 channelResponder = new KeyChannelResponder(keyEventChannel);
33 }
34
35 @Test
36 public void primaryResponderTest() {
37 final int[] completionCallbackInvocationCounter = {0};
38
39 doAnswer(
40 invocation -> {
41 ((EventResponseHandler) invocation.getArgument(2)).onFrameworkResponse(true);
42 return null;
43 })
44 .when(keyEventChannel)
45 .sendFlutterKeyEvent(
46 any(FlutterKeyEvent.class), any(boolean.class), any(EventResponseHandler.class));
47
48 final KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, 65);
49 channelResponder.handleEvent(
50 keyEvent,
51 (canHandleEvent) -> {
52 completionCallbackInvocationCounter[0]++;
53 });
54 assertEquals(completionCallbackInvocationCounter[0], 1);
55 }
56}
void handleEvent( @NonNull KeyEvent keyEvent, @NonNull OnKeyEventHandledCallback onKeyEventHandledCallback)
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530