iosWebViewFix/example/integration_test/in_app_webview/programmatic_zoom_scale.dart

149 lines
4.7 KiB
Dart
Raw Normal View History

part of 'main.dart';
2022-04-28 21:23:38 +00:00
void programmaticZoomScale() {
2022-04-29 11:39:28 +00:00
final shouldSkip = kIsWeb
? true
: ![
2022-04-28 21:23:38 +00:00
TargetPlatform.android,
2022-04-29 11:39:28 +00:00
TargetPlatform.iOS,
TargetPlatform.macOS,
2022-04-28 21:23:38 +00:00
].contains(defaultTargetPlatform);
skippableGroup('programmatic zoom scale', () {
2022-04-29 11:39:28 +00:00
final shouldSkipTest1 = kIsWeb
? true
: ![
TargetPlatform.android,
].contains(defaultTargetPlatform);
skippableTestWidgets('zoomIn/zoomOut', (WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 21:23:38 +00:00
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
2022-04-29 11:39:28 +00:00
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
2022-04-28 21:23:38 +00:00
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete();
},
),
),
);
final InAppWebViewController controller =
2022-04-29 11:39:28 +00:00
await controllerCompleter.future;
2022-04-28 21:23:38 +00:00
await pageLoaded.future;
expect(await controller.zoomIn(), true);
await Future.delayed(Duration(seconds: 1));
expect(await controller.zoomOut(), true);
}, skip: shouldSkipTest1);
skippableTestWidgets('onZoomScaleChanged', (WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 21:23:38 +00:00
final Completer<void> pageLoaded = Completer<void>();
final Completer<void> onZoomScaleChangedCompleter = Completer<void>();
var listenForScaleChange = false;
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
2022-04-29 11:39:28 +00:00
initialUrlRequest: URLRequest(url: TEST_URL_1),
2022-04-28 21:23:38 +00:00
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
2022-10-06 13:13:31 +00:00
if (!pageLoaded.isCompleted) {
pageLoaded.complete();
}
2022-04-28 21:23:38 +00:00
},
onZoomScaleChanged: (controller, oldScale, newScale) {
if (listenForScaleChange) {
onZoomScaleChangedCompleter.complete();
}
},
),
),
);
final InAppWebViewController controller =
2022-04-29 11:39:28 +00:00
await controllerCompleter.future;
2022-04-28 21:23:38 +00:00
await pageLoaded.future;
listenForScaleChange = true;
await controller.zoomBy(zoomFactor: 2);
await expectLater(onZoomScaleChangedCompleter.future, completes);
});
skippableTestWidgets('zoomBy', (WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 21:23:38 +00:00
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: WebUri('https://flutter.dev')),
2022-04-28 21:23:38 +00:00
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete();
},
),
),
);
final InAppWebViewController controller =
2022-04-29 11:39:28 +00:00
await controllerCompleter.future;
2022-04-28 21:23:38 +00:00
await pageLoaded.future;
await expectLater(
controller.zoomBy(zoomFactor: 3.0, animated: true), completes);
});
skippableTestWidgets('getZoomScale', (WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
2022-04-28 21:23:38 +00:00
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: WebUri('https://flutter.dev')),
2022-04-28 21:23:38 +00:00
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete();
},
),
),
);
final InAppWebViewController controller =
2022-04-29 11:39:28 +00:00
await controllerCompleter.future;
2022-04-28 21:23:38 +00:00
await pageLoaded.future;
final scale = await controller.getZoomScale();
expect(scale, isNonZero);
expect(scale, isPositive);
});
}, skip: shouldSkip);
}