diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart new file mode 100644 index 000000000000..def52b78f6b5 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart @@ -0,0 +1,38 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:math'; + +import '../web_kit/web_kit.dart'; + +/// A view that allows the scrolling and zooming of its contained views. +/// +/// Wraps [UIScrollView](https://developer.apple.com/documentation/uikit/uiscrollview?language=objc). +class UIScrollView { + /// Constructs a [UIScrollView] that is owned by [webView]. + // TODO(bparrishMines): Remove ignore once constructor is implemented. + // ignore: avoid_unused_constructor_parameters + UIScrollView.fromWebView(WKWebView webView); + + /// Point at which the origin of the content view is offset from the origin of the scroll view. + Future> get contentOffset { + throw UnimplementedError(); + } + + /// Move the scrolled position of this view. + /// + /// This method is not a part of UIKit and is only a helper method to make + /// scrollBy atomic. + Future scrollBy(Point offset) { + throw UnimplementedError(); + } + + /// Set point at which the origin of the content view is offset from the origin of the scroll view. + /// + /// The default value is `Point(0.0, 0.0)`. + set contentOffset(FutureOr> offset) { + throw UnimplementedError(); + } +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index d7fdf1db68c6..cd7e4a9aadcb 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart'; import '../foundation/foundation.dart'; +import '../ui_kit/ui_kit.dart'; /// Times at which to inject script content into a webpage. /// @@ -450,6 +451,9 @@ class WKWebView { late final WKWebViewConfiguration configuration = WKWebViewConfiguration._fromWebView(this); + /// The scrollable view associated with the web view. + late final UIScrollView scrollView = UIScrollView.fromWebView(this); + /// Used to integrate custom user interface elements into web view interactions. set uiDelegate(WKUIDelegate? delegate) { throw UnimplementedError(); @@ -472,4 +476,79 @@ class WKWebView { Future loadRequest(NSUrlRequest request) { throw UnimplementedError(); } + + /// Loads the contents of the specified HTML string and navigates to it. + Future loadHtmlString(String string, {String? baseUrl}) { + throw UnimplementedError(); + } + + /// Loads the web content from the specified file and navigates to it. + Future loadFileUrl(String url, {required String readAccessUrl}) { + throw UnimplementedError(); + } + + /// Loads the Flutter asset specified in the pubspec.yaml file. + /// + /// This method is not a part of WebKit and is only a Flutter specific helper + /// method. + Future loadFlutterAsset(String key) { + throw UnimplementedError(); + } + + /// Indicates whether there is a valid back item in the back-forward list. + Future get canGoBack { + throw UnimplementedError(); + } + + /// Indicates whether there is a valid forward item in the back-forward list. + Future get canGoForward { + throw UnimplementedError(); + } + + /// Navigates to the back item in the back-forward list. + Future goBack() { + throw UnimplementedError(); + } + + /// Navigates to the forward item in the back-forward list. + Future goForward() { + throw UnimplementedError(); + } + + /// Reloads the current webpage. + Future reload() { + throw UnimplementedError(); + } + + /// The page title. + Future get title { + throw UnimplementedError(); + } + + /// An estimate of what fraction of the current navigation has been loaded. + Future get estimatedProgress { + throw UnimplementedError(); + } + + /// Indicates whether horizontal swipe gestures trigger page navigation. + /// + /// The default value is false. + set allowsBackForwardNavigationGestures(bool allow) { + throw UnimplementedError(); + } + + /// The custom user agent string. + /// + /// The default value of this property is null. + set customUserAgent(String? userAgent) { + throw UnimplementedError(); + } + + /// Evaluates the specified JavaScript string. + /// + /// Throws a `PlatformException` if an error occurs or return value is not + /// supported. + Future evaluateJavaScript(String javaScriptString) { + throw UnimplementedError(); + } } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart index 87baeb45c368..67ea6a936e42 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart @@ -3,9 +3,12 @@ // found in the LICENSE file. import 'dart:async'; +import 'dart:math'; import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; +import 'package:path/path.dart' as path; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'foundation/foundation.dart'; @@ -194,6 +197,19 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { }; } + @override + Future loadHtmlString(String html, {String? baseUrl}) { + return webView.loadHtmlString(html, baseUrl: baseUrl); + } + + @override + Future loadFile(String absoluteFilePath) async { + await webView.loadFileUrl( + absoluteFilePath, + readAccessUrl: path.dirname(absoluteFilePath), + ); + } + @override Future clearCache() { return webView.configuration.webSiteDataStore.removeDataOfTypes( @@ -207,6 +223,124 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { ); } + @override + Future loadFlutterAsset(String key) async { + assert(key.isNotEmpty); + return webView.loadFlutterAsset(key); + } + + @override + Future loadUrl(String url, Map? headers) async { + final NSUrlRequest request = NSUrlRequest( + url: url, + allHttpHeaderFields: headers ?? {}, + ); + return webView.loadRequest(request); + } + + @override + Future loadRequest(WebViewRequest request) async { + if (!request.uri.hasScheme) { + throw ArgumentError('WebViewRequest#uri is required to have a scheme.'); + } + + final NSUrlRequest urlRequest = NSUrlRequest( + url: request.uri.toString(), + allHttpHeaderFields: request.headers, + httpMethod: describeEnum(request.method), + httpBody: request.body, + ); + + return webView.loadRequest(urlRequest); + } + + @override + Future canGoBack() => webView.canGoBack; + + @override + Future canGoForward() => webView.canGoForward; + + @override + Future goBack() => webView.goBack(); + + @override + Future goForward() => webView.goForward(); + + @override + Future reload() => webView.reload(); + + @override + Future evaluateJavascript(String javascript) async { + final Object? result = await webView.evaluateJavaScript(javascript); + // The legacy implementation of webview_flutter_wkwebview would convert + // objects to strings before returning them to Dart. This method attempts + // to converts Dart objects to Strings the way it is done in Objective-C + // to avoid breaking users expecting the same String format. + return _asObjectiveCString(result); + } + + @override + Future runJavascript(String javascript) async { + try { + await webView.evaluateJavaScript(javascript); + } on PlatformException catch (exception) { + // WebKit will throw an error when the type of the evaluated value is + // unsupported. This also goes for `null` and `undefined` on iOS 14+. For + // example, when running a void function. For ease of use, this specific + // error is ignored when no return value is expected. + // TODO(bparrishMines): Ensure the platform code includes the NSError in + // the FlutterError.details. + if (exception.details is! NSError || + exception.details.code != + WKErrorCode.javaScriptResultTypeIsUnsupported) { + rethrow; + } + } + } + + @override + Future runJavascriptReturningResult(String javascript) async { + final Object? result = await webView.evaluateJavaScript(javascript); + if (result == null) { + throw ArgumentError( + 'Result of JavaScript execution returned a `null` value. ' + 'Use `runJavascript` when expecting a null return value.', + ); + } + return result.toString(); + } + + @override + Future getTitle() => webView.title; + + @override + Future scrollTo(int x, int y) async { + webView.scrollView.contentOffset = Point( + x.toDouble(), + y.toDouble(), + ); + } + + @override + Future scrollBy(int x, int y) async { + await webView.scrollView.scrollBy(Point( + x.toDouble(), + y.toDouble(), + )); + } + + @override + Future getScrollX() async { + final Point offset = await webView.scrollView.contentOffset; + return offset.x.toInt(); + } + + @override + Future getScrollY() async { + final Point offset = await webView.scrollView.contentOffset; + return offset.y.toInt(); + } + @override Future updateSettings(WebSettings setting) async { if (setting.hasNavigationDelegate != null) { @@ -324,6 +458,35 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { errorType: errorType, ); } + + String _asObjectiveCString(Object? value, {bool inContainer = false}) { + if (value == null) { + // An NSNull inside an NSArray or NSDictionary is represented as a String + // differently than a nil. + if (inContainer) { + return '""'; + } + return '(null)'; + } else if (value is List) { + final List stringValues = []; + for (final Object? listValue in value) { + stringValues.add(_asObjectiveCString(listValue, inContainer: true)); + } + return '(${stringValues.join(',')})'; + } else if (value is Map) { + final List stringValues = []; + for (final MapEntry entry in value.entries) { + stringValues.add( + '${_asObjectiveCString(entry.key, inContainer: true)} ' + '= ' + '${_asObjectiveCString(entry.value, inContainer: true)}', + ); + } + return '{${stringValues.join(';')}}'; + } + + return value.toString(); + } } /// Handles constructing objects and calling static methods. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml index 91760df02c66..219d6ce49f4f 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml @@ -18,6 +18,7 @@ flutter: dependencies: flutter: sdk: flutter + path: ^1.8.0 webview_flutter_platform_interface: ^1.8.0 dev_dependencies: diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart index 358df898403a..e30e027734d0 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart @@ -3,19 +3,24 @@ // found in the LICENSE file. import 'dart:async'; +import 'dart:math'; +import 'dart:typed_data'; +import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart'; +import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart'; import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart'; import 'package:webview_flutter_wkwebview/src/web_kit_webview_widget.dart'; import 'web_kit_webview_widget_test.mocks.dart'; @GenerateMocks([ + UIScrollView, WKNavigationDelegate, WKScriptMessageHandler, WKWebView, @@ -36,6 +41,7 @@ void main() { late MockWKUserContentController mockUserContentController; late MockWKWebViewConfiguration mockWebViewConfiguration; late MockWKUIDelegate mockUIDelegate; + late MockUIScrollView mockScrollView; late MockWKWebsiteDataStore mockWebsiteDataStore; late MockWKNavigationDelegate mockNavigationDelegate; @@ -49,6 +55,7 @@ void main() { mockWebViewConfiguration = MockWKWebViewConfiguration(); mockUserContentController = MockWKUserContentController(); mockUIDelegate = MockWKUIDelegate(); + mockScrollView = MockUIScrollView(); mockWebsiteDataStore = MockWKWebsiteDataStore(); mockNavigationDelegate = MockWKNavigationDelegate(); mockWebViewWidgetProxy = MockWebViewWidgetProxy(); @@ -61,6 +68,9 @@ void main() { when(mockWebViewConfiguration.userContentController).thenReturn( mockUserContentController, ); + + when(mockWebView.scrollView).thenReturn(mockScrollView); + when(mockWebViewConfiguration.webSiteDataStore).thenReturn( mockWebsiteDataStore, ); @@ -212,6 +222,345 @@ void main() { }); group('$WebKitWebViewPlatformController', () { + testWidgets('loadFile', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.loadFile('/path/to/file.html'); + verify(mockWebView.loadFileUrl( + '/path/to/file.html', + readAccessUrl: '/path/to', + )); + }); + + testWidgets('loadFlutterAsset', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.loadFlutterAsset('test_assets/index.html'); + verify(mockWebView.loadFlutterAsset('test_assets/index.html')); + }); + + testWidgets('loadHtmlString', (WidgetTester tester) async { + await buildWidget(tester); + + const String htmlString = 'Test data.'; + await testController.loadHtmlString(htmlString, baseUrl: 'baseUrl'); + + verify(mockWebView.loadHtmlString( + 'Test data.', + baseUrl: 'baseUrl', + )); + }); + + testWidgets('loadUrl', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.loadUrl( + 'https://www.google.com', + {'a': 'header'}, + ); + + final NSUrlRequest request = verify(mockWebView.loadRequest(captureAny)) + .captured + .single as NSUrlRequest; + expect(request.url, 'https://www.google.com'); + expect(request.allHttpHeaderFields, {'a': 'header'}); + }); + + group('loadRequest', () { + testWidgets('Throws ArgumentError for empty scheme', + (WidgetTester tester) async { + await buildWidget(tester); + + expect( + () async => await testController.loadRequest( + WebViewRequest( + uri: Uri.parse('www.google.com'), + method: WebViewRequestMethod.get, + ), + ), + throwsA(const TypeMatcher())); + }); + + testWidgets('GET without headers', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.loadRequest(WebViewRequest( + uri: Uri.parse('https://www.google.com'), + method: WebViewRequestMethod.get, + )); + + final NSUrlRequest request = + verify(mockWebView.loadRequest(captureAny)).captured.single + as NSUrlRequest; + expect(request.url, 'https://www.google.com'); + expect(request.allHttpHeaderFields, {}); + expect(request.httpMethod, 'get'); + }); + + testWidgets('GET with headers', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.loadRequest(WebViewRequest( + uri: Uri.parse('https://www.google.com'), + method: WebViewRequestMethod.get, + headers: {'a': 'header'}, + )); + + final NSUrlRequest request = + verify(mockWebView.loadRequest(captureAny)).captured.single + as NSUrlRequest; + expect(request.url, 'https://www.google.com'); + expect(request.allHttpHeaderFields, {'a': 'header'}); + expect(request.httpMethod, 'get'); + }); + + testWidgets('POST without body', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.loadRequest(WebViewRequest( + uri: Uri.parse('https://www.google.com'), + method: WebViewRequestMethod.post, + )); + + final NSUrlRequest request = + verify(mockWebView.loadRequest(captureAny)).captured.single + as NSUrlRequest; + expect(request.url, 'https://www.google.com'); + expect(request.httpMethod, 'post'); + }); + + testWidgets('POST with body', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.loadRequest(WebViewRequest( + uri: Uri.parse('https://www.google.com'), + method: WebViewRequestMethod.post, + body: Uint8List.fromList('Test Body'.codeUnits))); + + final NSUrlRequest request = + verify(mockWebView.loadRequest(captureAny)).captured.single + as NSUrlRequest; + expect(request.url, 'https://www.google.com'); + expect(request.httpMethod, 'post'); + expect( + request.httpBody, + Uint8List.fromList('Test Body'.codeUnits), + ); + }); + }); + + testWidgets('canGoBack', (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.canGoBack).thenAnswer( + (_) => Future.value(false), + ); + expect(testController.canGoBack(), completion(false)); + }); + + testWidgets('canGoForward', (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.canGoForward).thenAnswer( + (_) => Future.value(true), + ); + expect(testController.canGoForward(), completion(true)); + }); + + testWidgets('goBack', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.goBack(); + verify(mockWebView.goBack()); + }); + + testWidgets('goForward', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.goForward(); + verify(mockWebView.goForward()); + }); + + testWidgets('reload', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.reload(); + verify(mockWebView.reload()); + }); + + testWidgets('evaluateJavascript', (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')).thenAnswer( + (_) => Future.value('returnString'), + ); + expect( + testController.evaluateJavascript('runJavaScript'), + completion('returnString'), + ); + }); + + testWidgets('evaluateJavascript with null return value', + (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')).thenAnswer( + (_) => Future.value(), + ); + // The legacy implementation of webview_flutter_wkwebview would convert + // objects to strings before returning them to Dart. This verifies null + // is represented the way it is in Objective-C. + expect( + testController.evaluateJavascript('runJavaScript'), + completion('(null)'), + ); + }); + + testWidgets('evaluateJavascript with list return value', + (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')).thenAnswer( + (_) => Future.value([1, 'string', null]), + ); + // The legacy implementation of webview_flutter_wkwebview would convert + // objects to strings before returning them to Dart. This verifies list + // is represented the way it is in Objective-C. + expect( + testController.evaluateJavascript('runJavaScript'), + completion('(1,string,"")'), + ); + }); + + testWidgets('evaluateJavascript with map return value', + (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')).thenAnswer( + (_) => Future.value({ + 1: 'string', + null: null, + }), + ); + // The legacy implementation of webview_flutter_wkwebview would convert + // objects to strings before returning them to Dart. This verifies map + // is represented the way it is in Objective-C. + expect( + testController.evaluateJavascript('runJavaScript'), + completion('{1 = string;"" = ""}'), + ); + }); + + testWidgets('evaluateJavascript throws exception', + (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')) + .thenThrow(Error()); + expect( + testController.evaluateJavascript('runJavaScript'), + throwsA(isA()), + ); + }); + + testWidgets('runJavascriptReturningResult', (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')).thenAnswer( + (_) => Future.value('returnString'), + ); + expect( + testController.runJavascriptReturningResult('runJavaScript'), + completion('returnString'), + ); + }); + + testWidgets( + 'runJavascriptReturningResult throws error on null return value', + (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')).thenAnswer( + (_) => Future.value(null), + ); + expect( + () => testController.runJavascriptReturningResult('runJavaScript'), + throwsArgumentError, + ); + }); + + testWidgets('runJavascript', (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')).thenAnswer( + (_) => Future.value('returnString'), + ); + expect( + testController.runJavascript('runJavaScript'), + completes, + ); + }); + + testWidgets( + 'runJavascript ignores exception with unsupported javascript type', + (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.evaluateJavaScript('runJavaScript')) + .thenThrow(PlatformException( + code: '', + details: const NSError( + code: WKErrorCode.javaScriptResultTypeIsUnsupported, + domain: '', + localizedDescription: '', + ), + )); + expect( + testController.runJavascript('runJavaScript'), + completes, + ); + }); + + testWidgets('getTitle', (WidgetTester tester) async { + await buildWidget(tester); + + when(mockWebView.title) + .thenAnswer((_) => Future.value('Web Title')); + expect(testController.getTitle(), completion('Web Title')); + }); + + testWidgets('scrollTo', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.scrollTo(2, 4); + verify(mockScrollView.contentOffset = const Point(2.0, 4.0)); + }); + + testWidgets('scrollBy', (WidgetTester tester) async { + await buildWidget(tester); + + await testController.scrollBy(2, 4); + verify(mockScrollView.scrollBy(const Point(2.0, 4.0))); + }); + + testWidgets('getScrollX', (WidgetTester tester) async { + await buildWidget(tester); + + when(mockScrollView.contentOffset).thenAnswer( + (_) => Future>.value(const Point(8.0, 16.0))); + expect(testController.getScrollX(), completion(8.0)); + }); + + testWidgets('getScrollY', (WidgetTester tester) async { + await buildWidget(tester); + + await buildWidget(tester); + + when(mockScrollView.contentOffset).thenAnswer( + (_) => Future>.value(const Point(8.0, 16.0))); + expect(testController.getScrollY(), completion(16.0)); + }); + testWidgets('clearCache', (WidgetTester tester) async { await buildWidget(tester); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart index 32f1731701a9..f200870ca98b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart @@ -2,19 +2,21 @@ // in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart. // Do not manually edit this file. -import 'dart:async' as _i3; +import 'dart:async' as _i5; +import 'dart:math' as _i2; import 'package:mockito/mockito.dart' as _i1; import 'package:webview_flutter_platform_interface/src/types/javascript_channel.dart' - as _i6; -import 'package:webview_flutter_platform_interface/src/types/types.dart' as _i7; + as _i8; +import 'package:webview_flutter_platform_interface/src/types/types.dart' as _i9; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart' - as _i5; + as _i7; import 'package:webview_flutter_wkwebview/src/foundation/foundation.dart' - as _i4; -import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i2; + as _i6; +import 'package:webview_flutter_wkwebview/src/ui_kit/ui_kit.dart' as _i4; +import 'package:webview_flutter_wkwebview/src/web_kit/web_kit.dart' as _i3; import 'package:webview_flutter_wkwebview/src/web_kit_webview_widget.dart' - as _i8; + as _i10; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -26,37 +28,65 @@ import 'package:webview_flutter_wkwebview/src/web_kit_webview_widget.dart' // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types -class _FakeWKWebViewConfiguration_0 extends _i1.Fake - implements _i2.WKWebViewConfiguration {} +class _FakePoint_0 extends _i1.Fake implements _i2.Point {} + +class _FakeWKWebViewConfiguration_1 extends _i1.Fake + implements _i3.WKWebViewConfiguration {} + +class _FakeUIScrollView_2 extends _i1.Fake implements _i4.UIScrollView {} -class _FakeWKUserContentController_1 extends _i1.Fake - implements _i2.WKUserContentController {} +class _FakeWKUserContentController_3 extends _i1.Fake + implements _i3.WKUserContentController {} -class _FakeWKWebsiteDataStore_2 extends _i1.Fake - implements _i2.WKWebsiteDataStore {} +class _FakeWKWebsiteDataStore_4 extends _i1.Fake + implements _i3.WKWebsiteDataStore {} -class _FakeWKWebView_3 extends _i1.Fake implements _i2.WKWebView {} +class _FakeWKWebView_5 extends _i1.Fake implements _i3.WKWebView {} -class _FakeWKScriptMessageHandler_4 extends _i1.Fake - implements _i2.WKScriptMessageHandler {} +class _FakeWKScriptMessageHandler_6 extends _i1.Fake + implements _i3.WKScriptMessageHandler {} -class _FakeWKUIDelegate_5 extends _i1.Fake implements _i2.WKUIDelegate {} +class _FakeWKUIDelegate_7 extends _i1.Fake implements _i3.WKUIDelegate {} -class _FakeWKNavigationDelegate_6 extends _i1.Fake - implements _i2.WKNavigationDelegate {} +class _FakeWKNavigationDelegate_8 extends _i1.Fake + implements _i3.WKNavigationDelegate {} + +/// A class which mocks [UIScrollView]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockUIScrollView extends _i1.Mock implements _i4.UIScrollView { + MockUIScrollView() { + _i1.throwOnMissingStub(this); + } + + @override + _i5.Future<_i2.Point> get contentOffset => (super.noSuchMethod( + Invocation.getter(#contentOffset), + returnValue: Future<_i2.Point>.value(_FakePoint_0())) + as _i5.Future<_i2.Point>); + @override + set contentOffset(_i5.FutureOr<_i2.Point>? offset) => + super.noSuchMethod(Invocation.setter(#contentOffset, offset), + returnValueForMissingStub: null); + @override + _i5.Future scrollBy(_i2.Point? offset) => + (super.noSuchMethod(Invocation.method(#scrollBy, [offset]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i5.Future); +} /// A class which mocks [WKNavigationDelegate]. /// /// See the documentation for Mockito's code generation for more information. class MockWKNavigationDelegate extends _i1.Mock - implements _i2.WKNavigationDelegate { + implements _i3.WKNavigationDelegate { MockWKNavigationDelegate() { _i1.throwOnMissingStub(this); } @override set didStartProvisionalNavigation( - void Function(_i2.WKWebView, String?)? + void Function(_i3.WKWebView, String?)? didStartProvisionalNavigation) => super.noSuchMethod( Invocation.setter( @@ -64,14 +94,14 @@ class MockWKNavigationDelegate extends _i1.Mock returnValueForMissingStub: null); @override set didFinishNavigation( - void Function(_i2.WKWebView, String?)? didFinishNavigation) => + void Function(_i3.WKWebView, String?)? didFinishNavigation) => super.noSuchMethod( Invocation.setter(#didFinishNavigation, didFinishNavigation), returnValueForMissingStub: null); @override set decidePolicyForNavigationAction( - _i3.Future<_i2.WKNavigationActionPolicy> Function( - _i2.WKWebView, _i2.WKNavigationAction)? + _i5.Future<_i3.WKNavigationActionPolicy> Function( + _i3.WKWebView, _i3.WKNavigationAction)? decidePolicyForNavigationAction) => super.noSuchMethod( Invocation.setter(#decidePolicyForNavigationAction, @@ -79,13 +109,13 @@ class MockWKNavigationDelegate extends _i1.Mock returnValueForMissingStub: null); @override set didFailNavigation( - void Function(_i2.WKWebView, _i4.NSError)? didFailNavigation) => + void Function(_i3.WKWebView, _i6.NSError)? didFailNavigation) => super.noSuchMethod( Invocation.setter(#didFailNavigation, didFailNavigation), returnValueForMissingStub: null); @override set didFailProvisionalNavigation( - void Function(_i2.WKWebView, _i4.NSError)? + void Function(_i3.WKWebView, _i6.NSError)? didFailProvisionalNavigation) => super.noSuchMethod( Invocation.setter( @@ -93,7 +123,7 @@ class MockWKNavigationDelegate extends _i1.Mock returnValueForMissingStub: null); @override set webViewWebContentProcessDidTerminate( - void Function(_i2.WKWebView)? webViewWebContentProcessDidTerminate) => + void Function(_i3.WKWebView)? webViewWebContentProcessDidTerminate) => super.noSuchMethod( Invocation.setter(#webViewWebContentProcessDidTerminate, webViewWebContentProcessDidTerminate), @@ -104,14 +134,14 @@ class MockWKNavigationDelegate extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWKScriptMessageHandler extends _i1.Mock - implements _i2.WKScriptMessageHandler { + implements _i3.WKScriptMessageHandler { MockWKScriptMessageHandler() { _i1.throwOnMissingStub(this); } @override set didReceiveScriptMessage( - void Function(_i2.WKUserContentController, _i2.WKScriptMessage)? + void Function(_i3.WKUserContentController, _i3.WKScriptMessage)? didReceiveScriptMessage) => super.noSuchMethod( Invocation.setter(#didReceiveScriptMessage, didReceiveScriptMessage), @@ -121,60 +151,125 @@ class MockWKScriptMessageHandler extends _i1.Mock /// A class which mocks [WKWebView]. /// /// See the documentation for Mockito's code generation for more information. -class MockWKWebView extends _i1.Mock implements _i2.WKWebView { +class MockWKWebView extends _i1.Mock implements _i3.WKWebView { MockWKWebView() { _i1.throwOnMissingStub(this); } @override - _i2.WKWebViewConfiguration get configuration => + _i3.WKWebViewConfiguration get configuration => (super.noSuchMethod(Invocation.getter(#configuration), - returnValue: _FakeWKWebViewConfiguration_0()) - as _i2.WKWebViewConfiguration); + returnValue: _FakeWKWebViewConfiguration_1()) + as _i3.WKWebViewConfiguration); + @override + _i4.UIScrollView get scrollView => + (super.noSuchMethod(Invocation.getter(#scrollView), + returnValue: _FakeUIScrollView_2()) as _i4.UIScrollView); @override - set uiDelegate(_i2.WKUIDelegate? delegate) => + set uiDelegate(_i3.WKUIDelegate? delegate) => super.noSuchMethod(Invocation.setter(#uiDelegate, delegate), returnValueForMissingStub: null); @override - set navigationDelegate(_i2.WKNavigationDelegate? delegate) => + set navigationDelegate(_i3.WKNavigationDelegate? delegate) => super.noSuchMethod(Invocation.setter(#navigationDelegate, delegate), returnValueForMissingStub: null); @override - _i3.Future get url => (super.noSuchMethod(Invocation.getter(#url), - returnValue: Future.value()) as _i3.Future); + _i5.Future get url => (super.noSuchMethod(Invocation.getter(#url), + returnValue: Future.value()) as _i5.Future); + @override + _i5.Future get canGoBack => + (super.noSuchMethod(Invocation.getter(#canGoBack), + returnValue: Future.value(false)) as _i5.Future); + @override + _i5.Future get canGoForward => + (super.noSuchMethod(Invocation.getter(#canGoForward), + returnValue: Future.value(false)) as _i5.Future); @override - _i3.Future loadRequest(_i4.NSUrlRequest? request) => + _i5.Future get title => + (super.noSuchMethod(Invocation.getter(#title), + returnValue: Future.value()) as _i5.Future); + @override + _i5.Future get estimatedProgress => + (super.noSuchMethod(Invocation.getter(#estimatedProgress), + returnValue: Future.value(0.0)) as _i5.Future); + @override + set allowsBackForwardNavigationGestures(bool? allow) => super.noSuchMethod( + Invocation.setter(#allowsBackForwardNavigationGestures, allow), + returnValueForMissingStub: null); + @override + set customUserAgent(String? userAgent) => + super.noSuchMethod(Invocation.setter(#customUserAgent, userAgent), + returnValueForMissingStub: null); + @override + _i5.Future loadRequest(_i6.NSUrlRequest? request) => (super.noSuchMethod(Invocation.method(#loadRequest, [request]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i3.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i5.Future loadHtmlString(String? string, {String? baseUrl}) => + (super.noSuchMethod( + Invocation.method(#loadHtmlString, [string], {#baseUrl: baseUrl}), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i5.Future loadFileUrl(String? url, {String? readAccessUrl}) => + (super.noSuchMethod( + Invocation.method( + #loadFileUrl, [url], {#readAccessUrl: readAccessUrl}), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i5.Future loadFlutterAsset(String? key) => + (super.noSuchMethod(Invocation.method(#loadFlutterAsset, [key]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i5.Future goBack() => + (super.noSuchMethod(Invocation.method(#goBack, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i5.Future goForward() => + (super.noSuchMethod(Invocation.method(#goForward, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i5.Future reload() => + (super.noSuchMethod(Invocation.method(#reload, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i5.Future); + @override + _i5.Future evaluateJavaScript(String? javaScriptString) => (super + .noSuchMethod(Invocation.method(#evaluateJavaScript, [javaScriptString]), + returnValue: Future.value()) as _i5.Future); } /// A class which mocks [WKWebViewConfiguration]. /// /// See the documentation for Mockito's code generation for more information. class MockWKWebViewConfiguration extends _i1.Mock - implements _i2.WKWebViewConfiguration { + implements _i3.WKWebViewConfiguration { MockWKWebViewConfiguration() { _i1.throwOnMissingStub(this); } @override - _i2.WKUserContentController get userContentController => + _i3.WKUserContentController get userContentController => (super.noSuchMethod(Invocation.getter(#userContentController), - returnValue: _FakeWKUserContentController_1()) - as _i2.WKUserContentController); + returnValue: _FakeWKUserContentController_3()) + as _i3.WKUserContentController); @override set userContentController( - _i2.WKUserContentController? _userContentController) => + _i3.WKUserContentController? _userContentController) => super.noSuchMethod( Invocation.setter(#userContentController, _userContentController), returnValueForMissingStub: null); @override - _i2.WKWebsiteDataStore get webSiteDataStore => + _i3.WKWebsiteDataStore get webSiteDataStore => (super.noSuchMethod(Invocation.getter(#webSiteDataStore), - returnValue: _FakeWKWebsiteDataStore_2()) as _i2.WKWebsiteDataStore); + returnValue: _FakeWKWebsiteDataStore_4()) as _i3.WKWebsiteDataStore); @override - set webSiteDataStore(_i2.WKWebsiteDataStore? websiteDataStore) => + set webSiteDataStore(_i3.WKWebsiteDataStore? websiteDataStore) => super.noSuchMethod(Invocation.setter(#webSiteDataStore, websiteDataStore), returnValueForMissingStub: null); @override @@ -183,7 +278,7 @@ class MockWKWebViewConfiguration extends _i1.Mock returnValueForMissingStub: null); @override set mediaTypesRequiringUserActionForPlayback( - Set<_i2.WKAudiovisualMediaType>? types) => + Set<_i3.WKAudiovisualMediaType>? types) => super.noSuchMethod( Invocation.setter(#mediaTypesRequiringUserActionForPlayback, types), returnValueForMissingStub: null); @@ -193,31 +288,31 @@ class MockWKWebViewConfiguration extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWKWebsiteDataStore extends _i1.Mock - implements _i2.WKWebsiteDataStore { + implements _i3.WKWebsiteDataStore { MockWKWebsiteDataStore() { _i1.throwOnMissingStub(this); } @override - _i3.Future removeDataOfTypes( - Set<_i2.WKWebsiteDataTypes>? dataTypes, DateTime? since) => + _i5.Future removeDataOfTypes( + Set<_i3.WKWebsiteDataTypes>? dataTypes, DateTime? since) => (super.noSuchMethod( Invocation.method(#removeDataOfTypes, [dataTypes, since]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i3.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); } /// A class which mocks [WKUIDelegate]. /// /// See the documentation for Mockito's code generation for more information. -class MockWKUIDelegate extends _i1.Mock implements _i2.WKUIDelegate { +class MockWKUIDelegate extends _i1.Mock implements _i3.WKUIDelegate { MockWKUIDelegate() { _i1.throwOnMissingStub(this); } @override set onCreateWebView( - void Function(_i2.WKWebViewConfiguration, _i2.WKNavigationAction)? + void Function(_i3.WKWebViewConfiguration, _i3.WKNavigationAction)? onCreateeWebView) => super.noSuchMethod(Invocation.setter(#onCreateWebView, onCreateeWebView), returnValueForMissingStub: null); @@ -227,61 +322,61 @@ class MockWKUIDelegate extends _i1.Mock implements _i2.WKUIDelegate { /// /// See the documentation for Mockito's code generation for more information. class MockWKUserContentController extends _i1.Mock - implements _i2.WKUserContentController { + implements _i3.WKUserContentController { MockWKUserContentController() { _i1.throwOnMissingStub(this); } @override - _i3.Future addScriptMessageHandler( - _i2.WKScriptMessageHandler? handler, String? name) => + _i5.Future addScriptMessageHandler( + _i3.WKScriptMessageHandler? handler, String? name) => (super.noSuchMethod( Invocation.method(#addScriptMessageHandler, [handler, name]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i3.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i3.Future removeScriptMessageHandler(String? name) => (super + _i5.Future removeScriptMessageHandler(String? name) => (super .noSuchMethod(Invocation.method(#removeScriptMessageHandler, [name]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i3.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i3.Future removeAllScriptMessageHandlers() => (super.noSuchMethod( + _i5.Future removeAllScriptMessageHandlers() => (super.noSuchMethod( Invocation.method(#removeAllScriptMessageHandlers, []), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i3.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i3.Future addUserScript(_i2.WKUserScript? userScript) => + _i5.Future addUserScript(_i3.WKUserScript? userScript) => (super.noSuchMethod(Invocation.method(#addUserScript, [userScript]), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i3.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); @override - _i3.Future removeAllUserScripts() => + _i5.Future removeAllUserScripts() => (super.noSuchMethod(Invocation.method(#removeAllUserScripts, []), returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i3.Future); + returnValueForMissingStub: Future.value()) as _i5.Future); } /// A class which mocks [JavascriptChannelRegistry]. /// /// See the documentation for Mockito's code generation for more information. class MockJavascriptChannelRegistry extends _i1.Mock - implements _i5.JavascriptChannelRegistry { + implements _i7.JavascriptChannelRegistry { MockJavascriptChannelRegistry() { _i1.throwOnMissingStub(this); } @override - Map get channels => + Map get channels => (super.noSuchMethod(Invocation.getter(#channels), - returnValue: {}) - as Map); + returnValue: {}) + as Map); @override void onJavascriptChannelMessage(String? channel, String? message) => super.noSuchMethod( Invocation.method(#onJavascriptChannelMessage, [channel, message]), returnValueForMissingStub: null); @override - void updateJavascriptChannelsFromSet(Set<_i6.JavascriptChannel>? channels) => + void updateJavascriptChannelsFromSet(Set<_i8.JavascriptChannel>? channels) => super.noSuchMethod( Invocation.method(#updateJavascriptChannelsFromSet, [channels]), returnValueForMissingStub: null); @@ -291,17 +386,17 @@ class MockJavascriptChannelRegistry extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWebViewPlatformCallbacksHandler extends _i1.Mock - implements _i5.WebViewPlatformCallbacksHandler { + implements _i7.WebViewPlatformCallbacksHandler { MockWebViewPlatformCallbacksHandler() { _i1.throwOnMissingStub(this); } @override - _i3.FutureOr onNavigationRequest({String? url, bool? isForMainFrame}) => + _i5.FutureOr onNavigationRequest({String? url, bool? isForMainFrame}) => (super.noSuchMethod( Invocation.method(#onNavigationRequest, [], {#url: url, #isForMainFrame: isForMainFrame}), - returnValue: Future.value(false)) as _i3.FutureOr); + returnValue: Future.value(false)) as _i5.FutureOr); @override void onPageStarted(String? url) => super.noSuchMethod(Invocation.method(#onPageStarted, [url]), @@ -315,7 +410,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock super.noSuchMethod(Invocation.method(#onProgress, [progress]), returnValueForMissingStub: null); @override - void onWebResourceError(_i7.WebResourceError? error) => + void onWebResourceError(_i9.WebResourceError? error) => super.noSuchMethod(Invocation.method(#onWebResourceError, [error]), returnValueForMissingStub: null); } @@ -324,26 +419,26 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWebViewWidgetProxy extends _i1.Mock - implements _i8.WebViewWidgetProxy { + implements _i10.WebViewWidgetProxy { MockWebViewWidgetProxy() { _i1.throwOnMissingStub(this); } @override - _i2.WKWebView createWebView(_i2.WKWebViewConfiguration? configuration) => + _i3.WKWebView createWebView(_i3.WKWebViewConfiguration? configuration) => (super.noSuchMethod(Invocation.method(#createWebView, [configuration]), - returnValue: _FakeWKWebView_3()) as _i2.WKWebView); + returnValue: _FakeWKWebView_5()) as _i3.WKWebView); @override - _i2.WKScriptMessageHandler createScriptMessageHandler() => + _i3.WKScriptMessageHandler createScriptMessageHandler() => (super.noSuchMethod(Invocation.method(#createScriptMessageHandler, []), - returnValue: _FakeWKScriptMessageHandler_4()) - as _i2.WKScriptMessageHandler); + returnValue: _FakeWKScriptMessageHandler_6()) + as _i3.WKScriptMessageHandler); @override - _i2.WKUIDelegate createUIDelgate() => + _i3.WKUIDelegate createUIDelgate() => (super.noSuchMethod(Invocation.method(#createUIDelgate, []), - returnValue: _FakeWKUIDelegate_5()) as _i2.WKUIDelegate); + returnValue: _FakeWKUIDelegate_7()) as _i3.WKUIDelegate); @override - _i2.WKNavigationDelegate createNavigationDelegate() => (super.noSuchMethod( + _i3.WKNavigationDelegate createNavigationDelegate() => (super.noSuchMethod( Invocation.method(#createNavigationDelegate, []), - returnValue: _FakeWKNavigationDelegate_6()) as _i2.WKNavigationDelegate); + returnValue: _FakeWKNavigationDelegate_8()) as _i3.WKNavigationDelegate); }