iosWebViewFix/example/integration_test/in_app_webview/load_file.dart

56 lines
1.6 KiB
Dart
Raw Normal View History

2022-04-28 18:34:54 +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 loadFile() {
2022-04-29 11:39:28 +00:00
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
2022-04-28 18:34:54 +00:00
testWidgets('loadFile', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final StreamController<String> pageLoads =
2022-04-29 11:39:28 +00:00
StreamController<String>.broadcast();
2022-04-28 18:34:54 +00:00
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());
},
),
),
);
2022-04-29 11:39:28 +00:00
final InAppWebViewController controller = await controllerCompleter.future;
2022-04-28 18:34:54 +00:00
await pageLoads.stream.first;
await controller.loadFile(
assetFilePath: "test_assets/in_app_webview_initial_file_test.html");
await pageLoads.stream.first;
final Uri? url = await controller.getUrl();
expect(url, isNotNull);
2022-10-11 08:49:01 +00:00
expect(url!.scheme, kIsWeb ? 'http' : 'file');
2022-04-28 18:34:54 +00:00
expect(url.path,
endsWith("test_assets/in_app_webview_initial_file_test.html"));
pageLoads.close();
}, skip: shouldSkip);
}