iosWebViewFix/example/integration_test/in_app_webview/on_permission_request.dart

63 lines
2.1 KiB
Dart
Raw Normal View History

2022-04-28 17:29:01 +00:00
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';
import '../constants.dart';
void onPermissionRequest() {
2022-04-29 11:39:28 +00:00
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
2022-04-28 17:29:01 +00:00
var expectedValue = [];
expectedValue = [PermissionResourceType.CAMERA];
2022-04-28 17:29:01 +00:00
testWidgets('onPermissionRequest', (WidgetTester tester) async {
2022-10-14 00:28:23 +00:00
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 17:29:01 +00:00
final Completer<void> pageLoaded = Completer<void>();
final Completer<List<PermissionResourceType>> onPermissionRequestCompleter =
2022-04-29 11:39:28 +00:00
Completer<List<PermissionResourceType>>();
2022-04-28 17:29:01 +00:00
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_PERMISSION_SITE),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete();
},
onPermissionRequest:
(controller, PermissionRequest permissionRequest) async {
onPermissionRequestCompleter.complete(permissionRequest.resources);
2022-04-29 11:39:28 +00:00
return PermissionResponse(
resources: permissionRequest.resources,
2022-04-29 00:07:01 +00:00
action: PermissionResponseAction.GRANT);
2022-04-28 17:29:01 +00:00
},
),
),
);
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
await controller.evaluateJavascript(
source: "document.querySelector('#camera').click();");
2022-04-29 00:07:01 +00:00
await tester.pump();
2022-04-28 17:29:01 +00:00
final List<PermissionResourceType> resources =
2022-04-29 11:39:28 +00:00
await onPermissionRequestCompleter.future;
2022-04-28 17:29:01 +00:00
expect(listEquals(resources, expectedValue), true);
}, skip: shouldSkip);
}