|
1 | 1 | package test.io.flutter.embedding.engine;
|
2 | 2 |
|
| 3 | +import io.flutter.plugin.platform.PlatformViewsController; |
3 | 4 | import io.flutter.plugins.GeneratedPluginRegistrant;
|
4 | 5 | import java.util.List;
|
5 | 6 | import org.junit.After;
|
6 | 7 | import org.junit.Before;
|
7 | 8 | import org.junit.Test;
|
8 | 9 | import org.junit.runner.RunWith;
|
| 10 | +import org.mockito.ArgumentCaptor; |
9 | 11 | import org.mockito.Mock;
|
10 | 12 | import org.mockito.MockitoAnnotations;
|
11 | 13 | import org.robolectric.RobolectricTestRunner;
|
|
17 | 19 | import io.flutter.embedding.engine.loader.FlutterLoader;
|
18 | 20 |
|
19 | 21 | import static org.junit.Assert.assertEquals;
|
| 22 | +import static org.junit.Assert.assertNotNull; |
20 | 23 | import static org.junit.Assert.assertTrue;
|
21 | 24 | import static org.mockito.Mockito.mock;
|
| 25 | +import static org.mockito.Mockito.times; |
| 26 | +import static org.mockito.Mockito.verify; |
22 | 27 | import static org.mockito.Mockito.when;
|
23 | 28 |
|
24 | 29 | @Config(manifest=Config.NONE)
|
@@ -64,4 +69,37 @@ public void itCanBeConfiguredToNotAutomaticallyRegisterPlugins() {
|
64 | 69 |
|
65 | 70 | assertTrue(GeneratedPluginRegistrant.getRegisteredEngines().isEmpty());
|
66 | 71 | }
|
| 72 | + |
| 73 | + @Test |
| 74 | + public void itNotifiesPlatformViewsControllerWhenDevHotRestart() { |
| 75 | + // Setup test. |
| 76 | + FlutterJNI mockFlutterJNI = mock(FlutterJNI.class); |
| 77 | + when(mockFlutterJNI.isAttached()).thenReturn(true); |
| 78 | + |
| 79 | + PlatformViewsController platformViewsController = mock(PlatformViewsController.class); |
| 80 | + |
| 81 | + ArgumentCaptor<FlutterEngine.EngineLifecycleListener> engineLifecycleListenerArgumentCaptor = ArgumentCaptor.forClass(FlutterEngine.EngineLifecycleListener.class); |
| 82 | + |
| 83 | + // Execute behavior under test. |
| 84 | + new FlutterEngine( |
| 85 | + RuntimeEnvironment.application, |
| 86 | + mock(FlutterLoader.class), |
| 87 | + mockFlutterJNI, |
| 88 | + platformViewsController, |
| 89 | + /*dartVmArgs=*/new String[] {}, |
| 90 | + /*automaticallyRegisterPlugins=*/false |
| 91 | + ); |
| 92 | + |
| 93 | + // Obtain the EngineLifecycleListener within FlutterEngine that was given to FlutterJNI. |
| 94 | + verify(mockFlutterJNI).addEngineLifecycleListener(engineLifecycleListenerArgumentCaptor.capture()); |
| 95 | + FlutterEngine.EngineLifecycleListener engineLifecycleListener = engineLifecycleListenerArgumentCaptor.getValue(); |
| 96 | + assertNotNull(engineLifecycleListener); |
| 97 | + |
| 98 | + // Simulate a pre-engine restart, AKA hot restart. |
| 99 | + engineLifecycleListener.onPreEngineRestart(); |
| 100 | + |
| 101 | + // Verify that FlutterEngine notified PlatformViewsController of the pre-engine restart, |
| 102 | + // AKA hot restart. |
| 103 | + verify(platformViewsController, times(1)).onPreEngineRestart(); |
| 104 | + } |
67 | 105 | }
|
0 commit comments