iosWebViewFix/example/integration_test/in_app_webview/initial_url_request.dart

83 lines
2.6 KiB
Dart
Raw Normal View History

2022-04-27 00:23:59 +00:00
import 'dart:async';
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 initialUrlRequest() {
2022-04-28 14:48:39 +00:00
final shouldSkip = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
group('initial url request', () {
final shouldSkipTest1 = !kIsWeb ||
![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('basic', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
),
2022-04-27 00:23:59 +00:00
),
2022-04-28 14:48:39 +00:00
);
final InAppWebViewController controller =
await controllerCompleter.future;
final String? currentUrl = (await controller.getUrl())?.toString();
2022-04-27 16:59:19 +00:00
2022-04-28 14:48:39 +00:00
expect(currentUrl, TEST_CROSS_PLATFORM_URL_1.toString());
}, skip: shouldSkipTest1);
2022-04-27 16:59:19 +00:00
2022-04-28 14:48:39 +00:00
final shouldSkipTest2 = kIsWeb ||
![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('launches with allowsBackForwardNavigationGestures true',
(WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SizedBox(
width: 400,
height: 300,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: TEST_URL_1),
initialSettings: InAppWebViewSettings(
allowsBackForwardNavigationGestures: true),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
),
),
),
);
final InAppWebViewController controller =
await controllerCompleter.future;
final String? currentUrl = (await controller.getUrl())?.toString();
expect(currentUrl, TEST_URL_1.toString());
}, skip: shouldSkipTest2);
});
}