From 79024b24da5a47b81c292e48e9fdc496915c2c16 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Wed, 15 Nov 2023 00:56:10 +0100 Subject: [PATCH] updated tests, fixed ios and macos headless to inappwebview conversion --- example/integration_test/in_app_webview/main.dart | 6 ++++++ .../integration_test/in_app_webview/web_message.dart | 2 +- example/integration_test/webview_flutter_test.dart | 4 ---- .../HeadlessInAppWebView/HeadlessInAppWebView.swift | 12 +++++++++--- .../HeadlessInAppWebView/HeadlessInAppWebView.swift | 12 +++++++++--- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/example/integration_test/in_app_webview/main.dart b/example/integration_test/in_app_webview/main.dart index f98ae5d1..6f9239db 100644 --- a/example/integration_test/in_app_webview/main.dart +++ b/example/integration_test/in_app_webview/main.dart @@ -194,6 +194,12 @@ void main() { ].contains(defaultTargetPlatform); skippableGroup('InAppWebView', () { + setUpAll(() async { + if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) { + await InAppWebViewController.setWebContentsDebuggingEnabled(true); + } + }); + initialUrlRequest(); setGetSettings(); javascriptCodeEvaluation(); diff --git a/example/integration_test/in_app_webview/web_message.dart b/example/integration_test/in_app_webview/web_message.dart index fe6e4327..2deafb9f 100644 --- a/example/integration_test/in_app_webview/web_message.dart +++ b/example/integration_test/in_app_webview/web_message.dart @@ -121,7 +121,7 @@ void webMessage() { if (event.ports[0] != null) { port = event.ports[0]; port.onmessage = function (event) { - console.log(event.data); + console.log(bufferToString(event.data)); }; } } diff --git a/example/integration_test/webview_flutter_test.dart b/example/integration_test/webview_flutter_test.dart index 69b407b3..cc7e6d0e 100644 --- a/example/integration_test/webview_flutter_test.dart +++ b/example/integration_test/webview_flutter_test.dart @@ -18,10 +18,6 @@ import 'tracing_controller/main.dart' as tracing_controller_tests; void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); - if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) { - InAppWebViewController.setWebContentsDebuggingEnabled(true); - } - WebView.debugLoggingSettings.usePrint = true; WebView.debugLoggingSettings.maxLogMessageLength = 7000; InAppBrowser.debugLoggingSettings.usePrint = true; diff --git a/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift b/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift index e7f035c9..57234cd2 100644 --- a/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift +++ b/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift @@ -71,20 +71,26 @@ public class HeadlessInAppWebView : Disposable { view.alpha = 1.0 // remove from parent view.removeFromSuperview() - dispose() + dispose(disposeWebView: false) } return newFlutterWebView } - public func dispose() { + public func dispose(disposeWebView: Bool) { channelDelegate?.dispose() channelDelegate = nil plugin?.headlessInAppWebViewManager?.webViews[id] = nil - flutterWebView?.dispose(removeFromSuperview: true) + if disposeWebView { + flutterWebView?.dispose(removeFromSuperview: true) + } flutterWebView = nil plugin = nil } + public func dispose() { + dispose(disposeWebView: true) + } + deinit { debugPrint("HeadlessInAppWebView - dealloc") dispose() diff --git a/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift b/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift index e32fbcda..cfc36a1a 100644 --- a/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift +++ b/macos/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift @@ -72,21 +72,27 @@ public class HeadlessInAppWebView : Disposable { view.alphaValue = 1.0 // remove from parent view.removeFromSuperview() - dispose() + dispose(disposeWebView: false) } return newFlutterWebView } - public func dispose() { + public func dispose(disposeWebView: Bool) { channelDelegate?.dispose() channelDelegate = nil plugin?.headlessInAppWebViewManager?.webViews[id] = nil - flutterWebView?.dispose(removeFromSuperview: true) + if disposeWebView { + flutterWebView?.dispose(removeFromSuperview: true) + } flutterWebView = nil plugin = nil } + public func dispose() { + dispose(disposeWebView: true) + } + deinit { debugPrint("HeadlessInAppWebView - dealloc") dispose()