iosWebViewFix/example/integration_test/in_app_webview/on_title_changed.dart

55 lines
1.7 KiB
Dart

import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_test/flutter_test.dart';
import '../constants.dart';
void onTitleChanged() {
final shouldSkip = kIsWeb
? false
: ![
TargetPlatform.android,
TargetPlatform.iOS,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
var url = !kIsWeb ? TEST_URL_1 : TEST_WEB_PLATFORM_URL_1;
testWidgets('onTitleChanged', (WidgetTester tester) async {
final Completer controllerCompleter = Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
final Completer<void> onTitleChangedCompleter = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: url),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete();
},
onTitleChanged: (controller, title) {
if (title == "title test") {
onTitleChangedCompleter.complete();
}
},
),
),
);
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
await tester.pump();
await controller.evaluateJavascript(
source: "document.title = 'title test';");
await expectLater(onTitleChangedCompleter.future, completes);
}, skip: shouldSkip);
}