This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] Add onReceivedError callback #2639
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
463b84b
Start of onReceivedError support
bparrishMines 6964b9b
Documentation
bparrishMines 38985d6
Format change and bug fix
bparrishMines 70347cf
Android format change
bparrishMines c8bd541
Add error test
bparrishMines 8915e9d
formatting
bparrishMines e7e5655
We actually do need to support deprecated method
bparrishMines d0e2ec1
Create WebResourceError. Seperate iOS and Android parts. Add test for…
bparrishMines c10e171
formatting
bparrishMines 4fb4b21
Add ios error types
bparrishMines 7ebb729
Format and change method name
bparrishMines 17f6246
fix flutter driver test
bparrishMines 28e67e3
Better documentation and good code suggestion
bparrishMines bcc1d45
version bump
bparrishMines 35fcf43
typa
bparrishMines a3bfcc6
Remove error code docs and clearer error documetation
bparrishMines e469165
another documentation fix
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -4,12 +4,14 @@ | |||
|
|
||||
| import 'dart:async'; | ||||
| import 'dart:convert'; | ||||
| import 'dart:io'; | ||||
| import 'dart:typed_data'; | ||||
|
|
||||
| import 'package:flutter/foundation.dart'; | ||||
| import 'package:flutter/services.dart'; | ||||
| import 'package:flutter/widgets.dart'; | ||||
| import 'package:flutter_test/flutter_test.dart'; | ||||
| import 'package:webview_flutter/platform_interface.dart'; | ||||
| import 'package:webview_flutter/webview_flutter.dart'; | ||||
| import 'package:e2e/e2e.dart'; | ||||
|
|
||||
|
|
@@ -576,6 +578,52 @@ void main() { | |||
| expect(currentUrl, 'https://www.google.com/'); | ||||
| }); | ||||
|
|
||||
| testWidgets('onWebResourceError', (WidgetTester tester) async { | ||||
| final Completer<WebResourceError> errorCompleter = | ||||
| Completer<WebResourceError>(); | ||||
|
|
||||
| await tester.pumpWidget( | ||||
| Directionality( | ||||
| textDirection: TextDirection.ltr, | ||||
| child: WebView( | ||||
| key: GlobalKey(), | ||||
| initialUrl: 'https://www.notawebsite..com', | ||||
| onWebResourceError: (WebResourceError error) { | ||||
| errorCompleter.complete(error); | ||||
| }, | ||||
| ), | ||||
| ), | ||||
| ); | ||||
|
|
||||
| final WebResourceError error = await errorCompleter.future; | ||||
| expect(error, isNotNull); | ||||
|
|
||||
| if (Platform.isIOS) expect(error.domain, isNotNull); | ||||
| if (Platform.isAndroid) expect(error.errorType, isNotNull); | ||||
| }); | ||||
|
|
||||
| testWidgets('onWebResourceError is not called with valid url', | ||||
| (WidgetTester tester) async { | ||||
| final Completer<WebResourceError> errorCompleter = | ||||
| Completer<WebResourceError>(); | ||||
|
|
||||
| await tester.pumpWidget( | ||||
| Directionality( | ||||
| textDirection: TextDirection.ltr, | ||||
| child: WebView( | ||||
| key: GlobalKey(), | ||||
| initialUrl: | ||||
| 'data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+', | ||||
| onWebResourceError: (WebResourceError error) { | ||||
| errorCompleter.complete(error); | ||||
| }, | ||||
| ), | ||||
| ), | ||||
| ); | ||||
|
|
||||
| expect(errorCompleter.future, doesNotComplete); | ||||
| }); | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a test with a valid url that verifies the error callback is not invoked on a valid url. I'd use a data url like:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||
|
|
||||
| testWidgets('can block requests', (WidgetTester tester) async { | ||||
| final Completer<WebViewController> controllerCompleter = | ||||
| Completer<WebViewController>(); | ||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
Is
%dformatting affected by the locale?Also seems like you can omit specifying
Locale.getDefault()as this is the default for theString.formatversion that doesn't take a locale.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only added the
Locale.getDefault()to get rid of the lint warning. It does change the digit to whatever locale the device is set to. I don't think it would change the interpretation of the digit though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, my read of https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax is that
%dformatting is not affected by the locale.