iosWebViewFix/example/integration_test/in_app_webview/set_get_settings.dart

67 lines
2.0 KiB
Dart
Raw Normal View History

2022-04-27 00:23:59 +00:00
import 'dart:async';
2022-04-27 16:59:19 +00:00
import 'package:flutter/foundation.dart';
2022-04-27 00:23:59 +00:00
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
2022-04-27 16:59:19 +00:00
import '../constants.dart';
2022-04-27 00:23:59 +00:00
void setGetSettings() {
2022-04-29 11:39:28 +00:00
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
2022-04-27 16:59:19 +00:00
final url = !kIsWeb ? TEST_CROSS_PLATFORM_URL_1 : TEST_WEB_PLATFORM_URL_1;
2022-04-27 00:23:59 +00:00
testWidgets('set/get settings', (WidgetTester tester) async {
2022-10-14 00:28:23 +00:00
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-27 00:23:59 +00:00
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
2022-04-29 11:39:28 +00:00
initialUrlRequest: URLRequest(url: url),
initialSettings: InAppWebViewSettings(javaScriptEnabled: false),
2022-04-27 00:23:59 +00:00
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete();
},
),
),
);
2022-04-29 11:39:28 +00:00
final InAppWebViewController controller = await controllerCompleter.future;
2022-04-27 00:23:59 +00:00
await pageLoaded.future;
InAppWebViewSettings? settings = await controller.getSettings();
expect(settings, isNotNull);
expect(settings!.javaScriptEnabled, false);
2022-04-27 16:59:19 +00:00
if (kIsWeb) {
expect(settings.iframeSandbox, isNotNull);
expect(settings.iframeSandbox!.contains(Sandbox.ALLOW_SCRIPTS), false);
}
2022-04-29 11:39:28 +00:00
await controller.setSettings(
settings: InAppWebViewSettings(javaScriptEnabled: true));
2022-04-27 00:23:59 +00:00
settings = await controller.getSettings();
expect(settings, isNotNull);
expect(settings!.javaScriptEnabled, true);
2022-04-27 16:59:19 +00:00
if (kIsWeb) {
expect(settings.iframeSandbox, isNotNull);
expect(settings.iframeSandbox!.contains(Sandbox.ALLOW_SCRIPTS), true);
}
}, skip: shouldSkip);
2022-04-29 11:39:28 +00:00
}