updated macos tests, fixed macos/Classes/ISettings.swift, fixed macos NSColor.swift extension

This commit is contained in:
Lorenzo Pichilli 2022-10-19 04:40:44 +02:00
parent 486b3207a0
commit 69fb76d10c
18 changed files with 104 additions and 91 deletions

View File

@ -8,6 +8,7 @@
- Removed `PrintJobInfo.printerId`
- All `InAppWebViewSettings`, `InAppBrowserSettings` properties are optionals
- `InAppBrowser.webViewController` can be null
## 6.0.0-beta.2

View File

@ -10,8 +10,7 @@ void customMenuItem() {
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
TargetPlatform.iOS
].contains(defaultTargetPlatform);
test('add custom menu item', () async {

View File

@ -8,7 +8,8 @@ import 'open_and_close.dart';
import 'trusted_web_activity.dart';
void main() {
const shouldSkip = kIsWeb;
final shouldSkip =
kIsWeb || [TargetPlatform.macOS].contains(defaultTargetPlatform);
group('ChromeSafariBrowser', () {
openAndClose();

View File

@ -10,8 +10,7 @@ void openAndClose() {
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
TargetPlatform.iOS
].contains(defaultTargetPlatform);
test('open and close', () async {

View File

@ -21,6 +21,20 @@ void setGetDelete() {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
final Completer<String> pageLoaded = Completer<String>();
var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
);
if (defaultTargetPlatform == TargetPlatform.macOS) {
headlessWebView.onLoadStop = (controller, url) async {
pageLoaded.complete(url!.toString());
};
await headlessWebView.run();
} else {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
@ -39,6 +53,7 @@ void setGetDelete() {
),
),
);
}
final url = Uri.parse(await pageLoaded.future);
@ -57,5 +72,9 @@ void setGetDelete() {
url: url, domain: ".${TEST_CROSS_PLATFORM_URL_1.host}");
cookies = await cookieManager.getCookies(url: url);
expect(cookies, isEmpty);
if (defaultTargetPlatform == TargetPlatform.macOS) {
headlessWebView.dispose();
}
}, skip: shouldSkip);
}

View File

@ -4,7 +4,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'find_interactions.dart';
void main() {
final shouldSkip = kIsWeb;
final shouldSkip =
kIsWeb || [TargetPlatform.macOS].contains(defaultTargetPlatform);
group('FindInteractionController', () {
findInteractions();

View File

@ -1,5 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
@ -52,12 +51,12 @@ void openDataAndClose() {
await inAppBrowser.firstPageLoaded.future;
var controller = inAppBrowser.webViewController;
final String? url = (await controller.getUrl())?.toString();
expect(controller, isNotNull);
final String? url = (await controller!.getUrl())?.toString();
expect(url, TEST_CROSS_PLATFORM_URL_1.toString());
await inAppBrowser.close();
expect(inAppBrowser.isOpened(), false);
expect(() async => await inAppBrowser.webViewController.getUrl(),
throwsA(isInstanceOf<MissingPluginException>()));
expect(inAppBrowser.webViewController, isNull);
}, skip: shouldSkip);
}

View File

@ -1,5 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
@ -34,12 +33,12 @@ void openFileAndClose() {
await inAppBrowser.firstPageLoaded.future;
var controller = inAppBrowser.webViewController;
final String? url = (await controller.getUrl())?.toString();
expect(controller, isNotNull);
final String? url = (await controller!.getUrl())?.toString();
expect(url, endsWith("in_app_webview_initial_file_test.html"));
await inAppBrowser.close();
expect(inAppBrowser.isOpened(), false);
expect(() async => await inAppBrowser.webViewController.getUrl(),
throwsA(isInstanceOf<MissingPluginException>()));
expect(inAppBrowser.webViewController, isNull);
}, skip: shouldSkip);
}

View File

@ -1,5 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
@ -33,12 +32,12 @@ void openUrlAndClose() {
await inAppBrowser.firstPageLoaded.future;
var controller = inAppBrowser.webViewController;
final String? url = (await controller.getUrl())?.toString();
expect(controller, isNotNull);
final String? url = (await controller!.getUrl())?.toString();
expect(url, TEST_URL_1.toString());
await inAppBrowser.close();
expect(inAppBrowser.isOpened(), false);
expect(() async => await inAppBrowser.webViewController.getUrl(),
throwsA(isInstanceOf<MissingPluginException>()));
expect(inAppBrowser.webViewController, isNull);
}, skip: shouldSkip);
}

View File

@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'apple_pay_api.dart';
@ -84,6 +85,8 @@ import 'web_message.dart';
import 'webview_windows.dart';
void main() {
final shouldSkip = [TargetPlatform.macOS].contains(defaultTargetPlatform);
group('InAppWebView', () {
initialUrlRequest();
setGetSettings();
@ -167,5 +170,5 @@ void main() {
createPdf();
applePayAPI();
handlesURLScheme();
});
}, skip: shouldSkip);
}

View File

