forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forwards Flutter View to platform views and detaches when needed. (fl…
- Loading branch information
1 parent
d8d0d3f
commit 5b952f2
Showing
4 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.flutter.plugin.platform; | ||
|
||
import android.view.View; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.RuntimeEnvironment; | ||
import org.robolectric.annotation.Config; | ||
|
||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@Config(manifest=Config.NONE) | ||
@RunWith(RobolectricTestRunner.class) | ||
public class PlatformViewsControllerTest { | ||
@Test | ||
public void itNotifiesVirtualDisplayControllersOfViewAttachmentAndDetachment() { | ||
// Setup test structure. | ||
// Create a fake View that represents the View that renders a Flutter UI. | ||
View fakeFlutterView = new View(RuntimeEnvironment.systemContext); | ||
|
||
// Create fake VirtualDisplayControllers. This requires internal knowledge of | ||
// PlatformViewsController. We know that all PlatformViewsController does is | ||
// forward view attachment/detachment calls to it's VirtualDisplayControllers. | ||
// | ||
// TODO(mattcarroll): once PlatformViewsController is refactored into testable | ||
// pieces, remove this test and avoid verifying private behavior. | ||
VirtualDisplayController fakeVdController1 = mock(VirtualDisplayController.class); | ||
VirtualDisplayController fakeVdController2 = mock(VirtualDisplayController.class); | ||
|
||
// Create the PlatformViewsController that is under test. | ||
PlatformViewsController platformViewsController = new PlatformViewsController(); | ||
|
||
// Manually inject fake VirtualDisplayControllers into the PlatformViewsController. | ||
platformViewsController.vdControllers.put(0, fakeVdController1); | ||
platformViewsController.vdControllers.put(1, fakeVdController1); | ||
|
||
// Execute test & verify results. | ||
// Attach PlatformViewsController to the fake Flutter View. | ||
platformViewsController.attachToView(fakeFlutterView); | ||
|
||
// Verify that all virtual display controllers were notified of View attachment. | ||
verify(fakeVdController1, times(1)).onFlutterViewAttached(eq(fakeFlutterView)); | ||
verify(fakeVdController1, never()).onFlutterViewDetached(); | ||
verify(fakeVdController2, times(1)).onFlutterViewAttached(eq(fakeFlutterView)); | ||
verify(fakeVdController2, never()).onFlutterViewDetached(); | ||
|
||
// Detach PlatformViewsController from the fake Flutter View. | ||
platformViewsController.detachFromView(); | ||
|
||
// Verify that all virtual display controllers were notified of the View detachment. | ||
verify(fakeVdController1, times(1)).onFlutterViewAttached(eq(fakeFlutterView)); | ||
verify(fakeVdController1, times(1)).onFlutterViewDetached(); | ||
verify(fakeVdController2, times(1)).onFlutterViewAttached(eq(fakeFlutterView)); | ||
verify(fakeVdController2, times(1)).onFlutterViewDetached(); | ||
} | ||
} |