Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview_flutter_lwe] Update webivew_flutter to 4.4.2 #633

Merged
merged 6 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/webview_flutter_lwe/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## NEXT
## 0.3.0

* Update webivew_flutter to 4.4.2.
* Update webview_flutter_platform_interface to 2.6.0.
* Update integration_test.
* Add pub topics to package metadata.
* Add support to retrieve the user agent. See `LweWebViewController.getUserAgent`.
* Apply Platform API change.
* Increase the minimum Flutter version to 3.3.

## 0.2.0
Expand Down
4 changes: 2 additions & 2 deletions packages/webview_flutter_lwe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ This package is not an _endorsed_ implementation of `webview_flutter`. Therefore

```yaml
dependencies:
webview_flutter: ^4.0.2
webview_flutter_lwe: ^0.2.0
webview_flutter: ^4.4.2
webview_flutter_lwe: ^0.3.0
```

## Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
Expand All @@ -20,7 +19,7 @@ Future<void> main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

final HttpServer server = await HttpServer.bind(InternetAddress.anyIPv4, 0);
server.forEach((HttpRequest request) {
unawaited(server.forEach((HttpRequest request) {
if (request.uri.path == '/hello.txt') {
request.response.writeln('Hello, world.');
} else if (request.uri.path == '/secondary.txt') {
Expand All @@ -33,19 +32,19 @@ Future<void> main() async {
fail('unexpected request: ${request.method} ${request.uri}');
}
request.response.close();
});
}));
final String prefixUrl = 'http://${server.address.address}:${server.port}';
final String primaryUrl = '$prefixUrl/hello.txt';
final String secondaryUrl = '$prefixUrl/secondary.txt';

testWidgets('loadRequest', (WidgetTester tester) async {
final Completer<void> pageFinished = Completer<void>();

final WebViewController controller = WebViewController()
..setNavigationDelegate(
NavigationDelegate(onPageFinished: (_) => pageFinished.complete()),
)
..loadRequest(Uri.parse(primaryUrl));
final WebViewController controller = WebViewController();
unawaited(controller.setNavigationDelegate(
NavigationDelegate(onPageFinished: (_) => pageFinished.complete()),
));
unawaited(controller.loadRequest(Uri.parse(primaryUrl)));

await tester.pumpWidget(WebViewWidget(controller: controller));

Expand All @@ -58,12 +57,12 @@ Future<void> main() async {
testWidgets('runJavaScriptReturningResult', (WidgetTester tester) async {
final Completer<void> pageFinished = Completer<void>();

final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(onPageFinished: (_) => pageFinished.complete()),
)
..loadRequest(Uri.parse(primaryUrl));
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(
NavigationDelegate(onPageFinished: (_) => pageFinished.complete()),
));
unawaited(controller.loadRequest(Uri.parse(primaryUrl)));

await tester.pumpWidget(WebViewWidget(controller: controller));

Expand All @@ -77,11 +76,11 @@ Future<void> main() async {

testWidgets('JavascriptChannel', (WidgetTester tester) async {
final Completer<void> pageFinished = Completer<void>();
final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(onPageFinished: (_) => pageFinished.complete()),
);
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(
NavigationDelegate(onPageFinished: (_) => pageFinished.complete()),
));

final Completer<String> channelCompleter = Completer<String>();
await controller.addJavaScriptChannel(
Expand Down Expand Up @@ -138,19 +137,19 @@ Future<void> main() async {
testWidgets('set custom userAgent', (WidgetTester tester) async {
final Completer<void> pageFinished = Completer<void>();

final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageFinished.complete(),
))
..setUserAgent('Custom_User_Agent1')
..loadRequest(Uri.parse('about:blank'));
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageFinished.complete(),
)));
unawaited(controller.setUserAgent('Custom_User_Agent1'));
unawaited(controller.loadRequest(Uri.parse('about:blank')));

await tester.pumpWidget(WebViewWidget(controller: controller));

await pageFinished.future;

final String customUserAgent = await _getUserAgent(controller);
final String? customUserAgent = await controller.getUserAgent();
expect(customUserAgent, 'Custom_User_Agent1');
});

Expand All @@ -167,14 +166,14 @@ Future<void> main() async {
base64Encode(const Utf8Encoder().convert(getTitleTest));
final Completer<void> pageLoaded = Completer<void>();

final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
))
..loadRequest(
Uri.parse('data:text/html;charset=utf-8;base64,$getTitleTestBase64'),
);
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
)));
unawaited(controller.loadRequest(
Uri.parse('data:text/html;charset=utf-8;base64,$getTitleTestBase64'),
));

await tester.pumpWidget(WebViewWidget(controller: controller));

Expand Down Expand Up @@ -217,14 +216,14 @@ Future<void> main() async {
base64Encode(const Utf8Encoder().convert(scrollTestPage));

final Completer<void> pageLoaded = Completer<void>();
final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
))
..loadRequest(Uri.parse(
'data:text/html;charset=utf-8;base64,$scrollTestPageBase64',
));
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
)));
unawaited(controller.loadRequest(Uri.parse(
'data:text/html;charset=utf-8;base64,$scrollTestPageBase64',
)));

