Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview_flutter_wkwebview] Repeatedly pump WebViews until one is garbage collected #4662

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,47 +69,50 @@ Future<void> main() async {
testWidgets(
'WKWebView is released by garbage collection',
(WidgetTester tester) async {
final Completer<void> webViewGCCompleter = Completer<void>();
bool aWebViewHasBeenGarbageCollected = false;

late final InstanceManager instanceManager;
instanceManager =
InstanceManager(onWeakReferenceRemoved: (int identifier) {
final Copyable instance =
instanceManager.getInstanceWithWeakReference(identifier)!;
if (instance is WKWebView && !webViewGCCompleter.isCompleted) {
webViewGCCompleter.complete();
if (!aWebViewHasBeenGarbageCollected) {
final Copyable instance =
instanceManager.getInstanceWithWeakReference(identifier)!;
if (instance is WKWebView) {
aWebViewHasBeenGarbageCollected = true;
}
}
});

await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
WebKitWebViewWidgetCreationParams(
instanceManager: instanceManager,
controller: PlatformWebViewController(
WebKitWebViewControllerCreationParams(
instanceManager: instanceManager,
// Wait for any WebView to be garbage collected.
while (!aWebViewHasBeenGarbageCollected) {
await tester.pumpWidget(
Builder(
builder: (BuildContext context) {
return PlatformWebViewWidget(
WebKitWebViewWidgetCreationParams(
instanceManager: instanceManager,
controller: PlatformWebViewController(
WebKitWebViewControllerCreationParams(
instanceManager: instanceManager,
),
),
),
),
).build(context);
},
),
);
await tester.pumpAndSettle();

await tester.pumpWidget(Container());

// Force garbage collection.
await IntegrationTestWidgetsFlutterBinding.instance
.watchPerformance(() async {
).build(context);
},
),
);
await tester.pumpAndSettle();
});

await expectLater(webViewGCCompleter.future, completes);
await tester.pumpWidget(Container());

// Force garbage collection.
await IntegrationTestWidgetsFlutterBinding.instance
.watchPerformance(() async {
await tester.pumpAndSettle();
});
}
},
timeout: const Timeout(Duration(seconds: 10)),
timeout: const Timeout(Duration(seconds: 30)),
);

testWidgets('loadRequest', (WidgetTester tester) async {
Expand Down