diff --git a/packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_controller.dart b/packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_controller.dart new file mode 100644 index 000000000000..bd03b247027e --- /dev/null +++ b/packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_controller.dart @@ -0,0 +1,260 @@ +// 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:math'; + +// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#104231) +// ignore: unnecessary_import +import 'dart:typed_data'; + +import 'package:flutter/material.dart'; +import 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_interface.dart'; + +/// Controls a WebView provided by the host platform. +/// +/// Pass this to a [WebViewWidget] to display the WebView. +class WebViewController { + /// Constructs a [WebViewController]. + WebViewController() + : this.fromPlatformCreationParams( + const PlatformWebViewControllerCreationParams(), + ); + + /// Constructs a [WebViewController] from creation params for a specific + /// platform. + WebViewController.fromPlatformCreationParams( + PlatformWebViewControllerCreationParams params, + ) : this.fromPlatform(PlatformWebViewController(params)); + + /// Constructs a [WebViewController] from a specific platform implementation. + WebViewController.fromPlatform(this.platform); + + /// Implementation of [PlatformWebViewController] for the current platform. + final PlatformWebViewController platform; + + /// Loads the file located on the specified [absoluteFilePath]. + /// + /// The [absoluteFilePath] parameter should contain the absolute path to the + /// file as it is stored on the device. For example: + /// `/Users/username/Documents/www/index.html`. + /// + /// Throws a `PlatformException` if the [absoluteFilePath] does not exist. + Future loadFile(String absoluteFilePath) { + return platform.loadFile(absoluteFilePath); + } + + /// Loads the Flutter asset specified in the pubspec.yaml file. + /// + /// Throws a `PlatformException` if [key] is not part of the specified assets + /// in the pubspec.yaml file. + Future loadFlutterAsset(String key) { + assert(key.isNotEmpty); + return platform.loadFlutterAsset(key); + } + + /// Loads the supplied HTML string. + /// + /// The [baseUrl] parameter is used when resolving relative URLs within the + /// HTML string. + Future loadHtmlString(String html, {String? baseUrl}) { + assert(html.isNotEmpty); + return platform.loadHtmlString(html, baseUrl: baseUrl); + } + + /// Makes a specific HTTP request ands loads the response in the webview. + /// + /// [method] must be one of the supported HTTP methods in [LoadRequestMethod]. + /// + /// If [headers] is not empty, its key-value pairs will be added as the + /// headers for the request. + /// + /// If [body] is not null, it will be added as the body for the request. + /// + /// Throws an ArgumentError if [uri] has an empty scheme. + Future loadRequest( + Uri uri, { + LoadRequestMethod method = LoadRequestMethod.get, + Map headers = const {}, + Uint8List? body, + }) { + if (uri.scheme.isEmpty) { + throw ArgumentError('Missing scheme in uri: $uri'); + } + return platform.loadRequest(LoadRequestParams( + uri: uri, + method: method, + headers: headers, + body: body, + )); + } + + /// Returns the current URL that the WebView is displaying. + /// + /// If no URL was ever loaded, returns `null`. + Future currentUrl() { + return platform.currentUrl(); + } + + /// Checks whether there's a back history item. + Future canGoBack() { + return platform.canGoBack(); + } + + /// Checks whether there's a forward history item. + Future canGoForward() { + return platform.canGoForward(); + } + + /// Goes back in the history of this WebView. + /// + /// If there is no back history item this is a no-op. + Future goBack() { + return platform.goBack(); + } + + /// Goes forward in the history of this WebView. + /// + /// If there is no forward history item this is a no-op. + Future goForward() { + return platform.goForward(); + } + + /// Reloads the current URL. + Future reload() { + return platform.reload(); + } + + /// Clears all caches used by the WebView. + /// + /// The following caches are cleared: + /// 1. Browser HTTP Cache. + /// 2. [Cache API](https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/cache-api) + /// caches. Service workers tend to use this cache. + /// 3. Application cache. + Future clearCache() { + return platform.clearCache(); + } + + /// Clears the local storage used by the WebView. + Future clearLocalStorage() { + return platform.clearLocalStorage(); + } + + /// Runs the given JavaScript in the context of the current page. + /// + /// The Future completes with an error if a JavaScript error occurred. + Future runJavaScript(String javaScript) { + return platform.runJavaScript(javaScript); + } + + /// Runs the given JavaScript in the context of the current page, and returns + /// the result. + /// + /// The Future completes with an error if a JavaScript error occurred, or if + /// the type the given expression evaluates to is unsupported. Unsupported + /// values include certain non-primitive types on iOS, as well as `undefined` + /// or `null` on iOS 14+. + Future runJavaScriptReturningResult(String javaScript) { + return platform.runJavaScriptReturningResult(javaScript); + } + + /// Adds a new JavaScript channel to the set of enabled channels. + /// + /// The JavaScript code can then call `postMessage` on that object to send a + /// message that will be passed to [onMessageReceived]. + /// + /// For example, after adding the following JavaScript channel: + /// + /// ```dart + /// final WebViewController controller = WebViewController(); + /// controller.addJavaScriptChannel( + /// name: 'Print', + /// onMessageReceived: (JavascriptMessage message) { + /// print(message.message); + /// }, + /// ); + /// ``` + /// + /// JavaScript code can call: + /// + /// ```javascript + /// Print.postMessage('Hello'); + /// ``` + /// + /// to asynchronously invoke the message handler which will print the message + /// to standard output. + /// + /// Adding a new JavaScript channel only takes affect after the next page is + /// loaded. + /// + /// A channel [name] cannot be the same for multiple channels. + Future addJavaScriptChannel( + String name, { + required void Function(JavaScriptMessage) onMessageReceived, + }) { + assert(name.isNotEmpty); + return platform.addJavaScriptChannel(JavaScriptChannelParams( + name: name, + onMessageReceived: onMessageReceived, + )); + } + + /// Removes the JavaScript channel with the matching name from the set of + /// enabled channels. + /// + /// This disables the channel with the matching name if it was previously + /// enabled through the [addJavaScriptChannel]. + Future removeJavaScriptChannel(String javaScriptChannelName) { + return platform.removeJavaScriptChannel(javaScriptChannelName); + } + + /// The title of the currently loaded page. + Future getTitle() { + return platform.getTitle(); + } + + /// Sets the scrolled position of this view. + /// + /// The parameters `x` and `y` specify the position to scroll to in WebView + /// pixels. + Future scrollTo(int x, int y) { + return platform.scrollTo(x, y); + } + + /// Moves the scrolled position of this view. + /// + /// The parameters `x` and `y` specify the amount of WebView pixels to scroll + /// by. + Future scrollBy(int x, int y) { + return platform.scrollBy(x, y); + } + + /// Returns the current scroll position of this view. + /// + /// Scroll position is measured from the top left. + Future getScrollPosition() async { + final Point position = await platform.getScrollPosition(); + return Offset(position.x.toDouble(), position.y.toDouble()); + } + + /// Whether to support zooming using the on-screen zoom controls and gestures. + Future enableZoom(bool enabled) { + return platform.enableZoom(enabled); + } + + /// Sets the current background color of this view. + Future setBackgroundColor(Color color) { + return platform.setBackgroundColor(color); + } + + /// Sets the JavaScript execution mode to be used by the WebView. + Future setJavaScriptMode(JavaScriptMode javaScriptMode) { + return platform.setJavaScriptMode(javaScriptMode); + } + + /// Sets the value used for the HTTP `User-Agent:` request header. + Future setUserAgent(String? userAgent) { + return platform.setUserAgent(userAgent); + } +} diff --git a/packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_cookie_manager.dart index c209e95a1917..a1091fa3c7b1 100644 --- a/packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_cookie_manager.dart +++ b/packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_cookie_manager.dart @@ -8,21 +8,19 @@ import 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_i class WebViewCookieManager { /// Constructs a [WebViewCookieManager]. WebViewCookieManager() - : this.fromPlatform( - platform: PlatformWebViewCookieManager( - const PlatformWebViewCookieManagerCreationParams(), - ), + : this.fromPlatformCreationParams( + const PlatformWebViewCookieManagerCreationParams(), ); /// Constructs a [WebViewCookieManager] from creation params for a specific /// platform. WebViewCookieManager.fromPlatformCreationParams( PlatformWebViewCookieManagerCreationParams params, - ) : this.fromPlatform(platform: PlatformWebViewCookieManager(params)); + ) : this.fromPlatform(PlatformWebViewCookieManager(params)); /// Constructs a [WebViewCookieManager] from a specific platform /// implementation. - WebViewCookieManager.fromPlatform({required this.platform}); + WebViewCookieManager.fromPlatform(this.platform); /// Implementation of [PlatformWebViewCookieManager] for the current platform. final PlatformWebViewCookieManager platform; diff --git a/packages/webview_flutter/webview_flutter/lib/src/v4/webview_flutter.dart b/packages/webview_flutter/webview_flutter/lib/src/v4/webview_flutter.dart index 6ab8c3a2f6c8..f3caf84dcf56 100644 --- a/packages/webview_flutter/webview_flutter/lib/src/v4/webview_flutter.dart +++ b/packages/webview_flutter/webview_flutter/lib/src/v4/webview_flutter.dart @@ -5,6 +5,7 @@ library webview_flutter; export 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_interface.dart' - show WebViewCookie; + show JavaScriptMessage, LoadRequestMethod, WebViewCookie; +export 'src/webview_controller.dart'; export 'src/webview_cookie_manager.dart'; diff --git a/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart new file mode 100644 index 000000000000..f767a2e48d5e --- /dev/null +++ b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart @@ -0,0 +1,353 @@ +// 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:math'; +import 'dart:typed_data'; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'package:webview_flutter/src/v4/src/webview_controller.dart'; +import 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_interface.dart'; + +import 'webview_controller_test.mocks.dart'; + +@GenerateMocks([PlatformWebViewController]) +void main() { + test('loadFile', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.loadFile('file/path'); + verify(mockPlatformWebViewController.loadFile('file/path')); + }); + + test('loadFlutterAsset', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.loadFlutterAsset('file/path'); + verify(mockPlatformWebViewController.loadFlutterAsset('file/path')); + }); + + test('loadHtmlString', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.loadHtmlString('html', baseUrl: 'baseUrl'); + verify(mockPlatformWebViewController.loadHtmlString( + 'html', + baseUrl: 'baseUrl', + )); + }); + + test('loadRequest', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.loadRequest( + Uri(scheme: 'https', host: 'dart.dev'), + method: LoadRequestMethod.post, + headers: {'a': 'header'}, + body: Uint8List(0), + ); + + final LoadRequestParams params = + verify(mockPlatformWebViewController.loadRequest(captureAny)) + .captured[0] as LoadRequestParams; + expect(params.uri, Uri(scheme: 'https', host: 'dart.dev')); + expect(params.method, LoadRequestMethod.post); + expect(params.headers, {'a': 'header'}); + expect(params.body, Uint8List(0)); + }); + + test('currentUrl', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + when(mockPlatformWebViewController.currentUrl()).thenAnswer( + (_) => Future.value('https://dart.dev'), + ); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await expectLater( + webViewController.currentUrl(), + completion('https://dart.dev'), + ); + }); + + test('canGoBack', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + when(mockPlatformWebViewController.canGoBack()).thenAnswer( + (_) => Future.value(false), + ); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await expectLater(webViewController.canGoBack(), completion(false)); + }); + + test('canGoForward', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + when(mockPlatformWebViewController.canGoForward()).thenAnswer( + (_) => Future.value(true), + ); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await expectLater(webViewController.canGoForward(), completion(true)); + }); + + test('goBack', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.goBack(); + verify(mockPlatformWebViewController.goBack()); + }); + + test('goForward', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.goForward(); + verify(mockPlatformWebViewController.goForward()); + }); + + test('reload', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.reload(); + verify(mockPlatformWebViewController.reload()); + }); + + test('clearCache', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.clearCache(); + verify(mockPlatformWebViewController.clearCache()); + }); + + test('clearLocalStorage', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.clearLocalStorage(); + verify(mockPlatformWebViewController.clearLocalStorage()); + }); + + test('runJavaScript', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.runJavaScript('1 + 1'); + verify(mockPlatformWebViewController.runJavaScript('1 + 1')); + }); + + test('runJavaScriptReturningResult', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + when(mockPlatformWebViewController.runJavaScriptReturningResult('1 + 1')) + .thenAnswer((_) => Future.value('2')); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await expectLater( + webViewController.runJavaScriptReturningResult('1 + 1'), + completion('2'), + ); + }); + + test('addJavaScriptChannel', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + void onMessageReceived(JavaScriptMessage message) {} + await webViewController.addJavaScriptChannel( + 'name', + onMessageReceived: onMessageReceived, + ); + + final JavaScriptChannelParams params = + verify(mockPlatformWebViewController.addJavaScriptChannel(captureAny)) + .captured[0] as JavaScriptChannelParams; + expect(params.name, 'name'); + expect(params.onMessageReceived, onMessageReceived); + }); + + test('removeJavaScriptChannel', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.removeJavaScriptChannel('channel'); + verify(mockPlatformWebViewController.removeJavaScriptChannel('channel')); + }); + + test('getTitle', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + when(mockPlatformWebViewController.getTitle()) + .thenAnswer((_) => Future.value('myTitle')); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await expectLater(webViewController.getTitle(), completion('myTitle')); + }); + + test('scrollTo', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.scrollTo(2, 3); + verify(mockPlatformWebViewController.scrollTo(2, 3)); + }); + + test('scrollBy', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.scrollBy(2, 3); + verify(mockPlatformWebViewController.scrollBy(2, 3)); + }); + + test('getScrollPosition', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + when(mockPlatformWebViewController.getScrollPosition()).thenAnswer( + (_) => Future>.value( + const Point(2, 3), + ), + ); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await expectLater( + webViewController.getScrollPosition(), + completion(const Offset(2.0, 3.0)), + ); + }); + + test('enableZoom', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.enableZoom(false); + verify(mockPlatformWebViewController.enableZoom(false)); + }); + + test('setBackgroundColor', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.setBackgroundColor(Colors.green); + verify(mockPlatformWebViewController.setBackgroundColor(Colors.green)); + }); + + test('setJavaScriptMode', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.setJavaScriptMode(JavaScriptMode.disabled); + verify( + mockPlatformWebViewController.setJavaScriptMode(JavaScriptMode.disabled), + ); + }); + + test('setUserAgent', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.fromPlatform( + mockPlatformWebViewController, + ); + + await webViewController.setUserAgent('userAgent'); + verify(mockPlatformWebViewController.setUserAgent('userAgent')); + }); +} diff --git a/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.mocks.dart new file mode 100644 index 000000000000..f0fb4b47fc6e --- /dev/null +++ b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.mocks.dart @@ -0,0 +1,203 @@ +// Mocks generated by Mockito 5.3.0 from annotations +// in webview_flutter/test/v4/webview_controller_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i5; +import 'dart:math' as _i3; +import 'dart:ui' as _i7; + +import 'package:mockito/mockito.dart' as _i1; +import 'package:webview_flutter_platform_interface/v4/src/platform_navigation_delegate.dart' + as _i6; +import 'package:webview_flutter_platform_interface/v4/src/platform_webview_controller.dart' + as _i4; +import 'package:webview_flutter_platform_interface/v4/src/webview_platform.dart' + as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakePlatformWebViewControllerCreationParams_0 extends _i1.SmartFake + implements _i2.PlatformWebViewControllerCreationParams { + _FakePlatformWebViewControllerCreationParams_0( + Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} + +class _FakePoint_1 extends _i1.SmartFake + implements _i3.Point { + _FakePoint_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} + +/// A class which mocks [PlatformWebViewController]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockPlatformWebViewController extends _i1.Mock + implements _i4.PlatformWebViewController { + MockPlatformWebViewController() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PlatformWebViewControllerCreationParams get params => + (super.noSuchMethod(Invocation.getter(#params), + returnValue: _FakePlatformWebViewControllerCreationParams_0( + this, Invocation.getter(#params))) + as _i2.PlatformWebViewControllerCreationParams); + @override + _i5.Future loadFile(String? absoluteFilePath) => (super.noSuchMethod( + Invocation.method(#loadFile, [absoluteFilePath]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future loadFlutterAsset(String? key) => (super.noSuchMethod( + Invocation.method(#loadFlutterAsset, [key]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future loadHtmlString(String? html, {String? baseUrl}) => + (super.noSuchMethod( + Invocation.method(#loadHtmlString, [html], {#baseUrl: baseUrl}), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) + as _i5.Future); + @override + _i5.Future loadRequest(_i2.LoadRequestParams? params) => + (super.noSuchMethod(Invocation.method(#loadRequest, [params]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) + as _i5.Future); + @override + _i5.Future currentUrl() => + (super.noSuchMethod(Invocation.method(#currentUrl, []), + returnValue: _i5.Future.value()) as _i5.Future); + @override + _i5.Future canGoBack() => + (super.noSuchMethod(Invocation.method(#canGoBack, []), + returnValue: _i5.Future.value(false)) as _i5.Future); + @override + _i5.Future canGoForward() => + (super.noSuchMethod(Invocation.method(#canGoForward, []), + returnValue: _i5.Future.value(false)) as _i5.Future); + @override + _i5.Future goBack() => (super.noSuchMethod( + Invocation.method(#goBack, []), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future goForward() => (super.noSuchMethod( + Invocation.method(#goForward, []), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future reload() => (super.noSuchMethod( + Invocation.method(#reload, []), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future clearCache() => (super.noSuchMethod( + Invocation.method(#clearCache, []), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future clearLocalStorage() => (super.noSuchMethod( + Invocation.method(#clearLocalStorage, []), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future setPlatformNavigationDelegate( + _i6.PlatformNavigationDelegate? handler) => + (super.noSuchMethod( + Invocation.method(#setPlatformNavigationDelegate, [handler]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) + as _i5.Future); + @override + _i5.Future runJavaScript(String? javaScript) => (super.noSuchMethod( + Invocation.method(#runJavaScript, [javaScript]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future runJavaScriptReturningResult(String? javaScript) => + (super.noSuchMethod( + Invocation.method(#runJavaScriptReturningResult, [javaScript]), + returnValue: _i5.Future.value('')) as _i5.Future); + @override + _i5.Future addJavaScriptChannel( + _i4.JavaScriptChannelParams? javaScriptChannelParams) => + (super.noSuchMethod( + Invocation.method(#addJavaScriptChannel, [javaScriptChannelParams]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: + _i5.Future.value()) as _i5.Future); + @override + _i5.Future removeJavaScriptChannel(String? javaScriptChannelName) => + (super.noSuchMethod( + Invocation.method(#removeJavaScriptChannel, [javaScriptChannelName]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: + _i5.Future.value()) as _i5.Future); + @override + _i5.Future getTitle() => + (super.noSuchMethod(Invocation.method(#getTitle, []), + returnValue: _i5.Future.value()) as _i5.Future); + @override + _i5.Future scrollTo(int? x, int? y) => (super.noSuchMethod( + Invocation.method(#scrollTo, [x, y]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future scrollBy(int? x, int? y) => (super.noSuchMethod( + Invocation.method(#scrollBy, [x, y]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future<_i3.Point> getScrollPosition() => + (super.noSuchMethod(Invocation.method(#getScrollPosition, []), + returnValue: _i5.Future<_i3.Point>.value(_FakePoint_1( + this, Invocation.method(#getScrollPosition, [])))) + as _i5.Future<_i3.Point>); + @override + _i5.Future enableDebugging(bool? enabled) => (super.noSuchMethod( + Invocation.method(#enableDebugging, [enabled]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future enableGestureNavigation(bool? enabled) => (super + .noSuchMethod(Invocation.method(#enableGestureNavigation, [enabled]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) + as _i5.Future); + @override + _i5.Future enableZoom(bool? enabled) => (super.noSuchMethod( + Invocation.method(#enableZoom, [enabled]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future setBackgroundColor(_i7.Color? color) => (super.noSuchMethod( + Invocation.method(#setBackgroundColor, [color]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); + @override + _i5.Future setJavaScriptMode(_i2.JavaScriptMode? javaScriptMode) => + (super.noSuchMethod( + Invocation.method(#setJavaScriptMode, [javaScriptMode]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) + as _i5.Future); + @override + _i5.Future setUserAgent(String? userAgent) => (super.noSuchMethod( + Invocation.method(#setUserAgent, [userAgent]), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value()) as _i5.Future); +} diff --git a/packages/webview_flutter/webview_flutter/test/v4/webview_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter/test/v4/webview_cookie_manager_test.dart index d7941ab60cc9..e8152407fb92 100644 --- a/packages/webview_flutter/webview_flutter/test/v4/webview_cookie_manager_test.dart +++ b/packages/webview_flutter/webview_flutter/test/v4/webview_cookie_manager_test.dart @@ -22,7 +22,7 @@ void main() { final WebViewCookieManager cookieManager = WebViewCookieManager.fromPlatform( - platform: mockPlatformWebViewCookieManager, + mockPlatformWebViewCookieManager, ); await expectLater(cookieManager.clearCookies(), completion(false)); @@ -34,7 +34,7 @@ void main() { final WebViewCookieManager cookieManager = WebViewCookieManager.fromPlatform( - platform: mockPlatformWebViewCookieManager, + mockPlatformWebViewCookieManager, ); const WebViewCookie cookie = WebViewCookie( diff --git a/packages/webview_flutter/webview_flutter/test/webview_flutter_test.mocks.dart b/packages/webview_flutter/webview_flutter/test/webview_flutter_test.mocks.dart index fe3060164df2..a7a21007d6be 100644 --- a/packages/webview_flutter/webview_flutter/test/webview_flutter_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter/test/webview_flutter_test.mocks.dart @@ -1,11 +1,8 @@ -// 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. - -// Mocks generated by Mockito 5.0.16 from annotations +// Mocks generated by Mockito 5.3.0 from annotations // in webview_flutter/test/webview_flutter_test.dart. // Do not manually edit this file. +// ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i9; import 'package:flutter/foundation.dart' as _i3; @@ -22,6 +19,7 @@ import 'package:webview_flutter_platform_interface/src/platform_interface/webvie as _i10; import 'package:webview_flutter_platform_interface/src/types/types.dart' as _i5; +// ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references @@ -30,8 +28,12 @@ import 'package:webview_flutter_platform_interface/src/types/types.dart' as _i5; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeWidget_0 extends _i1.SmartFake implements _i2.Widget { + _FakeWidget_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); -class _FakeWidget_0 extends _i1.Fake implements _i2.Widget { @override String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) => super.toString(); @@ -63,13 +65,21 @@ class MockWebViewPlatform extends _i1.Mock implements _i4.WebViewPlatform { #onWebViewPlatformCreated: onWebViewPlatformCreated, #gestureRecognizers: gestureRecognizers }), - returnValue: _FakeWidget_0()) as _i2.Widget); + returnValue: _FakeWidget_0( + this, + Invocation.method(#build, [], { + #context: context, + #creationParams: creationParams, + #webViewPlatformCallbacksHandler: + webViewPlatformCallbacksHandler, + #javascriptChannelRegistry: javascriptChannelRegistry, + #onWebViewPlatformCreated: onWebViewPlatformCreated, + #gestureRecognizers: gestureRecognizers + }))) as _i2.Widget); @override _i9.Future clearCookies() => (super.noSuchMethod(Invocation.method(#clearCookies, []), - returnValue: Future.value(false)) as _i9.Future); - @override - String toString() => super.toString(); + returnValue: _i9.Future.value(false)) as _i9.Future); } /// A class which mocks [WebViewPlatformController]. @@ -82,118 +92,122 @@ class MockWebViewPlatformController extends _i1.Mock } @override - _i9.Future loadFile(String? absoluteFilePath) => - (super.noSuchMethod(Invocation.method(#loadFile, [absoluteFilePath]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future loadFile(String? absoluteFilePath) => (super.noSuchMethod( + Invocation.method(#loadFile, [absoluteFilePath]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future loadFlutterAsset(String? key) => - (super.noSuchMethod(Invocation.method(#loadFlutterAsset, [key]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future loadFlutterAsset(String? key) => (super.noSuchMethod( + Invocation.method(#loadFlutterAsset, [key]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override _i9.Future loadHtmlString(String? html, {String? baseUrl}) => (super.noSuchMethod( - Invocation.method(#loadHtmlString, [html], {#baseUrl: baseUrl}), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + Invocation.method(#loadHtmlString, [html], {#baseUrl: baseUrl}), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) + as _i9.Future); @override _i9.Future loadUrl(String? url, Map? headers) => (super.noSuchMethod(Invocation.method(#loadUrl, [url, headers]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) + as _i9.Future); @override _i9.Future loadRequest(_i5.WebViewRequest? request) => (super.noSuchMethod(Invocation.method(#loadRequest, [request]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) + as _i9.Future); @override _i9.Future updateSettings(_i5.WebSettings? setting) => (super.noSuchMethod(Invocation.method(#updateSettings, [setting]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) + as _i9.Future); @override _i9.Future currentUrl() => (super.noSuchMethod(Invocation.method(#currentUrl, []), - returnValue: Future.value()) as _i9.Future); + returnValue: _i9.Future.value()) as _i9.Future); @override _i9.Future canGoBack() => (super.noSuchMethod(Invocation.method(#canGoBack, []), - returnValue: Future.value(false)) as _i9.Future); + returnValue: _i9.Future.value(false)) as _i9.Future); @override _i9.Future canGoForward() => (super.noSuchMethod(Invocation.method(#canGoForward, []), - returnValue: Future.value(false)) as _i9.Future); + returnValue: _i9.Future.value(false)) as _i9.Future); @override - _i9.Future goBack() => - (super.noSuchMethod(Invocation.method(#goBack, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future goBack() => (super.noSuchMethod( + Invocation.method(#goBack, []), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future goForward() => - (super.noSuchMethod(Invocation.method(#goForward, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future goForward() => (super.noSuchMethod( + Invocation.method(#goForward, []), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future reload() => - (super.noSuchMethod(Invocation.method(#reload, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future reload() => (super.noSuchMethod( + Invocation.method(#reload, []), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future clearCache() => - (super.noSuchMethod(Invocation.method(#clearCache, []), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future clearCache() => (super.noSuchMethod( + Invocation.method(#clearCache, []), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override _i9.Future evaluateJavascript(String? javascript) => (super.noSuchMethod(Invocation.method(#evaluateJavascript, [javascript]), - returnValue: Future.value('')) as _i9.Future); + returnValue: _i9.Future.value('')) as _i9.Future); @override - _i9.Future runJavascript(String? javascript) => - (super.noSuchMethod(Invocation.method(#runJavascript, [javascript]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future runJavascript(String? javascript) => (super.noSuchMethod( + Invocation.method(#runJavascript, [javascript]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override _i9.Future runJavascriptReturningResult(String? javascript) => (super.noSuchMethod( Invocation.method(#runJavascriptReturningResult, [javascript]), - returnValue: Future.value('')) as _i9.Future); + returnValue: _i9.Future.value('')) as _i9.Future); @override _i9.Future addJavascriptChannels(Set? javascriptChannelNames) => (super.noSuchMethod( Invocation.method(#addJavascriptChannels, [javascriptChannelNames]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: + _i9.Future.value()) as _i9.Future); @override _i9.Future removeJavascriptChannels( Set? javascriptChannelNames) => (super.noSuchMethod( - Invocation.method( - #removeJavascriptChannels, [javascriptChannelNames]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + Invocation.method( + #removeJavascriptChannels, [javascriptChannelNames]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) + as _i9.Future); @override _i9.Future getTitle() => (super.noSuchMethod(Invocation.method(#getTitle, []), - returnValue: Future.value()) as _i9.Future); + returnValue: _i9.Future.value()) as _i9.Future); @override - _i9.Future scrollTo(int? x, int? y) => - (super.noSuchMethod(Invocation.method(#scrollTo, [x, y]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future scrollTo(int? x, int? y) => (super.noSuchMethod( + Invocation.method(#scrollTo, [x, y]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override - _i9.Future scrollBy(int? x, int? y) => - (super.noSuchMethod(Invocation.method(#scrollBy, [x, y]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i9.Future); + _i9.Future scrollBy(int? x, int? y) => (super.noSuchMethod( + Invocation.method(#scrollBy, [x, y]), + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value()) as _i9.Future); @override _i9.Future getScrollX() => (super.noSuchMethod(Invocation.method(#getScrollX, []), - returnValue: Future.value(0)) as _i9.Future); + returnValue: _i9.Future.value(0)) as _i9.Future); @override _i9.Future getScrollY() => (super.noSuchMethod(Invocation.method(#getScrollY, []), - returnValue: Future.value(0)) as _i9.Future); - @override - String toString() => super.toString(); + returnValue: _i9.Future.value(0)) as _i9.Future); }