iosWebViewFix/example/integration_test/in_app_webview/apple_pay_api.dart

59 lines
1.7 KiB
Dart

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';
void applePayAPI() {
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
testWidgets('Apple Pay API enabled', (WidgetTester tester) async {
final Completer<void> pageLoaded = Completer<void>();
final Completer<String> alertMessageCompleter = Completer<String>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialData: InAppWebViewInitialData(data: """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Apple Pay API</title>
</head>
<body>
<script>
window.alert(window.ApplePaySession != null);
</script>
</body>
</html>
"""),
initialSettings: InAppWebViewSettings(
applePayAPIEnabled: true,
),
onLoadStop: (controller, url) {
pageLoaded.complete();
},
onJsAlert: (controller, jsAlertRequest) async {
alertMessageCompleter.complete(jsAlertRequest.message);
return null;
},
),
),
);
await pageLoaded.future;
final message = await alertMessageCompleter.future;
expect(message, 'true');
}, skip: shouldSkip);
}