2021-01-28 16:10:15 +00:00
|
|
|
import 'dart:async';
|
2021-02-22 22:38:30 +00:00
|
|
|
import 'dart:collection';
|
2021-01-28 16:10:15 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:integration_test/integration_test.dart';
|
|
|
|
|
2022-04-27 23:10:20 +00:00
|
|
|
import 'in_app_webview/main.dart' as in_app_webview_tests;
|
2022-04-27 00:23:59 +00:00
|
|
|
|
2021-01-28 16:10:15 +00:00
|
|
|
import '.env.dart';
|
|
|
|
|
2022-04-27 16:59:19 +00:00
|
|
|
import 'util.dart';
|
2021-02-22 11:16:23 +00:00
|
|
|
|
2021-02-22 22:38:30 +00:00
|
|
|
void main() {
|
|
|
|
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
2022-04-27 23:10:20 +00:00
|
|
|
|
2022-04-27 11:39:00 +00:00
|
|
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
2022-04-27 00:23:59 +00:00
|
|
|
InAppWebViewController.setWebContentsDebuggingEnabled(true);
|
2021-02-22 22:38:30 +00:00
|
|
|
}
|
|
|
|
|
2022-04-27 23:10:20 +00:00
|
|
|
in_app_webview_tests.main();
|
2021-03-01 19:26:57 +00:00
|
|
|
|
2022-04-27 23:10:20 +00:00
|
|
|
group('InAppWebView', () {
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-01-28 16:10:15 +00:00
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
testWidgets('web history - go back and forward',
|
|
|
|
(WidgetTester tester) async {
|
2021-02-22 22:38:30 +00:00
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
2021-03-01 19:26:57 +00:00
|
|
|
final StreamController<String> pageLoads =
|
|
|
|
StreamController<String>.broadcast();
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev/')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoads.add(url!.toString());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
var url = await pageLoads.stream.first;
|
|
|
|
var webHistory = await controller.getCopyBackForwardList();
|
|
|
|
expect(url, 'https://flutter.dev/');
|
|
|
|
expect(webHistory!.currentIndex, 0);
|
|
|
|
expect(webHistory.list!.length, 1);
|
|
|
|
expect(webHistory.list![0].url.toString(), 'https://flutter.dev/');
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await controller.loadUrl(
|
|
|
|
urlRequest: URLRequest(url: Uri.parse('https://github.com/flutter')));
|
2021-02-22 22:38:30 +00:00
|
|
|
url = await pageLoads.stream.first;
|
|
|
|
webHistory = await controller.getCopyBackForwardList();
|
|
|
|
expect(url, 'https://github.com/flutter');
|
|
|
|
expect(await controller.canGoBack(), true);
|
|
|
|
expect(await controller.canGoForward(), false);
|
|
|
|
expect(await controller.canGoBackOrForward(steps: -1), true);
|
|
|
|
expect(await controller.canGoBackOrForward(steps: 1), false);
|
|
|
|
expect(webHistory!.currentIndex, 1);
|
|
|
|
expect(webHistory.list!.length, 2);
|
|
|
|
expect(webHistory.list![0].url.toString(), 'https://flutter.dev/');
|
|
|
|
expect(webHistory.list![1].url.toString(), 'https://github.com/flutter');
|
|
|
|
|
2021-03-05 22:19:50 +00:00
|
|
|
await Future.delayed(Duration(seconds: 1));
|
2021-02-22 22:38:30 +00:00
|
|
|
await controller.goBack();
|
|
|
|
url = await pageLoads.stream.first;
|
|
|
|
webHistory = await controller.getCopyBackForwardList();
|
|
|
|
expect(url, 'https://flutter.dev/');
|
|
|
|
expect(await controller.canGoBack(), false);
|
|
|
|
expect(await controller.canGoForward(), true);
|
|
|
|
expect(await controller.canGoBackOrForward(steps: -1), false);
|
|
|
|
expect(await controller.canGoBackOrForward(steps: 1), true);
|
|
|
|
expect(webHistory!.currentIndex, 0);
|
|
|
|
expect(webHistory.list!.length, 2);
|
|
|
|
expect(webHistory.list![0].url.toString(), 'https://flutter.dev/');
|
|
|
|
expect(webHistory.list![1].url.toString(), 'https://github.com/flutter');
|
|
|
|
|
2021-03-05 22:19:50 +00:00
|
|
|
await Future.delayed(Duration(seconds: 1));
|
2021-02-22 22:38:30 +00:00
|
|
|
await controller.goForward();
|
|
|
|
url = await pageLoads.stream.first;
|
|
|
|
webHistory = await controller.getCopyBackForwardList();
|
|
|
|
expect(url, 'https://github.com/flutter');
|
|
|
|
expect(await controller.canGoBack(), true);
|
|
|
|
expect(await controller.canGoForward(), false);
|
|
|
|
expect(await controller.canGoBackOrForward(steps: -1), true);
|
|
|
|
expect(await controller.canGoBackOrForward(steps: 1), false);
|
|
|
|
expect(webHistory!.currentIndex, 1);
|
|
|
|
expect(webHistory.list!.length, 2);
|
|
|
|
expect(webHistory.list![0].url.toString(), 'https://flutter.dev/');
|
|
|
|
expect(webHistory.list![1].url.toString(), 'https://github.com/flutter');
|
|
|
|
|
2021-03-05 22:19:50 +00:00
|
|
|
await Future.delayed(Duration(seconds: 1));
|
2021-02-22 22:38:30 +00:00
|
|
|
await controller.goTo(historyItem: webHistory.list![0]);
|
|
|
|
url = await pageLoads.stream.first;
|
|
|
|
webHistory = await controller.getCopyBackForwardList();
|
|
|
|
expect(url, 'https://flutter.dev/');
|
|
|
|
expect(await controller.canGoBack(), false);
|
|
|
|
expect(await controller.canGoForward(), true);
|
|
|
|
expect(await controller.canGoBackOrForward(steps: -1), false);
|
|
|
|
expect(await controller.canGoBackOrForward(steps: 1), true);
|
|
|
|
expect(webHistory!.currentIndex, 0);
|
|
|
|
expect(webHistory.list!.length, 2);
|
|
|
|
expect(webHistory.list![0].url.toString(), 'https://flutter.dev/');
|
|
|
|
expect(webHistory.list![1].url.toString(), 'https://github.com/flutter');
|
2021-03-01 19:24:26 +00:00
|
|
|
|
|
|
|
pageLoads.close();
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('getProgress', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
final int? progress = await controller.getProgress();
|
|
|
|
expect(progress, 100);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('getHtml', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
final String? html = await controller.getHtml();
|
|
|
|
expect(html, isNotNull);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('getFavicons', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
final List<Favicon>? favicons = await controller.getFavicons();
|
|
|
|
expect(favicons, isNotNull);
|
|
|
|
expect(favicons, isNotEmpty);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('isLoading', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageStarted = Completer<void>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
initialOptions: InAppWebViewGroupOptions(
|
2021-03-01 19:26:57 +00:00
|
|
|
crossPlatform: InAppWebViewOptions(clearCache: true)),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStart: (controller, url) {
|
|
|
|
pageStarted.complete();
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageStarted.future;
|
|
|
|
expect(await controller.isLoading(), true);
|
|
|
|
|
|
|
|
await pageLoaded.future;
|
|
|
|
expect(await controller.isLoading(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('stopLoading', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
initialOptions: InAppWebViewGroupOptions(
|
2021-03-01 19:26:57 +00:00
|
|
|
crossPlatform: InAppWebViewOptions(clearCache: true)),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStart: (controller, url) {
|
|
|
|
controller.stopLoading();
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2022-04-27 11:39:00 +00:00
|
|
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
expect(await controller.evaluateJavascript(source: "document.body"),
|
2022-04-26 11:55:24 +00:00
|
|
|
isNullOrEmpty);
|
2022-04-27 11:39:00 +00:00
|
|
|
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
|
2021-02-22 22:38:30 +00:00
|
|
|
expect(pageLoaded.future, doesNotComplete);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('injectJavascriptFileFromUrl', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
2021-04-07 16:34:35 +00:00
|
|
|
final Completer<void> jQueryLoaded = Completer<void>();
|
|
|
|
final Completer<void> jQueryLoadError = Completer<void>();
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
2021-04-07 16:34:35 +00:00
|
|
|
await controller.injectJavascriptFileFromUrl(
|
2022-04-22 14:24:41 +00:00
|
|
|
urlFile:
|
|
|
|
Uri.parse('https://www.notawebsite..com/jquery-3.3.1.min.js'),
|
|
|
|
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(
|
|
|
|
id: 'jquery-error',
|
|
|
|
onError: () {
|
|
|
|
jQueryLoadError.complete();
|
|
|
|
},
|
|
|
|
));
|
2021-04-07 16:34:35 +00:00
|
|
|
await jQueryLoadError.future;
|
|
|
|
expect(
|
|
|
|
await controller.evaluateJavascript(
|
|
|
|
source: "document.body.querySelector('#jquery-error') == null;"),
|
|
|
|
false);
|
|
|
|
expect(
|
|
|
|
await controller.evaluateJavascript(source: "window.jQuery == null;"),
|
|
|
|
true);
|
|
|
|
|
2021-02-22 22:38:30 +00:00
|
|
|
await controller.injectJavascriptFileFromUrl(
|
2021-03-01 19:26:57 +00:00
|
|
|
urlFile: Uri.parse('https://code.jquery.com/jquery-3.3.1.min.js'),
|
2022-04-22 14:24:41 +00:00
|
|
|
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(
|
|
|
|
id: 'jquery',
|
|
|
|
onLoad: () {
|
|
|
|
jQueryLoaded.complete();
|
|
|
|
},
|
|
|
|
));
|
2021-04-07 16:34:35 +00:00
|
|
|
await jQueryLoaded.future;
|
2021-03-01 19:26:57 +00:00
|
|
|
expect(
|
|
|
|
await controller.evaluateJavascript(
|
|
|
|
source: "document.body.querySelector('#jquery') == null;"),
|
|
|
|
false);
|
|
|
|
expect(
|
|
|
|
await controller.evaluateJavascript(source: "window.jQuery == null;"),
|
|
|
|
false);
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('injectJavascriptFileFromAsset', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await controller.injectJavascriptFileFromAsset(
|
|
|
|
assetFilePath: 'test_assets/js/jquery-3.3.1.min.js');
|
|
|
|
expect(
|
|
|
|
await controller.evaluateJavascript(source: "window.jQuery == null;"),
|
|
|
|
false);
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('injectCSSCode', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
await controller.injectCSSCode(source: """
|
|
|
|
body {
|
|
|
|
background-color: rgb(0, 0, 255);
|
|
|
|
}
|
|
|
|
""");
|
|
|
|
|
|
|
|
String? backgroundColor = await controller.evaluateJavascript(source: """
|
|
|
|
var element = document.body;
|
|
|
|
var style = getComputedStyle(element);
|
|
|
|
style.backgroundColor;
|
|
|
|
""");
|
|
|
|
expect(backgroundColor, 'rgb(0, 0, 255)');
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('injectCSSFileFromUrl', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
await controller.injectCSSFileFromUrl(
|
2021-03-01 19:26:57 +00:00
|
|
|
urlFile: Uri.parse(
|
|
|
|
'https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css'),
|
|
|
|
cssLinkHtmlTagAttributes: CSSLinkHtmlTagAttributes(id: 'bootstrap'));
|
2021-02-22 22:38:30 +00:00
|
|
|
await Future.delayed(Duration(seconds: 2));
|
2021-03-01 19:26:57 +00:00
|
|
|
expect(
|
|
|
|
await controller.evaluateJavascript(
|
|
|
|
source: "document.head.querySelector('#bootstrap') == null;"),
|
|
|
|
false);
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('injectCSSFileFromAsset', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await controller.injectCSSFileFromAsset(
|
|
|
|
assetFilePath: 'test_assets/css/blue-body.css');
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
String? backgroundColor = await controller.evaluateJavascript(source: """
|
|
|
|
var element = document.body;
|
|
|
|
var style = getComputedStyle(element);
|
|
|
|
style.backgroundColor;
|
|
|
|
""");
|
|
|
|
expect(backgroundColor, 'rgb(0, 0, 255)');
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('takeScreenshot', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
var screenshotConfiguration = ScreenshotConfiguration(
|
|
|
|
compressFormat: CompressFormat.JPEG,
|
|
|
|
quality: 20,
|
|
|
|
rect: InAppWebViewRect(width: 100, height: 100, x: 50, y: 50));
|
|
|
|
var screenshot = await controller.takeScreenshot(
|
|
|
|
screenshotConfiguration: screenshotConfiguration);
|
2021-02-22 22:38:30 +00:00
|
|
|
expect(screenshot, isNotNull);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('clearCache', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
await expectLater(controller.clearCache(), completes);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('T-Rex Runner game', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
var html = await controller.getTRexRunnerHtml();
|
|
|
|
var css = await controller.getTRexRunnerCss();
|
|
|
|
|
|
|
|
expect(html, isNotNull);
|
|
|
|
expect(css, isNotNull);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('pause/resume timers', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
await controller.evaluateJavascript(source: """
|
|
|
|
var count = 0;
|
|
|
|
setInterval(function() {
|
|
|
|
count = count + 10;
|
|
|
|
}, 20);
|
|
|
|
""");
|
|
|
|
|
|
|
|
await controller.pauseTimers();
|
|
|
|
await Future.delayed(Duration(seconds: 2));
|
|
|
|
await controller.resumeTimers();
|
2021-03-01 19:26:57 +00:00
|
|
|
expect(
|
|
|
|
await controller.evaluateJavascript(source: "count;"), lessThan(50));
|
2021-02-22 22:38:30 +00:00
|
|
|
await Future.delayed(Duration(seconds: 4));
|
2021-03-01 19:26:57 +00:00
|
|
|
expect(await controller.evaluateJavascript(source: "count;"),
|
|
|
|
greaterThan(50));
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('printCurrentPage', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
await expectLater(controller.printCurrentPage(), completes);
|
|
|
|
}, skip: true);
|
|
|
|
|
|
|
|
testWidgets('getContentHeight', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
final contentHeight = await controller.getContentHeight();
|
|
|
|
expect(contentHeight, isNonZero);
|
|
|
|
expect(contentHeight, isPositive);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('zoomBy', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await expectLater(
|
2022-04-18 00:59:46 +00:00
|
|
|
controller.zoomBy(zoomFactor: 3.0, animated: true), completes);
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
2021-03-26 20:04:44 +00:00
|
|
|
testWidgets('getZoomScale', (WidgetTester tester) async {
|
2021-02-22 22:38:30 +00:00
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
2021-03-26 20:04:44 +00:00
|
|
|
final scale = await controller.getZoomScale();
|
2021-02-22 22:38:30 +00:00
|
|
|
expect(scale, isNonZero);
|
|
|
|
expect(scale, isPositive);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('clearFocus', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
await expectLater(controller.clearFocus(), completes);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('requestFocusNodeHref', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
await expectLater(controller.requestFocusNodeHref(), completes);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('requestImageRef', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
await expectLater(controller.requestImageRef(), completes);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('getMetaTags', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
List<MetaTag> metaTags = await controller.getMetaTags();
|
|
|
|
expect(metaTags, isNotEmpty);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('getMetaThemeColor', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest: URLRequest(url: Uri.parse('https://github.com')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
expect(await controller.getMetaThemeColor(), isNotNull);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('getCertificate', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
var sslCertificate = await controller.getCertificate();
|
|
|
|
expect(sslCertificate, isNotNull);
|
|
|
|
expect(sslCertificate!.x509Certificate, isNotNull);
|
|
|
|
expect(sslCertificate.issuedBy, isNotNull);
|
|
|
|
expect(sslCertificate.issuedTo, isNotNull);
|
|
|
|
expect(sslCertificate.validNotAfterDate, isNotNull);
|
|
|
|
expect(sslCertificate.validNotBeforeDate, isNotNull);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('add/remove user scripts', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
2021-03-01 19:26:57 +00:00
|
|
|
final StreamController<String> pageLoads =
|
|
|
|
StreamController<String>.broadcast();
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoads.add(url!.toString());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoads.stream.first;
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
var userScript1 = UserScript(
|
|
|
|
source: "window.foo = 49;",
|
|
|
|
injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START);
|
|
|
|
var userScript2 = UserScript(
|
|
|
|
source: "window.bar = 19;",
|
|
|
|
injectionTime: UserScriptInjectionTime.AT_DOCUMENT_END);
|
2021-02-22 22:38:30 +00:00
|
|
|
await controller.addUserScripts(userScripts: [userScript1, userScript2]);
|
|
|
|
await controller.reload();
|
|
|
|
await pageLoads.stream.first;
|
|
|
|
var value = await controller.evaluateJavascript(source: "window.foo;");
|
|
|
|
expect(value, 49);
|
|
|
|
value = await controller.evaluateJavascript(source: "window.bar;");
|
|
|
|
expect(value, 19);
|
|
|
|
|
|
|
|
await controller.removeUserScript(userScript: userScript1);
|
|
|
|
await controller.reload();
|
|
|
|
await pageLoads.stream.first;
|
|
|
|
value = await controller.evaluateJavascript(source: "window.foo;");
|
|
|
|
expect(value, isNull);
|
|
|
|
value = await controller.evaluateJavascript(source: "window.bar;");
|
|
|
|
expect(value, 19);
|
|
|
|
|
|
|
|
await controller.removeAllUserScripts();
|
|
|
|
await controller.reload();
|
|
|
|
await pageLoads.stream.first;
|
|
|
|
value = await controller.evaluateJavascript(source: "window.foo;");
|
|
|
|
expect(value, isNull);
|
|
|
|
value = await controller.evaluateJavascript(source: "window.bar;");
|
|
|
|
expect(value, isNull);
|
2021-03-01 19:24:26 +00:00
|
|
|
|
|
|
|
pageLoads.close();
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
2022-04-27 11:39:00 +00:00
|
|
|
// testWidgets('saveWebArchive', (WidgetTester tester) async {
|
|
|
|
// final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
// final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
//
|
|
|
|
// await tester.pumpWidget(
|
|
|
|
// Directionality(
|
|
|
|
// textDirection: TextDirection.ltr,
|
|
|
|
// child: InAppWebView(
|
|
|
|
// key: GlobalKey(),
|
|
|
|
// initialUrlRequest:
|
|
|
|
// URLRequest(url: Uri.parse('https://github.com/flutter')),
|
|
|
|
// onWebViewCreated: (controller) {
|
|
|
|
// controllerCompleter.complete(controller);
|
|
|
|
// },
|
|
|
|
// onLoadStop: (controller, url) {
|
|
|
|
// pageLoaded.complete();
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// final InAppWebViewController controller =
|
|
|
|
// await controllerCompleter.future;
|
|
|
|
// await pageLoaded.future;
|
|
|
|
//
|
|
|
|
// // wait a little bit after page load otherwise Android will not save the web archive
|
|
|
|
// await Future.delayed(Duration(seconds: 1));
|
|
|
|
//
|
|
|
|
// var supportDir = await getApplicationSupportDirectory();
|
|
|
|
//
|
|
|
|
// var fileName = "flutter-website.";
|
|
|
|
// if (defaultTargetPlatform == TargetPlatform.android) {
|
|
|
|
// fileName = fileName + WebArchiveFormat.MHT.toValue();
|
|
|
|
// } else if (defaultTargetPlatform == TargetPlatform.iOS) {
|
|
|
|
// fileName = fileName + WebArchiveFormat.WEBARCHIVE.toValue();
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// var fullPath = supportDir.path + Platform.pathSeparator + fileName;
|
|
|
|
// var path = await controller.saveWebArchive(filePath: fullPath);
|
|
|
|
// expect(path, isNotNull);
|
|
|
|
// expect(path, endsWith(fileName));
|
|
|
|
//
|
|
|
|
// path = await controller.saveWebArchive(
|
|
|
|
// filePath: supportDir.path, autoname: true);
|
|
|
|
// expect(path, isNotNull);
|
|
|
|
// });
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
testWidgets('isSecureContext', (WidgetTester tester) async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
2021-03-01 19:26:57 +00:00
|
|
|
final StreamController<String> pageLoads =
|
|
|
|
StreamController<String>.broadcast();
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoads.add(url!.toString());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoads.stream.first;
|
|
|
|
expect(await controller.isSecureContext(), true);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await controller.loadUrl(
|
|
|
|
urlRequest: URLRequest(url: Uri.parse('http://example.com/')));
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoads.stream.first;
|
|
|
|
expect(await controller.isSecureContext(), false);
|
2021-03-01 19:24:26 +00:00
|
|
|
|
|
|
|
pageLoads.close();
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getDefaultUserAgent', () async {
|
|
|
|
expect(await InAppWebViewController.getDefaultUserAgent(), isNotNull);
|
|
|
|
});
|
|
|
|
|
2022-04-22 14:24:41 +00:00
|
|
|
testWidgets('launches with pull-to-refresh feature',
|
|
|
|
(WidgetTester tester) async {
|
2021-03-05 22:19:50 +00:00
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final pullToRefreshController = PullToRefreshController(
|
|
|
|
options: PullToRefreshOptions(
|
2022-04-22 14:24:41 +00:00
|
|
|
color: Colors.blue,
|
|
|
|
size: AndroidPullToRefreshSize.DEFAULT,
|
|
|
|
backgroundColor: Colors.grey,
|
|
|
|
enabled: true,
|
|
|
|
slingshotDistance: 150,
|
|
|
|
distanceToTriggerSync: 150,
|
|
|
|
attributedTitle: IOSNSAttributedString(string: "test")),
|
|
|
|
onRefresh: () {},
|
2021-03-05 22:19:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2022-04-22 14:24:41 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://github.com/flutter')),
|
2021-03-06 15:10:31 +00:00
|
|
|
initialOptions: InAppWebViewGroupOptions(
|
2022-04-22 14:24:41 +00:00
|
|
|
android:
|
|
|
|
AndroidInAppWebViewOptions(useHybridComposition: true)),
|
2021-03-05 22:19:50 +00:00
|
|
|
pullToRefreshController: pullToRefreshController,
|
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
final InAppWebViewController controller =
|
2022-04-22 14:24:41 +00:00
|
|
|
await controllerCompleter.future;
|
2021-03-05 22:19:50 +00:00
|
|
|
final String? currentUrl = (await controller.getUrl())?.toString();
|
|
|
|
expect(currentUrl, 'https://github.com/flutter');
|
|
|
|
});
|
|
|
|
|
2021-03-19 16:34:32 +00:00
|
|
|
group('WebMessage', () {
|
|
|
|
testWidgets('WebMessageChannel', (WidgetTester tester) async {
|
2022-04-22 14:24:41 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-03-19 16:34:32 +00:00
|
|
|
final Completer webMessageCompleter = Completer<String>();
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2022-04-22 14:24:41 +00:00
|
|
|
initialData: InAppWebViewInitialData(data: """
|
2021-03-19 16:34:32 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>WebMessageChannel Test</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<button id="button" onclick="port.postMessage(input.value);" />Send</button>
|
|
|
|
<br />
|
|
|
|
<input id="input" type="text" value="JavaScript To Native" />
|
2021-03-24 09:57:26 +00:00
|
|
|
|
2021-03-19 16:34:32 +00:00
|
|
|
<script>
|
|
|
|
var port;
|
|
|
|
window.addEventListener('message', function(event) {
|
|
|
|
if (event.data == 'capturePort') {
|
|
|
|
if (event.ports[0] != null) {
|
|
|
|
port = event.ports[0];
|
|
|
|
port.onmessage = function (event) {
|
|
|
|
console.log(event.data);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
"""),
|
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onConsoleMessage: (controller, consoleMessage) {
|
|
|
|
webMessageCompleter.complete(consoleMessage.message);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) async {
|
2022-04-22 14:24:41 +00:00
|
|
|
var webMessageChannel =
|
|
|
|
await controller.createWebMessageChannel();
|
2021-03-19 16:34:32 +00:00
|
|
|
var port1 = webMessageChannel!.port1;
|
|
|
|
var port2 = webMessageChannel.port2;
|
|
|
|
|
|
|
|
await port1.setWebMessageCallback((message) async {
|
2022-04-22 14:24:41 +00:00
|
|
|
await port1
|
|
|
|
.postMessage(WebMessage(data: message! + " and back"));
|
2021-03-19 16:34:32 +00:00
|
|
|
});
|
2022-04-22 14:24:41 +00:00
|
|
|
await controller.postWebMessage(
|
|
|
|
message: WebMessage(data: "capturePort", ports: [port2]),
|
|
|
|
targetOrigin: Uri.parse("*"));
|
|
|
|
await controller.evaluateJavascript(
|
|
|
|
source: "document.getElementById('button').click();");
|
2021-03-19 16:34:32 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await controllerCompleter.future;
|
|
|
|
|
|
|
|
final String message = await webMessageCompleter.future;
|
|
|
|
expect(message, 'JavaScript To Native and back');
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('WebMessageListener', (WidgetTester tester) async {
|
2022-04-22 14:24:41 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-03-19 16:34:32 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
final Completer webMessageCompleter = Completer<String>();
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
|
|
|
onWebViewCreated: (controller) async {
|
|
|
|
await controller.addWebMessageListener(WebMessageListener(
|
|
|
|
jsObjectName: "myTestObj",
|
|
|
|
allowedOriginRules: Set.from(["https://*.example.com"]),
|
2022-04-22 14:24:41 +00:00
|
|
|
onPostMessage:
|
|
|
|
(message, sourceOrigin, isMainFrame, replyProxy) {
|
|
|
|
assert(
|
|
|
|
sourceOrigin.toString() == "https://www.example.com");
|
2021-03-22 15:21:56 +00:00
|
|
|
assert(isMainFrame);
|
2021-03-19 16:34:32 +00:00
|
|
|
|
|
|
|
replyProxy.postMessage(message! + " and back");
|
|
|
|
},
|
|
|
|
));
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onConsoleMessage: (controller, consoleMessage) {
|
|
|
|
webMessageCompleter.complete(consoleMessage.message);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) async {
|
|
|
|
if (url.toString() == "https://www.example.com/") {
|
|
|
|
pageLoaded.complete();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
final controller = await controllerCompleter.future;
|
2022-04-22 14:24:41 +00:00
|
|
|
await controller.loadUrl(
|
|
|
|
urlRequest: URLRequest(url: Uri.parse("https://www.example.com/")));
|
2021-03-19 16:34:32 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
await controller.evaluateJavascript(source: """
|
|
|
|
myTestObj.addEventListener('message', function(event) {
|
|
|
|
console.log(event.data);
|
|
|
|
});
|
|
|
|
myTestObj.postMessage('JavaScript To Native');
|
|
|
|
""");
|
|
|
|
|
|
|
|
final String message = await webMessageCompleter.future;
|
|
|
|
expect(message, 'JavaScript To Native and back');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-02-22 22:38:30 +00:00
|
|
|
group('android methods', () {
|
|
|
|
testWidgets('clearSslPreferences', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-02-22 22:38:30 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
await expectLater(controller.android.clearSslPreferences(), completes);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
testWidgets('pause/resume', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-02-22 22:38:30 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
await expectLater(controller.android.pause(), completes);
|
|
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
await expectLater(controller.android.resume(), completes);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
testWidgets('getOriginalUrl', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-02-22 22:38:30 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
2021-03-05 22:19:50 +00:00
|
|
|
URLRequest(url: Uri.parse('https://github.com/flutter')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
2022-04-17 17:05:16 +00:00
|
|
|
var originUrl = (await controller.getOriginalUrl())?.toString();
|
2021-03-05 22:19:50 +00:00
|
|
|
expect(originUrl, 'https://github.com/flutter');
|
2022-04-17 17:05:16 +00:00
|
|
|
});
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
testWidgets('pageDown/pageUp', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-02-22 22:38:30 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
expect(await controller.android.pageDown(bottom: false), true);
|
|
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
expect(await controller.android.pageUp(top: false), true);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
testWidgets('zoomIn/zoomOut', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-02-22 22:38:30 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
expect(await controller.android.zoomIn(), true);
|
|
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
expect(await controller.android.zoomOut(), true);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
testWidgets('clearHistory', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
|
|
|
final StreamController<String> pageLoads =
|
|
|
|
StreamController<String>.broadcast();
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoads.add(url!.toString());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoads.stream.first;
|
2021-03-01 19:26:57 +00:00
|
|
|
await controller.loadUrl(
|
|
|
|
urlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://github.com/flutter')));
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoads.stream.first;
|
|
|
|
|
|
|
|
var webHistory = await controller.getCopyBackForwardList();
|
|
|
|
expect(webHistory!.list!.length, 2);
|
|
|
|
|
|
|
|
await controller.android.clearHistory();
|
|
|
|
|
|
|
|
webHistory = await controller.getCopyBackForwardList();
|
|
|
|
expect(webHistory!.list!.length, 1);
|
2021-03-01 19:24:26 +00:00
|
|
|
|
|
|
|
pageLoads.close();
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
test('clearClientCertPreferences', () async {
|
2021-03-01 19:26:57 +00:00
|
|
|
await expectLater(
|
|
|
|
AndroidInAppWebViewController.clearClientCertPreferences(),
|
|
|
|
completes);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
test('getSafeBrowsingPrivacyPolicyUrl', () async {
|
2021-03-01 19:26:57 +00:00
|
|
|
expect(
|
|
|
|
await AndroidInAppWebViewController
|
|
|
|
.getSafeBrowsingPrivacyPolicyUrl(),
|
|
|
|
isNotNull);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
test('setSafeBrowsingWhitelist', () async {
|
2021-03-01 19:26:57 +00:00
|
|
|
expect(
|
|
|
|
await AndroidInAppWebViewController.setSafeBrowsingWhitelist(
|
|
|
|
hosts: ["flutter.dev", "github.com"]),
|
|
|
|
true);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
test('getCurrentWebViewPackage', () async {
|
2021-03-01 19:26:57 +00:00
|
|
|
expect(await AndroidInAppWebViewController.getCurrentWebViewPackage(),
|
|
|
|
isNotNull);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2022-04-18 21:57:11 +00:00
|
|
|
|
|
|
|
test('setWebContentsDebuggingEnabled', () async {
|
2022-04-22 14:24:41 +00:00
|
|
|
expect(
|
|
|
|
AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true),
|
|
|
|
completes);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-02-24 23:00:46 +00:00
|
|
|
group('ios methods', () {
|
|
|
|
testWidgets('reloadFromOrigin', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-02-24 23:00:46 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-02-24 23:00:46 +00:00
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-24 23:00:46 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
2021-02-22 22:38:30 +00:00
|
|
|
),
|
2021-02-24 23:00:46 +00:00
|
|
|
),
|
|
|
|
);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-24 23:00:46 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
await expectLater(controller.ios.reloadFromOrigin(), completes);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.iOS);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-02-24 23:00:46 +00:00
|
|
|
testWidgets('createPdf', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-02-24 23:00:46 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-02-24 23:00:46 +00:00
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-24 23:00:46 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
2021-02-22 22:38:30 +00:00
|
|
|
),
|
2021-02-24 23:00:46 +00:00
|
|
|
),
|
|
|
|
);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-24 23:00:46 +00:00
|
|
|
await pageLoaded.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
var iosWKPdfConfiguration = IOSWKPDFConfiguration(
|
|
|
|
rect: InAppWebViewRect(width: 100, height: 100, x: 50, y: 50));
|
|
|
|
var pdf = await controller.ios
|
|
|
|
.createPdf(iosWKPdfConfiguration: iosWKPdfConfiguration);
|
2021-02-24 23:00:46 +00:00
|
|
|
expect(pdf, isNotNull);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.iOS);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-02-24 23:00:46 +00:00
|
|
|
testWidgets('createWebArchiveData', (WidgetTester tester) async {
|
2021-03-01 19:26:57 +00:00
|
|
|
final Completer controllerCompleter =
|
|
|
|
Completer<InAppWebViewController>();
|
2021-02-24 23:00:46 +00:00
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev')),
|
2021-02-24 23:00:46 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
2021-02-22 22:38:30 +00:00
|
|
|
),
|
2021-02-24 23:00:46 +00:00
|
|
|
),
|
|
|
|
);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-24 23:00:46 +00:00
|
|
|
await pageLoaded.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-02-24 23:00:46 +00:00
|
|
|
expect(await controller.ios.createWebArchiveData(), isNotNull);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.iOS);
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-03-25 11:01:05 +00:00
|
|
|
testWidgets('Apple Pay API enabled', (WidgetTester tester) async {
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
final Completer<String> alertMessageCompleter = Completer<String>();
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2022-04-22 14:24:41 +00:00
|
|
|
initialData: InAppWebViewInitialData(data: """
|
2021-03-25 11:01:05 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Apple Pay API</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script>
|
|
|
|
window.alert(window.ApplePaySession != null);
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
2022-04-22 14:24:41 +00:00
|
|
|
"""),
|
2021-03-25 11:01:05 +00:00
|
|
|
initialOptions: InAppWebViewGroupOptions(
|
|
|
|
ios: IOSInAppWebViewOptions(
|
|
|
|
applePayAPIEnabled: true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
onJsAlert: (controller, jsAlertRequest) async {
|
|
|
|
alertMessageCompleter.complete(jsAlertRequest.message);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await pageLoaded.future;
|
|
|
|
final message = await alertMessageCompleter.future;
|
|
|
|
expect(message, 'true');
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.iOS);
|
2021-03-25 11:01:05 +00:00
|
|
|
|
2021-02-24 23:00:46 +00:00
|
|
|
test('handlesURLScheme', () async {
|
|
|
|
expect(await IOSInAppWebViewController.handlesURLScheme("http"), true);
|
|
|
|
expect(await IOSInAppWebViewController.handlesURLScheme("https"), true);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.iOS);
|
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.iOS);
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
2022-04-22 14:24:41 +00:00
|
|
|
group('Service Worker', () {
|
2022-04-25 10:55:35 +00:00
|
|
|
testWidgets('shouldInterceptRequest', (WidgetTester tester) async {
|
2022-04-22 14:24:41 +00:00
|
|
|
final Completer completer = Completer();
|
|
|
|
|
|
|
|
var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
|
|
|
|
AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE);
|
|
|
|
var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported(
|
|
|
|
AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST);
|
|
|
|
|
|
|
|
if (swAvailable && swInterceptAvailable) {
|
|
|
|
AndroidServiceWorkerController serviceWorkerController =
|
|
|
|
AndroidServiceWorkerController.instance();
|
|
|
|
|
|
|
|
await serviceWorkerController
|
|
|
|
.setServiceWorkerClient(AndroidServiceWorkerClient(
|
|
|
|
shouldInterceptRequest: (request) async {
|
|
|
|
if (!completer.isCompleted) {
|
|
|
|
completer.complete();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
completer.complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://mdn.github.io/sw-test/')),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(completer.future, completes);
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2022-04-25 10:55:35 +00:00
|
|
|
|
|
|
|
testWidgets('setServiceWorkerClient to null', (WidgetTester tester) async {
|
|
|
|
final Completer<String> pageLoaded = Completer<String>();
|
|
|
|
|
|
|
|
var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
|
|
|
|
AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE);
|
|
|
|
var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported(
|
|
|
|
AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST);
|
|
|
|
|
|
|
|
if (swAvailable && swInterceptAvailable) {
|
|
|
|
AndroidServiceWorkerController serviceWorkerController =
|
2022-04-26 11:55:24 +00:00
|
|
|
AndroidServiceWorkerController.instance();
|
2022-04-25 10:55:35 +00:00
|
|
|
|
|
|
|
await serviceWorkerController.setServiceWorkerClient(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
|
|
|
initialUrlRequest:
|
2022-04-26 11:55:24 +00:00
|
|
|
URLRequest(url: Uri.parse('https://mdn.github.io/sw-test/')),
|
2022-04-25 10:55:35 +00:00
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete(url!.toString());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
final String url = await pageLoaded.future;
|
|
|
|
expect(url, "https://mdn.github.io/sw-test/");
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2022-04-22 14:24:41 +00:00
|
|
|
});
|
|
|
|
|
2021-02-22 22:38:30 +00:00
|
|
|
group('Cookie Manager', () {
|
|
|
|
testWidgets('set, get, delete', (WidgetTester tester) async {
|
|
|
|
CookieManager cookieManager = CookieManager.instance();
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<String> pageLoaded = Completer<String>();
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2021-03-01 19:26:57 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse('https://flutter.dev/')),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
initialOptions: InAppWebViewGroupOptions(
|
|
|
|
crossPlatform: InAppWebViewOptions(
|
2021-03-01 19:26:57 +00:00
|
|
|
clearCache: true,
|
|
|
|
)),
|
2021-02-22 22:38:30 +00:00
|
|
|
onLoadStop: (controller, url) {
|
|
|
|
pageLoaded.complete(url!.toString());
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
final url = Uri.parse(await pageLoaded.future);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await cookieManager.setCookie(
|
|
|
|
url: url, name: "myCookie", value: "myValue");
|
2021-02-22 22:38:30 +00:00
|
|
|
List<Cookie> cookies = await cookieManager.getCookies(url: url);
|
|
|
|
expect(cookies, isNotEmpty);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
Cookie? cookie =
|
|
|
|
await cookieManager.getCookie(url: url, name: "myCookie");
|
2021-02-22 22:38:30 +00:00
|
|
|
expect(cookie?.value.toString(), "myValue");
|
|
|
|
|
|
|
|
await cookieManager.deleteCookie(url: url, name: "myCookie");
|
|
|
|
cookie = await cookieManager.getCookie(url: url, name: "myCookie");
|
|
|
|
expect(cookie, isNull);
|
|
|
|
|
|
|
|
await cookieManager.deleteCookies(url: url);
|
|
|
|
cookies = await cookieManager.getCookies(url: url);
|
|
|
|
expect(cookies, isEmpty);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('HeadlessInAppWebView', () {
|
|
|
|
test('run and dispose', () async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
2021-03-28 02:17:09 +00:00
|
|
|
var headlessWebView = new HeadlessInAppWebView(
|
2022-04-22 14:24:41 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse("https://github.com/flutter")),
|
2021-03-28 02:17:09 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
headlessWebView.onLoadStop = (controller, url) async {
|
|
|
|
pageLoaded.complete();
|
|
|
|
};
|
|
|
|
|
|
|
|
await headlessWebView.run();
|
|
|
|
expect(headlessWebView.isRunning(), true);
|
|
|
|
|
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
final String? url = (await controller.getUrl())?.toString();
|
|
|
|
expect(url, 'https://github.com/flutter');
|
|
|
|
|
|
|
|
await headlessWebView.dispose();
|
|
|
|
|
|
|
|
expect(headlessWebView.isRunning(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('take screenshot', () async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
2021-02-22 22:38:30 +00:00
|
|
|
var headlessWebView = new HeadlessInAppWebView(
|
2022-04-22 14:24:41 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse("https://github.com/flutter")),
|
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) async {
|
|
|
|
pageLoaded.complete();
|
|
|
|
});
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
await headlessWebView.run();
|
2021-03-24 09:57:26 +00:00
|
|
|
expect(headlessWebView.isRunning(), true);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
2022-04-22 14:24:41 +00:00
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
final String? url = (await controller.getUrl())?.toString();
|
2021-03-05 22:19:50 +00:00
|
|
|
expect(url, 'https://github.com/flutter');
|
2021-02-22 22:38:30 +00:00
|
|
|
|
2021-03-28 02:17:09 +00:00
|
|
|
final Size? size = await headlessWebView.getSize();
|
|
|
|
expect(size, isNotNull);
|
|
|
|
|
|
|
|
final Uint8List? screenshot = await controller.takeScreenshot();
|
|
|
|
expect(screenshot, isNotNull);
|
|
|
|
|
2021-02-22 22:38:30 +00:00
|
|
|
await headlessWebView.dispose();
|
|
|
|
|
2021-03-28 02:17:09 +00:00
|
|
|
expect(headlessWebView.isRunning(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('set and get custom size', () async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
|
|
|
|
var headlessWebView = new HeadlessInAppWebView(
|
2022-04-22 14:24:41 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse("https://github.com/flutter")),
|
|
|
|
initialSize: Size(600, 800),
|
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
2021-03-28 02:17:09 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await headlessWebView.run();
|
|
|
|
expect(headlessWebView.isRunning(), true);
|
|
|
|
|
|
|
|
final Size? size = await headlessWebView.getSize();
|
|
|
|
expect(size, isNotNull);
|
|
|
|
expect(size, Size(600, 800));
|
|
|
|
|
|
|
|
await headlessWebView.setSize(Size(1080, 1920));
|
|
|
|
final Size? newSize = await headlessWebView.getSize();
|
|
|
|
expect(newSize, isNotNull);
|
|
|
|
expect(newSize, Size(1080, 1920));
|
|
|
|
|
|
|
|
await headlessWebView.dispose();
|
|
|
|
|
|
|
|
expect(headlessWebView.isRunning(), false);
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('set/get options', () async {
|
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
final Completer<void> pageLoaded = Completer<void>();
|
|
|
|
|
|
|
|
var headlessWebView = new HeadlessInAppWebView(
|
2022-04-22 14:24:41 +00:00
|
|
|
initialUrlRequest:
|
|
|
|
URLRequest(url: Uri.parse("https://github.com/flutter")),
|
2021-02-22 22:38:30 +00:00
|
|
|
initialOptions: InAppWebViewGroupOptions(
|
2021-03-01 19:26:57 +00:00
|
|
|
crossPlatform: InAppWebViewOptions(javaScriptEnabled: false)),
|
2021-02-22 22:38:30 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
onLoadStop: (controller, url) async {
|
|
|
|
pageLoaded.complete();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
await headlessWebView.run();
|
2021-03-01 19:26:57 +00:00
|
|
|
final InAppWebViewController controller =
|
|
|
|
await controllerCompleter.future;
|
2021-02-22 22:38:30 +00:00
|
|
|
await pageLoaded.future;
|
|
|
|
|
|
|
|
InAppWebViewGroupOptions? options = await controller.getOptions();
|
|
|
|
expect(options, isNotNull);
|
|
|
|
expect(options!.crossPlatform.javaScriptEnabled, false);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await controller.setOptions(
|
|
|
|
options: InAppWebViewGroupOptions(
|
|
|
|
crossPlatform: InAppWebViewOptions(javaScriptEnabled: true)));
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
options = await controller.getOptions();
|
|
|
|
expect(options, isNotNull);
|
|
|
|
expect(options!.crossPlatform.javaScriptEnabled, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('InAppBrowser', () {
|
2021-03-05 22:19:50 +00:00
|
|
|
test('openUrlRequest and close', () async {
|
2021-02-22 22:38:30 +00:00
|
|
|
var inAppBrowser = new MyInAppBrowser();
|
|
|
|
expect(inAppBrowser.isOpened(), false);
|
|
|
|
expect(() async {
|
|
|
|
await inAppBrowser.show();
|
|
|
|
}, throwsA(isInstanceOf<InAppBrowserNotOpenedException>()));
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await inAppBrowser.openUrlRequest(
|
2021-03-05 22:19:50 +00:00
|
|
|
urlRequest: URLRequest(url: Uri.parse("https://github.com/flutter")));
|
|
|
|
await inAppBrowser.browserCreated.future;
|
|
|
|
expect(inAppBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
|
|
|
await inAppBrowser.openUrlRequest(
|
2022-04-22 14:24:41 +00:00
|
|
|
urlRequest: URLRequest(url: Uri.parse("https://flutter.dev")));
|
2021-03-05 22:19:50 +00:00
|
|
|
}, throwsA(isInstanceOf<InAppBrowserAlreadyOpenedException>()));
|
|
|
|
|
|
|
|
await inAppBrowser.firstPageLoaded.future;
|
|
|
|
var controller = inAppBrowser.webViewController;
|
|
|
|
|
|
|
|
final String? url = (await controller.getUrl())?.toString();
|
|
|
|
expect(url, 'https://github.com/flutter');
|
|
|
|
|
|
|
|
await inAppBrowser.close();
|
|
|
|
expect(inAppBrowser.isOpened(), false);
|
|
|
|
expect(() async => await inAppBrowser.webViewController.getUrl(),
|
|
|
|
throwsA(isInstanceOf<MissingPluginException>()));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('openFile and close', () async {
|
|
|
|
var inAppBrowser = new MyInAppBrowser();
|
|
|
|
expect(inAppBrowser.isOpened(), false);
|
|
|
|
expect(() async {
|
|
|
|
await inAppBrowser.show();
|
|
|
|
}, throwsA(isInstanceOf<InAppBrowserNotOpenedException>()));
|
|
|
|
|
2022-04-22 14:24:41 +00:00
|
|
|
await inAppBrowser.openFile(
|
|
|
|
assetFilePath: "test_assets/in_app_webview_initial_file_test.html");
|
2021-03-05 22:19:50 +00:00
|
|
|
await inAppBrowser.browserCreated.future;
|
|
|
|
expect(inAppBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
|
|
|
await inAppBrowser.openUrlRequest(
|
|
|
|
urlRequest:
|
2022-04-22 14:24:41 +00:00
|
|
|
URLRequest(url: Uri.parse("https://github.com/flutter")));
|
2021-03-05 22:19:50 +00:00
|
|
|
}, throwsA(isInstanceOf<InAppBrowserAlreadyOpenedException>()));
|
|
|
|
|
|
|
|
await inAppBrowser.firstPageLoaded.future;
|
|
|
|
var controller = inAppBrowser.webViewController;
|
|
|
|
|
|
|
|
final String? url = (await controller.getUrl())?.toString();
|
|
|
|
expect(url, endsWith("in_app_webview_initial_file_test.html"));
|
|
|
|
|
|
|
|
await inAppBrowser.close();
|
|
|
|
expect(inAppBrowser.isOpened(), false);
|
|
|
|
expect(() async => await inAppBrowser.webViewController.getUrl(),
|
|
|
|
throwsA(isInstanceOf<MissingPluginException>()));
|
|
|
|
});
|
|
|
|
|
2021-03-28 02:17:09 +00:00
|
|
|
test('openData and close', () async {
|
2021-03-05 22:19:50 +00:00
|
|
|
var inAppBrowser = new MyInAppBrowser();
|
|
|
|
expect(inAppBrowser.isOpened(), false);
|
|
|
|
expect(() async {
|
|
|
|
await inAppBrowser.show();
|
|
|
|
}, throwsA(isInstanceOf<InAppBrowserNotOpenedException>()));
|
|
|
|
|
2022-04-22 14:24:41 +00:00
|
|
|
await inAppBrowser.openData(
|
|
|
|
data: """
|
2021-03-05 22:19:50 +00:00
|
|
|
<!doctype html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
|
|
<link rel="stylesheet" href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css">
|
|
|
|
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<img src="https://via.placeholder.com/100x50" alt="placeholder 100x50">
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
""",
|
|
|
|
encoding: 'utf-8',
|
|
|
|
mimeType: 'text/html',
|
|
|
|
androidHistoryUrl: Uri.parse("https://flutter.dev"),
|
|
|
|
baseUrl: Uri.parse("https://flutter.dev"));
|
2021-02-22 22:38:30 +00:00
|
|
|
await inAppBrowser.browserCreated.future;
|
|
|
|
expect(inAppBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
2021-03-01 19:26:57 +00:00
|
|
|
await inAppBrowser.openUrlRequest(
|
|
|
|
urlRequest:
|
2022-04-22 14:24:41 +00:00
|
|
|
URLRequest(url: Uri.parse("https://github.com/flutter")));
|
2021-02-22 22:38:30 +00:00
|
|
|
}, throwsA(isInstanceOf<InAppBrowserAlreadyOpenedException>()));
|
|
|
|
|
|
|
|
await inAppBrowser.firstPageLoaded.future;
|
|
|
|
var controller = inAppBrowser.webViewController;
|
|
|
|
|
|
|
|
final String? url = (await controller.getUrl())?.toString();
|
|
|
|
expect(url, 'https://flutter.dev/');
|
|
|
|
|
|
|
|
await inAppBrowser.close();
|
|
|
|
expect(inAppBrowser.isOpened(), false);
|
2021-03-01 19:26:57 +00:00
|
|
|
expect(() async => await inAppBrowser.webViewController.getUrl(),
|
|
|
|
throwsA(isInstanceOf<MissingPluginException>()));
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('set/get options', () async {
|
|
|
|
var inAppBrowser = new MyInAppBrowser();
|
2021-03-01 19:26:57 +00:00
|
|
|
await inAppBrowser.openUrlRequest(
|
2021-03-05 22:19:50 +00:00
|
|
|
urlRequest: URLRequest(url: Uri.parse("https://github.com/flutter")),
|
2021-03-01 19:26:57 +00:00
|
|
|
options: InAppBrowserClassOptions(
|
|
|
|
crossPlatform: InAppBrowserOptions(hideToolbarTop: true)));
|
2021-02-22 22:38:30 +00:00
|
|
|
await inAppBrowser.browserCreated.future;
|
|
|
|
await inAppBrowser.firstPageLoaded.future;
|
|
|
|
|
|
|
|
InAppBrowserClassOptions? options = await inAppBrowser.getOptions();
|
|
|
|
expect(options, isNotNull);
|
|
|
|
expect(options!.crossPlatform.hideToolbarTop, true);
|
|
|
|
|
2021-03-01 19:26:57 +00:00
|
|
|
await inAppBrowser.setOptions(
|
|
|
|
options: InAppBrowserClassOptions(
|
|
|
|
crossPlatform: InAppBrowserOptions(hideToolbarTop: false)));
|
2021-02-22 22:38:30 +00:00
|
|
|
|
|
|
|
options = await inAppBrowser.getOptions();
|
|
|
|
expect(options, isNotNull);
|
|
|
|
expect(options!.crossPlatform.hideToolbarTop, false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('ChromeSafariBrowser', () {
|
|
|
|
test('open and close', () async {
|
|
|
|
var chromeSafariBrowser = new MyChromeSafariBrowser();
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
|
2022-04-22 14:24:41 +00:00
|
|
|
await chromeSafariBrowser.open(
|
|
|
|
url: Uri.parse("https://github.com/flutter"));
|
2021-02-22 22:38:30 +00:00
|
|
|
await chromeSafariBrowser.browserCreated.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
2022-04-22 14:24:41 +00:00
|
|
|
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
|
2021-02-22 22:38:30 +00:00
|
|
|
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
|
|
|
|
|
|
|
|
await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes);
|
|
|
|
await chromeSafariBrowser.close();
|
|
|
|
await chromeSafariBrowser.browserClosed.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
});
|
2022-04-18 21:12:17 +00:00
|
|
|
|
2022-04-25 15:39:04 +00:00
|
|
|
test('add custom menu item', () async {
|
|
|
|
var chromeSafariBrowser = new MyChromeSafariBrowser();
|
|
|
|
chromeSafariBrowser.addMenuItem(ChromeSafariBrowserMenuItem(
|
|
|
|
id: 2,
|
|
|
|
label: 'Custom item menu 1',
|
|
|
|
action: (url, title) {
|
|
|
|
print('Custom item menu 1 clicked!');
|
|
|
|
}));
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
|
|
|
|
await chromeSafariBrowser.open(
|
|
|
|
url: Uri.parse("https://github.com/flutter"));
|
|
|
|
await chromeSafariBrowser.browserCreated.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
|
|
|
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
|
|
|
|
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
|
|
|
|
|
|
|
|
await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes);
|
|
|
|
await chromeSafariBrowser.close();
|
|
|
|
await chromeSafariBrowser.browserClosed.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
});
|
|
|
|
|
2022-04-18 21:12:17 +00:00
|
|
|
group('Android Custom Tabs', () {
|
2022-04-25 15:39:04 +00:00
|
|
|
test('add custom action button', () async {
|
|
|
|
var chromeSafariBrowser = new MyChromeSafariBrowser();
|
2022-04-26 11:55:24 +00:00
|
|
|
var actionButtonIcon =
|
|
|
|
await rootBundle.load('test_assets/images/flutter-logo.png');
|
2022-04-25 15:39:04 +00:00
|
|
|
chromeSafariBrowser.setActionButton(ChromeSafariBrowserActionButton(
|
|
|
|
id: 1,
|
|
|
|
description: 'Action Button description',
|
|
|
|
icon: actionButtonIcon.buffer.asUint8List(),
|
|
|
|
action: (url, title) {
|
|
|
|
print('Action Button 1 clicked!');
|
|
|
|
}));
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
|
|
|
|
await chromeSafariBrowser.open(
|
|
|
|
url: Uri.parse("https://github.com/flutter"));
|
|
|
|
await chromeSafariBrowser.browserCreated.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
|
|
|
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
|
|
|
|
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
|
|
|
|
|
2022-04-26 11:55:24 +00:00
|
|
|
await expectLater(
|
|
|
|
chromeSafariBrowser.firstPageLoaded.future, completes);
|
2022-04-25 15:39:04 +00:00
|
|
|
await chromeSafariBrowser.close();
|
|
|
|
await chromeSafariBrowser.browserClosed.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
});
|
|
|
|
|
2022-04-18 21:12:17 +00:00
|
|
|
test('Custom Tabs single instance', () async {
|
|
|
|
var chromeSafariBrowser = new MyChromeSafariBrowser();
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
|
|
|
|
await chromeSafariBrowser.open(
|
2022-04-22 14:24:41 +00:00
|
|
|
url: Uri.parse("https://github.com/flutter"),
|
|
|
|
options: ChromeSafariBrowserClassOptions(
|
|
|
|
android:
|
|
|
|
AndroidChromeCustomTabsOptions(isSingleInstance: true)));
|
2022-04-18 21:12:17 +00:00
|
|
|
await chromeSafariBrowser.browserCreated.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
2022-04-22 14:24:41 +00:00
|
|
|
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
|
2022-04-18 21:12:17 +00:00
|
|
|
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
|
|
|
|
|
2022-04-22 14:24:41 +00:00
|
|
|
await expectLater(
|
|
|
|
chromeSafariBrowser.firstPageLoaded.future, completes);
|
2022-04-18 21:12:17 +00:00
|
|
|
await chromeSafariBrowser.close();
|
|
|
|
await chromeSafariBrowser.browserClosed.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Trusted Web Activity', () async {
|
|
|
|
var chromeSafariBrowser = new MyChromeSafariBrowser();
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
|
|
|
|
await chromeSafariBrowser.open(
|
|
|
|
url: Uri.parse("https://github.com/flutter"),
|
|
|
|
options: ChromeSafariBrowserClassOptions(
|
|
|
|
android: AndroidChromeCustomTabsOptions(
|
2022-04-22 14:24:41 +00:00
|
|
|
isTrustedWebActivity: true)));
|
2022-04-18 21:12:17 +00:00
|
|
|
await chromeSafariBrowser.browserCreated.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
2022-04-22 14:24:41 +00:00
|
|
|
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
|
2022-04-18 21:12:17 +00:00
|
|
|
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
|
|
|
|
|
2022-04-22 14:24:41 +00:00
|
|
|
await expectLater(
|
|
|
|
chromeSafariBrowser.firstPageLoaded.future, completes);
|
2022-04-18 21:12:17 +00:00
|
|
|
await chromeSafariBrowser.close();
|
|
|
|
await chromeSafariBrowser.browserClosed.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Trusted Web Activity single instance', () async {
|
|
|
|
var chromeSafariBrowser = new MyChromeSafariBrowser();
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
|
|
|
|
await chromeSafariBrowser.open(
|
|
|
|
url: Uri.parse("https://github.com/flutter"),
|
|
|
|
options: ChromeSafariBrowserClassOptions(
|
|
|
|
android: AndroidChromeCustomTabsOptions(
|
2022-04-22 14:24:41 +00:00
|
|
|
isTrustedWebActivity: true, isSingleInstance: true)));
|
2022-04-18 21:12:17 +00:00
|
|
|
await chromeSafariBrowser.browserCreated.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), true);
|
|
|
|
expect(() async {
|
2022-04-22 14:24:41 +00:00
|
|
|
await chromeSafariBrowser.open(url: Uri.parse("https://flutter.dev"));
|
2022-04-18 21:12:17 +00:00
|
|
|
}, throwsA(isInstanceOf<ChromeSafariBrowserAlreadyOpenedException>()));
|
|
|
|
|
2022-04-22 14:24:41 +00:00
|
|
|
await expectLater(
|
|
|
|
chromeSafariBrowser.firstPageLoaded.future, completes);
|
2022-04-18 21:12:17 +00:00
|
|
|
await chromeSafariBrowser.close();
|
|
|
|
await chromeSafariBrowser.browserClosed.future;
|
|
|
|
expect(chromeSafariBrowser.isOpened(), false);
|
|
|
|
});
|
2022-04-27 11:39:00 +00:00
|
|
|
}, skip: defaultTargetPlatform != TargetPlatform.android);
|
2021-02-22 22:38:30 +00:00
|
|
|
});
|
2021-03-18 16:24:13 +00:00
|
|
|
|
|
|
|
group('InAppLocalhostServer', () {
|
|
|
|
final InAppLocalhostServer localhostServer = InAppLocalhostServer();
|
|
|
|
|
|
|
|
setUpAll(() async {
|
2021-03-24 09:57:26 +00:00
|
|
|
await localhostServer.start();
|
2021-03-18 16:24:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('load asset file', (WidgetTester tester) async {
|
2021-03-24 09:57:26 +00:00
|
|
|
expect(localhostServer.isRunning(), true);
|
|
|
|
|
2021-03-18 16:24:13 +00:00
|
|
|
final Completer controllerCompleter = Completer<InAppWebViewController>();
|
|
|
|
await tester.pumpWidget(
|
|
|
|
Directionality(
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
child: InAppWebView(
|
|
|
|
key: GlobalKey(),
|
2022-04-22 14:24:41 +00:00
|
|
|
initialUrlRequest: URLRequest(
|
|
|
|
url: Uri.parse('http://localhost:8080/test_assets/index.html')),
|
2021-03-18 16:24:13 +00:00
|
|
|
onWebViewCreated: (controller) {
|
|
|
|
controllerCompleter.complete(controller);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
final InAppWebViewController controller =
|
2022-04-22 14:24:41 +00:00
|
|
|
await controllerCompleter.future;
|
2021-03-18 16:24:13 +00:00
|
|
|
final String? currentUrl = (await controller.getUrl())?.toString();
|
|
|
|
expect(currentUrl, 'http://localhost:8080/test_assets/index.html');
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDownAll(() async {
|
2021-03-24 09:57:26 +00:00
|
|
|
await localhostServer.close();
|
2021-03-18 16:24:13 +00:00
|
|
|
});
|
|
|
|
});
|
2021-01-28 16:10:15 +00:00
|
|
|
}
|