Flutter Engine
The Flutter Engine
MouseCursorPluginTest.java
Go to the documentation of this file.
1package io.flutter.plugin.mouse;
2
3import static io.flutter.Build.API_LEVELS;
4import static org.junit.Assert.assertEquals;
5import static org.mockito.Mockito.any;
6import static org.mockito.Mockito.mock;
7import static org.mockito.Mockito.spy;
8import static org.mockito.Mockito.times;
9import static org.mockito.Mockito.verify;
10
11import android.annotation.TargetApi;
12import android.app.Activity;
13import android.view.PointerIcon;
14import androidx.test.ext.junit.runners.AndroidJUnit4;
15import io.flutter.embedding.android.FlutterView;
16import io.flutter.embedding.engine.dart.DartExecutor;
17import io.flutter.embedding.engine.systemchannels.MouseCursorChannel;
18import io.flutter.plugin.common.MethodCall;
19import io.flutter.plugin.common.MethodChannel;
20import java.util.HashMap;
21import org.json.JSONException;
22import org.junit.Test;
23import org.junit.runner.RunWith;
24import org.robolectric.Robolectric;
25import org.robolectric.annotation.Config;
26
27@Config(
28 manifest = Config.NONE,
29 minSdk = API_LEVELS.API_24,
30 shadows = {})
31@RunWith(AndroidJUnit4.class)
32@TargetApi(API_LEVELS.API_24)
34
35 @SuppressWarnings("deprecation")
36 // Robolectric.setupActivity.
37 // TODO(reidbaker): https://github.com/flutter/flutter/issues/133151
38 @Test
39 public void mouseCursorPlugin_SetsSystemCursorOnRequest() throws JSONException {
40 // Migrate to ActivityScenario by following https://github.com/robolectric/robolectric/pull/4736
41 // Initialize a general MouseCursorPlugin.
42 FlutterView testView = spy(new FlutterView(Robolectric.setupActivity(Activity.class)));
43 MouseCursorChannel mouseCursorChannel = new MouseCursorChannel(mock(DartExecutor.class));
44
45 MouseCursorPlugin mouseCursorPlugin = new MouseCursorPlugin(testView, mouseCursorChannel);
46
47 final StoredResult methodResult = new StoredResult();
48 mouseCursorChannel.synthesizeMethodCall(
49 new MethodCall(
50 "activateSystemCursor",
51 new HashMap<String, Object>() {
52 private static final long serialVersionUID = 1L;
53
54 {
55 put("device", 1);
56 put("kind", "text");
57 }
58 }),
59 methodResult);
60 verify(testView, times(1)).getSystemPointerIcon(PointerIcon.TYPE_TEXT);
61 verify(testView, times(1)).setPointerIcon(any(PointerIcon.class));
62 assertEquals(methodResult.result, Boolean.TRUE);
63 }
64}
65
66class StoredResult implements MethodChannel.Result {
67 Object result;
68
69 @Override
70 public void success(Object result) {
71 this.result = result;
72 }
73
74 @Override
75 public void error(String errorCode, String errorMessage, Object errorDetails) {}
76
77 @Override
78 public void notImplemented() {}
79}
static SkISize times(const SkISize &size, float factor)
void synthesizeMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result)
void error(String errorCode, String errorMessage, Object errorDetails)
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530