iosWebViewFix/example/integration_test/in_app_webview/set_get_settings.dart

60 lines
1.8 KiB
Dart
Raw Normal View History

part of 'main.dart';
2022-04-27 16:59:19 +00:00
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;
skippableTestWidgets('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
}