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 shouldInterceptRequest() { final shouldSkip = kIsWeb ? true : ![ TargetPlatform.android, ].contains(defaultTargetPlatform); testWidgets('shouldInterceptRequest', (WidgetTester tester) async { List resourceList = [ "https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css", "https://code.jquery.com/jquery-3.3.1.min.js", "https://via.placeholder.com/100x50" ]; List resourceLoaded = []; final Completer controllerCompleter = Completer(); final Completer pageLoaded = Completer(); final Completer loadedResourceCompleter = Completer(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: InAppWebView( key: GlobalKey(), initialData: InAppWebViewInitialData(data: """ placeholder 100x50 """), initialSettings: InAppWebViewSettings(useShouldInterceptRequest: true), onWebViewCreated: (controller) { controllerCompleter.complete(controller); }, onLoadStop: (controller, url) { pageLoaded.complete(); }, shouldInterceptRequest: (controller, request) async { resourceLoaded.add(request.url.toString()); if (resourceLoaded.length == resourceList.length) { loadedResourceCompleter.complete(); } return null; }, ), ), ); await pageLoaded.future; await loadedResourceCompleter.future; expect(resourceLoaded, containsAll(resourceList)); }, skip: shouldSkip); }