Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DeferredComponentChannelTest.java
Go to the documentation of this file.
1package io.flutter.embedding.engine.systemchannels;
2
3import static org.mockito.Mockito.mock;
4import static org.mockito.Mockito.verify;
5
6import android.content.res.AssetManager;
7import androidx.test.ext.junit.runners.AndroidJUnit4;
8import io.flutter.embedding.engine.FlutterJNI;
9import io.flutter.embedding.engine.dart.DartExecutor;
10import io.flutter.embedding.engine.deferredcomponents.DeferredComponentManager;
11import io.flutter.plugin.common.MethodCall;
12import io.flutter.plugin.common.MethodChannel;
13import java.util.HashMap;
14import java.util.Map;
15import org.junit.Test;
16import org.junit.runner.RunWith;
17import org.robolectric.annotation.Config;
18
19class TestDeferredComponentManager implements DeferredComponentManager {
22
23 public void setJNI(FlutterJNI flutterJNI) {}
24
28
29 public void installDeferredComponent(int loadingUnitId, String componentName) {
30 this.componentName = componentName;
31 }
32
36
37 public String getDeferredComponentInstallState(int loadingUnitId, String componentName) {
38 return "installed";
39 }
40
41 public void loadAssets(int loadingUnitId, String componentName) {}
42
43 public void loadDartLibrary(int loadingUnitId, String componentName) {}
44
45 public boolean uninstallDeferredComponent(int loadingUnitId, String componentName) {
46 return true;
47 }
48
49 public void destroy() {}
50}
51
52@Config(manifest = Config.NONE)
53@RunWith(AndroidJUnit4.class)
55 @Test
57 MethodChannel rawChannel = mock(MethodChannel.class);
58 FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
59 DartExecutor dartExecutor = new DartExecutor(mockFlutterJNI, mock(AssetManager.class));
60 TestDeferredComponentManager testDeferredComponentManager = new TestDeferredComponentManager();
61 DeferredComponentChannel fakeDeferredComponentChannel =
62 new DeferredComponentChannel(dartExecutor);
63 fakeDeferredComponentChannel.setDeferredComponentManager(testDeferredComponentManager);
64 testDeferredComponentManager.setDeferredComponentChannel(fakeDeferredComponentChannel);
65
66 Map<String, Object> args = new HashMap<>();
67 args.put("loadingUnitId", -1);
68 args.put("componentName", "hello");
69 MethodCall methodCall = new MethodCall("installDeferredComponent", args);
70 MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
71 fakeDeferredComponentChannel.parsingMethodHandler.onMethodCall(methodCall, mockResult);
72
73 testDeferredComponentManager.completeInstall();
74 verify(mockResult).success(null);
75 }
76
77 @Test
79 MethodChannel rawChannel = mock(MethodChannel.class);
80 FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
81 DartExecutor dartExecutor = new DartExecutor(mockFlutterJNI, mock(AssetManager.class));
82 TestDeferredComponentManager testDeferredComponentManager = new TestDeferredComponentManager();
83 DeferredComponentChannel fakeDeferredComponentChannel =
84 new DeferredComponentChannel(dartExecutor);
85 fakeDeferredComponentChannel.setDeferredComponentManager(testDeferredComponentManager);
86 testDeferredComponentManager.setDeferredComponentChannel(fakeDeferredComponentChannel);
87
88 Map<String, Object> args = new HashMap<>();
89 args.put("loadingUnitId", -1);
90 args.put("componentName", "hello");
91 MethodCall methodCall = new MethodCall("installDeferredComponent", args);
92 MethodChannel.Result mockResult1 = mock(MethodChannel.Result.class);
93 MethodChannel.Result mockResult2 = mock(MethodChannel.Result.class);
94 fakeDeferredComponentChannel.parsingMethodHandler.onMethodCall(methodCall, mockResult1);
95 fakeDeferredComponentChannel.parsingMethodHandler.onMethodCall(methodCall, mockResult2);
96
97 testDeferredComponentManager.completeInstall();
98 verify(mockResult1).success(null);
99 verify(mockResult2).success(null);
100 }
101
102 @Test
104 MethodChannel rawChannel = mock(MethodChannel.class);
105 FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
106 DartExecutor dartExecutor = new DartExecutor(mockFlutterJNI, mock(AssetManager.class));
107 TestDeferredComponentManager testDeferredComponentManager = new TestDeferredComponentManager();
108 DeferredComponentChannel fakeDeferredComponentChannel =
109 new DeferredComponentChannel(dartExecutor);
110 fakeDeferredComponentChannel.setDeferredComponentManager(testDeferredComponentManager);
111 testDeferredComponentManager.setDeferredComponentChannel(fakeDeferredComponentChannel);
112
113 Map<String, Object> args = new HashMap<>();
114 args.put("loadingUnitId", -1);
115 args.put("componentName", "hello");
116 MethodCall methodCall = new MethodCall("getDeferredComponentInstallState", args);
117 MethodChannel.Result mockResult = mock(MethodChannel.Result.class);
118 fakeDeferredComponentChannel.parsingMethodHandler.onMethodCall(methodCall, mockResult);
119
120 testDeferredComponentManager.completeInstall();
121 verify(mockResult).success("installed");
122 }
123}
void setDeferredComponentManager( @Nullable DeferredComponentManager deferredComponentManager)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static ::testing::Matcher< GBytes * > MethodCall(const std::string &name, ::testing::Matcher< FlValue * > args)