Skip to content

Commit

Permalink
Add test, support js window open on Android as well, update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
amirh committed Feb 6, 2020
1 parent f614cca commit dc6e7df
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.3.19+6

* On iOS, enable opening links with href where target="_blank".
* Enable opening links that target the "_blank" window (links open in same window).

## 0.3.19+5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
platformThreadHandler = new Handler(context.getMainLooper());
// Allow local storage.
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

methodChannel = new MethodChannel(messenger, "plugins.flutter.io/webview_" + id);
methodChannel.setMethodCallHandler(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: _globalKey,
initialUrl: 'https://flutter.dev/',
initialUrl: 'about:blank',
javascriptMode: JavascriptMode.unrestricted,
userAgent: 'Custom_User_Agent1',
onWebViewCreated: (WebViewController controller) {
Expand All @@ -263,7 +263,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: _globalKey,
initialUrl: 'https://flutter.dev/',
initialUrl: 'about:blank',
javascriptMode: JavascriptMode.unrestricted,
userAgent: 'Custom_User_Agent2',
),
Expand Down Expand Up @@ -301,7 +301,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: _globalKey,
initialUrl: 'https://flutter.dev/',
initialUrl: 'about:blank',
javascriptMode: JavascriptMode.unrestricted,
userAgent: 'Custom_User_Agent',
),
Expand All @@ -315,7 +315,7 @@ void main() {
textDirection: TextDirection.ltr,
child: WebView(
key: _globalKey,
initialUrl: 'https://flutter.dev/',
initialUrl: 'about:blank',
javascriptMode: JavascriptMode.unrestricted,
),
),
Expand Down Expand Up @@ -678,6 +678,33 @@ void main() {
final String currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
});

testWidgets('target _blank opens in same window',
(WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: WebView(
key: GlobalKey(),
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
},
javascriptMode: JavascriptMode.unrestricted,
onPageFinished: (String url) {
pageLoaded.complete(null);
},
),
),
);
final WebViewController controller = await controllerCompleter.future;
await controller.evaluateJavascript('window.open("about:blank", "_blank")');
await pageLoaded.future;
final String currentUrl = await controller.currentUrl();
expect(currentUrl, 'about:blank');
});
}

// JavaScript booleans evaluate to different string values on Android and iOS.
Expand Down

0 comments on commit dc6e7df

Please sign in to comment.