Flutter Engine
The Flutter Engine
AccessibilityChannelTest.java
Go to the documentation of this file.
1package io.flutter.embedding.engine.systemchannels;
2
3import static io.flutter.Build.API_LEVELS;
4import static org.mockito.Mockito.mock;
5import static org.mockito.Mockito.verify;
6
7import android.annotation.TargetApi;
8import io.flutter.embedding.engine.FlutterJNI;
9import io.flutter.embedding.engine.dart.DartExecutor;
10import io.flutter.plugin.common.BasicMessageChannel;
11import java.util.HashMap;
12import org.json.JSONException;
13import org.json.JSONObject;
14import org.junit.Test;
15import org.junit.runner.RunWith;
16import org.robolectric.RobolectricTestRunner;
17import org.robolectric.annotation.Config;
18
19@Config(
20 manifest = Config.NONE,
21 shadows = {})
22@RunWith(RobolectricTestRunner.class)
23@TargetApi(API_LEVELS.API_24)
25 @Test
26 public void repliesWhenNoAccessibilityHandler() throws JSONException {
27 AccessibilityChannel accessibilityChannel =
28 new AccessibilityChannel(mock(DartExecutor.class), mock(FlutterJNI.class));
29 JSONObject arguments = new JSONObject();
30 arguments.put("type", "announce");
31 BasicMessageChannel.Reply reply = mock(BasicMessageChannel.Reply.class);
32 accessibilityChannel.parsingMessageHandler.onMessage(arguments, reply);
33 verify(reply).reply(null);
34 }
35
36 @Test
37 public void handleFocus() throws JSONException {
38 AccessibilityChannel accessibilityChannel =
39 new AccessibilityChannel(mock(DartExecutor.class), mock(FlutterJNI.class));
40 HashMap<String, Object> arguments = new HashMap<>();
41 arguments.put("type", "focus");
42 arguments.put("nodeId", 123);
43 AccessibilityChannel.AccessibilityMessageHandler handler =
45 accessibilityChannel.setAccessibilityMessageHandler(handler);
46 BasicMessageChannel.Reply reply = mock(BasicMessageChannel.Reply.class);
47 accessibilityChannel.parsingMessageHandler.onMessage(arguments, reply);
48 verify(handler).onFocus(123);
49 }
50}
final BasicMessageChannel.MessageHandler< Object > parsingMessageHandler
void setAccessibilityMessageHandler(@Nullable AccessibilityMessageHandler handler)