Skip to content

Add test case for AndroidView clipBehavior#67913

Merged
fluttergithubbot merged 3 commits intoflutter:masterfrom
xu-baolin:cliptest101201
Oct 14, 2020
Merged

Add test case for AndroidView clipBehavior#67913
fluttergithubbot merged 3 commits intoflutter:masterfrom
xu-baolin:cliptest101201

Conversation

@xu-baolin
Copy link
Member

@xu-baolin xu-baolin commented Oct 12, 2020

Description

@liyuqian

Add a test case for AndroidView clipBehavior

Related Issues

Fixes #67455
#67343

Tests

See files.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 12, 2020
@google-cla google-cla bot added the cla: yes label Oct 12, 2020
Copy link
Contributor

@liyuqian liyuqian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing this test! Here are a few minor comments.

}
});

testWidgets('clipBehavior test', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make the test name more descriptive such as 'clip is handled correctly during resizing'

);
}

await tester.pumpWidget(buildView(200.0, 200.0, Clip.none));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems to rely on RenderAndroidView to be retained in its last size while the parent widget resizes. I can't find any description about this behavior in https://master-api.flutter.dev/flutter/widgets/AndroidView-class.html. CC @cyanglaz @amirh to double check if this is expected and whether we can rely on this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an existing test case to test this behavior:

testWidgets('Resize Android view', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
final FakeAndroidPlatformViewsController viewsController = FakeAndroidPlatformViewsController();
viewsController.registerViewType('webview');
await tester.pumpWidget(
const Center(
child: SizedBox(
width: 200.0,
height: 100.0,
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
),
),
);
viewsController.resizeCompleter = Completer<void>();
await tester.pumpWidget(
const Center(
child: SizedBox(
width: 100.0,
height: 50.0,
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
),
),
);
final Layer textureParentLayer = tester.layers[tester.layers.length - 2];
expect(textureParentLayer, isA<ClipRectLayer>());
final ClipRectLayer clipRect = textureParentLayer as ClipRectLayer;
expect(clipRect.clipRect, const Rect.fromLTWH(0.0, 0.0, 100.0, 50.0));
expect(
viewsController.views,
unorderedEquals(<FakeAndroidPlatformView>[
FakeAndroidPlatformView(currentViewId + 1, 'webview', const Size(200.0, 100.0),
AndroidViewController.kAndroidLayoutDirectionLtr, null),
]),
);
viewsController.resizeCompleter.complete();
await tester.pump();
expect(
viewsController.views,
unorderedEquals(<FakeAndroidPlatformView>[
FakeAndroidPlatformView(currentViewId + 1, 'webview', const Size(100.0, 50.0),
AndroidViewController.kAndroidLayoutDirectionLtr, null),
]),
);
});

// No clip happen when the clip behavior is `Clip.none` .
expect(tester.layers.whereType<ClipRectLayer>(), hasLength(0));

// No clip happen when the clip behavior only change.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// No clip happen when the clip behavior only change. -> // No clip when only the clip behavior changes while the size remains the same.

Copy link
Contributor

@liyuqian liyuqian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a test for RenderAndroidView's clip logic

4 participants