fixed nativeValue in case of null, updated log debug settings for flutter test cases

This commit is contained in:
Lorenzo Pichilli 2022-10-05 19:48:34 +02:00
parent 8a9bb5cabc
commit caf8ae915b
39 changed files with 236 additions and 72 deletions

View File

@ -10,12 +10,12 @@ import java.util.HashMap;
import java.util.Map;
public class WebResourceErrorExt {
private int errorCode;
private int type;
@NonNull
private String description;
public WebResourceErrorExt(int errorCode, @NonNull String description) {
this.errorCode = errorCode;
public WebResourceErrorExt(int type, @NonNull String description) {
this.type = type;
this.description = description;
}
@ -26,17 +26,17 @@ public class WebResourceErrorExt {
public Map<String, Object> toMap() {
Map<String, Object> webResourceErrorMap = new HashMap<>();
webResourceErrorMap.put("errorCode", getErrorCode());
webResourceErrorMap.put("type", getType());
webResourceErrorMap.put("description", getDescription());
return webResourceErrorMap;
}
public int getErrorCode() {
return errorCode;
public int getType() {
return type;
}
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
public void setType(int type) {
this.type = type;
}
@NonNull
@ -55,13 +55,13 @@ public class WebResourceErrorExt {
WebResourceErrorExt that = (WebResourceErrorExt) o;
if (errorCode != that.errorCode) return false;
if (type != that.type) return false;
return description.equals(that.description);
}
@Override
public int hashCode() {
int result = errorCode;
int result = type;
result = 31 * result + description.hashCode();
return result;
}
@ -69,7 +69,7 @@ public class WebResourceErrorExt {
@Override
public String toString() {
return "WebResourceErrorExt{" +
"errorCode=" + errorCode +
"type=" + type +
", description='" + description + '\'' +
'}';
}

View File

@ -519,6 +519,9 @@ class ExchangeableObjectGenerator
} else {
return value;
}
} else if (elementType.isDartCoreMap) {
final genericTypes = Util.getGenericTypes(elementType);
return "$value${isNullable ? '?' : ''}.cast<${genericTypes.elementAt(0)}, ${genericTypes.elementAt(1)}>()";
} else if (fieldTypeElement != null && hasFromMapMethod(fieldTypeElement)) {
final hasNullableFromMap = hasNullableFromMapFactory(fieldTypeElement);
// remove class reference terminating with "_"

View File

@ -18,6 +18,15 @@ void main() {
InAppWebViewController.setWebContentsDebuggingEnabled(true);
}
WebView.debugLoggingSettings.usePrint = true;
WebView.debugLoggingSettings.maxLogMessageLength = -1;
InAppBrowser.debugLoggingSettings.usePrint = true;
InAppBrowser.debugLoggingSettings.maxLogMessageLength = -1;
ChromeSafariBrowser.debugLoggingSettings.usePrint = true;
ChromeSafariBrowser.debugLoggingSettings.maxLogMessageLength = -1;
WebAuthenticationSession.debugLoggingSettings.usePrint = true;
WebAuthenticationSession.debugLoggingSettings.maxLogMessageLength = -1;
in_app_webview_tests.main();
service_worker_controller_tests.main();
proxy_controller_tests.main();

View File

@ -3,12 +3,11 @@
export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.10.4"
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/lib/main.dart"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/.dart_tool/package_config.json"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"

View File

@ -1818,7 +1818,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate,
}
let webResourceRequest = WebResourceRequest(url: urlError, headers: nil)
let webResourceError = WebResourceError(errorCode: errorCode, errorDescription: errorDescription)
let webResourceError = WebResourceError(type: errorCode, errorDescription: errorDescription)
channelDelegate?.onReceivedError(request: webResourceRequest, error: webResourceError)

View File

@ -8,17 +8,17 @@
import Foundation
public class WebResourceError: NSObject {
var errorCode: Int
var type: Int
var errorDescription: String
public init(errorCode: Int, errorDescription: String) {
self.errorCode = errorCode
public init(type: Int, errorDescription: String) {
self.type = type
self.errorDescription = errorDescription
}
public func toMap () -> [String:Any?] {
return [
"errorCode": errorCode,
"type": type,
"description": errorDescription
]
}

View File

@ -27,7 +27,14 @@ class ProxyController {
}
static ProxyController _init() {
_channel.setMethodCallHandler(_handleMethod);
_channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_instance = ProxyController();
return _instance!;
}

View File

@ -38,7 +38,14 @@ class ServiceWorkerController {
}
static ServiceWorkerController _init() {
_channel.setMethodCallHandler(_handleMethod);
_channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_instance = ServiceWorkerController();
return _instance!;
}
@ -222,7 +229,14 @@ class AndroidServiceWorkerController {
}
static AndroidServiceWorkerController _init() {
_channel.setMethodCallHandler(_handleMethod);
_channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_instance = AndroidServiceWorkerController();
return _instance!;
}

View File

@ -62,7 +62,14 @@ class ChromeSafariBrowser {
id = IdGenerator.generate();
this._channel =
MethodChannel('com.pichillilorenzo/flutter_chromesafaribrowser_$id');
this._channel.setMethodCallHandler(_handleMethod);
this._channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_isOpened = false;
}
@ -83,7 +90,11 @@ class ChromeSafariBrowser {
if (maxLogMessageLength >= 0 && message.length > maxLogMessageLength) {
message = message.substring(0, maxLogMessageLength) + "...";
}
developer.log(message, name: this.runtimeType.toString());
if (!ChromeSafariBrowser.debugLoggingSettings.usePrint) {
developer.log(message, name: this.runtimeType.toString());
} else {
print("[${this.runtimeType.toString()}] $message");
}
}
}

View File

@ -42,7 +42,14 @@ class CookieManager {
}
static CookieManager _init() {
_channel.setMethodCallHandler(_handleMethod);
_channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_instance = CookieManager();
// ignore: deprecated_member_use_from_same_package
_instance!.ios = IOSCookieManager.instance();

View File

@ -21,9 +21,13 @@ class DebugLoggingSettings {
///The default value is `-1`.
int maxLogMessageLength;
///Use [print] instead of `developer.log` to log messages.
bool usePrint;
DebugLoggingSettings({
this.enabled = kDebugMode,
this.excludeFilter = const [],
this.maxLogMessageLength = -1
this.maxLogMessageLength = -1,
this.usePrint = false
});
}

View File

@ -23,7 +23,14 @@ class HttpAuthCredentialDatabase {
}
static HttpAuthCredentialDatabase _init() {
_channel.setMethodCallHandler(_handleMethod);
_channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_instance = HttpAuthCredentialDatabase();
return _instance!;
}

View File

@ -85,7 +85,14 @@ class InAppBrowser {
id = IdGenerator.generate();
this._channel =
MethodChannel('com.pichillilorenzo/flutter_inappbrowser_$id');
this._channel.setMethodCallHandler(_handleMethod);
this._channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_isOpened = false;
webViewController = new InAppWebViewController.fromInAppBrowser(
this._channel, this, this.initialUserScripts);
@ -108,7 +115,11 @@ class InAppBrowser {
if (maxLogMessageLength >= 0 && message.length > maxLogMessageLength) {
message = message.substring(0, maxLogMessageLength) + "...";
}
developer.log(message, name: this.runtimeType.toString());
if (!InAppBrowser.debugLoggingSettings.usePrint) {
developer.log(message, name: this.runtimeType.toString());
} else {
print("[${this.runtimeType.toString()}] $message");
}
}
}

View File

@ -159,7 +159,14 @@ class HeadlessInAppWebView implements WebView, Disposable {
webViewController = new InAppWebViewController(id, this);
this._channel =
MethodChannel('com.pichillilorenzo/flutter_headless_inappwebview_$id');
this._channel.setMethodCallHandler(handleMethod);
this._channel.setMethodCallHandler((call) async {
try {
return await handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
Future<dynamic> handleMethod(MethodCall call) async {

View File

@ -78,7 +78,14 @@ class InAppWebViewController {
this._id = id;
this._channel =
MethodChannel('com.pichillilorenzo/flutter_inappwebview_$id');
this._channel.setMethodCallHandler(handleMethod);
this._channel.setMethodCallHandler((call) async {
try {
return await handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
this._webview = webview;
this._userScripts =
List<UserScript>.from(webview.initialUserScripts ?? <UserScript>[]);
@ -123,7 +130,11 @@ class InAppWebViewController {
if (maxLogMessageLength >= 0 && message.length > maxLogMessageLength) {
message = message.substring(0, maxLogMessageLength) + "...";
}
developer.log(message, name: this.runtimeType.toString());
if (!WebView.debugLoggingSettings.usePrint) {
developer.log(message, name: this.runtimeType.toString());
} else {
print("[${this.runtimeType.toString()}] $message");
}
}
}
@ -175,13 +186,13 @@ class InAppWebViewController {
else if (isForMainFrame) {
// ignore: deprecated_member_use_from_same_package
_webview!.onLoadError!(this, request.url,
error.type.toNativeValue(), error.description);
error.type.toNativeValue() ?? -1, error.description);
}
} else {
if (isForMainFrame) {
_inAppBrowser!
// ignore: deprecated_member_use_from_same_package
.onLoadError(request.url, error.type.toNativeValue(),
.onLoadError(request.url, error.type.toNativeValue() ?? -1,
error.description);
}
_inAppBrowser!.onReceivedError(request, error);

View File

@ -12,7 +12,14 @@ class PlatformUtil {
}
static PlatformUtil _init() {
_channel.setMethodCallHandler(_handleMethod);
_channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_instance = PlatformUtil();
return _instance!;
}

View File

@ -23,7 +23,14 @@ class PrintJobController implements Disposable {
{required this.id}) {
this._channel = MethodChannel(
'com.pichillilorenzo/flutter_inappwebview_printjobcontroller_$id');
this._channel.setMethodCallHandler(_handleMethod);
this._channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
Future<dynamic> _handleMethod(MethodCall call) async {

View File

@ -166,6 +166,13 @@ class PullToRefreshController {
void initMethodChannel(dynamic id) {
this._channel = MethodChannel(
'com.pichillilorenzo/flutter_inappwebview_pull_to_refresh_$id');
this._channel?.setMethodCallHandler(_handleMethod);
this._channel?.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
}

View File

@ -119,7 +119,7 @@ class AjaxRequest {
responseText: map['responseText'],
responseXML: map['responseXML'],
statusText: map['statusText'],
responseHeaders: map['responseHeaders'],
responseHeaders: map['responseHeaders']?.cast<String, dynamic>(),
event: AjaxRequestEvent.fromMap(map['event']?.cast<String, dynamic>()),
);
instance.action = AjaxRequestAction.fromNativeValue(map['action']);

View File

@ -69,7 +69,7 @@ class FetchRequest {
final instance = FetchRequest(
url: map['url'] != null ? Uri.parse(map['url']) : null,
method: map['method'],
headers: map['headers'],
headers: map['headers']?.cast<String, dynamic>(),
body: map['body'],
mode: map['mode'],
credentials: _fetchRequestCredentialDeserializer(map['credentials']),

View File

@ -11,7 +11,7 @@ class PrintJobDuplexMode_ {
// ignore: unused_field
final String _value;
// ignore: unused_field
final int _nativeValue = 0;
final int? _nativeValue = null;
const PrintJobDuplexMode_._internal(this._value);

View File

@ -9,7 +9,7 @@ part of 'print_job_duplex_mode.dart';
///Class representing the orientation of a [PrintJobController].
class PrintJobDuplexMode {
final String _value;
final int _nativeValue;
final int? _nativeValue;
const PrintJobDuplexMode._internal(this._value, this._nativeValue);
// ignore: unused_element
factory PrintJobDuplexMode._internalMultiPlatform(
@ -107,8 +107,8 @@ class PrintJobDuplexMode {
///Gets [String] value.
String toValue() => _value;
///Gets [int] native value.
int toNativeValue() => _nativeValue;
///Gets [int?] native value.
int? toNativeValue() => _nativeValue;
@override
int get hashCode => _value.hashCode;

View File

@ -13,7 +13,7 @@ class SslErrorType_ {
// ignore: unused_field
final String _value;
// ignore: unused_field
final int _nativeValue = -1;
final int? _nativeValue = null;
const SslErrorType_._internal(this._value);
///The certificate is not yet valid.

View File

@ -10,7 +10,7 @@ part of 'ssl_error_type.dart';
///Used by the [ServerTrustChallenge] class.
class SslErrorType {
final String _value;
final int _nativeValue;
final int? _nativeValue;
const SslErrorType._internal(this._value, this._nativeValue);
// ignore: unused_element
factory SslErrorType._internalMultiPlatform(
@ -253,8 +253,8 @@ class SslErrorType {
///Gets [String] value.
String toValue() => _value;
///Gets [int] native value.
int toNativeValue() => _nativeValue;
///Gets [int?] native value.
int? toNativeValue() => _nativeValue;
@override
int get hashCode => _value.hashCode;

View File

@ -189,7 +189,7 @@ class URLRequest {
url: map['url'] != null ? Uri.parse(map['url']) : null,
method: map['method'],
body: map['body'],
headers: map['headers'],
headers: map['headers']?.cast<String, String>(),
iosAllowsCellularAccess: map['allowsCellularAccess'],
allowsCellularAccess: map['allowsCellularAccess'],
iosAllowsConstrainedNetworkAccess: map['allowsConstrainedNetworkAccess'],

View File

@ -2,10 +2,6 @@ import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_i
part 'url_response.g.dart';
Map<String, String>? _headersDeserializer(dynamic value) {
return value?.cast<String, String>();
}
///The metadata associated with the response to a URL load request, independent of protocol and URL scheme.
@ExchangeableObject()
class URLResponse_ {
@ -25,7 +21,6 @@ class URLResponse_ {
String? textEncodingName;
///All HTTP header fields of the response.
@ExchangeableObjectProperty(deserializer: _headersDeserializer)
Map<String, String>? headers;
///The responses HTTP status code.
@ -61,7 +56,6 @@ class IOSURLResponse_ {
String? textEncodingName;
///All HTTP header fields of the response.
@ExchangeableObjectProperty(deserializer: _headersDeserializer)
Map<String, String>? headers;
///The responses HTTP status code.

View File

@ -48,7 +48,7 @@ class URLResponse {
mimeType: map['mimeType'],
suggestedFilename: map['suggestedFilename'],
textEncodingName: map['textEncodingName'],
headers: _headersDeserializer(map['headers']),
headers: map['headers']?.cast<String, String>(),
statusCode: map['statusCode'],
);
return instance;
@ -121,7 +121,7 @@ class IOSURLResponse {
mimeType: map['mimeType'],
suggestedFilename: map['suggestedFilename'],
textEncodingName: map['textEncodingName'],
headers: _headersDeserializer(map['headers']),
headers: map['headers']?.cast<String, String>(),
statusCode: map['statusCode'],
);
return instance;

View File

@ -9,7 +9,7 @@ class WebResourceErrorType_ {
// ignore: unused_field
final String _value;
// ignore: unused_field
final int _nativeValue = 0;
final int? _nativeValue = null;
const WebResourceErrorType_._internal(this._value);

View File

@ -9,7 +9,7 @@ part of 'web_resource_error_type.dart';
///Class that represents the error types returned by URL loading APIs.
class WebResourceErrorType {
final String _value;
final int _nativeValue;
final int? _nativeValue;
const WebResourceErrorType._internal(this._value, this._nativeValue);
// ignore: unused_element
factory WebResourceErrorType._internalMultiPlatform(
@ -1005,8 +1005,8 @@ class WebResourceErrorType {
///Gets [String] value.
String toValue() => _value;
///Gets [int] native value.
int toNativeValue() => _nativeValue;
///Gets [int?] native value.
int? toNativeValue() => _nativeValue;
@override
int get hashCode => _value.hashCode;

View File

@ -53,7 +53,7 @@ class WebResourceRequest {
}
final instance = WebResourceRequest(
url: Uri.parse(map['url']),
headers: map['headers'],
headers: map['headers']?.cast<String, String>(),
method: map['method'],
hasGesture: map['hasGesture'],
isForMainFrame: map['isForMainFrame'],

View File

@ -48,7 +48,7 @@ class WebResourceResponse {
}
final instance = WebResourceResponse(
data: map['data'],
headers: map['headers'],
headers: map['headers']?.cast<String, String>(),
statusCode: map['statusCode'],
reasonPhrase: map['reasonPhrase'],
);

View File

@ -24,7 +24,14 @@ class HeadlessInAppWebViewWebElement implements Disposable {
_messenger,
);
this._channel?.setMethodCallHandler(handleMethodCall);
this._channel?.setMethodCallHandler((call) async {
try {
return await handleMethodCall(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
Future<dynamic> handleMethodCall(MethodCall call) async {

View File

@ -20,8 +20,14 @@ class HeadlessInAppWebViewManager {
const StandardMethodCodec(),
_messenger,
);
HeadlessInAppWebViewManager._sharedChannel
.setMethodCallHandler(handleMethod);
HeadlessInAppWebViewManager._sharedChannel.setMethodCallHandler((call) async {
try {
return await handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
Future<dynamic> handleMethod(MethodCall call) async {

View File

@ -40,7 +40,14 @@ class InAppWebViewWebElement implements Disposable {
_messenger,
);
this._channel?.setMethodCallHandler(handleMethodCall);
this._channel?.setMethodCallHandler((call) async {
try {
return await handleMethodCall(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
bridgeJsObject = js.JsObject.fromBrowserObject(
js.context[WebPlatformManager.BRIDGE_JS_OBJECT_NAME]);

View File

@ -19,7 +19,14 @@ class PlatformUtil implements Disposable {
_messenger,
);
this._channel?.setMethodCallHandler(handleMethodCall);
this._channel?.setMethodCallHandler((call) async {
try {
return await handleMethodCall(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
Future<dynamic> handleMethodCall(MethodCall call) async {

View File

@ -95,7 +95,14 @@ class WebAuthenticationSession implements Disposable {
initialSettings ?? WebAuthenticationSessionSettings();
this._channel = MethodChannel(
'com.pichillilorenzo/flutter_webauthenticationsession_$id');
this._channel.setMethodCallHandler(_handleMethod);
this._channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
_debugLog(String method, dynamic args) {
@ -115,7 +122,11 @@ class WebAuthenticationSession implements Disposable {
if (maxLogMessageLength >= 0 && message.length > maxLogMessageLength) {
message = message.substring(0, maxLogMessageLength) + "...";
}
developer.log(message, name: this.runtimeType.toString());
if (!WebAuthenticationSession.debugLoggingSettings.usePrint) {
developer.log(message, name: this.runtimeType.toString());
} else {
print("[${this.runtimeType.toString()}] $message");
}
}
}

View File

@ -19,7 +19,14 @@ class WebMessageChannel {
{required this.id, required this.port1, required this.port2}) {
this._channel = MethodChannel(
'com.pichillilorenzo/flutter_inappwebview_web_message_channel_$id');
this._channel.setMethodCallHandler(_handleMethod);
this._channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
static WebMessageChannel? fromMap(Map<String, dynamic>? map) {

View File

@ -36,7 +36,14 @@ class WebMessageListener {
"allowedOriginRules cannot contain empty strings");
this._channel = MethodChannel(
'com.pichillilorenzo/flutter_inappwebview_web_message_listener_$jsObjectName');
this._channel.setMethodCallHandler(_handleMethod);
this._channel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
}
Future<dynamic> _handleMethod(MethodCall call) async {

View File

@ -31,7 +31,14 @@ class WebStorageManager {
}
static WebStorageManager _init() {
_staticChannel.setMethodCallHandler(_handleMethod);
_staticChannel.setMethodCallHandler((call) async {
try {
return await _handleMethod(call);
} on Error catch (e) {
print(e);
print(e.stackTrace);
}
});
_instance = new WebStorageManager();
return _instance!;
}