@ -1,7 +1,6 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
@ -21,27 +20,23 @@ void takeScreenshot() {
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete();
},
),
),
);
headlessWebView.onLoadStop = (controller, url) async {
pageLoaded.complete();
};
await headlessWebView.run();
expect(headlessWebView.isRunning(), true);
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
await Future.delayed(Duration(seconds: 1));
await tester.pump();
var screenshotConfiguration = ScreenshotConfiguration(
compressFormat: CompressFormat.JPEG,

View File

@ -33,13 +33,13 @@ void main() {
FindInteractionController.debugLoggingSettings.usePrint = true;
FindInteractionController.debugLoggingSettings.maxLogMessageLength = 7000;
in_app_webview_tests.main();
find_interaction_controller_tests.main();
// in_app_webview_tests.main();
// find_interaction_controller_tests.main();
service_worker_controller_tests.main();
proxy_controller_tests.main();
headless_in_app_webview_tests.main();
cookie_manager_tests.main();
in_app_browser_tests.main();
chrome_safari_browser_tests.main();
// chrome_safari_browser_tests.main();
in_app_localhost_server_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

@ -76,11 +76,11 @@ class _InAppBrowserExampleScreenState extends State<InAppBrowserExampleScreen> {
),
onRefresh: () async {
if (Platform.isAndroid) {
widget.browser.webViewController.reload();
widget.browser.webViewController?.reload();
} else if (Platform.isIOS) {
widget.browser.webViewController.loadUrl(
widget.browser.webViewController?.loadUrl(
urlRequest: URLRequest(
url: await widget.browser.webViewController.getUrl()));
url: await widget.browser.webViewController?.getUrl()));
}
},
);

View File

@ -73,8 +73,12 @@ class InAppBrowser {
static const MethodChannel _sharedChannel =
const MethodChannel('com.pichillilorenzo/flutter_inappbrowser');
/// WebView Controller that can be used to access the [InAppWebViewController] API.
late final InAppWebViewController webViewController;
InAppWebViewController? _webViewController;
///WebView Controller that can be used to access the [InAppWebViewController] API.
///When [onExit] is fired, this will be `null` and cannot be used anymore.
InAppWebViewController? get webViewController {
return _webViewController;
}
///The window id of a [CreateWindowAction.windowId].
final int? windowId;
@ -99,7 +103,7 @@ class InAppBrowser {
}
});
_isOpened = false;
webViewController = new InAppWebViewController.fromInAppBrowser(
_webViewController = new InAppWebViewController.fromInAppBrowser(
this._channel, this, this.initialUserScripts);
}
@ -139,10 +143,11 @@ class InAppBrowser {
case "onExit":
_debugLog(call.method, call.arguments);
this._isOpened = false;
this._webViewController = null;
onExit();
break;
default:
return webViewController.handleMethod(call);
return _webViewController?.handleMethod(call);
}
}

View File

@ -29,17 +29,12 @@ public class ISettings<T>: NSObject {
func toMap() -> [String: Any?] {
var settings: [String: Any?] = [:]
var counts = UInt32()
let properties = class_copyPropertyList(object_getClass(self), &counts)
for i in 0..<counts {
if let property = properties?.advanced(by: Int(i)).pointee {
let cName = property_getName(property)
let name = String(cString: cName)
let key = !name.hasPrefix("_") ? name : String(name.suffix(from: name.index(name.startIndex, offsetBy: 1)))
settings[key] = self.value(forKey: key)
let mirrored_object = Mirror(reflecting: self)
for (_, attr) in mirrored_object.children.enumerated() {
if let property_name = attr.label as String? {
settings[property_name] = attr.value
}
}
free(properties)
return settings
}

View File

@ -85,8 +85,8 @@ public class InAppWebViewSettings: ISettings<InAppWebView> {
realSettings["isFraudulentWebsiteWarningEnabled"] = configuration.preferences.isFraudulentWebsiteWarningEnabled
realSettings["preferredContentMode"] = configuration.defaultWebpagePreferences.preferredContentMode.rawValue
}
realSettings["allowUniversalAccessFromFileURLs"] = configuration.value(forKey: "allowUniversalAccessFromFileURLs")
realSettings["allowFileAccessFromFileURLs"] = configuration.preferences.value(forKey: "allowFileAccessFromFileURLs")
realSettings["allowUniversalAccessFromFileURLs"] = configuration.value(forKey: "allowUniversalAccessFromFileURLs") as? Bool
realSettings["allowFileAccessFromFileURLs"] = configuration.preferences.value(forKey: "allowFileAccessFromFileURLs") as? Bool
realSettings["javaScriptEnabled"] = configuration.preferences.javaScriptEnabled
if #available(macOS 11.0, *) {
realSettings["mediaType"] = webView.mediaType

View File

@ -27,30 +27,29 @@ extension NSColor {
}
var hexString: String? {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
let multiplier = CGFloat(255.999999)
self.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
guard let rgbColor = usingColorSpace(.sRGB) else {
return "#FFFFFF"
}
var red: CGFloat = rgbColor.redComponent
var green: CGFloat = rgbColor.greenComponent
var blue: CGFloat = rgbColor.blueComponent
var alpha: CGFloat = rgbColor.alphaComponent
if alpha == 1.0 {
return String(
format: "#%02lX%02lX%02lX",
Int(red * multiplier),
Int(green * multiplier),
Int(blue * multiplier)
Int(red * 0xFF),
Int(green * 0xFF),
Int(blue * 0xFF)
)
}
else {
return String(
format: "#%02lX%02lX%02lX%02lX",
Int(red * multiplier),
Int(green * multiplier),
Int(blue * multiplier),
Int(alpha * multiplier)
Int(red * 0xFF),
Int(green * 0xFF),
Int(blue * 0xFF),
Int(alpha * 0xFF)
)
}
}