From d57f1d739c8f99b7539d21321d826a8988cd4bf2 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 9 Aug 2022 11:08:42 -0700 Subject: [PATCH 1/9] start of webview controller --- .../lib/src/v4/src/webview_controller.dart | 250 ++++++++++++++++++ .../lib/src/v4/webview_flutter.dart | 3 + 2 files changed, 253 insertions(+) create mode 100644 packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_controller.dart create mode 100644 packages/webview_flutter/webview_flutter/lib/src/v4/webview_flutter.dart 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..b0118c349b12 --- /dev/null +++ b/packages/webview_flutter/webview_flutter/lib/src/v4/src/webview_controller.dart @@ -0,0 +1,250 @@ + + +import 'dart:math'; + +// TODO: +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. +class WebViewController { + /// Constructs a [WebViewController]. + WebViewController({ + PlatformWebViewControllerCreationParams params = + const PlatformWebViewControllerCreationParams(), + }) : this.fromPlatform(platform: PlatformWebViewController(params)); + + // TODO: should specify how + /// Constructor for the plugin to write platform agnostic unit tests by mocking `delegate`. + WebViewController.fromPlatform({required 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, + )); + } + + /// Accessor to 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. + /// These are not yet supported in iOS WkWebView. 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, + }) { + 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(); + } + + /// Set 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); + } + + /// Move 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); + } + + /// Return 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); + } + + /// Set 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/webview_flutter.dart b/packages/webview_flutter/webview_flutter/lib/src/v4/webview_flutter.dart new file mode 100644 index 000000000000..775e99db3fbb --- /dev/null +++ b/packages/webview_flutter/webview_flutter/lib/src/v4/webview_flutter.dart @@ -0,0 +1,3 @@ +library webview_flutter; + +export 'src/webview_controller.dart'; From eb51fbb2d60d9239f3884673c2f55af191e98a49 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:21:00 -0700 Subject: [PATCH 2/9] license and added a constructor --- .../lib/src/v4/src/webview_controller.dart | 30 ++++++++++++------- .../lib/src/v4/webview_flutter.dart | 4 +++ 2 files changed, 24 insertions(+), 10 deletions(-) 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 index b0118c349b12..4c7e354a56a8 100644 --- 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 @@ -1,8 +1,11 @@ - +// 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: +// 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'; @@ -11,14 +14,21 @@ import 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_i /// Controls a WebView provided by the host platform. class WebViewController { /// Constructs a [WebViewController]. - WebViewController({ - PlatformWebViewControllerCreationParams params = - const PlatformWebViewControllerCreationParams(), - }) : this.fromPlatform(platform: PlatformWebViewController(params)); - - // TODO: should specify how - /// Constructor for the plugin to write platform agnostic unit tests by mocking `delegate`. - WebViewController.fromPlatform({required this.platform}); + WebViewController() + : this.withPlatform( + platform: PlatformWebViewController( + const PlatformWebViewControllerCreationParams(), + ), + ); + + /// Constructs a [WebViewController] with creation params for a specific + /// platform. + WebViewController.withPlatformCreationParams( + PlatformWebViewControllerCreationParams params, + ) : this.withPlatform(platform: PlatformWebViewController(params)); + + /// Constructs a [WebViewController] with a specific platform implementation. + WebViewController.withPlatform({required this.platform}); /// Implementation of [PlatformWebViewController] for the current platform. final PlatformWebViewController 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 775e99db3fbb..557f69dbb4e5 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 @@ -1,3 +1,7 @@ +// 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. + library webview_flutter; export 'src/webview_controller.dart'; From adc272da9fec7f548770d35f47a749340900ae0b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 16 Aug 2022 18:36:14 -0700 Subject: [PATCH 3/9] tests --- .../lib/src/v4/src/webview_controller.dart | 1 + .../test/v4/webview_controller_test.dart | 355 ++++++++++++++++++ .../v4/webview_controller_test.mocks.dart | 203 ++++++++++ .../test/webview_flutter_test.mocks.dart | 156 ++++---- 4 files changed, 644 insertions(+), 71 deletions(-) create mode 100644 packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart create mode 100644 packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.mocks.dart 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 index 4c7e354a56a8..da75ffd6aa67 100644 --- 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 @@ -194,6 +194,7 @@ class WebViewController { String name, { required void Function(JavaScriptMessage) onMessageReceived, }) { + assert(name.isNotEmpty); return platform.addJavaScriptChannel(JavaScriptChannelParams( name: name, onMessageReceived: onMessageReceived, 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..2cbdfa01b3a4 --- /dev/null +++ b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart @@ -0,0 +1,355 @@ +// 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'; + +typedef VoidCallback = void Function(); + +@GenerateMocks([PlatformWebViewController]) +void main() { + test('loadFile', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.loadFile('file/path'); + verify(mockPlatformWebViewController.loadFile('file/path')); + }); + + test('loadFlutterAsset', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.loadFlutterAsset('file/path'); + verify(mockPlatformWebViewController.loadFlutterAsset('file/path')); + }); + + test('loadHtmlString', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.loadHtmlString('html', baseUrl: 'baseUrl'); + verify(mockPlatformWebViewController.loadHtmlString( + 'html', + baseUrl: 'baseUrl', + )); + }); + + test('loadRequest', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: 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.withPlatform( + platform: 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.withPlatform( + platform: 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.withPlatform( + platform: mockPlatformWebViewController, + ); + + await expectLater(webViewController.canGoForward(), completion(true)); + }); + + test('goBack', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.goBack(); + verify(mockPlatformWebViewController.goBack()); + }); + + test('goForward', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.goForward(); + verify(mockPlatformWebViewController.goForward()); + }); + + test('reload', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.reload(); + verify(mockPlatformWebViewController.reload()); + }); + + test('clearCache', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.clearCache(); + verify(mockPlatformWebViewController.clearCache()); + }); + + test('clearLocalStorage', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.clearLocalStorage(); + verify(mockPlatformWebViewController.clearLocalStorage()); + }); + + test('runJavaScript', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: 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.withPlatform( + platform: mockPlatformWebViewController, + ); + + await expectLater( + webViewController.runJavaScriptReturningResult('1 + 1'), + completion('2'), + ); + }); + + test('addJavaScriptChannel', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: 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.withPlatform( + platform: 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.withPlatform( + platform: mockPlatformWebViewController, + ); + + await expectLater(webViewController.getTitle(), completion('myTitle')); + }); + + test('scrollTo', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.scrollTo(2, 3); + verify(mockPlatformWebViewController.scrollTo(2, 3)); + }); + + test('scrollBy', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: 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.withPlatform( + platform: mockPlatformWebViewController, + ); + + await expectLater( + webViewController.getScrollPosition(), + completion(const Offset(2.0, 3.0)), + ); + }); + + test('enableZoom', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.enableZoom(false); + verify(mockPlatformWebViewController.enableZoom(false)); + }); + + test('setBackgroundColor', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.setBackgroundColor(Colors.green); + verify(mockPlatformWebViewController.setBackgroundColor(Colors.green)); + }); + + test('setJavaScriptMode', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: mockPlatformWebViewController, + ); + + await webViewController.setJavaScriptMode(JavaScriptMode.disabled); + verify( + mockPlatformWebViewController.setJavaScriptMode(JavaScriptMode.disabled), + ); + }); + + test('setUserAgent', () async { + final MockPlatformWebViewController mockPlatformWebViewController = + MockPlatformWebViewController(); + + final WebViewController webViewController = WebViewController.withPlatform( + platform: 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/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); } From b739258a72b7a413c6c5fd479a6c396a20ca45fd Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 16 Aug 2022 18:38:46 -0700 Subject: [PATCH 4/9] remove voidcallback --- .../webview_flutter/test/v4/webview_controller_test.dart | 2 -- 1 file changed, 2 deletions(-) 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 index 2cbdfa01b3a4..ee89d933c3a6 100644 --- a/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart @@ -14,8 +14,6 @@ import 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_i import 'webview_controller_test.mocks.dart'; -typedef VoidCallback = void Function(); - @GenerateMocks([PlatformWebViewController]) void main() { test('loadFile', () async { From 1344aaca886d5153381568832ff24558c5c239d5 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 31 Aug 2022 09:00:19 -0400 Subject: [PATCH 5/9] version bump --- .../webview_flutter/lib/src/v4/src/webview_controller.dart | 2 ++ packages/webview_flutter/webview_flutter/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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 index da75ffd6aa67..74201a5c14ad 100644 --- 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 @@ -12,6 +12,8 @@ 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() diff --git a/packages/webview_flutter/webview_flutter/pubspec.yaml b/packages/webview_flutter/webview_flutter/pubspec.yaml index 996f6478b800..a02b0323e7ab 100644 --- a/packages/webview_flutter/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter/pubspec.yaml @@ -20,7 +20,7 @@ dependencies: flutter: sdk: flutter webview_flutter_android: ^2.8.0 - webview_flutter_platform_interface: ^1.8.0 + webview_flutter_platform_interface: ^1.9.3 webview_flutter_wkwebview: ^2.7.0 dev_dependencies: From 3aa227c2f530d5b6fd95b7961c3da9ca50da066f Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 31 Aug 2022 11:04:16 -0400 Subject: [PATCH 6/9] change with to from --- .../lib/src/v4/src/webview_controller.dart | 12 ++--- .../test/v4/webview_controller_test.dart | 48 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) 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 index 74201a5c14ad..4fcafd97d90b 100644 --- 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 @@ -17,20 +17,20 @@ import 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_i class WebViewController { /// Constructs a [WebViewController]. WebViewController() - : this.withPlatform( + : this.fromPlatform( platform: PlatformWebViewController( const PlatformWebViewControllerCreationParams(), ), ); - /// Constructs a [WebViewController] with creation params for a specific + /// Constructs a [WebViewController] from creation params for a specific /// platform. - WebViewController.withPlatformCreationParams( + WebViewController.fromPlatformCreationParams( PlatformWebViewControllerCreationParams params, - ) : this.withPlatform(platform: PlatformWebViewController(params)); + ) : this.fromPlatform(platform: PlatformWebViewController(params)); - /// Constructs a [WebViewController] with a specific platform implementation. - WebViewController.withPlatform({required this.platform}); + /// Constructs a [WebViewController] from a specific platform implementation. + WebViewController.fromPlatform({required this.platform}); /// Implementation of [PlatformWebViewController] for the current platform. final PlatformWebViewController platform; 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 index ee89d933c3a6..f17ba426f03d 100644 --- a/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart @@ -20,7 +20,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -32,7 +32,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -44,7 +44,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -59,7 +59,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -86,7 +86,7 @@ void main() { (_) => Future.value('https://dart.dev'), ); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -103,7 +103,7 @@ void main() { (_) => Future.value(false), ); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -117,7 +117,7 @@ void main() { (_) => Future.value(true), ); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -128,7 +128,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -140,7 +140,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -152,7 +152,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -164,7 +164,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -176,7 +176,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -188,7 +188,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -202,7 +202,7 @@ void main() { when(mockPlatformWebViewController.runJavaScriptReturningResult('1 + 1')) .thenAnswer((_) => Future.value('2')); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -216,7 +216,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -237,7 +237,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -251,7 +251,7 @@ void main() { when(mockPlatformWebViewController.getTitle()) .thenAnswer((_) => Future.value('myTitle')); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -262,7 +262,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -274,7 +274,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -291,7 +291,7 @@ void main() { ), ); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -305,7 +305,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -317,7 +317,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -329,7 +329,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); @@ -343,7 +343,7 @@ void main() { final MockPlatformWebViewController mockPlatformWebViewController = MockPlatformWebViewController(); - final WebViewController webViewController = WebViewController.withPlatform( + final WebViewController webViewController = WebViewController.fromPlatform( platform: mockPlatformWebViewController, ); From 67917c808464a84caead88a0b5279944a762c7fb Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 31 Aug 2022 11:11:24 -0400 Subject: [PATCH 7/9] expose the required types --- .../webview_flutter/lib/src/v4/webview_flutter.dart | 3 +++ 1 file changed, 3 insertions(+) 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 557f69dbb4e5..632986b121ad 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 @@ -4,4 +4,7 @@ library webview_flutter; +export 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_interface.dart' + show JavaScriptMessage, LoadRequestMethod; + export 'src/webview_controller.dart'; From 62a169cf8a3feec67acf74c76de75c70b670322d Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:29:16 -0400 Subject: [PATCH 8/9] updates docs to a consistent format --- .../lib/src/v4/src/webview_controller.dart | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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 index 4fcafd97d90b..b1b2156058be 100644 --- 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 @@ -91,7 +91,7 @@ class WebViewController { )); } - /// Accessor to the current URL that the WebView is displaying. + /// Returns the current URL that the WebView is displaying. /// /// If no URL was ever loaded, returns `null`. Future currentUrl() { @@ -131,9 +131,8 @@ class WebViewController { /// /// 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. - /// These are not yet supported in iOS WkWebView. Service workers tend to - /// use this 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(); @@ -217,7 +216,7 @@ class WebViewController { return platform.getTitle(); } - /// Set the scrolled position of this view. + /// Sets the scrolled position of this view. /// /// The parameters `x` and `y` specify the position to scroll to in WebView /// pixels. @@ -225,7 +224,7 @@ class WebViewController { return platform.scrollTo(x, y); } - /// Move the scrolled position of this view. + /// Moves the scrolled position of this view. /// /// The parameters `x` and `y` specify the amount of WebView pixels to scroll /// by. @@ -233,7 +232,7 @@ class WebViewController { return platform.scrollBy(x, y); } - /// Return the current scroll position of this view. + /// Returns the current scroll position of this view. /// /// Scroll position is measured from the top left. Future getScrollPosition() async { @@ -246,7 +245,7 @@ class WebViewController { return platform.enableZoom(enabled); } - /// Set the current background color of this view. + /// Sets the current background color of this view. Future setBackgroundColor(Color color) { return platform.setBackgroundColor(color); } From 85d93d9c5efd997009303202988eb925bc0714f1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 1 Sep 2022 15:56:07 -0400 Subject: [PATCH 9/9] use creation params constructor and use unnamed parameter --- .../lib/src/v4/src/webview_controller.dart | 10 ++-- .../src/v4/src/webview_cookie_manager.dart | 10 ++-- .../test/v4/webview_controller_test.dart | 48 +++++++++---------- .../test/v4/webview_cookie_manager_test.dart | 4 +- 4 files changed, 34 insertions(+), 38 deletions(-) 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 index b1b2156058be..bd03b247027e 100644 --- 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 @@ -17,20 +17,18 @@ import 'package:webview_flutter_platform_interface/v4/webview_flutter_platform_i class WebViewController { /// Constructs a [WebViewController]. WebViewController() - : this.fromPlatform( - platform: PlatformWebViewController( - const PlatformWebViewControllerCreationParams(), - ), + : this.fromPlatformCreationParams( + const PlatformWebViewControllerCreationParams(), ); /// Constructs a [WebViewController] from creation params for a specific /// platform. WebViewController.fromPlatformCreationParams( PlatformWebViewControllerCreationParams params, - ) : this.fromPlatform(platform: PlatformWebViewController(params)); + ) : this.fromPlatform(PlatformWebViewController(params)); /// Constructs a [WebViewController] from a specific platform implementation. - WebViewController.fromPlatform({required this.platform}); + WebViewController.fromPlatform(this.platform); /// Implementation of [PlatformWebViewController] for the current platform. final PlatformWebViewController platform; 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/test/v4/webview_controller_test.dart b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart index f17ba426f03d..f767a2e48d5e 100644 --- a/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter/test/v4/webview_controller_test.dart @@ -21,7 +21,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.loadFile('file/path'); @@ -33,7 +33,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.loadFlutterAsset('file/path'); @@ -45,7 +45,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.loadHtmlString('html', baseUrl: 'baseUrl'); @@ -60,7 +60,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.loadRequest( @@ -87,7 +87,7 @@ void main() { ); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await expectLater( @@ -104,7 +104,7 @@ void main() { ); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await expectLater(webViewController.canGoBack(), completion(false)); @@ -118,7 +118,7 @@ void main() { ); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await expectLater(webViewController.canGoForward(), completion(true)); @@ -129,7 +129,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.goBack(); @@ -141,7 +141,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.goForward(); @@ -153,7 +153,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.reload(); @@ -165,7 +165,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.clearCache(); @@ -177,7 +177,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.clearLocalStorage(); @@ -189,7 +189,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.runJavaScript('1 + 1'); @@ -203,7 +203,7 @@ void main() { .thenAnswer((_) => Future.value('2')); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await expectLater( @@ -217,7 +217,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); void onMessageReceived(JavaScriptMessage message) {} @@ -238,7 +238,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.removeJavaScriptChannel('channel'); @@ -252,7 +252,7 @@ void main() { .thenAnswer((_) => Future.value('myTitle')); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await expectLater(webViewController.getTitle(), completion('myTitle')); @@ -263,7 +263,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.scrollTo(2, 3); @@ -275,7 +275,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.scrollBy(2, 3); @@ -292,7 +292,7 @@ void main() { ); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await expectLater( @@ -306,7 +306,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.enableZoom(false); @@ -318,7 +318,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.setBackgroundColor(Colors.green); @@ -330,7 +330,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.setJavaScriptMode(JavaScriptMode.disabled); @@ -344,7 +344,7 @@ void main() { MockPlatformWebViewController(); final WebViewController webViewController = WebViewController.fromPlatform( - platform: mockPlatformWebViewController, + mockPlatformWebViewController, ); await webViewController.setUserAgent('userAgent'); 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(