await tester.pumpWidget(WebViewWidget(controller: controller));

Expand Down Expand Up @@ -264,20 +263,20 @@ Future<void> main() async {
testWidgets('can allow requests', (WidgetTester tester) async {
Completer<void> pageLoaded = Completer<void>();

final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
onNavigationRequest: (NavigationRequest navigationRequest) {
return (navigationRequest.url.contains('youtube.com'))
? NavigationDecision.prevent
: NavigationDecision.navigate;
},
));
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
onNavigationRequest: (NavigationRequest navigationRequest) {
return (navigationRequest.url.contains('youtube.com'))
? NavigationDecision.prevent
: NavigationDecision.navigate;
},
)));

await tester.pumpWidget(WebViewWidget(controller: controller));

controller.loadRequest(Uri.parse(blankPageEncoded));
unawaited(controller.loadRequest(Uri.parse(blankPageEncoded)));

await pageLoaded.future; // Wait for initial page load.

Expand All @@ -293,13 +292,14 @@ Future<void> main() async {
final Completer<WebResourceError> errorCompleter =
Completer<WebResourceError>();

final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(onWebResourceError: (WebResourceError error) {
errorCompleter.complete(error);
}))
..loadRequest(Uri.parse('https://www.notawebsite..com'));
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(
NavigationDelegate(onWebResourceError: (WebResourceError error) {
errorCompleter.complete(error);
})));
unawaited(
controller.loadRequest(Uri.parse('https://www.notawebsite..com')));

await tester.pumpWidget(WebViewWidget(controller: controller));

Expand All @@ -313,17 +313,17 @@ Future<void> main() async {
Completer<WebResourceError>();
final Completer<void> pageFinishCompleter = Completer<void>();

final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageFinishCompleter.complete(),
onWebResourceError: (WebResourceError error) {
errorCompleter.complete(error);
},
))
..loadRequest(
Uri.parse('data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+'),
);
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageFinishCompleter.complete(),
onWebResourceError: (WebResourceError error) {
errorCompleter.complete(error);
},
)));
unawaited(controller.loadRequest(
Uri.parse('data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+'),
));

await tester.pumpWidget(WebViewWidget(controller: controller));

Expand All @@ -334,19 +334,19 @@ Future<void> main() async {
testWidgets('can block requests', (WidgetTester tester) async {
Completer<void> pageLoaded = Completer<void>();

final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
onNavigationRequest: (NavigationRequest navigationRequest) {
return (navigationRequest.url.contains('youtube.com'))
? NavigationDecision.prevent
: NavigationDecision.navigate;
}));
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
onNavigationRequest: (NavigationRequest navigationRequest) {
return (navigationRequest.url.contains('youtube.com'))
? NavigationDecision.prevent
: NavigationDecision.navigate;
})));

await tester.pumpWidget(WebViewWidget(controller: controller));

controller.loadRequest(Uri.parse(blankPageEncoded));
unawaited(controller.loadRequest(Uri.parse(blankPageEncoded)));

await pageLoaded.future; // Wait for initial page load.

Expand All @@ -366,21 +366,21 @@ Future<void> main() async {
testWidgets('supports asynchronous decisions', (WidgetTester tester) async {
Completer<void> pageLoaded = Completer<void>();

final WebViewController controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
onNavigationRequest: (NavigationRequest navigationRequest) async {
NavigationDecision decision = NavigationDecision.prevent;
decision = await Future<NavigationDecision>.delayed(
const Duration(milliseconds: 10),
() => NavigationDecision.navigate);
return decision;
}));
final WebViewController controller = WebViewController();
unawaited(controller.setJavaScriptMode(JavaScriptMode.unrestricted));
unawaited(controller.setNavigationDelegate(NavigationDelegate(
onPageFinished: (_) => pageLoaded.complete(),
onNavigationRequest: (NavigationRequest navigationRequest) async {
NavigationDecision decision = NavigationDecision.prevent;
decision = await Future<NavigationDecision>.delayed(
const Duration(milliseconds: 10),
() => NavigationDecision.navigate);
return decision;
})));

await tester.pumpWidget(WebViewWidget(controller: controller));

controller.loadRequest(Uri.parse(blankPageEncoded));
unawaited(controller.loadRequest(Uri.parse(blankPageEncoded)));

await pageLoaded.future; // Wait for initial page load.

Expand All @@ -394,23 +394,6 @@ Future<void> main() async {
});
}

/// Returns the value used for the HTTP User-Agent: request header in subsequent HTTP requests.
Future<String> _getUserAgent(WebViewController controller) async {
return _runJavascriptReturningResult(controller, 'navigator.userAgent;');
}

Future<String> _runJavascriptReturningResult(
WebViewController controller,
String js,
) async {
if (defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.linux) {
return await controller.runJavaScriptReturningResult(js) as String;
}
return jsonDecode(await controller.runJavaScriptReturningResult(js) as String)
as String;
}

class ResizableWebView extends StatefulWidget {
const ResizableWebView({
super.key,
Expand Down
Loading