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 loadData() { final shouldSkip = kIsWeb ? false : ![ TargetPlatform.android, TargetPlatform.iOS, TargetPlatform.macOS, ].contains(defaultTargetPlatform); testWidgets('loadData', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); final StreamController pageLoads = StreamController.broadcast(); await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: InAppWebView( key: GlobalKey(), initialUrlRequest: URLRequest(url: TEST_URL_ABOUT_BLANK), onWebViewCreated: (controller) { controllerCompleter.complete(controller); }, onLoadStop: (controller, url) { pageLoads.add(url!.toString()); }, ), ), ); final InAppWebViewController controller = await controllerCompleter.future; await pageLoads.stream.first; final data = """ placeholder 100x50 """; final mimeType = 'text/html'; await controller.loadData( data: data, encoding: 'utf-8', mimeType: mimeType, historyUrl: TEST_CROSS_PLATFORM_URL_1, baseUrl: TEST_CROSS_PLATFORM_URL_1); await pageLoads.stream.first; final String? currentUrl = (await controller.getUrl())?.toString(); if (!kIsWeb) { expect(currentUrl, TEST_CROSS_PLATFORM_URL_1.toString()); } else { expect(currentUrl, 'data:$mimeType,' + Uri.encodeFull(data)); } pageLoads.close(); }, skip: shouldSkip); }