Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bd5dc53

Browse files
author
Emmanuel Garcia
committed
Fix test
1 parent 557f3e6 commit bd5dc53

4 files changed

Lines changed: 62 additions & 21 deletions

File tree

shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ private void create(@NonNull MethodCall call, @NonNull MethodChannel.Result resu
9999
createArgs.containsKey("params")
100100
? ByteBuffer.wrap((byte[]) createArgs.get("params"))
101101
: null);
102+
System.out.println("YEAA");
102103
try {
103104
if (usesHybridComposition) {
104105
handler.createAndroidViewForPlatformView(request);

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
5959
private View flutterView;
6060

6161
// The texture registry maintaining the textures into which the embedded views will be rendered.
62-
private TextureRegistry textureRegistry;
62+
@Nullable private TextureRegistry textureRegistry;
6363

6464
@Nullable private TextInputPlugin textInputPlugin;
6565

shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
import android.content.Context;
99
import android.content.res.AssetManager;
10+
import android.graphics.SurfaceTexture;
1011
import android.util.SparseArray;
1112
import android.view.MotionEvent;
1213
import android.view.Surface;
1314
import android.view.SurfaceHolder;
1415
import android.view.SurfaceView;
1516
import android.view.View;
1617
import android.view.ViewParent;
18+
import android.widget.FrameLayout.LayoutParams;
1719
import io.flutter.embedding.android.FlutterImageView;
1820
import io.flutter.embedding.android.FlutterView;
1921
import io.flutter.embedding.android.MotionEventTracker;
@@ -32,6 +34,7 @@
3234
import io.flutter.plugin.common.MethodCall;
3335
import io.flutter.plugin.common.StandardMethodCodec;
3436
import io.flutter.plugin.localization.LocalizationPlugin;
37+
import io.flutter.view.TextureRegistry;
3538
import java.nio.ByteBuffer;
3639
import java.util.Arrays;
3740
import java.util.HashMap;
@@ -232,7 +235,7 @@ public void getPlatformViewById__hybridComposition() {
232235
attach(jni, platformViewsController);
233236

234237
// Simulate create call from the framework.
235-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
238+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
236239

237240
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
238241

@@ -259,7 +262,7 @@ public void createPlatformViewMessage__initializesAndroidView() {
259262
attach(jni, platformViewsController);
260263

261264
// Simulate create call from the framework.
262-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
265+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
263266
verify(viewFactory, times(1)).create(any(), eq(platformViewId), any());
264267
}
265268

@@ -281,7 +284,7 @@ public void createPlatformViewMessage__throwsIfViewIsNull() {
281284
attach(jni, platformViewsController);
282285

283286
// Simulate create call from the framework.
284-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
287+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
285288
assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
286289

287290
assertThrows(
@@ -301,15 +304,20 @@ public void onDetachedFromJNI_clearsPlatformViewContext() {
301304

302305
PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
303306
PlatformView platformView = mock(PlatformView.class);
304-
when(platformView.getView()).thenReturn(null);
307+
308+
View pv = mock(View.class);
309+
when(pv.getLayoutParams()).thenReturn(new LayoutParams(1, 1));
310+
311+
when(platformView.getView()).thenReturn(pv);
305312
when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
306313
platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
307314

308315
FlutterJNI jni = new FlutterJNI();
309316
attach(jni, platformViewsController);
310317

311318
// Simulate create call from the framework.
312-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
319+
createPlatformView(
320+
jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
313321

314322
assertFalse(platformViewsController.contextToPlatformView.isEmpty());
315323
platformViewsController.onDetachedFromJNI();
@@ -326,15 +334,20 @@ public void onPreEngineRestart_clearsPlatformViewContext() {
326334

327335
PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
328336
PlatformView platformView = mock(PlatformView.class);
329-
when(platformView.getView()).thenReturn(null);
337+
338+
View pv = mock(View.class);
339+
when(pv.getLayoutParams()).thenReturn(new LayoutParams(1, 1));
340+
341+
when(platformView.getView()).thenReturn(pv);
330342
when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
331343
platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
332344

333345
FlutterJNI jni = new FlutterJNI();
334346
attach(jni, platformViewsController);
335347

336348
// Simulate create call from the framework.
337-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
349+
createPlatformView(
350+
jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
338351

339352
assertFalse(platformViewsController.contextToPlatformView.isEmpty());
340353
platformViewsController.onDetachedFromJNI();
@@ -361,7 +374,7 @@ public void createPlatformViewMessage__throwsIfViewHasParent() {
361374
attach(jni, platformViewsController);
362375

363376
// Simulate create call from the framework.
364-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
377+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
365378
assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
366379

367380
assertThrows(
@@ -393,7 +406,7 @@ public void disposeAndroidView__hybridComposition() {
393406
attach(jni, platformViewsController);
394407

395408
// Simulate create call from the framework.
396-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
409+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
397410
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
398411

399412
assertNotNull(androidView.getParent());
@@ -404,7 +417,7 @@ public void disposeAndroidView__hybridComposition() {
404417
assertNull(androidView.getParent());
405418

406419
// Simulate create call from the framework.
407-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
420+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
408421
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
409422

410423
assertNotNull(androidView.getParent());
@@ -434,7 +447,7 @@ public void onEndFrame__destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView() {
434447
jni.onFirstFrame();
435448

436449
// Simulate create call from the framework.
437-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
450+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
438451

439452
// Produce a frame that displays a platform view and an overlay surface.
440453
platformViewsController.onBeginFrame();
@@ -497,7 +510,7 @@ public void onEndFrame__removesPlatformView() {
497510
jni.onFirstFrame();
498511

499512
// Simulate create call from the framework.
500-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
513+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
501514

502515
// Simulate first frame from the framework.
503516
jni.onFirstFrame();
@@ -534,7 +547,7 @@ public void onEndFrame__removesPlatformViewParent() {
534547
jni.onFirstFrame();
535548

536549
// Simulate create call from the framework.
537-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
550+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
538551
platformViewsController.initializePlatformViewIfNeeded(platformViewId);
539552
assertEquals(flutterView.getChildCount(), 2);
540553

@@ -570,7 +583,7 @@ public void detach__destroysOverlaySurfaces() {
570583
jni.onFirstFrame();
571584

572585
// Simulate create call from the framework.
573-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
586+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
574587

575588
// Produce a frame that displays a platform view and an overlay surface.
576589
platformViewsController.onBeginFrame();
@@ -703,7 +716,7 @@ public void convertPlatformViewRenderSurfaceAsDefault() {
703716
jni.onFirstFrame();
704717

705718
// Simulate create call from the framework.
706-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
719+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
707720

708721
// Produce a frame that displays a platform view and an overlay surface.
709722
platformViewsController.onBeginFrame();
@@ -752,7 +765,7 @@ public void dontConverRenderSurfaceWhenFlagIsTrue() {
752765
synchronizeToNativeViewHierarchy(jni, platformViewsController, false);
753766

754767
// Simulate create call from the framework.
755-
createPlatformView(jni, platformViewsController, platformViewId, "testType");
768+
createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
756769

757770
// Produce a frame that displays a platform view and an overlay surface.
758771
platformViewsController.onBeginFrame();
@@ -784,12 +797,16 @@ private static void createPlatformView(
784797
FlutterJNI jni,
785798
PlatformViewsController platformViewsController,
786799
int platformViewId,
787-
String viewType) {
800+
String viewType,
801+
boolean hybrid) {
788802
final Map<String, Object> platformViewCreateArguments = new HashMap<>();
789-
platformViewCreateArguments.put("hybrid", true);
803+
platformViewCreateArguments.put("hybrid", hybrid);
790804
platformViewCreateArguments.put("id", platformViewId);
791805
platformViewCreateArguments.put("viewType", viewType);
792806
platformViewCreateArguments.put("direction", 0);
807+
platformViewCreateArguments.put("width", 1.0);
808+
platformViewCreateArguments.put("height", 1.0);
809+
793810
final MethodCall platformCreateMethodCall =
794811
new MethodCall("create", platformViewCreateArguments);
795812

@@ -826,7 +843,30 @@ private static FlutterView attach(
826843
executor.onAttachedToJNI();
827844

828845
final Context context = RuntimeEnvironment.application.getApplicationContext();
829-
platformViewsController.attach(context, null, executor);
846+
final TextureRegistry registry =
847+
new TextureRegistry() {
848+
public void TextureRegistry() {}
849+
850+
@Override
851+
public SurfaceTextureEntry createSurfaceTexture() {
852+
return new SurfaceTextureEntry() {
853+
@Override
854+
public SurfaceTexture surfaceTexture() {
855+
return mock(SurfaceTexture.class);
856+
}
857+
858+
@Override
859+
public long id() {
860+
return 0;
861+
}
862+
863+
@Override
864+
public void release() {}
865+
};
866+
}
867+
};
868+
869+
platformViewsController.attach(context, registry, executor);
830870

831871
final FlutterView view =
832872
new FlutterView(context, FlutterView.RenderMode.surface) {

testing/run_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def AssertExpectedJavaVersion():
320320
"""Checks that the user has Java 8 which is the supported Java version for Android"""
321321
EXPECTED_VERSION = '1.8'
322322
# `java -version` is output to stderr. https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4380614
323-
version_output = subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)
323+
version_output = str(subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT), 'utf-8')
324324
match = bool(re.compile('version "%s' % EXPECTED_VERSION).search(version_output))
325325
message = "JUnit tests need to be run with Java %s. Check the `java -version` on your PATH." % EXPECTED_VERSION
326326
assert match, message

0 commit comments

Comments
 (0)