46 lines
1.4 KiB
Dart
46 lines
1.4 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void setGetSettings() {
|
|
testWidgets('set/get settings', (WidgetTester tester) async {
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: InAppWebView(
|
|
key: GlobalKey(),
|
|
initialUrlRequest:
|
|
URLRequest(url: Uri.parse('https://github.com/flutter')),
|
|
initialSettings: InAppWebViewSettings(
|
|
javaScriptEnabled: false
|
|
),
|
|
onWebViewCreated: (controller) {
|
|
controllerCompleter.complete(controller);
|
|
},
|
|
onLoadStop: (controller, url) {
|
|
pageLoaded.complete();
|
|
},
|
|
),
|
|
),
|
|
);
|
|
final InAppWebViewController controller =
|
|
await controllerCompleter.future;
|
|
await pageLoaded.future;
|
|
|
|
InAppWebViewSettings? settings = await controller.getSettings();
|
|
expect(settings, isNotNull);
|
|
expect(settings!.javaScriptEnabled, false);
|
|
|
|
await controller.setSettings(settings: InAppWebViewSettings(
|
|
javaScriptEnabled: true));
|
|
|
|
settings = await controller.getSettings();
|
|
expect(settings, isNotNull);
|
|
expect(settings!.javaScriptEnabled, true);
|
|
});
|
|
} |