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';
|
|
|
|
|
|
|
|
void onLoadResource() {
|
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
|
|
|
|
|
|
|
testWidgets('onLoadResource', (WidgetTester tester) async {
|
|
|
|
List<String> 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<String> resourceLoaded = [];
|
|
|
|
|
|
|
|
final Completer<void> loadedResourceCompleter = Completer<void>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
|
|
|
initialFile:
|
|
|
|
"test_assets/in_app_webview_on_load_resource_test.html",
|
|
|
|
initialSettings:
|
All PrintJobSettings properties are optionals, All PullToRefreshSettings properties are optionals, All WebAuthenticationSessionSettings properties are optionals, Automatically infer useShouldOverrideUrlLoading, useOnLoadResource, useOnDownloadStart, useShouldInterceptAjaxRequest, useShouldInterceptFetchRequest, useShouldInterceptRequest, useOnRenderProcessGone, useOnNavigationResponse settings if their value is null and the corresponding event is implemented by the WebView (InAppWebView and HeadlessInAppWebView, not InAppBrowser) before it's native initialization
2022-11-22 21:40:45 +00:00
|
|
|
InAppWebViewSettings(clearCache: true),
|
2022-04-28 17:29:01 +00:00
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
onLoadResource: (controller, response) async {
|
|
|
|
resourceLoaded.add(response.url!.toString());
|
|
|
|
if (resourceLoaded.length == resourceList.length) {
|
|
|
|
loadedResourceCompleter.complete();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await pageLoaded.future;
|
|
|
|
await loadedResourceCompleter.future;
|
|
|
|
|
|
|
|
expect(resourceLoaded, unorderedEquals(resourceList));
|
|
|
|
}, skip: shouldSkip);
|
|
|
|
}
|