iosWebViewFix/example/integration_test/in_app_webview/webview_asset_loader.dart

57 lines
1.8 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';
import '../constants.dart';
void webViewAssetLoader() {
final shouldSkip = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
testWidgets('WebViewAssetLoader', (WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
final Completer<String> pageLoaded = Completer<String>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_WEBVIEW_ASSET_LOADER_URL),
initialSettings: InAppWebViewSettings(
allowFileAccessFromFileURLs: false,
allowUniversalAccessFromFileURLs: false,
allowFileAccess: false,
allowContentAccess: false,
webViewAssetLoader: WebViewAssetLoader(
domain: TEST_WEBVIEW_ASSET_LOADER_DOMAIN,
pathHandlers: [AssetsPathHandler(path: '/assets/')])),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete(url.toString());
},
),
),
);
final InAppWebViewController controller = await controllerCompleter.future;
final url = await pageLoaded.future;
expect(url, TEST_WEBVIEW_ASSET_LOADER_URL.toString());
expect(
await controller.evaluateJavascript(
source: "document.querySelector('h1').innerHTML"),
'WebViewAssetLoader');
}, skip: shouldSkip);
}