From 61b792d47a361dee55cd19198b37732a5294de3d Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Wed, 15 May 2024 13:29:22 +0200 Subject: [PATCH 01/20] Fix Web --- .../lib/src/http_request_factory.dart | 5 +- .../lib/src/web_webview_controller.dart | 8 +- .../lib/src/webview_flutter_web_legacy.dart | 21 +- .../webview_flutter_web/pubspec.yaml | 1 + .../test/legacy/webview_flutter_web_test.dart | 12 +- .../webview_flutter_web_test.mocks.dart | 2879 ----------------- .../web_webview_controller_test.mocks.dart | 406 --- 7 files changed, 26 insertions(+), 3306 deletions(-) delete mode 100644 packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart delete mode 100644 packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart index 4bd92f0db1d..df3a9d7e510 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart @@ -1,8 +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. - -import 'dart:html'; +import 'package:web/web.dart'; /// Factory class for creating [HttpRequest] instances. class HttpRequestFactory { @@ -61,7 +60,7 @@ class HttpRequestFactory { /// when the file cannot be found. /// /// See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access_authentication). - Future request(String url, + Future request(String url, {String? method, bool? withCredentials, String? responseType, diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart index 79f28b858bf..dcff6443a4a 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart @@ -3,10 +3,10 @@ // found in the LICENSE file. import 'dart:convert'; -import 'dart:html' as html; import 'dart:ui_web' as ui_web; import 'package:flutter/cupertino.dart'; +import 'package:web/web.dart' as html; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'content_type.dart'; @@ -38,7 +38,7 @@ class WebWebViewControllerCreationParams /// The underlying element used as the WebView. @visibleForTesting - final html.IFrameElement iFrame = html.IFrameElement() + final html.HTMLIFrameElement iFrame = html.HTMLIFrameElement() ..id = 'webView${_nextIFrameId++}' ..style.width = '100%' ..style.height = '100%' @@ -86,7 +86,7 @@ class WebWebViewController extends PlatformWebViewController { /// Performs an AJAX request defined by [params]. Future _updateIFrameFromXhr(LoadRequestParams params) async { - final html.HttpRequest httpReq = + final html.XMLHttpRequest httpReq = await _webWebViewParams.httpRequestFactory.request( params.uri.toString(), method: params.method.serialize(), @@ -101,7 +101,7 @@ class WebWebViewController extends PlatformWebViewController { // ignore: unsafe_html _webWebViewParams.iFrame.src = Uri.dataFromString( - httpReq.responseText ?? '', + httpReq.responseText, mimeType: contentType.mimeType, encoding: encoding, ).toString(); diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart index 1f83bf440be..cfbb7e8a8ed 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart @@ -4,15 +4,16 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:html'; import 'dart:ui_web' as ui_web; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; +import 'package:web/web.dart' as html; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; + import 'http_request_factory.dart'; /// Builds an iframe based WebView. @@ -23,7 +24,7 @@ class WebWebViewPlatform implements WebViewPlatform { WebWebViewPlatform() { ui_web.platformViewRegistry.registerViewFactory( 'webview-iframe', - (int viewId) => IFrameElement() + (int viewId) => html.HTMLIFrameElement() ..id = 'webview-$viewId' ..width = '100%' ..height = '100%' @@ -45,11 +46,13 @@ class WebWebViewPlatform implements WebViewPlatform { if (onWebViewPlatformCreated == null) { return; } - final IFrameElement element = - document.getElementById('webview-$viewId')! as IFrameElement; - if (creationParams.initialUrl != null) { + final html.HTMLIFrameElement element = + html.document.getElementById('webview-$viewId')! as html.HTMLIFrameElement; + + final String? initialUrl = creationParams.initialUrl; + if (initialUrl != null) { // ignore: unsafe_html - element.src = creationParams.initialUrl; + element.src = initialUrl; } onWebViewPlatformCreated(WebWebViewPlatformController( element, @@ -70,7 +73,7 @@ class WebWebViewPlatformController implements WebViewPlatformController { /// Constructs a [WebWebViewPlatformController]. WebWebViewPlatformController(this._element); - final IFrameElement _element; + final html.HTMLIFrameElement _element; HttpRequestFactory _httpRequestFactory = const HttpRequestFactory(); /// Setter for setting the HttpRequestFactory, for testing purposes. @@ -199,7 +202,7 @@ class WebWebViewPlatformController implements WebViewPlatformController { if (!request.uri.hasScheme) { throw ArgumentError('WebViewRequest#uri is required to have a scheme.'); } - final HttpRequest httpReq = await _httpRequestFactory.request( + final html.XMLHttpRequest httpReq = await _httpRequestFactory.request( request.uri.toString(), method: request.method.serialize(), requestHeaders: request.headers, @@ -208,7 +211,7 @@ class WebWebViewPlatformController implements WebViewPlatformController { httpReq.getResponseHeader('content-type') ?? 'text/html'; // ignore: unsafe_html _element.src = Uri.dataFromString( - httpReq.responseText ?? '', + httpReq.responseText, mimeType: contentType, encoding: utf8, ).toString(); diff --git a/packages/webview_flutter/webview_flutter_web/pubspec.yaml b/packages/webview_flutter/webview_flutter_web/pubspec.yaml index 484c795b4a7..7d0bfc00343 100644 --- a/packages/webview_flutter/webview_flutter_web/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_web/pubspec.yaml @@ -21,6 +21,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter + web: ^0.5.1 webview_flutter_platform_interface: ^2.0.0 dev_dependencies: diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart index 54e53bb1192..3bb069f317e 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:html'; + +import 'package:web/helpers.dart'; +import 'package:web/web.dart' as html; import 'dart:typed_data'; import 'package:flutter/material.dart'; @@ -16,12 +18,12 @@ import 'package:webview_flutter_web/src/webview_flutter_web_legacy.dart'; import 'webview_flutter_web_test.mocks.dart'; @GenerateMocks([ - IFrameElement, + html.HTMLIFrameElement, BuildContext, CreationParams, WebViewPlatformCallbacksHandler, HttpRequestFactory, - HttpRequest, + html.XMLHttpRequest, ]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -123,7 +125,7 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(mockHttpRequest)); controller.httpRequestFactory = mockHttpRequestFactory; // Run await controller.loadRequest( @@ -162,7 +164,7 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(mockHttpRequest)); controller.httpRequestFactory = mockHttpRequestFactory; // Run await controller.loadRequest( diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart deleted file mode 100644 index 08d5dfc7b35..00000000000 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart +++ /dev/null @@ -1,2879 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in webview_flutter_web/test/legacy/webview_flutter_web_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i7; -import 'dart:html' as _i2; -import 'dart:math' as _i3; - -import 'package:flutter/foundation.dart' as _i5; -import 'package:flutter/src/widgets/notification_listener.dart' as _i8; -import 'package:flutter/widgets.dart' as _i4; -import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i6; -import 'package:webview_flutter_platform_interface/src/legacy/platform_interface/webview_platform_callbacks_handler.dart' - as _i10; -import 'package:webview_flutter_platform_interface/src/legacy/types/types.dart' - as _i9; -import 'package:webview_flutter_web/src/http_request_factory.dart' as _i11; - -// 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: deprecated_member_use -// ignore_for_file: deprecated_member_use_from_same_package -// 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 _FakeCssClassSet_0 extends _i1.SmartFake implements _i2.CssClassSet { - _FakeCssClassSet_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeRectangle_1 extends _i1.SmartFake - implements _i3.Rectangle { - _FakeRectangle_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeCssRect_2 extends _i1.SmartFake implements _i2.CssRect { - _FakeCssRect_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakePoint_3 extends _i1.SmartFake - implements _i3.Point { - _FakePoint_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeElementEvents_4 extends _i1.SmartFake implements _i2.ElementEvents { - _FakeElementEvents_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeCssStyleDeclaration_5 extends _i1.SmartFake - implements _i2.CssStyleDeclaration { - _FakeCssStyleDeclaration_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeElementStream_6 extends _i1.SmartFake - implements _i2.ElementStream { - _FakeElementStream_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeElementList_7 extends _i1.SmartFake - implements _i2.ElementList { - _FakeElementList_7( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeScrollState_8 extends _i1.SmartFake implements _i2.ScrollState { - _FakeScrollState_8( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeAnimation_9 extends _i1.SmartFake implements _i2.Animation { - _FakeAnimation_9( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeElement_10 extends _i1.SmartFake implements _i2.Element { - _FakeElement_10( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeShadowRoot_11 extends _i1.SmartFake implements _i2.ShadowRoot { - _FakeShadowRoot_11( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeDocumentFragment_12 extends _i1.SmartFake - implements _i2.DocumentFragment { - _FakeDocumentFragment_12( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeNode_13 extends _i1.SmartFake implements _i2.Node { - _FakeNode_13( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWidget_14 extends _i1.SmartFake implements _i4.Widget { - _FakeWidget_14( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); - - @override - String toString({_i5.DiagnosticLevel? minLevel = _i5.DiagnosticLevel.info}) => - super.toString(); -} - -class _FakeInheritedWidget_15 extends _i1.SmartFake - implements _i4.InheritedWidget { - _FakeInheritedWidget_15( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); - - @override - String toString({_i5.DiagnosticLevel? minLevel = _i5.DiagnosticLevel.info}) => - super.toString(); -} - -class _FakeDiagnosticsNode_16 extends _i1.SmartFake - implements _i5.DiagnosticsNode { - _FakeDiagnosticsNode_16( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); - - @override - String toString({ - _i5.TextTreeConfiguration? parentConfiguration, - _i5.DiagnosticLevel? minLevel = _i5.DiagnosticLevel.info, - }) => - super.toString(); -} - -class _FakeHttpRequest_17 extends _i1.SmartFake implements _i2.HttpRequest { - _FakeHttpRequest_17( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeHttpRequestUpload_18 extends _i1.SmartFake - implements _i2.HttpRequestUpload { - _FakeHttpRequestUpload_18( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeEvents_19 extends _i1.SmartFake implements _i2.Events { - _FakeEvents_19( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [IFrameElement]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockIFrameElement extends _i1.Mock implements _i2.IFrameElement { - MockIFrameElement() { - _i1.throwOnMissingStub(this); - } - - @override - set allow(String? value) => super.noSuchMethod( - Invocation.setter( - #allow, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set allowFullscreen(bool? value) => super.noSuchMethod( - Invocation.setter( - #allowFullscreen, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set allowPaymentRequest(bool? value) => super.noSuchMethod( - Invocation.setter( - #allowPaymentRequest, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set csp(String? value) => super.noSuchMethod( - Invocation.setter( - #csp, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set height(String? value) => super.noSuchMethod( - Invocation.setter( - #height, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set name(String? value) => super.noSuchMethod( - Invocation.setter( - #name, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set referrerPolicy(String? value) => super.noSuchMethod( - Invocation.setter( - #referrerPolicy, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set src(String? value) => super.noSuchMethod( - Invocation.setter( - #src, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set srcdoc(String? value) => super.noSuchMethod( - Invocation.setter( - #srcdoc, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set width(String? value) => super.noSuchMethod( - Invocation.setter( - #width, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set nonce(String? value) => super.noSuchMethod( - Invocation.setter( - #nonce, - value, - ), - returnValueForMissingStub: null, - ); - - @override - Map get attributes => (super.noSuchMethod( - Invocation.getter(#attributes), - returnValue: {}, - ) as Map); - - @override - set attributes(Map? value) => super.noSuchMethod( - Invocation.setter( - #attributes, - value, - ), - returnValueForMissingStub: null, - ); - - @override - List<_i2.Element> get children => (super.noSuchMethod( - Invocation.getter(#children), - returnValue: <_i2.Element>[], - ) as List<_i2.Element>); - - @override - set children(List<_i2.Element>? value) => super.noSuchMethod( - Invocation.setter( - #children, - value, - ), - returnValueForMissingStub: null, - ); - - @override - _i2.CssClassSet get classes => (super.noSuchMethod( - Invocation.getter(#classes), - returnValue: _FakeCssClassSet_0( - this, - Invocation.getter(#classes), - ), - ) as _i2.CssClassSet); - - @override - set classes(Iterable? value) => super.noSuchMethod( - Invocation.setter( - #classes, - value, - ), - returnValueForMissingStub: null, - ); - - @override - Map get dataset => (super.noSuchMethod( - Invocation.getter(#dataset), - returnValue: {}, - ) as Map); - - @override - set dataset(Map? value) => super.noSuchMethod( - Invocation.setter( - #dataset, - value, - ), - returnValueForMissingStub: null, - ); - - @override - _i3.Rectangle get client => (super.noSuchMethod( - Invocation.getter(#client), - returnValue: _FakeRectangle_1( - this, - Invocation.getter(#client), - ), - ) as _i3.Rectangle); - - @override - _i3.Rectangle get offset => (super.noSuchMethod( - Invocation.getter(#offset), - returnValue: _FakeRectangle_1( - this, - Invocation.getter(#offset), - ), - ) as _i3.Rectangle); - - @override - String get localName => (super.noSuchMethod( - Invocation.getter(#localName), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#localName), - ), - ) as String); - - @override - _i2.CssRect get contentEdge => (super.noSuchMethod( - Invocation.getter(#contentEdge), - returnValue: _FakeCssRect_2( - this, - Invocation.getter(#contentEdge), - ), - ) as _i2.CssRect); - - @override - _i2.CssRect get paddingEdge => (super.noSuchMethod( - Invocation.getter(#paddingEdge), - returnValue: _FakeCssRect_2( - this, - Invocation.getter(#paddingEdge), - ), - ) as _i2.CssRect); - - @override - _i2.CssRect get borderEdge => (super.noSuchMethod( - Invocation.getter(#borderEdge), - returnValue: _FakeCssRect_2( - this, - Invocation.getter(#borderEdge), - ), - ) as _i2.CssRect); - - @override - _i2.CssRect get marginEdge => (super.noSuchMethod( - Invocation.getter(#marginEdge), - returnValue: _FakeCssRect_2( - this, - Invocation.getter(#marginEdge), - ), - ) as _i2.CssRect); - - @override - _i3.Point get documentOffset => (super.noSuchMethod( - Invocation.getter(#documentOffset), - returnValue: _FakePoint_3( - this, - Invocation.getter(#documentOffset), - ), - ) as _i3.Point); - - @override - set innerHtml(String? html) => super.noSuchMethod( - Invocation.setter( - #innerHtml, - html, - ), - returnValueForMissingStub: null, - ); - - @override - String get innerText => (super.noSuchMethod( - Invocation.getter(#innerText), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#innerText), - ), - ) as String); - - @override - set innerText(String? value) => super.noSuchMethod( - Invocation.setter( - #innerText, - value, - ), - returnValueForMissingStub: null, - ); - - @override - _i2.ElementEvents get on => (super.noSuchMethod( - Invocation.getter(#on), - returnValue: _FakeElementEvents_4( - this, - Invocation.getter(#on), - ), - ) as _i2.ElementEvents); - - @override - int get offsetHeight => (super.noSuchMethod( - Invocation.getter(#offsetHeight), - returnValue: 0, - ) as int); - - @override - int get offsetLeft => (super.noSuchMethod( - Invocation.getter(#offsetLeft), - returnValue: 0, - ) as int); - - @override - int get offsetTop => (super.noSuchMethod( - Invocation.getter(#offsetTop), - returnValue: 0, - ) as int); - - @override - int get offsetWidth => (super.noSuchMethod( - Invocation.getter(#offsetWidth), - returnValue: 0, - ) as int); - - @override - int get scrollHeight => (super.noSuchMethod( - Invocation.getter(#scrollHeight), - returnValue: 0, - ) as int); - - @override - int get scrollLeft => (super.noSuchMethod( - Invocation.getter(#scrollLeft), - returnValue: 0, - ) as int); - - @override - set scrollLeft(int? value) => super.noSuchMethod( - Invocation.setter( - #scrollLeft, - value, - ), - returnValueForMissingStub: null, - ); - - @override - int get scrollTop => (super.noSuchMethod( - Invocation.getter(#scrollTop), - returnValue: 0, - ) as int); - - @override - set scrollTop(int? value) => super.noSuchMethod( - Invocation.setter( - #scrollTop, - value, - ), - returnValueForMissingStub: null, - ); - - @override - int get scrollWidth => (super.noSuchMethod( - Invocation.getter(#scrollWidth), - returnValue: 0, - ) as int); - - @override - String get contentEditable => (super.noSuchMethod( - Invocation.getter(#contentEditable), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#contentEditable), - ), - ) as String); - - @override - set contentEditable(String? value) => super.noSuchMethod( - Invocation.setter( - #contentEditable, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set dir(String? value) => super.noSuchMethod( - Invocation.setter( - #dir, - value, - ), - returnValueForMissingStub: null, - ); - - @override - bool get draggable => (super.noSuchMethod( - Invocation.getter(#draggable), - returnValue: false, - ) as bool); - - @override - set draggable(bool? value) => super.noSuchMethod( - Invocation.setter( - #draggable, - value, - ), - returnValueForMissingStub: null, - ); - - @override - bool get hidden => (super.noSuchMethod( - Invocation.getter(#hidden), - returnValue: false, - ) as bool); - - @override - set hidden(bool? value) => super.noSuchMethod( - Invocation.setter( - #hidden, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set inert(bool? value) => super.noSuchMethod( - Invocation.setter( - #inert, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set inputMode(String? value) => super.noSuchMethod( - Invocation.setter( - #inputMode, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set lang(String? value) => super.noSuchMethod( - Invocation.setter( - #lang, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set spellcheck(bool? value) => super.noSuchMethod( - Invocation.setter( - #spellcheck, - value, - ), - returnValueForMissingStub: null, - ); - - @override - _i2.CssStyleDeclaration get style => (super.noSuchMethod( - Invocation.getter(#style), - returnValue: _FakeCssStyleDeclaration_5( - this, - Invocation.getter(#style), - ), - ) as _i2.CssStyleDeclaration); - - @override - set tabIndex(int? value) => super.noSuchMethod( - Invocation.setter( - #tabIndex, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set title(String? value) => super.noSuchMethod( - Invocation.setter( - #title, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set translate(bool? value) => super.noSuchMethod( - Invocation.setter( - #translate, - value, - ), - returnValueForMissingStub: null, - ); - - @override - String get className => (super.noSuchMethod( - Invocation.getter(#className), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#className), - ), - ) as String); - - @override - set className(String? value) => super.noSuchMethod( - Invocation.setter( - #className, - value, - ), - returnValueForMissingStub: null, - ); - - @override - int get clientHeight => (super.noSuchMethod( - Invocation.getter(#clientHeight), - returnValue: 0, - ) as int); - - @override - int get clientWidth => (super.noSuchMethod( - Invocation.getter(#clientWidth), - returnValue: 0, - ) as int); - - @override - String get id => (super.noSuchMethod( - Invocation.getter(#id), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#id), - ), - ) as String); - - @override - set id(String? value) => super.noSuchMethod( - Invocation.setter( - #id, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set slot(String? value) => super.noSuchMethod( - Invocation.setter( - #slot, - value, - ), - returnValueForMissingStub: null, - ); - - @override - String get tagName => (super.noSuchMethod( - Invocation.getter(#tagName), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#tagName), - ), - ) as String); - - @override - _i2.ElementStream<_i2.Event> get onAbort => (super.noSuchMethod( - Invocation.getter(#onAbort), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onAbort), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onBeforeCopy => (super.noSuchMethod( - Invocation.getter(#onBeforeCopy), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onBeforeCopy), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onBeforeCut => (super.noSuchMethod( - Invocation.getter(#onBeforeCut), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onBeforeCut), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onBeforePaste => (super.noSuchMethod( - Invocation.getter(#onBeforePaste), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onBeforePaste), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onBlur => (super.noSuchMethod( - Invocation.getter(#onBlur), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onBlur), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onCanPlay => (super.noSuchMethod( - Invocation.getter(#onCanPlay), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onCanPlay), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onCanPlayThrough => (super.noSuchMethod( - Invocation.getter(#onCanPlayThrough), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onCanPlayThrough), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onChange => (super.noSuchMethod( - Invocation.getter(#onChange), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onChange), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onClick => (super.noSuchMethod( - Invocation.getter(#onClick), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onClick), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onContextMenu => (super.noSuchMethod( - Invocation.getter(#onContextMenu), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onContextMenu), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.ClipboardEvent> get onCopy => (super.noSuchMethod( - Invocation.getter(#onCopy), - returnValue: _FakeElementStream_6<_i2.ClipboardEvent>( - this, - Invocation.getter(#onCopy), - ), - ) as _i2.ElementStream<_i2.ClipboardEvent>); - - @override - _i2.ElementStream<_i2.ClipboardEvent> get onCut => (super.noSuchMethod( - Invocation.getter(#onCut), - returnValue: _FakeElementStream_6<_i2.ClipboardEvent>( - this, - Invocation.getter(#onCut), - ), - ) as _i2.ElementStream<_i2.ClipboardEvent>); - - @override - _i2.ElementStream<_i2.Event> get onDoubleClick => (super.noSuchMethod( - Invocation.getter(#onDoubleClick), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onDoubleClick), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onDrag => (super.noSuchMethod( - Invocation.getter(#onDrag), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onDrag), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onDragEnd => (super.noSuchMethod( - Invocation.getter(#onDragEnd), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onDragEnd), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onDragEnter => (super.noSuchMethod( - Invocation.getter(#onDragEnter), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onDragEnter), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onDragLeave => (super.noSuchMethod( - Invocation.getter(#onDragLeave), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onDragLeave), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onDragOver => (super.noSuchMethod( - Invocation.getter(#onDragOver), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onDragOver), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onDragStart => (super.noSuchMethod( - Invocation.getter(#onDragStart), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onDragStart), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onDrop => (super.noSuchMethod( - Invocation.getter(#onDrop), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onDrop), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.Event> get onDurationChange => (super.noSuchMethod( - Invocation.getter(#onDurationChange), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onDurationChange), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onEmptied => (super.noSuchMethod( - Invocation.getter(#onEmptied), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onEmptied), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onEnded => (super.noSuchMethod( - Invocation.getter(#onEnded), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onEnded), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onError => (super.noSuchMethod( - Invocation.getter(#onError), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onError), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onFocus => (super.noSuchMethod( - Invocation.getter(#onFocus), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onFocus), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onInput => (super.noSuchMethod( - Invocation.getter(#onInput), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onInput), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onInvalid => (super.noSuchMethod( - Invocation.getter(#onInvalid), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onInvalid), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.KeyboardEvent> get onKeyDown => (super.noSuchMethod( - Invocation.getter(#onKeyDown), - returnValue: _FakeElementStream_6<_i2.KeyboardEvent>( - this, - Invocation.getter(#onKeyDown), - ), - ) as _i2.ElementStream<_i2.KeyboardEvent>); - - @override - _i2.ElementStream<_i2.KeyboardEvent> get onKeyPress => (super.noSuchMethod( - Invocation.getter(#onKeyPress), - returnValue: _FakeElementStream_6<_i2.KeyboardEvent>( - this, - Invocation.getter(#onKeyPress), - ), - ) as _i2.ElementStream<_i2.KeyboardEvent>); - - @override - _i2.ElementStream<_i2.KeyboardEvent> get onKeyUp => (super.noSuchMethod( - Invocation.getter(#onKeyUp), - returnValue: _FakeElementStream_6<_i2.KeyboardEvent>( - this, - Invocation.getter(#onKeyUp), - ), - ) as _i2.ElementStream<_i2.KeyboardEvent>); - - @override - _i2.ElementStream<_i2.Event> get onLoad => (super.noSuchMethod( - Invocation.getter(#onLoad), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onLoad), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onLoadedData => (super.noSuchMethod( - Invocation.getter(#onLoadedData), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onLoadedData), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onLoadedMetadata => (super.noSuchMethod( - Invocation.getter(#onLoadedMetadata), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onLoadedMetadata), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onMouseDown => (super.noSuchMethod( - Invocation.getter(#onMouseDown), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onMouseDown), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onMouseEnter => (super.noSuchMethod( - Invocation.getter(#onMouseEnter), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onMouseEnter), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onMouseLeave => (super.noSuchMethod( - Invocation.getter(#onMouseLeave), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onMouseLeave), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onMouseMove => (super.noSuchMethod( - Invocation.getter(#onMouseMove), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onMouseMove), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onMouseOut => (super.noSuchMethod( - Invocation.getter(#onMouseOut), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onMouseOut), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onMouseOver => (super.noSuchMethod( - Invocation.getter(#onMouseOver), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onMouseOver), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.MouseEvent> get onMouseUp => (super.noSuchMethod( - Invocation.getter(#onMouseUp), - returnValue: _FakeElementStream_6<_i2.MouseEvent>( - this, - Invocation.getter(#onMouseUp), - ), - ) as _i2.ElementStream<_i2.MouseEvent>); - - @override - _i2.ElementStream<_i2.WheelEvent> get onMouseWheel => (super.noSuchMethod( - Invocation.getter(#onMouseWheel), - returnValue: _FakeElementStream_6<_i2.WheelEvent>( - this, - Invocation.getter(#onMouseWheel), - ), - ) as _i2.ElementStream<_i2.WheelEvent>); - - @override - _i2.ElementStream<_i2.ClipboardEvent> get onPaste => (super.noSuchMethod( - Invocation.getter(#onPaste), - returnValue: _FakeElementStream_6<_i2.ClipboardEvent>( - this, - Invocation.getter(#onPaste), - ), - ) as _i2.ElementStream<_i2.ClipboardEvent>); - - @override - _i2.ElementStream<_i2.Event> get onPause => (super.noSuchMethod( - Invocation.getter(#onPause), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onPause), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onPlay => (super.noSuchMethod( - Invocation.getter(#onPlay), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onPlay), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onPlaying => (super.noSuchMethod( - Invocation.getter(#onPlaying), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onPlaying), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onRateChange => (super.noSuchMethod( - Invocation.getter(#onRateChange), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onRateChange), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onReset => (super.noSuchMethod( - Invocation.getter(#onReset), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onReset), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onResize => (super.noSuchMethod( - Invocation.getter(#onResize), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onResize), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onScroll => (super.noSuchMethod( - Invocation.getter(#onScroll), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onScroll), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onSearch => (super.noSuchMethod( - Invocation.getter(#onSearch), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onSearch), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onSeeked => (super.noSuchMethod( - Invocation.getter(#onSeeked), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onSeeked), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onSeeking => (super.noSuchMethod( - Invocation.getter(#onSeeking), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onSeeking), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onSelect => (super.noSuchMethod( - Invocation.getter(#onSelect), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onSelect), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onSelectStart => (super.noSuchMethod( - Invocation.getter(#onSelectStart), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onSelectStart), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onStalled => (super.noSuchMethod( - Invocation.getter(#onStalled), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onStalled), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onSubmit => (super.noSuchMethod( - Invocation.getter(#onSubmit), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onSubmit), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onSuspend => (super.noSuchMethod( - Invocation.getter(#onSuspend), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onSuspend), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onTimeUpdate => (super.noSuchMethod( - Invocation.getter(#onTimeUpdate), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onTimeUpdate), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.TouchEvent> get onTouchCancel => (super.noSuchMethod( - Invocation.getter(#onTouchCancel), - returnValue: _FakeElementStream_6<_i2.TouchEvent>( - this, - Invocation.getter(#onTouchCancel), - ), - ) as _i2.ElementStream<_i2.TouchEvent>); - - @override - _i2.ElementStream<_i2.TouchEvent> get onTouchEnd => (super.noSuchMethod( - Invocation.getter(#onTouchEnd), - returnValue: _FakeElementStream_6<_i2.TouchEvent>( - this, - Invocation.getter(#onTouchEnd), - ), - ) as _i2.ElementStream<_i2.TouchEvent>); - - @override - _i2.ElementStream<_i2.TouchEvent> get onTouchEnter => (super.noSuchMethod( - Invocation.getter(#onTouchEnter), - returnValue: _FakeElementStream_6<_i2.TouchEvent>( - this, - Invocation.getter(#onTouchEnter), - ), - ) as _i2.ElementStream<_i2.TouchEvent>); - - @override - _i2.ElementStream<_i2.TouchEvent> get onTouchLeave => (super.noSuchMethod( - Invocation.getter(#onTouchLeave), - returnValue: _FakeElementStream_6<_i2.TouchEvent>( - this, - Invocation.getter(#onTouchLeave), - ), - ) as _i2.ElementStream<_i2.TouchEvent>); - - @override - _i2.ElementStream<_i2.TouchEvent> get onTouchMove => (super.noSuchMethod( - Invocation.getter(#onTouchMove), - returnValue: _FakeElementStream_6<_i2.TouchEvent>( - this, - Invocation.getter(#onTouchMove), - ), - ) as _i2.ElementStream<_i2.TouchEvent>); - - @override - _i2.ElementStream<_i2.TouchEvent> get onTouchStart => (super.noSuchMethod( - Invocation.getter(#onTouchStart), - returnValue: _FakeElementStream_6<_i2.TouchEvent>( - this, - Invocation.getter(#onTouchStart), - ), - ) as _i2.ElementStream<_i2.TouchEvent>); - - @override - _i2.ElementStream<_i2.TransitionEvent> get onTransitionEnd => - (super.noSuchMethod( - Invocation.getter(#onTransitionEnd), - returnValue: _FakeElementStream_6<_i2.TransitionEvent>( - this, - Invocation.getter(#onTransitionEnd), - ), - ) as _i2.ElementStream<_i2.TransitionEvent>); - - @override - _i2.ElementStream<_i2.Event> get onVolumeChange => (super.noSuchMethod( - Invocation.getter(#onVolumeChange), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onVolumeChange), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onWaiting => (super.noSuchMethod( - Invocation.getter(#onWaiting), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onWaiting), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onFullscreenChange => (super.noSuchMethod( - Invocation.getter(#onFullscreenChange), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onFullscreenChange), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.Event> get onFullscreenError => (super.noSuchMethod( - Invocation.getter(#onFullscreenError), - returnValue: _FakeElementStream_6<_i2.Event>( - this, - Invocation.getter(#onFullscreenError), - ), - ) as _i2.ElementStream<_i2.Event>); - - @override - _i2.ElementStream<_i2.WheelEvent> get onWheel => (super.noSuchMethod( - Invocation.getter(#onWheel), - returnValue: _FakeElementStream_6<_i2.WheelEvent>( - this, - Invocation.getter(#onWheel), - ), - ) as _i2.ElementStream<_i2.WheelEvent>); - - @override - List<_i2.Node> get nodes => (super.noSuchMethod( - Invocation.getter(#nodes), - returnValue: <_i2.Node>[], - ) as List<_i2.Node>); - - @override - set nodes(Iterable<_i2.Node>? value) => super.noSuchMethod( - Invocation.setter( - #nodes, - value, - ), - returnValueForMissingStub: null, - ); - - @override - List<_i2.Node> get childNodes => (super.noSuchMethod( - Invocation.getter(#childNodes), - returnValue: <_i2.Node>[], - ) as List<_i2.Node>); - - @override - int get nodeType => (super.noSuchMethod( - Invocation.getter(#nodeType), - returnValue: 0, - ) as int); - - @override - set text(String? value) => super.noSuchMethod( - Invocation.setter( - #text, - value, - ), - returnValueForMissingStub: null, - ); - - @override - String? getAttribute(String? name) => (super.noSuchMethod(Invocation.method( - #getAttribute, - [name], - )) as String?); - - @override - String? getAttributeNS( - String? namespaceURI, - String? name, - ) => - (super.noSuchMethod(Invocation.method( - #getAttributeNS, - [ - namespaceURI, - name, - ], - )) as String?); - - @override - bool hasAttribute(String? name) => (super.noSuchMethod( - Invocation.method( - #hasAttribute, - [name], - ), - returnValue: false, - ) as bool); - - @override - bool hasAttributeNS( - String? namespaceURI, - String? name, - ) => - (super.noSuchMethod( - Invocation.method( - #hasAttributeNS, - [ - namespaceURI, - name, - ], - ), - returnValue: false, - ) as bool); - - @override - void removeAttribute(String? name) => super.noSuchMethod( - Invocation.method( - #removeAttribute, - [name], - ), - returnValueForMissingStub: null, - ); - - @override - void removeAttributeNS( - String? namespaceURI, - String? name, - ) => - super.noSuchMethod( - Invocation.method( - #removeAttributeNS, - [ - namespaceURI, - name, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setAttribute( - String? name, - Object? value, - ) => - super.noSuchMethod( - Invocation.method( - #setAttribute, - [ - name, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setAttributeNS( - String? namespaceURI, - String? name, - Object? value, - ) => - super.noSuchMethod( - Invocation.method( - #setAttributeNS, - [ - namespaceURI, - name, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i2.ElementList querySelectorAll( - String? selectors) => - (super.noSuchMethod( - Invocation.method( - #querySelectorAll, - [selectors], - ), - returnValue: _FakeElementList_7( - this, - Invocation.method( - #querySelectorAll, - [selectors], - ), - ), - ) as _i2.ElementList); - - @override - _i7.Future<_i2.ScrollState> setApplyScroll(String? nativeScrollBehavior) => - (super.noSuchMethod( - Invocation.method( - #setApplyScroll, - [nativeScrollBehavior], - ), - returnValue: _i7.Future<_i2.ScrollState>.value(_FakeScrollState_8( - this, - Invocation.method( - #setApplyScroll, - [nativeScrollBehavior], - ), - )), - ) as _i7.Future<_i2.ScrollState>); - - @override - _i7.Future<_i2.ScrollState> setDistributeScroll( - String? nativeScrollBehavior) => - (super.noSuchMethod( - Invocation.method( - #setDistributeScroll, - [nativeScrollBehavior], - ), - returnValue: _i7.Future<_i2.ScrollState>.value(_FakeScrollState_8( - this, - Invocation.method( - #setDistributeScroll, - [nativeScrollBehavior], - ), - )), - ) as _i7.Future<_i2.ScrollState>); - - @override - Map getNamespacedAttributes(String? namespace) => - (super.noSuchMethod( - Invocation.method( - #getNamespacedAttributes, - [namespace], - ), - returnValue: {}, - ) as Map); - - @override - _i2.CssStyleDeclaration getComputedStyle([String? pseudoElement]) => - (super.noSuchMethod( - Invocation.method( - #getComputedStyle, - [pseudoElement], - ), - returnValue: _FakeCssStyleDeclaration_5( - this, - Invocation.method( - #getComputedStyle, - [pseudoElement], - ), - ), - ) as _i2.CssStyleDeclaration); - - @override - void appendText(String? text) => super.noSuchMethod( - Invocation.method( - #appendText, - [text], - ), - returnValueForMissingStub: null, - ); - - @override - void appendHtml( - String? text, { - _i2.NodeValidator? validator, - _i2.NodeTreeSanitizer? treeSanitizer, - }) => - super.noSuchMethod( - Invocation.method( - #appendHtml, - [text], - { - #validator: validator, - #treeSanitizer: treeSanitizer, - }, - ), - returnValueForMissingStub: null, - ); - - @override - void attached() => super.noSuchMethod( - Invocation.method( - #attached, - [], - ), - returnValueForMissingStub: null, - ); - - @override - void detached() => super.noSuchMethod( - Invocation.method( - #detached, - [], - ), - returnValueForMissingStub: null, - ); - - @override - void enteredView() => super.noSuchMethod( - Invocation.method( - #enteredView, - [], - ), - returnValueForMissingStub: null, - ); - - @override - List<_i3.Rectangle> getClientRects() => (super.noSuchMethod( - Invocation.method( - #getClientRects, - [], - ), - returnValue: <_i3.Rectangle>[], - ) as List<_i3.Rectangle>); - - @override - void leftView() => super.noSuchMethod( - Invocation.method( - #leftView, - [], - ), - returnValueForMissingStub: null, - ); - - @override - _i2.Animation animate( - Iterable>? frames, [ - dynamic timing, - ]) => - (super.noSuchMethod( - Invocation.method( - #animate, - [ - frames, - timing, - ], - ), - returnValue: _FakeAnimation_9( - this, - Invocation.method( - #animate, - [ - frames, - timing, - ], - ), - ), - ) as _i2.Animation); - - @override - void attributeChanged( - String? name, - String? oldValue, - String? newValue, - ) => - super.noSuchMethod( - Invocation.method( - #attributeChanged, - [ - name, - oldValue, - newValue, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void scrollIntoView([_i2.ScrollAlignment? alignment]) => super.noSuchMethod( - Invocation.method( - #scrollIntoView, - [alignment], - ), - returnValueForMissingStub: null, - ); - - @override - void insertAdjacentText( - String? where, - String? text, - ) => - super.noSuchMethod( - Invocation.method( - #insertAdjacentText, - [ - where, - text, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void insertAdjacentHtml( - String? where, - String? html, { - _i2.NodeValidator? validator, - _i2.NodeTreeSanitizer? treeSanitizer, - }) => - super.noSuchMethod( - Invocation.method( - #insertAdjacentHtml, - [ - where, - html, - ], - { - #validator: validator, - #treeSanitizer: treeSanitizer, - }, - ), - returnValueForMissingStub: null, - ); - - @override - _i2.Element insertAdjacentElement( - String? where, - _i2.Element? element, - ) => - (super.noSuchMethod( - Invocation.method( - #insertAdjacentElement, - [ - where, - element, - ], - ), - returnValue: _FakeElement_10( - this, - Invocation.method( - #insertAdjacentElement, - [ - where, - element, - ], - ), - ), - ) as _i2.Element); - - @override - bool matches(String? selectors) => (super.noSuchMethod( - Invocation.method( - #matches, - [selectors], - ), - returnValue: false, - ) as bool); - - @override - bool matchesWithAncestors(String? selectors) => (super.noSuchMethod( - Invocation.method( - #matchesWithAncestors, - [selectors], - ), - returnValue: false, - ) as bool); - - @override - _i2.ShadowRoot createShadowRoot() => (super.noSuchMethod( - Invocation.method( - #createShadowRoot, - [], - ), - returnValue: _FakeShadowRoot_11( - this, - Invocation.method( - #createShadowRoot, - [], - ), - ), - ) as _i2.ShadowRoot); - - @override - _i3.Point offsetTo(_i2.Element? parent) => (super.noSuchMethod( - Invocation.method( - #offsetTo, - [parent], - ), - returnValue: _FakePoint_3( - this, - Invocation.method( - #offsetTo, - [parent], - ), - ), - ) as _i3.Point); - - @override - _i2.DocumentFragment createFragment( - String? html, { - _i2.NodeValidator? validator, - _i2.NodeTreeSanitizer? treeSanitizer, - }) => - (super.noSuchMethod( - Invocation.method( - #createFragment, - [html], - { - #validator: validator, - #treeSanitizer: treeSanitizer, - }, - ), - returnValue: _FakeDocumentFragment_12( - this, - Invocation.method( - #createFragment, - [html], - { - #validator: validator, - #treeSanitizer: treeSanitizer, - }, - ), - ), - ) as _i2.DocumentFragment); - - @override - void setInnerHtml( - String? html, { - _i2.NodeValidator? validator, - _i2.NodeTreeSanitizer? treeSanitizer, - }) => - super.noSuchMethod( - Invocation.method( - #setInnerHtml, - [html], - { - #validator: validator, - #treeSanitizer: treeSanitizer, - }, - ), - returnValueForMissingStub: null, - ); - - @override - _i7.Future requestFullscreen([Map? options]) => - (super.noSuchMethod( - Invocation.method( - #requestFullscreen, - [options], - ), - returnValue: _i7.Future.value(), - returnValueForMissingStub: _i7.Future.value(), - ) as _i7.Future); - - @override - void blur() => super.noSuchMethod( - Invocation.method( - #blur, - [], - ), - returnValueForMissingStub: null, - ); - - @override - void click() => super.noSuchMethod( - Invocation.method( - #click, - [], - ), - returnValueForMissingStub: null, - ); - - @override - void focus() => super.noSuchMethod( - Invocation.method( - #focus, - [], - ), - returnValueForMissingStub: null, - ); - - @override - _i2.ShadowRoot attachShadow(Map? shadowRootInitDict) => - (super.noSuchMethod( - Invocation.method( - #attachShadow, - [shadowRootInitDict], - ), - returnValue: _FakeShadowRoot_11( - this, - Invocation.method( - #attachShadow, - [shadowRootInitDict], - ), - ), - ) as _i2.ShadowRoot); - - @override - _i2.Element? closest(String? selectors) => - (super.noSuchMethod(Invocation.method( - #closest, - [selectors], - )) as _i2.Element?); - - @override - List<_i2.Animation> getAnimations() => (super.noSuchMethod( - Invocation.method( - #getAnimations, - [], - ), - returnValue: <_i2.Animation>[], - ) as List<_i2.Animation>); - - @override - List getAttributeNames() => (super.noSuchMethod( - Invocation.method( - #getAttributeNames, - [], - ), - returnValue: [], - ) as List); - - @override - _i3.Rectangle getBoundingClientRect() => (super.noSuchMethod( - Invocation.method( - #getBoundingClientRect, - [], - ), - returnValue: _FakeRectangle_1( - this, - Invocation.method( - #getBoundingClientRect, - [], - ), - ), - ) as _i3.Rectangle); - - @override - List<_i2.Node> getDestinationInsertionPoints() => (super.noSuchMethod( - Invocation.method( - #getDestinationInsertionPoints, - [], - ), - returnValue: <_i2.Node>[], - ) as List<_i2.Node>); - - @override - List<_i2.Node> getElementsByClassName(String? classNames) => - (super.noSuchMethod( - Invocation.method( - #getElementsByClassName, - [classNames], - ), - returnValue: <_i2.Node>[], - ) as List<_i2.Node>); - - @override - bool hasPointerCapture(int? pointerId) => (super.noSuchMethod( - Invocation.method( - #hasPointerCapture, - [pointerId], - ), - returnValue: false, - ) as bool); - - @override - void releasePointerCapture(int? pointerId) => super.noSuchMethod( - Invocation.method( - #releasePointerCapture, - [pointerId], - ), - returnValueForMissingStub: null, - ); - - @override - void requestPointerLock() => super.noSuchMethod( - Invocation.method( - #requestPointerLock, - [], - ), - returnValueForMissingStub: null, - ); - - @override - void scroll([ - dynamic options_OR_x, - num? y, - ]) => - super.noSuchMethod( - Invocation.method( - #scroll, - [ - options_OR_x, - y, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void scrollBy([ - dynamic options_OR_x, - num? y, - ]) => - super.noSuchMethod( - Invocation.method( - #scrollBy, - [ - options_OR_x, - y, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void scrollIntoViewIfNeeded([bool? centerIfNeeded]) => super.noSuchMethod( - Invocation.method( - #scrollIntoViewIfNeeded, - [centerIfNeeded], - ), - returnValueForMissingStub: null, - ); - - @override - void scrollTo([ - dynamic options_OR_x, - num? y, - ]) => - super.noSuchMethod( - Invocation.method( - #scrollTo, - [ - options_OR_x, - y, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setPointerCapture(int? pointerId) => super.noSuchMethod( - Invocation.method( - #setPointerCapture, - [pointerId], - ), - returnValueForMissingStub: null, - ); - - @override - void after(Object? nodes) => super.noSuchMethod( - Invocation.method( - #after, - [nodes], - ), - returnValueForMissingStub: null, - ); - - @override - void before(Object? nodes) => super.noSuchMethod( - Invocation.method( - #before, - [nodes], - ), - returnValueForMissingStub: null, - ); - - @override - _i2.Element? querySelector(String? selectors) => - (super.noSuchMethod(Invocation.method( - #querySelector, - [selectors], - )) as _i2.Element?); - - @override - void remove() => super.noSuchMethod( - Invocation.method( - #remove, - [], - ), - returnValueForMissingStub: null, - ); - - @override - _i2.Node replaceWith(_i2.Node? otherNode) => (super.noSuchMethod( - Invocation.method( - #replaceWith, - [otherNode], - ), - returnValue: _FakeNode_13( - this, - Invocation.method( - #replaceWith, - [otherNode], - ), - ), - ) as _i2.Node); - - @override - void insertAllBefore( - Iterable<_i2.Node>? newNodes, - _i2.Node? child, - ) => - super.noSuchMethod( - Invocation.method( - #insertAllBefore, - [ - newNodes, - child, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i2.Node append(_i2.Node? node) => (super.noSuchMethod( - Invocation.method( - #append, - [node], - ), - returnValue: _FakeNode_13( - this, - Invocation.method( - #append, - [node], - ), - ), - ) as _i2.Node); - - @override - _i2.Node clone(bool? deep) => (super.noSuchMethod( - Invocation.method( - #clone, - [deep], - ), - returnValue: _FakeNode_13( - this, - Invocation.method( - #clone, - [deep], - ), - ), - ) as _i2.Node); - - @override - bool contains(_i2.Node? other) => (super.noSuchMethod( - Invocation.method( - #contains, - [other], - ), - returnValue: false, - ) as bool); - - @override - _i2.Node getRootNode([Map? options]) => (super.noSuchMethod( - Invocation.method( - #getRootNode, - [options], - ), - returnValue: _FakeNode_13( - this, - Invocation.method( - #getRootNode, - [options], - ), - ), - ) as _i2.Node); - - @override - bool hasChildNodes() => (super.noSuchMethod( - Invocation.method( - #hasChildNodes, - [], - ), - returnValue: false, - ) as bool); - - @override - _i2.Node insertBefore( - _i2.Node? node, - _i2.Node? child, - ) => - (super.noSuchMethod( - Invocation.method( - #insertBefore, - [ - node, - child, - ], - ), - returnValue: _FakeNode_13( - this, - Invocation.method( - #insertBefore, - [ - node, - child, - ], - ), - ), - ) as _i2.Node); - - @override - void addEventListener( - String? type, - _i2.EventListener? listener, [ - bool? useCapture, - ]) => - super.noSuchMethod( - Invocation.method( - #addEventListener, - [ - type, - listener, - useCapture, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void removeEventListener( - String? type, - _i2.EventListener? listener, [ - bool? useCapture, - ]) => - super.noSuchMethod( - Invocation.method( - #removeEventListener, - [ - type, - listener, - useCapture, - ], - ), - returnValueForMissingStub: null, - ); - - @override - bool dispatchEvent(_i2.Event? event) => (super.noSuchMethod( - Invocation.method( - #dispatchEvent, - [event], - ), - returnValue: false, - ) as bool); -} - -/// A class which mocks [BuildContext]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockBuildContext extends _i1.Mock implements _i4.BuildContext { - MockBuildContext() { - _i1.throwOnMissingStub(this); - } - - @override - _i4.Widget get widget => (super.noSuchMethod( - Invocation.getter(#widget), - returnValue: _FakeWidget_14( - this, - Invocation.getter(#widget), - ), - ) as _i4.Widget); - - @override - bool get mounted => (super.noSuchMethod( - Invocation.getter(#mounted), - returnValue: false, - ) as bool); - - @override - bool get debugDoingBuild => (super.noSuchMethod( - Invocation.getter(#debugDoingBuild), - returnValue: false, - ) as bool); - - @override - _i4.InheritedWidget dependOnInheritedElement( - _i4.InheritedElement? ancestor, { - Object? aspect, - }) => - (super.noSuchMethod( - Invocation.method( - #dependOnInheritedElement, - [ancestor], - {#aspect: aspect}, - ), - returnValue: _FakeInheritedWidget_15( - this, - Invocation.method( - #dependOnInheritedElement, - [ancestor], - {#aspect: aspect}, - ), - ), - ) as _i4.InheritedWidget); - - @override - void visitAncestorElements(_i4.ConditionalElementVisitor? visitor) => - super.noSuchMethod( - Invocation.method( - #visitAncestorElements, - [visitor], - ), - returnValueForMissingStub: null, - ); - - @override - void visitChildElements(_i4.ElementVisitor? visitor) => super.noSuchMethod( - Invocation.method( - #visitChildElements, - [visitor], - ), - returnValueForMissingStub: null, - ); - - @override - void dispatchNotification(_i8.Notification? notification) => - super.noSuchMethod( - Invocation.method( - #dispatchNotification, - [notification], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.DiagnosticsNode describeElement( - String? name, { - _i5.DiagnosticsTreeStyle? style = _i5.DiagnosticsTreeStyle.errorProperty, - }) => - (super.noSuchMethod( - Invocation.method( - #describeElement, - [name], - {#style: style}, - ), - returnValue: _FakeDiagnosticsNode_16( - this, - Invocation.method( - #describeElement, - [name], - {#style: style}, - ), - ), - ) as _i5.DiagnosticsNode); - - @override - _i5.DiagnosticsNode describeWidget( - String? name, { - _i5.DiagnosticsTreeStyle? style = _i5.DiagnosticsTreeStyle.errorProperty, - }) => - (super.noSuchMethod( - Invocation.method( - #describeWidget, - [name], - {#style: style}, - ), - returnValue: _FakeDiagnosticsNode_16( - this, - Invocation.method( - #describeWidget, - [name], - {#style: style}, - ), - ), - ) as _i5.DiagnosticsNode); - - @override - List<_i5.DiagnosticsNode> describeMissingAncestor( - {required Type? expectedAncestorType}) => - (super.noSuchMethod( - Invocation.method( - #describeMissingAncestor, - [], - {#expectedAncestorType: expectedAncestorType}, - ), - returnValue: <_i5.DiagnosticsNode>[], - ) as List<_i5.DiagnosticsNode>); - - @override - _i5.DiagnosticsNode describeOwnershipChain(String? name) => - (super.noSuchMethod( - Invocation.method( - #describeOwnershipChain, - [name], - ), - returnValue: _FakeDiagnosticsNode_16( - this, - Invocation.method( - #describeOwnershipChain, - [name], - ), - ), - ) as _i5.DiagnosticsNode); -} - -/// A class which mocks [CreationParams]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockCreationParams extends _i1.Mock implements _i9.CreationParams { - MockCreationParams() { - _i1.throwOnMissingStub(this); - } - - @override - Set get javascriptChannelNames => (super.noSuchMethod( - Invocation.getter(#javascriptChannelNames), - returnValue: {}, - ) as Set); - - @override - _i9.AutoMediaPlaybackPolicy get autoMediaPlaybackPolicy => - (super.noSuchMethod( - Invocation.getter(#autoMediaPlaybackPolicy), - returnValue: - _i9.AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, - ) as _i9.AutoMediaPlaybackPolicy); - - @override - List<_i9.WebViewCookie> get cookies => (super.noSuchMethod( - Invocation.getter(#cookies), - returnValue: <_i9.WebViewCookie>[], - ) as List<_i9.WebViewCookie>); -} - -/// A class which mocks [WebViewPlatformCallbacksHandler]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockWebViewPlatformCallbacksHandler extends _i1.Mock - implements _i10.WebViewPlatformCallbacksHandler { - MockWebViewPlatformCallbacksHandler() { - _i1.throwOnMissingStub(this); - } - - @override - _i7.FutureOr onNavigationRequest({ - required String? url, - required bool? isForMainFrame, - }) => - (super.noSuchMethod( - Invocation.method( - #onNavigationRequest, - [], - { - #url: url, - #isForMainFrame: isForMainFrame, - }, - ), - returnValue: _i7.Future.value(false), - ) as _i7.FutureOr); - - @override - void onPageStarted(String? url) => super.noSuchMethod( - Invocation.method( - #onPageStarted, - [url], - ), - returnValueForMissingStub: null, - ); - - @override - void onPageFinished(String? url) => super.noSuchMethod( - Invocation.method( - #onPageFinished, - [url], - ), - returnValueForMissingStub: null, - ); - - @override - void onProgress(int? progress) => super.noSuchMethod( - Invocation.method( - #onProgress, - [progress], - ), - returnValueForMissingStub: null, - ); - - @override - void onWebResourceError(_i9.WebResourceError? error) => super.noSuchMethod( - Invocation.method( - #onWebResourceError, - [error], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [HttpRequestFactory]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockHttpRequestFactory extends _i1.Mock - implements _i11.HttpRequestFactory { - MockHttpRequestFactory() { - _i1.throwOnMissingStub(this); - } - - @override - _i7.Future<_i2.HttpRequest> request( - String? url, { - String? method, - bool? withCredentials, - String? responseType, - String? mimeType, - Map? requestHeaders, - dynamic sendData, - void Function(_i2.ProgressEvent)? onProgress, - }) => - (super.noSuchMethod( - Invocation.method( - #request, - [url], - { - #method: method, - #withCredentials: withCredentials, - #responseType: responseType, - #mimeType: mimeType, - #requestHeaders: requestHeaders, - #sendData: sendData, - #onProgress: onProgress, - }, - ), - returnValue: _i7.Future<_i2.HttpRequest>.value(_FakeHttpRequest_17( - this, - Invocation.method( - #request, - [url], - { - #method: method, - #withCredentials: withCredentials, - #responseType: responseType, - #mimeType: mimeType, - #requestHeaders: requestHeaders, - #sendData: sendData, - #onProgress: onProgress, - }, - ), - )), - ) as _i7.Future<_i2.HttpRequest>); -} - -/// A class which mocks [HttpRequest]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockHttpRequest extends _i1.Mock implements _i2.HttpRequest { - MockHttpRequest() { - _i1.throwOnMissingStub(this); - } - - @override - Map get responseHeaders => (super.noSuchMethod( - Invocation.getter(#responseHeaders), - returnValue: {}, - ) as Map); - - @override - int get readyState => (super.noSuchMethod( - Invocation.getter(#readyState), - returnValue: 0, - ) as int); - - @override - String get responseType => (super.noSuchMethod( - Invocation.getter(#responseType), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#responseType), - ), - ) as String); - - @override - set responseType(String? value) => super.noSuchMethod( - Invocation.setter( - #responseType, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set timeout(int? value) => super.noSuchMethod( - Invocation.setter( - #timeout, - value, - ), - returnValueForMissingStub: null, - ); - - @override - _i2.HttpRequestUpload get upload => (super.noSuchMethod( - Invocation.getter(#upload), - returnValue: _FakeHttpRequestUpload_18( - this, - Invocation.getter(#upload), - ), - ) as _i2.HttpRequestUpload); - - @override - set withCredentials(bool? value) => super.noSuchMethod( - Invocation.setter( - #withCredentials, - value, - ), - returnValueForMissingStub: null, - ); - - @override - _i7.Stream<_i2.Event> get onReadyStateChange => (super.noSuchMethod( - Invocation.getter(#onReadyStateChange), - returnValue: _i7.Stream<_i2.Event>.empty(), - ) as _i7.Stream<_i2.Event>); - - @override - _i7.Stream<_i2.ProgressEvent> get onAbort => (super.noSuchMethod( - Invocation.getter(#onAbort), - returnValue: _i7.Stream<_i2.ProgressEvent>.empty(), - ) as _i7.Stream<_i2.ProgressEvent>); - - @override - _i7.Stream<_i2.ProgressEvent> get onError => (super.noSuchMethod( - Invocation.getter(#onError), - returnValue: _i7.Stream<_i2.ProgressEvent>.empty(), - ) as _i7.Stream<_i2.ProgressEvent>); - - @override - _i7.Stream<_i2.ProgressEvent> get onLoad => (super.noSuchMethod( - Invocation.getter(#onLoad), - returnValue: _i7.Stream<_i2.ProgressEvent>.empty(), - ) as _i7.Stream<_i2.ProgressEvent>); - - @override - _i7.Stream<_i2.ProgressEvent> get onLoadEnd => (super.noSuchMethod( - Invocation.getter(#onLoadEnd), - returnValue: _i7.Stream<_i2.ProgressEvent>.empty(), - ) as _i7.Stream<_i2.ProgressEvent>); - - @override - _i7.Stream<_i2.ProgressEvent> get onLoadStart => (super.noSuchMethod( - Invocation.getter(#onLoadStart), - returnValue: _i7.Stream<_i2.ProgressEvent>.empty(), - ) as _i7.Stream<_i2.ProgressEvent>); - - @override - _i7.Stream<_i2.ProgressEvent> get onProgress => (super.noSuchMethod( - Invocation.getter(#onProgress), - returnValue: _i7.Stream<_i2.ProgressEvent>.empty(), - ) as _i7.Stream<_i2.ProgressEvent>); - - @override - _i7.Stream<_i2.ProgressEvent> get onTimeout => (super.noSuchMethod( - Invocation.getter(#onTimeout), - returnValue: _i7.Stream<_i2.ProgressEvent>.empty(), - ) as _i7.Stream<_i2.ProgressEvent>); - - @override - _i2.Events get on => (super.noSuchMethod( - Invocation.getter(#on), - returnValue: _FakeEvents_19( - this, - Invocation.getter(#on), - ), - ) as _i2.Events); - - @override - void open( - String? method, - String? url, { - bool? async, - String? user, - String? password, - }) => - super.noSuchMethod( - Invocation.method( - #open, - [ - method, - url, - ], - { - #async: async, - #user: user, - #password: password, - }, - ), - returnValueForMissingStub: null, - ); - - @override - void abort() => super.noSuchMethod( - Invocation.method( - #abort, - [], - ), - returnValueForMissingStub: null, - ); - - @override - String getAllResponseHeaders() => (super.noSuchMethod( - Invocation.method( - #getAllResponseHeaders, - [], - ), - returnValue: _i6.dummyValue( - this, - Invocation.method( - #getAllResponseHeaders, - [], - ), - ), - ) as String); - - @override - String? getResponseHeader(String? name) => - (super.noSuchMethod(Invocation.method( - #getResponseHeader, - [name], - )) as String?); - - @override - void overrideMimeType(String? mime) => super.noSuchMethod( - Invocation.method( - #overrideMimeType, - [mime], - ), - returnValueForMissingStub: null, - ); - - @override - void send([dynamic body_OR_data]) => super.noSuchMethod( - Invocation.method( - #send, - [body_OR_data], - ), - returnValueForMissingStub: null, - ); - - @override - void setRequestHeader( - String? name, - String? value, - ) => - super.noSuchMethod( - Invocation.method( - #setRequestHeader, - [ - name, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void addEventListener( - String? type, - _i2.EventListener? listener, [ - bool? useCapture, - ]) => - super.noSuchMethod( - Invocation.method( - #addEventListener, - [ - type, - listener, - useCapture, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void removeEventListener( - String? type, - _i2.EventListener? listener, [ - bool? useCapture, - ]) => - super.noSuchMethod( - Invocation.method( - #removeEventListener, - [ - type, - listener, - useCapture, - ], - ), - returnValueForMissingStub: null, - ); - - @override - bool dispatchEvent(_i2.Event? event) => (super.noSuchMethod( - Invocation.method( - #dispatchEvent, - [event], - ), - returnValue: false, - ) as bool); -} diff --git a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart deleted file mode 100644 index 52e6e15aeb0..00000000000 --- a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart +++ /dev/null @@ -1,406 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in webview_flutter_web/test/web_webview_controller_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; -import 'dart:html' as _i2; - -import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i3; -import 'package:webview_flutter_web/src/http_request_factory.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 -// ignore_for_file: deprecated_member_use -// ignore_for_file: deprecated_member_use_from_same_package -// 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 _FakeHttpRequestUpload_0 extends _i1.SmartFake - implements _i2.HttpRequestUpload { - _FakeHttpRequestUpload_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeEvents_1 extends _i1.SmartFake implements _i2.Events { - _FakeEvents_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeHttpRequest_2 extends _i1.SmartFake implements _i2.HttpRequest { - _FakeHttpRequest_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [HttpRequest]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockHttpRequest extends _i1.Mock implements _i2.HttpRequest { - @override - Map get responseHeaders => (super.noSuchMethod( - Invocation.getter(#responseHeaders), - returnValue: {}, - returnValueForMissingStub: {}, - ) as Map); - - @override - int get readyState => (super.noSuchMethod( - Invocation.getter(#readyState), - returnValue: 0, - returnValueForMissingStub: 0, - ) as int); - - @override - String get responseType => (super.noSuchMethod( - Invocation.getter(#responseType), - returnValue: _i3.dummyValue( - this, - Invocation.getter(#responseType), - ), - returnValueForMissingStub: _i3.dummyValue( - this, - Invocation.getter(#responseType), - ), - ) as String); - - @override - set responseType(String? value) => super.noSuchMethod( - Invocation.setter( - #responseType, - value, - ), - returnValueForMissingStub: null, - ); - - @override - set timeout(int? value) => super.noSuchMethod( - Invocation.setter( - #timeout, - value, - ), - returnValueForMissingStub: null, - ); - - @override - _i2.HttpRequestUpload get upload => (super.noSuchMethod( - Invocation.getter(#upload), - returnValue: _FakeHttpRequestUpload_0( - this, - Invocation.getter(#upload), - ), - returnValueForMissingStub: _FakeHttpRequestUpload_0( - this, - Invocation.getter(#upload), - ), - ) as _i2.HttpRequestUpload); - - @override - set withCredentials(bool? value) => super.noSuchMethod( - Invocation.setter( - #withCredentials, - value, - ), - returnValueForMissingStub: null, - ); - - @override - _i4.Stream<_i2.Event> get onReadyStateChange => (super.noSuchMethod( - Invocation.getter(#onReadyStateChange), - returnValue: _i4.Stream<_i2.Event>.empty(), - returnValueForMissingStub: _i4.Stream<_i2.Event>.empty(), - ) as _i4.Stream<_i2.Event>); - - @override - _i4.Stream<_i2.ProgressEvent> get onAbort => (super.noSuchMethod( - Invocation.getter(#onAbort), - returnValue: _i4.Stream<_i2.ProgressEvent>.empty(), - returnValueForMissingStub: _i4.Stream<_i2.ProgressEvent>.empty(), - ) as _i4.Stream<_i2.ProgressEvent>); - - @override - _i4.Stream<_i2.ProgressEvent> get onError => (super.noSuchMethod( - Invocation.getter(#onError), - returnValue: _i4.Stream<_i2.ProgressEvent>.empty(), - returnValueForMissingStub: _i4.Stream<_i2.ProgressEvent>.empty(), - ) as _i4.Stream<_i2.ProgressEvent>); - - @override - _i4.Stream<_i2.ProgressEvent> get onLoad => (super.noSuchMethod( - Invocation.getter(#onLoad), - returnValue: _i4.Stream<_i2.ProgressEvent>.empty(), - returnValueForMissingStub: _i4.Stream<_i2.ProgressEvent>.empty(), - ) as _i4.Stream<_i2.ProgressEvent>); - - @override - _i4.Stream<_i2.ProgressEvent> get onLoadEnd => (super.noSuchMethod( - Invocation.getter(#onLoadEnd), - returnValue: _i4.Stream<_i2.ProgressEvent>.empty(), - returnValueForMissingStub: _i4.Stream<_i2.ProgressEvent>.empty(), - ) as _i4.Stream<_i2.ProgressEvent>); - - @override - _i4.Stream<_i2.ProgressEvent> get onLoadStart => (super.noSuchMethod( - Invocation.getter(#onLoadStart), - returnValue: _i4.Stream<_i2.ProgressEvent>.empty(), - returnValueForMissingStub: _i4.Stream<_i2.ProgressEvent>.empty(), - ) as _i4.Stream<_i2.ProgressEvent>); - - @override - _i4.Stream<_i2.ProgressEvent> get onProgress => (super.noSuchMethod( - Invocation.getter(#onProgress), - returnValue: _i4.Stream<_i2.ProgressEvent>.empty(), - returnValueForMissingStub: _i4.Stream<_i2.ProgressEvent>.empty(), - ) as _i4.Stream<_i2.ProgressEvent>); - - @override - _i4.Stream<_i2.ProgressEvent> get onTimeout => (super.noSuchMethod( - Invocation.getter(#onTimeout), - returnValue: _i4.Stream<_i2.ProgressEvent>.empty(), - returnValueForMissingStub: _i4.Stream<_i2.ProgressEvent>.empty(), - ) as _i4.Stream<_i2.ProgressEvent>); - - @override - _i2.Events get on => (super.noSuchMethod( - Invocation.getter(#on), - returnValue: _FakeEvents_1( - this, - Invocation.getter(#on), - ), - returnValueForMissingStub: _FakeEvents_1( - this, - Invocation.getter(#on), - ), - ) as _i2.Events); - - @override - void open( - String? method, - String? url, { - bool? async, - String? user, - String? password, - }) => - super.noSuchMethod( - Invocation.method( - #open, - [ - method, - url, - ], - { - #async: async, - #user: user, - #password: password, - }, - ), - returnValueForMissingStub: null, - ); - - @override - void abort() => super.noSuchMethod( - Invocation.method( - #abort, - [], - ), - returnValueForMissingStub: null, - ); - - @override - String getAllResponseHeaders() => (super.noSuchMethod( - Invocation.method( - #getAllResponseHeaders, - [], - ), - returnValue: _i3.dummyValue( - this, - Invocation.method( - #getAllResponseHeaders, - [], - ), - ), - returnValueForMissingStub: _i3.dummyValue( - this, - Invocation.method( - #getAllResponseHeaders, - [], - ), - ), - ) as String); - - @override - String? getResponseHeader(String? name) => (super.noSuchMethod( - Invocation.method( - #getResponseHeader, - [name], - ), - returnValueForMissingStub: null, - ) as String?); - - @override - void overrideMimeType(String? mime) => super.noSuchMethod( - Invocation.method( - #overrideMimeType, - [mime], - ), - returnValueForMissingStub: null, - ); - - @override - void send([dynamic body_OR_data]) => super.noSuchMethod( - Invocation.method( - #send, - [body_OR_data], - ), - returnValueForMissingStub: null, - ); - - @override - void setRequestHeader( - String? name, - String? value, - ) => - super.noSuchMethod( - Invocation.method( - #setRequestHeader, - [ - name, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void addEventListener( - String? type, - _i2.EventListener? listener, [ - bool? useCapture, - ]) => - super.noSuchMethod( - Invocation.method( - #addEventListener, - [ - type, - listener, - useCapture, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void removeEventListener( - String? type, - _i2.EventListener? listener, [ - bool? useCapture, - ]) => - super.noSuchMethod( - Invocation.method( - #removeEventListener, - [ - type, - listener, - useCapture, - ], - ), - returnValueForMissingStub: null, - ); - - @override - bool dispatchEvent(_i2.Event? event) => (super.noSuchMethod( - Invocation.method( - #dispatchEvent, - [event], - ), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); -} - -/// A class which mocks [HttpRequestFactory]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockHttpRequestFactory extends _i1.Mock - implements _i5.HttpRequestFactory { - @override - _i4.Future<_i2.HttpRequest> request( - String? url, { - String? method, - bool? withCredentials, - String? responseType, - String? mimeType, - Map? requestHeaders, - dynamic sendData, - void Function(_i2.ProgressEvent)? onProgress, - }) => - (super.noSuchMethod( - Invocation.method( - #request, - [url], - { - #method: method, - #withCredentials: withCredentials, - #responseType: responseType, - #mimeType: mimeType, - #requestHeaders: requestHeaders, - #sendData: sendData, - #onProgress: onProgress, - }, - ), - returnValue: _i4.Future<_i2.HttpRequest>.value(_FakeHttpRequest_2( - this, - Invocation.method( - #request, - [url], - { - #method: method, - #withCredentials: withCredentials, - #responseType: responseType, - #mimeType: mimeType, - #requestHeaders: requestHeaders, - #sendData: sendData, - #onProgress: onProgress, - }, - ), - )), - returnValueForMissingStub: - _i4.Future<_i2.HttpRequest>.value(_FakeHttpRequest_2( - this, - Invocation.method( - #request, - [url], - { - #method: method, - #withCredentials: withCredentials, - #responseType: responseType, - #mimeType: mimeType, - #requestHeaders: requestHeaders, - #sendData: sendData, - #onProgress: onProgress, - }, - ), - )), - ) as _i4.Future<_i2.HttpRequest>); -} From 5775d2e445a727aa5d90e7bbe4aa795ffa01a602 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Thu, 23 May 2024 21:26:31 +0200 Subject: [PATCH 02/20] Attempt to fix tests --- .../lib/src/http_request_factory.dart | 49 +- .../lib/src/web_webview_controller.dart | 10 +- .../lib/src/webview_flutter_web_legacy.dart | 18 +- .../webview_flutter_web/pubspec.yaml | 1 + .../test/legacy/webview_flutter_web_test.dart | 49 +- .../webview_flutter_web_test.mocks.dart | 432 ++++++++++++++++++ .../test/web_webview_controller_test.dart | 43 +- .../web_webview_controller_test.mocks.dart | 142 ++++++ 8 files changed, 677 insertions(+), 67 deletions(-) create mode 100644 packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart create mode 100644 packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart index df3a9d7e510..df695093ae2 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart @@ -1,7 +1,10 @@ // 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 'package:web/web.dart'; +import 'dart:typed_data'; + +import 'package:http/browser_client.dart'; +import 'package:http/http.dart' as http; /// Factory class for creating [HttpRequest] instances. class HttpRequestFactory { @@ -60,21 +63,33 @@ class HttpRequestFactory { /// when the file cannot be found. /// /// See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access_authentication). - Future request(String url, - {String? method, - bool? withCredentials, - String? responseType, - String? mimeType, - Map? requestHeaders, - dynamic sendData, - void Function(ProgressEvent e)? onProgress}) { - return HttpRequest.request(url, - method: method, - withCredentials: withCredentials, - responseType: responseType, - mimeType: mimeType, - requestHeaders: requestHeaders, - sendData: sendData, - onProgress: onProgress); + Future request( + String url, { + String? method, + bool? withCredentials, + String? mimeType, + Map? requestHeaders, + Uint8List? sendData, + }) { + final BrowserClient client = BrowserClient(); + if (withCredentials != null) { + client.withCredentials = withCredentials; + } + + final http.Request request = http.Request(method ?? 'GET', Uri.parse(url)); + + if (sendData != null) { + request.bodyBytes = sendData.toList(); + } + + if (mimeType != null) { + request.headers['content-type'] = mimeType; + } + + if (requestHeaders != null) { + request.headers.addAll(requestHeaders); + } + + return client.send(request); } } diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart index dcff6443a4a..9491141d764 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart @@ -7,6 +7,7 @@ import 'dart:ui_web' as ui_web; import 'package:flutter/cupertino.dart'; import 'package:web/web.dart' as html; +import 'package:http/http.dart' as http; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'content_type.dart'; @@ -86,7 +87,7 @@ class WebWebViewController extends PlatformWebViewController { /// Performs an AJAX request defined by [params]. Future _updateIFrameFromXhr(LoadRequestParams params) async { - final html.XMLHttpRequest httpReq = + final http.StreamedResponse httpReq = await _webWebViewParams.httpRequestFactory.request( params.uri.toString(), method: params.method.serialize(), @@ -94,14 +95,15 @@ class WebWebViewController extends PlatformWebViewController { sendData: params.body, ); - final String header = - httpReq.getResponseHeader('content-type') ?? 'text/html'; + final String header = httpReq.headers['content-type'] ?? 'text/html'; final ContentType contentType = ContentType.parse(header); final Encoding encoding = Encoding.getByName(contentType.charset) ?? utf8; + final http.Response response = await http.Response.fromStream(httpReq); + // ignore: unsafe_html _webWebViewParams.iFrame.src = Uri.dataFromString( - httpReq.responseText, + response.body, mimeType: contentType.mimeType, encoding: encoding, ).toString(); diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart index cfbb7e8a8ed..853a22444f7 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart @@ -10,7 +10,9 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; +import 'package:http/src/streamed_response.dart'; import 'package:web/web.dart' as html; +import 'package:http/http.dart' as http; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; @@ -46,8 +48,8 @@ class WebWebViewPlatform implements WebViewPlatform { if (onWebViewPlatformCreated == null) { return; } - final html.HTMLIFrameElement element = - html.document.getElementById('webview-$viewId')! as html.HTMLIFrameElement; + final html.HTMLIFrameElement element = html.document + .getElementById('webview-$viewId')! as html.HTMLIFrameElement; final String? initialUrl = creationParams.initialUrl; if (initialUrl != null) { @@ -202,16 +204,18 @@ class WebWebViewPlatformController implements WebViewPlatformController { if (!request.uri.hasScheme) { throw ArgumentError('WebViewRequest#uri is required to have a scheme.'); } - final html.XMLHttpRequest httpReq = await _httpRequestFactory.request( + final http.StreamedResponse httpReq = await _httpRequestFactory.request( request.uri.toString(), method: request.method.serialize(), requestHeaders: request.headers, sendData: request.body); - final String contentType = - httpReq.getResponseHeader('content-type') ?? 'text/html'; - // ignore: unsafe_html + + final String contentType = httpReq.headers['content-type'] ?? 'text/html'; + + final http.Response response = await http.Response.fromStream(httpReq); + _element.src = Uri.dataFromString( - httpReq.responseText, + response.body, mimeType: contentType, encoding: utf8, ).toString(); diff --git a/packages/webview_flutter/webview_flutter_web/pubspec.yaml b/packages/webview_flutter/webview_flutter_web/pubspec.yaml index 7d0bfc00343..1264186bdfd 100644 --- a/packages/webview_flutter/webview_flutter_web/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_web/pubspec.yaml @@ -21,6 +21,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter + http: ^1.2.1 web: ^0.5.1 webview_flutter_platform_interface: ^2.0.0 diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart index 3bb069f317e..563fc42f658 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - -import 'package:web/helpers.dart'; -import 'package:web/web.dart' as html; import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart' as http; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; +import 'package:web/web.dart' as html; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; import 'package:webview_flutter_web/src/http_request_factory.dart'; import 'package:webview_flutter_web/src/webview_flutter_web_legacy.dart'; @@ -23,7 +22,7 @@ import 'webview_flutter_web_test.mocks.dart'; CreationParams, WebViewPlatformCallbacksHandler, HttpRequestFactory, - html.XMLHttpRequest, + http.StreamedResponse, ]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -47,7 +46,7 @@ void main() { group('WebWebViewPlatformController', () { test('loadUrl sets url on iframe src attribute', () { // Setup - final MockIFrameElement mockElement = MockIFrameElement(); + final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -61,7 +60,7 @@ void main() { group('loadHtmlString', () { test('loadHtmlString loads html into iframe', () { // Setup - final MockIFrameElement mockElement = MockIFrameElement(); + final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -75,7 +74,7 @@ void main() { test('loadHtmlString escapes "#" correctly', () { // Setup - final MockIFrameElement mockElement = MockIFrameElement(); + final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -83,14 +82,14 @@ void main() { // Run controller.loadHtmlString('#'); // Verify - verify(mockElement.src = argThat(contains('%23'))); + verify(mockElement.src = argThat(contains('%23')) ?? ''); }); }); group('loadRequest', () { test('loadRequest throws ArgumentError on missing scheme', () { // Setup - final MockIFrameElement mockElement = MockIFrameElement(); + final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -109,15 +108,17 @@ void main() { test('loadRequest makes request and loads response into iframe', () async { // Setup - final MockIFrameElement mockElement = MockIFrameElement(); + final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, ); - final MockHttpRequest mockHttpRequest = MockHttpRequest(); - when(mockHttpRequest.getResponseHeader('content-type')) - .thenReturn('text/plain'); - when(mockHttpRequest.responseText).thenReturn('test data'); + final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + when(mockHttpRequest.headers['content-type']).thenReturn('text/plain'); + + final http.Response res = + await http.Response.fromStream(mockHttpRequest); + when(res.body).thenReturn('test data'); final MockHttpRequestFactory mockHttpRequestFactory = MockHttpRequestFactory(); when(mockHttpRequestFactory.request( @@ -125,7 +126,8 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer( + (_) => Future.value(mockHttpRequest)); controller.httpRequestFactory = mockHttpRequestFactory; // Run await controller.loadRequest( @@ -148,15 +150,17 @@ void main() { test('loadRequest escapes "#" correctly', () async { // Setup - final MockIFrameElement mockElement = MockIFrameElement(); + final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, ); - final MockHttpRequest mockHttpRequest = MockHttpRequest(); - when(mockHttpRequest.getResponseHeader('content-type')) - .thenReturn('text/html'); - when(mockHttpRequest.responseText).thenReturn('#'); + final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + when(mockHttpRequest.headers['content-type']).thenReturn('text/html'); + + final http.Response res = + await http.Response.fromStream(mockHttpRequest); + when(res.body).thenReturn('#'); final MockHttpRequestFactory mockHttpRequestFactory = MockHttpRequestFactory(); when(mockHttpRequestFactory.request( @@ -164,7 +168,8 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer( + (_) => Future.value(mockHttpRequest)); controller.httpRequestFactory = mockHttpRequestFactory; // Run await controller.loadRequest( @@ -175,7 +180,7 @@ void main() { headers: {'Foo': 'Bar'}), ); // Verify - verify(mockElement.src = argThat(contains('%23'))); + verify(mockElement.src = argThat(contains('%23')) ?? ''); }); }); }); diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart new file mode 100644 index 00000000000..abeee5ed047 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart @@ -0,0 +1,432 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in webview_flutter_web/test/legacy/webview_flutter_web_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:_js_types' as _i5; +import 'dart:async' as _i9; +import 'dart:typed_data' as _i11; + +import 'package:flutter/foundation.dart' as _i3; +import 'package:flutter/src/widgets/notification_listener.dart' as _i6; +import 'package:flutter/widgets.dart' as _i2; +import 'package:http/http.dart' as _i4; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i12; +import 'package:webview_flutter_platform_interface/src/legacy/platform_interface/webview_platform_callbacks_handler.dart' + as _i8; +import 'package:webview_flutter_platform_interface/src/legacy/types/types.dart' + as _i7; +import 'package:webview_flutter_web/src/http_request_factory.dart' as _i10; + +// 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: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// 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 _FakeWidget_0 extends _i1.SmartFake implements _i2.Widget { + _FakeWidget_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); + + @override + String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) => + super.toString(); +} + +class _FakeInheritedWidget_1 extends _i1.SmartFake + implements _i2.InheritedWidget { + _FakeInheritedWidget_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); + + @override + String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) => + super.toString(); +} + +class _FakeDiagnosticsNode_2 extends _i1.SmartFake + implements _i3.DiagnosticsNode { + _FakeDiagnosticsNode_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); + + @override + String toString({ + _i3.TextTreeConfiguration? parentConfiguration, + _i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info, + }) => + super.toString(); +} + +class _FakeStreamedResponse_3 extends _i1.SmartFake + implements _i4.StreamedResponse { + _FakeStreamedResponse_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [JSObjectRepType]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockJSObjectRepType extends _i1.Mock implements _i5.JSObjectRepType { + MockJSObjectRepType() { + _i1.throwOnMissingStub(this); + } +} + +/// A class which mocks [BuildContext]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockBuildContext extends _i1.Mock implements _i2.BuildContext { + MockBuildContext() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.Widget get widget => (super.noSuchMethod( + Invocation.getter(#widget), + returnValue: _FakeWidget_0( + this, + Invocation.getter(#widget), + ), + ) as _i2.Widget); + + @override + bool get mounted => (super.noSuchMethod( + Invocation.getter(#mounted), + returnValue: false, + ) as bool); + + @override + bool get debugDoingBuild => (super.noSuchMethod( + Invocation.getter(#debugDoingBuild), + returnValue: false, + ) as bool); + + @override + _i2.InheritedWidget dependOnInheritedElement( + _i2.InheritedElement? ancestor, { + Object? aspect, + }) => + (super.noSuchMethod( + Invocation.method( + #dependOnInheritedElement, + [ancestor], + {#aspect: aspect}, + ), + returnValue: _FakeInheritedWidget_1( + this, + Invocation.method( + #dependOnInheritedElement, + [ancestor], + {#aspect: aspect}, + ), + ), + ) as _i2.InheritedWidget); + + @override + void visitAncestorElements(_i2.ConditionalElementVisitor? visitor) => + super.noSuchMethod( + Invocation.method( + #visitAncestorElements, + [visitor], + ), + returnValueForMissingStub: null, + ); + + @override + void visitChildElements(_i2.ElementVisitor? visitor) => super.noSuchMethod( + Invocation.method( + #visitChildElements, + [visitor], + ), + returnValueForMissingStub: null, + ); + + @override + void dispatchNotification(_i6.Notification? notification) => + super.noSuchMethod( + Invocation.method( + #dispatchNotification, + [notification], + ), + returnValueForMissingStub: null, + ); + + @override + _i3.DiagnosticsNode describeElement( + String? name, { + _i3.DiagnosticsTreeStyle? style = _i3.DiagnosticsTreeStyle.errorProperty, + }) => + (super.noSuchMethod( + Invocation.method( + #describeElement, + [name], + {#style: style}, + ), + returnValue: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeElement, + [name], + {#style: style}, + ), + ), + ) as _i3.DiagnosticsNode); + + @override + _i3.DiagnosticsNode describeWidget( + String? name, { + _i3.DiagnosticsTreeStyle? style = _i3.DiagnosticsTreeStyle.errorProperty, + }) => + (super.noSuchMethod( + Invocation.method( + #describeWidget, + [name], + {#style: style}, + ), + returnValue: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeWidget, + [name], + {#style: style}, + ), + ), + ) as _i3.DiagnosticsNode); + + @override + List<_i3.DiagnosticsNode> describeMissingAncestor( + {required Type? expectedAncestorType}) => + (super.noSuchMethod( + Invocation.method( + #describeMissingAncestor, + [], + {#expectedAncestorType: expectedAncestorType}, + ), + returnValue: <_i3.DiagnosticsNode>[], + ) as List<_i3.DiagnosticsNode>); + + @override + _i3.DiagnosticsNode describeOwnershipChain(String? name) => + (super.noSuchMethod( + Invocation.method( + #describeOwnershipChain, + [name], + ), + returnValue: _FakeDiagnosticsNode_2( + this, + Invocation.method( + #describeOwnershipChain, + [name], + ), + ), + ) as _i3.DiagnosticsNode); +} + +/// A class which mocks [CreationParams]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockCreationParams extends _i1.Mock implements _i7.CreationParams { + MockCreationParams() { + _i1.throwOnMissingStub(this); + } + + @override + Set get javascriptChannelNames => (super.noSuchMethod( + Invocation.getter(#javascriptChannelNames), + returnValue: {}, + ) as Set); + + @override + _i7.AutoMediaPlaybackPolicy get autoMediaPlaybackPolicy => + (super.noSuchMethod( + Invocation.getter(#autoMediaPlaybackPolicy), + returnValue: + _i7.AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, + ) as _i7.AutoMediaPlaybackPolicy); + + @override + List<_i7.WebViewCookie> get cookies => (super.noSuchMethod( + Invocation.getter(#cookies), + returnValue: <_i7.WebViewCookie>[], + ) as List<_i7.WebViewCookie>); +} + +/// A class which mocks [WebViewPlatformCallbacksHandler]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWebViewPlatformCallbacksHandler extends _i1.Mock + implements _i8.WebViewPlatformCallbacksHandler { + MockWebViewPlatformCallbacksHandler() { + _i1.throwOnMissingStub(this); + } + + @override + _i9.FutureOr onNavigationRequest({ + required String? url, + required bool? isForMainFrame, + }) => + (super.noSuchMethod( + Invocation.method( + #onNavigationRequest, + [], + { + #url: url, + #isForMainFrame: isForMainFrame, + }, + ), + returnValue: _i9.Future.value(false), + ) as _i9.FutureOr); + + @override + void onPageStarted(String? url) => super.noSuchMethod( + Invocation.method( + #onPageStarted, + [url], + ), + returnValueForMissingStub: null, + ); + + @override + void onPageFinished(String? url) => super.noSuchMethod( + Invocation.method( + #onPageFinished, + [url], + ), + returnValueForMissingStub: null, + ); + + @override + void onProgress(int? progress) => super.noSuchMethod( + Invocation.method( + #onProgress, + [progress], + ), + returnValueForMissingStub: null, + ); + + @override + void onWebResourceError(_i7.WebResourceError? error) => super.noSuchMethod( + Invocation.method( + #onWebResourceError, + [error], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [HttpRequestFactory]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockHttpRequestFactory extends _i1.Mock + implements _i10.HttpRequestFactory { + MockHttpRequestFactory() { + _i1.throwOnMissingStub(this); + } + + @override + _i9.Future<_i4.StreamedResponse> request( + String? url, { + String? method, + bool? withCredentials, + String? mimeType, + Map? requestHeaders, + _i11.Uint8List? sendData, + }) => + (super.noSuchMethod( + Invocation.method( + #request, + [url], + { + #method: method, + #withCredentials: withCredentials, + #mimeType: mimeType, + #requestHeaders: requestHeaders, + #sendData: sendData, + }, + ), + returnValue: + _i9.Future<_i4.StreamedResponse>.value(_FakeStreamedResponse_3( + this, + Invocation.method( + #request, + [url], + { + #method: method, + #withCredentials: withCredentials, + #mimeType: mimeType, + #requestHeaders: requestHeaders, + #sendData: sendData, + }, + ), + )), + ) as _i9.Future<_i4.StreamedResponse>); +} + +/// A class which mocks [StreamedResponse]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockStreamedResponse extends _i1.Mock implements _i4.StreamedResponse { + MockStreamedResponse() { + _i1.throwOnMissingStub(this); + } + + @override + _i4.ByteStream get stream => (super.noSuchMethod( + Invocation.getter(#stream), + returnValue: _i12.dummyValue<_i4.ByteStream>( + this, + Invocation.getter(#stream), + ), + ) as _i4.ByteStream); + + @override + int get statusCode => (super.noSuchMethod( + Invocation.getter(#statusCode), + returnValue: 0, + ) as int); + + @override + Map get headers => (super.noSuchMethod( + Invocation.getter(#headers), + returnValue: {}, + ) as Map); + + @override + bool get isRedirect => (super.noSuchMethod( + Invocation.getter(#isRedirect), + returnValue: false, + ) as bool); + + @override + bool get persistentConnection => (super.noSuchMethod( + Invocation.getter(#persistentConnection), + returnValue: false, + ) as bool); +} diff --git a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart index e07b8a873c4..91f6fc1e54a 100644 --- a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart @@ -3,11 +3,11 @@ // found in the LICENSE file. import 'dart:convert'; -import 'dart:html'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart' as http; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; @@ -16,7 +16,7 @@ import 'package:webview_flutter_web/webview_flutter_web.dart'; import 'web_webview_controller_test.mocks.dart'; @GenerateMocks([], customMocks: >[ - MockSpec(onMissingStub: OnMissingStub.returnDefault), + MockSpec(onMissingStub: OnMissingStub.returnDefault), MockSpec(onMissingStub: OnMissingStub.returnDefault), ]) void main() { @@ -105,17 +105,20 @@ void main() { httpRequestFactory: mockHttpRequestFactory, )); - final MockHttpRequest mockHttpRequest = MockHttpRequest(); - when(mockHttpRequest.getResponseHeader('content-type')) - .thenReturn('text/plain'); - when(mockHttpRequest.responseText).thenReturn('test data'); + final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + when(mockHttpRequest.headers['content-type']).thenReturn('text/plain'); + + final http.Response res = + await http.Response.fromStream(mockHttpRequest); + when(res.body).thenReturn('test data'); when(mockHttpRequestFactory.request( any, method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer( + (_) => Future.value(mockHttpRequest)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), @@ -147,10 +150,12 @@ void main() { final Encoding iso = Encoding.getByName('latin1')!; - final MockHttpRequest mockHttpRequest = MockHttpRequest(); - when(mockHttpRequest.responseText) - .thenReturn(String.fromCharCodes(iso.encode('España'))); - when(mockHttpRequest.getResponseHeader('content-type')) + final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + final http.Response res = + await http.Response.fromStream(mockHttpRequest); + + when(res.body).thenReturn(String.fromCharCodes(iso.encode('España'))); + when(mockHttpRequest.headers['content-type']) .thenReturn('Text/HTmL; charset=latin1'); when(mockHttpRequestFactory.request( @@ -158,7 +163,8 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer( + (_) => Future.value(mockHttpRequest)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), @@ -179,16 +185,19 @@ void main() { httpRequestFactory: mockHttpRequestFactory, )); - final MockHttpRequest mockHttpRequest = MockHttpRequest(); - when(mockHttpRequest.getResponseHeader('content-type')) - .thenReturn('text/html'); - when(mockHttpRequest.responseText).thenReturn('#'); + final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + when(mockHttpRequest.headers['content-type']).thenReturn('text/html'); + + final http.Response res = + await http.Response.fromStream(mockHttpRequest); + when(res.body).thenReturn('#'); when(mockHttpRequestFactory.request( any, method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer( + (_) => Future.value(mockHttpRequest)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), diff --git a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart new file mode 100644 index 00000000000..a2e9c8a1637 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart @@ -0,0 +1,142 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in webview_flutter_web/test/web_webview_controller_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i6; +import 'dart:typed_data' as _i7; + +import 'package:http/src/byte_stream.dart' as _i3; +import 'package:http/src/streamed_response.dart' as _i2; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i4; +import 'package:webview_flutter_web/src/http_request_factory.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 +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// 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 _FakeStreamedResponse_0 extends _i1.SmartFake + implements _i2.StreamedResponse { + _FakeStreamedResponse_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [StreamedResponse]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockStreamedResponse extends _i1.Mock implements _i2.StreamedResponse { + @override + _i3.ByteStream get stream => (super.noSuchMethod( + Invocation.getter(#stream), + returnValue: _i4.dummyValue<_i3.ByteStream>( + this, + Invocation.getter(#stream), + ), + returnValueForMissingStub: _i4.dummyValue<_i3.ByteStream>( + this, + Invocation.getter(#stream), + ), + ) as _i3.ByteStream); + + @override + int get statusCode => (super.noSuchMethod( + Invocation.getter(#statusCode), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + + @override + Map get headers => (super.noSuchMethod( + Invocation.getter(#headers), + returnValue: {}, + returnValueForMissingStub: {}, + ) as Map); + + @override + bool get isRedirect => (super.noSuchMethod( + Invocation.getter(#isRedirect), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + bool get persistentConnection => (super.noSuchMethod( + Invocation.getter(#persistentConnection), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); +} + +/// A class which mocks [HttpRequestFactory]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockHttpRequestFactory extends _i1.Mock + implements _i5.HttpRequestFactory { + @override + _i6.Future<_i2.StreamedResponse> request( + String? url, { + String? method, + bool? withCredentials, + String? mimeType, + Map? requestHeaders, + _i7.Uint8List? sendData, + }) => + (super.noSuchMethod( + Invocation.method( + #request, + [url], + { + #method: method, + #withCredentials: withCredentials, + #mimeType: mimeType, + #requestHeaders: requestHeaders, + #sendData: sendData, + }, + ), + returnValue: + _i6.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_0( + this, + Invocation.method( + #request, + [url], + { + #method: method, + #withCredentials: withCredentials, + #mimeType: mimeType, + #requestHeaders: requestHeaders, + #sendData: sendData, + }, + ), + )), + returnValueForMissingStub: + _i6.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_0( + this, + Invocation.method( + #request, + [url], + { + #method: method, + #withCredentials: withCredentials, + #mimeType: mimeType, + #requestHeaders: requestHeaders, + #sendData: sendData, + }, + ), + )), + ) as _i6.Future<_i2.StreamedResponse>); +} From efbad8972014f0f8aef9c237bc34fcd423ed2bb8 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Fri, 24 May 2024 19:58:32 +0200 Subject: [PATCH 03/20] Do not create iframe mock --- .../test/legacy/webview_flutter_web_test.dart | 1 - .../webview_flutter_web_test.mocks.dart | 62 ++++++++----------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart index 563fc42f658..334454adb3d 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart @@ -17,7 +17,6 @@ import 'package:webview_flutter_web/src/webview_flutter_web_legacy.dart'; import 'webview_flutter_web_test.mocks.dart'; @GenerateMocks([ - html.HTMLIFrameElement, BuildContext, CreationParams, WebViewPlatformCallbacksHandler, diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart index abeee5ed047..5cdb9da81a3 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart @@ -3,21 +3,20 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:_js_types' as _i5; -import 'dart:async' as _i9; -import 'dart:typed_data' as _i11; +import 'dart:async' as _i8; +import 'dart:typed_data' as _i10; import 'package:flutter/foundation.dart' as _i3; -import 'package:flutter/src/widgets/notification_listener.dart' as _i6; +import 'package:flutter/src/widgets/notification_listener.dart' as _i5; import 'package:flutter/widgets.dart' as _i2; import 'package:http/http.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i12; +import 'package:mockito/src/dummies.dart' as _i11; import 'package:webview_flutter_platform_interface/src/legacy/platform_interface/webview_platform_callbacks_handler.dart' - as _i8; -import 'package:webview_flutter_platform_interface/src/legacy/types/types.dart' as _i7; -import 'package:webview_flutter_web/src/http_request_factory.dart' as _i10; +import 'package:webview_flutter_platform_interface/src/legacy/types/types.dart' + as _i6; +import 'package:webview_flutter_web/src/http_request_factory.dart' as _i9; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -90,15 +89,6 @@ class _FakeStreamedResponse_3 extends _i1.SmartFake ); } -/// A class which mocks [JSObjectRepType]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockJSObjectRepType extends _i1.Mock implements _i5.JSObjectRepType { - MockJSObjectRepType() { - _i1.throwOnMissingStub(this); - } -} - /// A class which mocks [BuildContext]. /// /// See the documentation for Mockito's code generation for more information. @@ -169,7 +159,7 @@ class MockBuildContext extends _i1.Mock implements _i2.BuildContext { ); @override - void dispatchNotification(_i6.Notification? notification) => + void dispatchNotification(_i5.Notification? notification) => super.noSuchMethod( Invocation.method( #dispatchNotification, @@ -252,7 +242,7 @@ class MockBuildContext extends _i1.Mock implements _i2.BuildContext { /// A class which mocks [CreationParams]. /// /// See the documentation for Mockito's code generation for more information. -class MockCreationParams extends _i1.Mock implements _i7.CreationParams { +class MockCreationParams extends _i1.Mock implements _i6.CreationParams { MockCreationParams() { _i1.throwOnMissingStub(this); } @@ -264,31 +254,31 @@ class MockCreationParams extends _i1.Mock implements _i7.CreationParams { ) as Set); @override - _i7.AutoMediaPlaybackPolicy get autoMediaPlaybackPolicy => + _i6.AutoMediaPlaybackPolicy get autoMediaPlaybackPolicy => (super.noSuchMethod( Invocation.getter(#autoMediaPlaybackPolicy), returnValue: - _i7.AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, - ) as _i7.AutoMediaPlaybackPolicy); + _i6.AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, + ) as _i6.AutoMediaPlaybackPolicy); @override - List<_i7.WebViewCookie> get cookies => (super.noSuchMethod( + List<_i6.WebViewCookie> get cookies => (super.noSuchMethod( Invocation.getter(#cookies), - returnValue: <_i7.WebViewCookie>[], - ) as List<_i7.WebViewCookie>); + returnValue: <_i6.WebViewCookie>[], + ) as List<_i6.WebViewCookie>); } /// A class which mocks [WebViewPlatformCallbacksHandler]. /// /// See the documentation for Mockito's code generation for more information. class MockWebViewPlatformCallbacksHandler extends _i1.Mock - implements _i8.WebViewPlatformCallbacksHandler { + implements _i7.WebViewPlatformCallbacksHandler { MockWebViewPlatformCallbacksHandler() { _i1.throwOnMissingStub(this); } @override - _i9.FutureOr onNavigationRequest({ + _i8.FutureOr onNavigationRequest({ required String? url, required bool? isForMainFrame, }) => @@ -301,8 +291,8 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock #isForMainFrame: isForMainFrame, }, ), - returnValue: _i9.Future.value(false), - ) as _i9.FutureOr); + returnValue: _i8.Future.value(false), + ) as _i8.FutureOr); @override void onPageStarted(String? url) => super.noSuchMethod( @@ -332,7 +322,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock ); @override - void onWebResourceError(_i7.WebResourceError? error) => super.noSuchMethod( + void onWebResourceError(_i6.WebResourceError? error) => super.noSuchMethod( Invocation.method( #onWebResourceError, [error], @@ -345,19 +335,19 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockHttpRequestFactory extends _i1.Mock - implements _i10.HttpRequestFactory { + implements _i9.HttpRequestFactory { MockHttpRequestFactory() { _i1.throwOnMissingStub(this); } @override - _i9.Future<_i4.StreamedResponse> request( + _i8.Future<_i4.StreamedResponse> request( String? url, { String? method, bool? withCredentials, String? mimeType, Map? requestHeaders, - _i11.Uint8List? sendData, + _i10.Uint8List? sendData, }) => (super.noSuchMethod( Invocation.method( @@ -372,7 +362,7 @@ class MockHttpRequestFactory extends _i1.Mock }, ), returnValue: - _i9.Future<_i4.StreamedResponse>.value(_FakeStreamedResponse_3( + _i8.Future<_i4.StreamedResponse>.value(_FakeStreamedResponse_3( this, Invocation.method( #request, @@ -386,7 +376,7 @@ class MockHttpRequestFactory extends _i1.Mock }, ), )), - ) as _i9.Future<_i4.StreamedResponse>); + ) as _i8.Future<_i4.StreamedResponse>); } /// A class which mocks [StreamedResponse]. @@ -400,7 +390,7 @@ class MockStreamedResponse extends _i1.Mock implements _i4.StreamedResponse { @override _i4.ByteStream get stream => (super.noSuchMethod( Invocation.getter(#stream), - returnValue: _i12.dummyValue<_i4.ByteStream>( + returnValue: _i11.dummyValue<_i4.ByteStream>( this, Invocation.getter(#stream), ), From d622bb5f56a79fd29ed45ddd948eaf1b9ba95188 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Fri, 24 May 2024 20:14:15 +0200 Subject: [PATCH 04/20] Refactoring --- .../lib/src/webview_flutter_web_legacy.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart index 853a22444f7..44b37279f8a 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart @@ -10,9 +10,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; -import 'package:http/src/streamed_response.dart'; -import 'package:web/web.dart' as html; import 'package:http/http.dart' as http; +import 'package:web/web.dart' as html; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; From 2e11ac24fa99bcb9f9ebf8efd690e314edf2bcd2 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Fri, 24 May 2024 21:11:42 +0200 Subject: [PATCH 05/20] Webview Flutter Web Changelog --- .../webview_flutter_web/CHANGELOG.md | 5 +- .../example/web/index.html | 96 ++++--------------- .../webview_flutter_web/pubspec.yaml | 2 +- 3 files changed, 23 insertions(+), 80 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/CHANGELOG.md b/packages/webview_flutter/webview_flutter_web/CHANGELOG.md index 87645f14d73..21ff550a469 100644 --- a/packages/webview_flutter/webview_flutter_web/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_web/CHANGELOG.md @@ -1,5 +1,8 @@ -## NEXT +## 0.2.2+5 +* Migrates to `package:web` +* Updates `HttpRequestFactory.request` to use `package:http` `BrowserClient` +* Updates `ìndex.html` in the example to use `flutter_bootstrap.js` * Updates minimum supported SDK version to Flutter 3.16/Dart 3.2. ## 0.2.2+4 diff --git a/packages/webview_flutter/webview_flutter_web/example/web/index.html b/packages/webview_flutter/webview_flutter_web/example/web/index.html index 8b8b5bf92f8..3f56b9da197 100644 --- a/packages/webview_flutter/webview_flutter_web/example/web/index.html +++ b/packages/webview_flutter/webview_flutter_web/example/web/index.html @@ -3,8 +3,9 @@ Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> + - - + - - - + + + - - - - - + + + + + - webview_flutter_web Example - + webview_flutter_web Example + + - - + - + + \ No newline at end of file diff --git a/packages/webview_flutter/webview_flutter_web/pubspec.yaml b/packages/webview_flutter/webview_flutter_web/pubspec.yaml index 1264186bdfd..b2852f62f9f 100644 --- a/packages/webview_flutter/webview_flutter_web/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_web/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_web description: A Flutter plugin that provides a WebView widget on web. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 0.2.2+4 +version: 0.2.2+5 environment: sdk: ^3.2.0 From ab527d92ef822d451ead4ea18305d119643ec63b Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Fri, 24 May 2024 21:25:25 +0200 Subject: [PATCH 06/20] Sort directives --- .../webview_flutter_web/lib/src/web_webview_controller.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart index 9491141d764..8465f609d15 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart @@ -6,8 +6,8 @@ import 'dart:convert'; import 'dart:ui_web' as ui_web; import 'package:flutter/cupertino.dart'; -import 'package:web/web.dart' as html; import 'package:http/http.dart' as http; +import 'package:web/web.dart' as html; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'content_type.dart'; From 39b12b6f372f4b658814fcfa3618d5f937a789e6 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Fri, 24 May 2024 22:02:49 +0200 Subject: [PATCH 07/20] Return Response instead, closing client on finally --- .../lib/src/http_request_factory.dart | 12 +++-- .../lib/src/web_webview_controller.dart | 6 +-- .../lib/src/webview_flutter_web_legacy.dart | 6 +-- .../test/legacy/webview_flutter_web_test.dart | 20 +++----- .../webview_flutter_web_test.mocks.dart | 34 ++++++++------ .../test/web_webview_controller_test.dart | 31 +++++-------- .../web_webview_controller_test.mocks.dart | 46 ++++++++++--------- 7 files changed, 75 insertions(+), 80 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart index df695093ae2..b8710c4082a 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart @@ -63,14 +63,14 @@ class HttpRequestFactory { /// when the file cannot be found. /// /// See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access_authentication). - Future request( + Future request( String url, { String? method, bool? withCredentials, String? mimeType, Map? requestHeaders, Uint8List? sendData, - }) { + }) async { final BrowserClient client = BrowserClient(); if (withCredentials != null) { client.withCredentials = withCredentials; @@ -90,6 +90,12 @@ class HttpRequestFactory { request.headers.addAll(requestHeaders); } - return client.send(request); + try { + final http.StreamedResponse req = await client.send(request); + + return http.Response.fromStream(req); + } finally { + client.close(); + } } } diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart index 8465f609d15..bbb7a24dece 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart @@ -87,7 +87,7 @@ class WebWebViewController extends PlatformWebViewController { /// Performs an AJAX request defined by [params]. Future _updateIFrameFromXhr(LoadRequestParams params) async { - final http.StreamedResponse httpReq = + final http.Response httpReq = await _webWebViewParams.httpRequestFactory.request( params.uri.toString(), method: params.method.serialize(), @@ -99,11 +99,9 @@ class WebWebViewController extends PlatformWebViewController { final ContentType contentType = ContentType.parse(header); final Encoding encoding = Encoding.getByName(contentType.charset) ?? utf8; - final http.Response response = await http.Response.fromStream(httpReq); - // ignore: unsafe_html _webWebViewParams.iFrame.src = Uri.dataFromString( - response.body, + httpReq.body, mimeType: contentType.mimeType, encoding: encoding, ).toString(); diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart index 44b37279f8a..dc24e37bca5 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart @@ -203,7 +203,7 @@ class WebWebViewPlatformController implements WebViewPlatformController { if (!request.uri.hasScheme) { throw ArgumentError('WebViewRequest#uri is required to have a scheme.'); } - final http.StreamedResponse httpReq = await _httpRequestFactory.request( + final http.Response httpReq = await _httpRequestFactory.request( request.uri.toString(), method: request.method.serialize(), requestHeaders: request.headers, @@ -211,10 +211,8 @@ class WebWebViewPlatformController implements WebViewPlatformController { final String contentType = httpReq.headers['content-type'] ?? 'text/html'; - final http.Response response = await http.Response.fromStream(httpReq); - _element.src = Uri.dataFromString( - response.body, + httpReq.body, mimeType: contentType, encoding: utf8, ).toString(); diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart index 334454adb3d..7fd985f5ebe 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart @@ -21,7 +21,7 @@ import 'webview_flutter_web_test.mocks.dart'; CreationParams, WebViewPlatformCallbacksHandler, HttpRequestFactory, - http.StreamedResponse, + http.Response, ]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -112,12 +112,10 @@ void main() { WebWebViewPlatformController( mockElement, ); - final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + final MockResponse mockHttpRequest = MockResponse(); when(mockHttpRequest.headers['content-type']).thenReturn('text/plain'); - final http.Response res = - await http.Response.fromStream(mockHttpRequest); - when(res.body).thenReturn('test data'); + when(mockHttpRequest.body).thenReturn('test data'); final MockHttpRequestFactory mockHttpRequestFactory = MockHttpRequestFactory(); when(mockHttpRequestFactory.request( @@ -125,8 +123,7 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer( - (_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(mockHttpRequest)); controller.httpRequestFactory = mockHttpRequestFactory; // Run await controller.loadRequest( @@ -154,12 +151,10 @@ void main() { WebWebViewPlatformController( mockElement, ); - final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + final MockResponse mockHttpRequest = MockResponse(); when(mockHttpRequest.headers['content-type']).thenReturn('text/html'); - final http.Response res = - await http.Response.fromStream(mockHttpRequest); - when(res.body).thenReturn('#'); + when(mockHttpRequest.body).thenReturn('#'); final MockHttpRequestFactory mockHttpRequestFactory = MockHttpRequestFactory(); when(mockHttpRequestFactory.request( @@ -167,8 +162,7 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer( - (_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(mockHttpRequest)); controller.httpRequestFactory = mockHttpRequestFactory; // Run await controller.loadRequest( diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart index 5cdb9da81a3..8356398d7b6 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart @@ -78,9 +78,8 @@ class _FakeDiagnosticsNode_2 extends _i1.SmartFake super.toString(); } -class _FakeStreamedResponse_3 extends _i1.SmartFake - implements _i4.StreamedResponse { - _FakeStreamedResponse_3( +class _FakeResponse_3 extends _i1.SmartFake implements _i4.Response { + _FakeResponse_3( Object parent, Invocation parentInvocation, ) : super( @@ -341,7 +340,7 @@ class MockHttpRequestFactory extends _i1.Mock } @override - _i8.Future<_i4.StreamedResponse> request( + _i8.Future<_i4.Response> request( String? url, { String? method, bool? withCredentials, @@ -361,8 +360,7 @@ class MockHttpRequestFactory extends _i1.Mock #sendData: sendData, }, ), - returnValue: - _i8.Future<_i4.StreamedResponse>.value(_FakeStreamedResponse_3( + returnValue: _i8.Future<_i4.Response>.value(_FakeResponse_3( this, Invocation.method( #request, @@ -376,25 +374,31 @@ class MockHttpRequestFactory extends _i1.Mock }, ), )), - ) as _i8.Future<_i4.StreamedResponse>); + ) as _i8.Future<_i4.Response>); } -/// A class which mocks [StreamedResponse]. +/// A class which mocks [Response]. /// /// See the documentation for Mockito's code generation for more information. -class MockStreamedResponse extends _i1.Mock implements _i4.StreamedResponse { - MockStreamedResponse() { +class MockResponse extends _i1.Mock implements _i4.Response { + MockResponse() { _i1.throwOnMissingStub(this); } @override - _i4.ByteStream get stream => (super.noSuchMethod( - Invocation.getter(#stream), - returnValue: _i11.dummyValue<_i4.ByteStream>( + _i10.Uint8List get bodyBytes => (super.noSuchMethod( + Invocation.getter(#bodyBytes), + returnValue: _i10.Uint8List(0), + ) as _i10.Uint8List); + + @override + String get body => (super.noSuchMethod( + Invocation.getter(#body), + returnValue: _i11.dummyValue( this, - Invocation.getter(#stream), + Invocation.getter(#body), ), - ) as _i4.ByteStream); + ) as String); @override int get statusCode => (super.noSuchMethod( diff --git a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart index 91f6fc1e54a..a4dd4c29db3 100644 --- a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart @@ -16,7 +16,7 @@ import 'package:webview_flutter_web/webview_flutter_web.dart'; import 'web_webview_controller_test.mocks.dart'; @GenerateMocks([], customMocks: >[ - MockSpec(onMissingStub: OnMissingStub.returnDefault), + MockSpec(onMissingStub: OnMissingStub.returnDefault), MockSpec(onMissingStub: OnMissingStub.returnDefault), ]) void main() { @@ -105,20 +105,17 @@ void main() { httpRequestFactory: mockHttpRequestFactory, )); - final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + final MockResponse mockHttpRequest = MockResponse(); when(mockHttpRequest.headers['content-type']).thenReturn('text/plain'); - final http.Response res = - await http.Response.fromStream(mockHttpRequest); - when(res.body).thenReturn('test data'); + when(mockHttpRequest.body).thenReturn('test data'); when(mockHttpRequestFactory.request( any, method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer( - (_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(mockHttpRequest)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), @@ -149,12 +146,10 @@ void main() { )); final Encoding iso = Encoding.getByName('latin1')!; + final MockResponse mockHttpRequest = MockResponse(); - final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); - final http.Response res = - await http.Response.fromStream(mockHttpRequest); - - when(res.body).thenReturn(String.fromCharCodes(iso.encode('España'))); + when(mockHttpRequest.body) + .thenReturn(String.fromCharCodes(iso.encode('España'))); when(mockHttpRequest.headers['content-type']) .thenReturn('Text/HTmL; charset=latin1'); @@ -163,8 +158,7 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer( - (_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(mockHttpRequest)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), @@ -185,19 +179,16 @@ void main() { httpRequestFactory: mockHttpRequestFactory, )); - final MockStreamedResponse mockHttpRequest = MockStreamedResponse(); + final MockResponse mockHttpRequest = MockResponse(); when(mockHttpRequest.headers['content-type']).thenReturn('text/html'); - final http.Response res = - await http.Response.fromStream(mockHttpRequest); - when(res.body).thenReturn('#'); + when(mockHttpRequest.body).thenReturn('#'); when(mockHttpRequestFactory.request( any, method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer( - (_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(mockHttpRequest)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), diff --git a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart index a2e9c8a1637..ca0f0c188af 100644 --- a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart @@ -4,10 +4,9 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i6; -import 'dart:typed_data' as _i7; +import 'dart:typed_data' as _i3; -import 'package:http/src/byte_stream.dart' as _i3; -import 'package:http/src/streamed_response.dart' as _i2; +import 'package:http/src/response.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i4; import 'package:webview_flutter_web/src/http_request_factory.dart' as _i5; @@ -25,9 +24,8 @@ import 'package:webview_flutter_web/src/http_request_factory.dart' as _i5; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeStreamedResponse_0 extends _i1.SmartFake - implements _i2.StreamedResponse { - _FakeStreamedResponse_0( +class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { + _FakeResponse_0( Object parent, Invocation parentInvocation, ) : super( @@ -36,22 +34,29 @@ class _FakeStreamedResponse_0 extends _i1.SmartFake ); } -/// A class which mocks [StreamedResponse]. +/// A class which mocks [Response]. /// /// See the documentation for Mockito's code generation for more information. -class MockStreamedResponse extends _i1.Mock implements _i2.StreamedResponse { +class MockResponse extends _i1.Mock implements _i2.Response { @override - _i3.ByteStream get stream => (super.noSuchMethod( - Invocation.getter(#stream), - returnValue: _i4.dummyValue<_i3.ByteStream>( + _i3.Uint8List get bodyBytes => (super.noSuchMethod( + Invocation.getter(#bodyBytes), + returnValue: _i3.Uint8List(0), + returnValueForMissingStub: _i3.Uint8List(0), + ) as _i3.Uint8List); + + @override + String get body => (super.noSuchMethod( + Invocation.getter(#body), + returnValue: _i4.dummyValue( this, - Invocation.getter(#stream), + Invocation.getter(#body), ), - returnValueForMissingStub: _i4.dummyValue<_i3.ByteStream>( + returnValueForMissingStub: _i4.dummyValue( this, - Invocation.getter(#stream), + Invocation.getter(#body), ), - ) as _i3.ByteStream); + ) as String); @override int get statusCode => (super.noSuchMethod( @@ -88,13 +93,13 @@ class MockStreamedResponse extends _i1.Mock implements _i2.StreamedResponse { class MockHttpRequestFactory extends _i1.Mock implements _i5.HttpRequestFactory { @override - _i6.Future<_i2.StreamedResponse> request( + _i6.Future<_i2.Response> request( String? url, { String? method, bool? withCredentials, String? mimeType, Map? requestHeaders, - _i7.Uint8List? sendData, + _i3.Uint8List? sendData, }) => (super.noSuchMethod( Invocation.method( @@ -108,8 +113,7 @@ class MockHttpRequestFactory extends _i1.Mock #sendData: sendData, }, ), - returnValue: - _i6.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_0( + returnValue: _i6.Future<_i2.Response>.value(_FakeResponse_0( this, Invocation.method( #request, @@ -124,7 +128,7 @@ class MockHttpRequestFactory extends _i1.Mock ), )), returnValueForMissingStub: - _i6.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_0( + _i6.Future<_i2.Response>.value(_FakeResponse_0( this, Invocation.method( #request, @@ -138,5 +142,5 @@ class MockHttpRequestFactory extends _i1.Mock }, ), )), - ) as _i6.Future<_i2.StreamedResponse>); + ) as _i6.Future<_i2.Response>); } From 5e378c4701bac3b9cb06b6f5ba8941f7a552ac26 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Fri, 24 May 2024 22:15:37 +0200 Subject: [PATCH 08/20] Fix mock response headers to return valid object --- .../test/legacy/webview_flutter_web_test.dart | 6 ++++-- .../test/web_webview_controller_test.dart | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart index 7fd985f5ebe..66198cc3512 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart @@ -113,7 +113,8 @@ void main() { mockElement, ); final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.headers['content-type']).thenReturn('text/plain'); + when(mockHttpRequest.headers) + .thenReturn({'content-type': 'text/plain'}); when(mockHttpRequest.body).thenReturn('test data'); final MockHttpRequestFactory mockHttpRequestFactory = @@ -152,7 +153,8 @@ void main() { mockElement, ); final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.headers['content-type']).thenReturn('text/html'); + when(mockHttpRequest.headers) + .thenReturn({'content-type': 'text/html'}); when(mockHttpRequest.body).thenReturn('#'); final MockHttpRequestFactory mockHttpRequestFactory = diff --git a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart index a4dd4c29db3..7c2180519a8 100644 --- a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart @@ -106,7 +106,8 @@ void main() { )); final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.headers['content-type']).thenReturn('text/plain'); + when(mockHttpRequest.headers) + .thenReturn({'content-type': 'text/plain'}); when(mockHttpRequest.body).thenReturn('test data'); @@ -150,8 +151,8 @@ void main() { when(mockHttpRequest.body) .thenReturn(String.fromCharCodes(iso.encode('España'))); - when(mockHttpRequest.headers['content-type']) - .thenReturn('Text/HTmL; charset=latin1'); + when(mockHttpRequest.headers).thenReturn( + {'content-type': 'Text/HTmL; charset=latin1'}); when(mockHttpRequestFactory.request( any, @@ -180,7 +181,8 @@ void main() { )); final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.headers['content-type']).thenReturn('text/html'); + when(mockHttpRequest.headers) + .thenReturn({'content-type': 'text/html'}); when(mockHttpRequest.body).thenReturn('#'); when(mockHttpRequestFactory.request( From 516c357b6e49c951963dc5d361c9516b4bb2b549 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Fri, 24 May 2024 23:49:25 +0200 Subject: [PATCH 09/20] Set SDK requirement to ^3.3.0 --- packages/webview_flutter/webview_flutter_web/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/pubspec.yaml b/packages/webview_flutter/webview_flutter_web/pubspec.yaml index b2852f62f9f..0e917349de4 100644 --- a/packages/webview_flutter/webview_flutter_web/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_web/pubspec.yaml @@ -5,7 +5,7 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 0.2.2+5 environment: - sdk: ^3.2.0 + sdk: ^3.3.0 flutter: ">=3.16.0" flutter: @@ -22,7 +22,7 @@ dependencies: flutter_web_plugins: sdk: flutter http: ^1.2.1 - web: ^0.5.1 + web: ^0.5.0 webview_flutter_platform_interface: ^2.0.0 dev_dependencies: From d03c9fc16eebc88da3210e176aa0977cc820ffc2 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Sat, 25 May 2024 00:12:51 +0200 Subject: [PATCH 10/20] Mock IFrame --- .../webview_flutter_web/CHANGELOG.md | 1 + .../example/web/index.html | 30 ++++++------- .../test/legacy/mock_fake_iframe_element.dart | 13 ++++++ .../test/legacy/webview_flutter_web_test.dart | 43 +++++++++++++++---- 4 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart diff --git a/packages/webview_flutter/webview_flutter_web/CHANGELOG.md b/packages/webview_flutter/webview_flutter_web/CHANGELOG.md index 21ff550a469..0c7a525a377 100644 --- a/packages/webview_flutter/webview_flutter_web/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_web/CHANGELOG.md @@ -3,6 +3,7 @@ * Migrates to `package:web` * Updates `HttpRequestFactory.request` to use `package:http` `BrowserClient` * Updates `ìndex.html` in the example to use `flutter_bootstrap.js` +* Updates minimum dart sdk to `^3.3.0` * Updates minimum supported SDK version to Flutter 3.16/Dart 3.2. ## 0.2.2+4 diff --git a/packages/webview_flutter/webview_flutter_web/example/web/index.html b/packages/webview_flutter/webview_flutter_web/example/web/index.html index 3f56b9da197..faf1f7e92cc 100644 --- a/packages/webview_flutter/webview_flutter_web/example/web/index.html +++ b/packages/webview_flutter/webview_flutter_web/example/web/index.html @@ -5,7 +5,7 @@ - - + - - - + + + - - - - - + + + + + - webview_flutter_web Example - + webview_flutter_web Example + - - + https://developers.google.com/web/fundamentals/primers/service-workers --> + \ No newline at end of file diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart new file mode 100644 index 00000000000..7f5b8d89cd3 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart @@ -0,0 +1,13 @@ +import 'dart:js_interop'; +import 'package:web/web.dart' as html; + +@JSExport() +class FakeIFrameElement { + @JSExport('src') + String? src; +} + +extension type MockHTMLIFrameElement(JSObject _) + implements html.HTMLIFrameElement, JSObject { + external String? src; +} diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart index 66198cc3512..bbdacb7ee36 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:js_interop'; import 'dart:typed_data'; import 'package:flutter/material.dart'; @@ -9,11 +10,11 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http/http.dart' as http; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:web/web.dart' as html; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; import 'package:webview_flutter_web/src/http_request_factory.dart'; import 'package:webview_flutter_web/src/webview_flutter_web_legacy.dart'; +import 'mock_fake_iframe_element.dart'; import 'webview_flutter_web_test.mocks.dart'; @GenerateMocks([ @@ -45,7 +46,11 @@ void main() { group('WebWebViewPlatformController', () { test('loadUrl sets url on iframe src attribute', () { // Setup - final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); + final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockHTMLIFrameElement mockElement = + createJSInteropWrapper(fakeElem) + as MockHTMLIFrameElement; + final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -59,7 +64,11 @@ void main() { group('loadHtmlString', () { test('loadHtmlString loads html into iframe', () { // Setup - final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); + final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockHTMLIFrameElement mockElement = + createJSInteropWrapper(fakeElem) + as MockHTMLIFrameElement; + final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -73,7 +82,11 @@ void main() { test('loadHtmlString escapes "#" correctly', () { // Setup - final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); + final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockHTMLIFrameElement mockElement = + createJSInteropWrapper(fakeElem) + as MockHTMLIFrameElement; + final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -81,14 +94,18 @@ void main() { // Run controller.loadHtmlString('#'); // Verify - verify(mockElement.src = argThat(contains('%23')) ?? ''); + verify(mockElement.src = argThat(contains('%23'))); }); }); group('loadRequest', () { test('loadRequest throws ArgumentError on missing scheme', () { // Setup - final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); + final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockHTMLIFrameElement mockElement = + createJSInteropWrapper(fakeElem) + as MockHTMLIFrameElement; + final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -107,7 +124,11 @@ void main() { test('loadRequest makes request and loads response into iframe', () async { // Setup - final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); + final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockHTMLIFrameElement mockElement = + createJSInteropWrapper(fakeElem) + as MockHTMLIFrameElement; + final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -147,7 +168,11 @@ void main() { test('loadRequest escapes "#" correctly', () async { // Setup - final html.HTMLIFrameElement mockElement = html.HTMLIFrameElement(); + final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockHTMLIFrameElement mockElement = + createJSInteropWrapper(fakeElem) + as MockHTMLIFrameElement; + final WebWebViewPlatformController controller = WebWebViewPlatformController( mockElement, @@ -175,7 +200,7 @@ void main() { headers: {'Foo': 'Bar'}), ); // Verify - verify(mockElement.src = argThat(contains('%23')) ?? ''); + verify(mockElement.src = argThat(contains('%23'))); }); }); }); From bd2d8a74ac05b8c1271e76e2181a19d1838d1af8 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Sat, 25 May 2024 00:21:17 +0200 Subject: [PATCH 11/20] Mock object of the fake iframe class --- .../test/legacy/webview_flutter_web_test.dart | 13 ++-- .../webview_flutter_web_test.mocks.dart | 78 ++++++++++++------- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart index bbdacb7ee36..07ebec7def4 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart @@ -18,6 +18,7 @@ import 'mock_fake_iframe_element.dart'; import 'webview_flutter_web_test.mocks.dart'; @GenerateMocks([ + FakeIFrameElement, BuildContext, CreationParams, WebViewPlatformCallbacksHandler, @@ -46,7 +47,7 @@ void main() { group('WebWebViewPlatformController', () { test('loadUrl sets url on iframe src attribute', () { // Setup - final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); final MockHTMLIFrameElement mockElement = createJSInteropWrapper(fakeElem) as MockHTMLIFrameElement; @@ -64,7 +65,7 @@ void main() { group('loadHtmlString', () { test('loadHtmlString loads html into iframe', () { // Setup - final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); final MockHTMLIFrameElement mockElement = createJSInteropWrapper(fakeElem) as MockHTMLIFrameElement; @@ -82,7 +83,7 @@ void main() { test('loadHtmlString escapes "#" correctly', () { // Setup - final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); final MockHTMLIFrameElement mockElement = createJSInteropWrapper(fakeElem) as MockHTMLIFrameElement; @@ -101,7 +102,7 @@ void main() { group('loadRequest', () { test('loadRequest throws ArgumentError on missing scheme', () { // Setup - final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); final MockHTMLIFrameElement mockElement = createJSInteropWrapper(fakeElem) as MockHTMLIFrameElement; @@ -124,7 +125,7 @@ void main() { test('loadRequest makes request and loads response into iframe', () async { // Setup - final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); final MockHTMLIFrameElement mockElement = createJSInteropWrapper(fakeElem) as MockHTMLIFrameElement; @@ -168,7 +169,7 @@ void main() { test('loadRequest escapes "#" correctly', () async { // Setup - final FakeIFrameElement fakeElem = FakeIFrameElement(); + final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); final MockHTMLIFrameElement mockElement = createJSInteropWrapper(fakeElem) as MockHTMLIFrameElement; diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart index 8356398d7b6..9cdc8b2511c 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart @@ -3,20 +3,22 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i8; -import 'dart:typed_data' as _i10; +import 'dart:async' as _i9; +import 'dart:typed_data' as _i11; import 'package:flutter/foundation.dart' as _i3; -import 'package:flutter/src/widgets/notification_listener.dart' as _i5; +import 'package:flutter/src/widgets/notification_listener.dart' as _i6; import 'package:flutter/widgets.dart' as _i2; import 'package:http/http.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i11; +import 'package:mockito/src/dummies.dart' as _i12; import 'package:webview_flutter_platform_interface/src/legacy/platform_interface/webview_platform_callbacks_handler.dart' - as _i7; + as _i8; import 'package:webview_flutter_platform_interface/src/legacy/types/types.dart' - as _i6; -import 'package:webview_flutter_web/src/http_request_factory.dart' as _i9; + as _i7; +import 'package:webview_flutter_web/src/http_request_factory.dart' as _i10; + +import 'mock_fake_iframe_element.dart' as _i5; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -88,6 +90,24 @@ class _FakeResponse_3 extends _i1.SmartFake implements _i4.Response { ); } +/// A class which mocks [FakeIFrameElement]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockFakeIFrameElement extends _i1.Mock implements _i5.FakeIFrameElement { + MockFakeIFrameElement() { + _i1.throwOnMissingStub(this); + } + + @override + set src(String? _src) => super.noSuchMethod( + Invocation.setter( + #src, + _src, + ), + returnValueForMissingStub: null, + ); +} + /// A class which mocks [BuildContext]. /// /// See the documentation for Mockito's code generation for more information. @@ -158,7 +178,7 @@ class MockBuildContext extends _i1.Mock implements _i2.BuildContext { ); @override - void dispatchNotification(_i5.Notification? notification) => + void dispatchNotification(_i6.Notification? notification) => super.noSuchMethod( Invocation.method( #dispatchNotification, @@ -241,7 +261,7 @@ class MockBuildContext extends _i1.Mock implements _i2.BuildContext { /// A class which mocks [CreationParams]. /// /// See the documentation for Mockito's code generation for more information. -class MockCreationParams extends _i1.Mock implements _i6.CreationParams { +class MockCreationParams extends _i1.Mock implements _i7.CreationParams { MockCreationParams() { _i1.throwOnMissingStub(this); } @@ -253,31 +273,31 @@ class MockCreationParams extends _i1.Mock implements _i6.CreationParams { ) as Set); @override - _i6.AutoMediaPlaybackPolicy get autoMediaPlaybackPolicy => + _i7.AutoMediaPlaybackPolicy get autoMediaPlaybackPolicy => (super.noSuchMethod( Invocation.getter(#autoMediaPlaybackPolicy), returnValue: - _i6.AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, - ) as _i6.AutoMediaPlaybackPolicy); + _i7.AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, + ) as _i7.AutoMediaPlaybackPolicy); @override - List<_i6.WebViewCookie> get cookies => (super.noSuchMethod( + List<_i7.WebViewCookie> get cookies => (super.noSuchMethod( Invocation.getter(#cookies), - returnValue: <_i6.WebViewCookie>[], - ) as List<_i6.WebViewCookie>); + returnValue: <_i7.WebViewCookie>[], + ) as List<_i7.WebViewCookie>); } /// A class which mocks [WebViewPlatformCallbacksHandler]. /// /// See the documentation for Mockito's code generation for more information. class MockWebViewPlatformCallbacksHandler extends _i1.Mock - implements _i7.WebViewPlatformCallbacksHandler { + implements _i8.WebViewPlatformCallbacksHandler { MockWebViewPlatformCallbacksHandler() { _i1.throwOnMissingStub(this); } @override - _i8.FutureOr onNavigationRequest({ + _i9.FutureOr onNavigationRequest({ required String? url, required bool? isForMainFrame, }) => @@ -290,8 +310,8 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock #isForMainFrame: isForMainFrame, }, ), - returnValue: _i8.Future.value(false), - ) as _i8.FutureOr); + returnValue: _i9.Future.value(false), + ) as _i9.FutureOr); @override void onPageStarted(String? url) => super.noSuchMethod( @@ -321,7 +341,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock ); @override - void onWebResourceError(_i6.WebResourceError? error) => super.noSuchMethod( + void onWebResourceError(_i7.WebResourceError? error) => super.noSuchMethod( Invocation.method( #onWebResourceError, [error], @@ -334,19 +354,19 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockHttpRequestFactory extends _i1.Mock - implements _i9.HttpRequestFactory { + implements _i10.HttpRequestFactory { MockHttpRequestFactory() { _i1.throwOnMissingStub(this); } @override - _i8.Future<_i4.Response> request( + _i9.Future<_i4.Response> request( String? url, { String? method, bool? withCredentials, String? mimeType, Map? requestHeaders, - _i10.Uint8List? sendData, + _i11.Uint8List? sendData, }) => (super.noSuchMethod( Invocation.method( @@ -360,7 +380,7 @@ class MockHttpRequestFactory extends _i1.Mock #sendData: sendData, }, ), - returnValue: _i8.Future<_i4.Response>.value(_FakeResponse_3( + returnValue: _i9.Future<_i4.Response>.value(_FakeResponse_3( this, Invocation.method( #request, @@ -374,7 +394,7 @@ class MockHttpRequestFactory extends _i1.Mock }, ), )), - ) as _i8.Future<_i4.Response>); + ) as _i9.Future<_i4.Response>); } /// A class which mocks [Response]. @@ -386,15 +406,15 @@ class MockResponse extends _i1.Mock implements _i4.Response { } @override - _i10.Uint8List get bodyBytes => (super.noSuchMethod( + _i11.Uint8List get bodyBytes => (super.noSuchMethod( Invocation.getter(#bodyBytes), - returnValue: _i10.Uint8List(0), - ) as _i10.Uint8List); + returnValue: _i11.Uint8List(0), + ) as _i11.Uint8List); @override String get body => (super.noSuchMethod( Invocation.getter(#body), - returnValue: _i11.dummyValue( + returnValue: _i12.dummyValue( this, Invocation.getter(#body), ), From 4d4f6d722a165ee8243e891993f64e5ee0965546 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Sat, 25 May 2024 00:28:27 +0200 Subject: [PATCH 12/20] Add License to missing file --- .../test/legacy/mock_fake_iframe_element.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart index 7f5b8d89cd3..cd9b39b5c6a 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.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. + import 'dart:js_interop'; import 'package:web/web.dart' as html; From b77d3fb6a9fe306edfcab7f63879d794e27e7312 Mon Sep 17 00:00:00 2001 From: Thomas Aunvik Date: Sat, 25 May 2024 00:41:09 +0200 Subject: [PATCH 13/20] Pubspec Flutter Version, Getters and Setters for in par with implemented type --- packages/webview_flutter/webview_flutter_web/pubspec.yaml | 2 +- .../test/legacy/mock_fake_iframe_element.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/pubspec.yaml b/packages/webview_flutter/webview_flutter_web/pubspec.yaml index 0e917349de4..f93f58f090d 100644 --- a/packages/webview_flutter/webview_flutter_web/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_web/pubspec.yaml @@ -6,7 +6,7 @@ version: 0.2.2+5 environment: sdk: ^3.3.0 - flutter: ">=3.16.0" + flutter: ">=3.19.0" flutter: plugin: diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart index cd9b39b5c6a..4541f31f6cd 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart @@ -1,7 +1,6 @@ // 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:js_interop'; import 'package:web/web.dart' as html; @@ -13,5 +12,6 @@ class FakeIFrameElement { extension type MockHTMLIFrameElement(JSObject _) implements html.HTMLIFrameElement, JSObject { - external String? src; + external set src(String? value); + external String? get src; } From a890b220e12c0c757640dd77629c9c87740536db Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 8 Jul 2024 20:16:15 -0700 Subject: [PATCH 14/20] Implement HttpRequestFactory with fetch. Remove package:http dep. --- .../lib/src/http_request_factory.dart | 70 ++++++++----------- .../webview_flutter_web/pubspec.yaml | 1 - 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart index b8710c4082a..1d9eefc4183 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart @@ -1,10 +1,12 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. + +import 'dart:async'; +import 'dart:js_interop'; import 'dart:typed_data'; -import 'package:http/browser_client.dart'; -import 'package:http/http.dart' as http; +import 'package:web/web.dart' as web; /// Factory class for creating [HttpRequest] instances. class HttpRequestFactory { @@ -13,20 +15,16 @@ class HttpRequestFactory { /// Creates and sends a URL request for the specified [url]. /// + /// Returns an `Object` (so this class can be mocked by mockito), which can be + /// cast as [web.Response] from `package:web`. + /// /// By default `request` will perform an HTTP GET request, but a different /// method (`POST`, `PUT`, `DELETE`, etc) can be used by specifying the - /// [method] parameter. (See also [HttpRequest.postFormData] for `POST` - /// requests only. - /// - /// The Future is completed when the response is available. + /// [method] parameter. /// - /// If specified, `sendData` will send data in the form of a [ByteBuffer], - /// [Blob], [Document], [String], or [FormData] along with the HttpRequest. + /// The Future is completed when the [web.Response] is available. /// - /// If specified, [responseType] sets the desired response format for the - /// request. By default it is [String], but can also be 'arraybuffer', 'blob', - /// 'document', 'json', or 'text'. See also [HttpRequest.responseType] - /// for more information. + /// If specified, `sendData` will be sent as the `body` of the fetch. /// /// The [withCredentials] parameter specified that credentials such as a cookie /// (already) set in the header or @@ -57,45 +55,33 @@ class HttpRequestFactory { /// // Do something with the response. /// }); /// - /// Note that requests for file:// URIs are only supported by Chrome extensions + /// Requests for file:// URIs are only supported by Chrome extensions /// with appropriate permissions in their manifest. Requests to file:// URIs /// will also never fail- the Future will always complete successfully, even /// when the file cannot be found. /// /// See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access_authentication). - Future request( + Future request( String url, { - String? method, - bool? withCredentials, + String method = 'GET', + bool withCredentials = false, String? mimeType, Map? requestHeaders, Uint8List? sendData, }) async { - final BrowserClient client = BrowserClient(); - if (withCredentials != null) { - client.withCredentials = withCredentials; - } - - final http.Request request = http.Request(method ?? 'GET', Uri.parse(url)); - - if (sendData != null) { - request.bodyBytes = sendData.toList(); - } - - if (mimeType != null) { - request.headers['content-type'] = mimeType; - } - - if (requestHeaders != null) { - request.headers.addAll(requestHeaders); - } - - try { - final http.StreamedResponse req = await client.send(request); - - return http.Response.fromStream(req); - } finally { - client.close(); - } + final Map headers = { + if (mimeType != null) 'content-type': mimeType, + ...?requestHeaders, + }; + return web.window + .fetch( + url.toJS, + web.RequestInit( + method: method, + body: sendData?.toJS, + credentials: withCredentials ? 'include' : 'same-origin', + headers: headers.jsify()! as web.HeadersInit, + )) + .toDart; } } diff --git a/packages/webview_flutter/webview_flutter_web/pubspec.yaml b/packages/webview_flutter/webview_flutter_web/pubspec.yaml index f93f58f090d..8a9f969718e 100644 --- a/packages/webview_flutter/webview_flutter_web/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_web/pubspec.yaml @@ -21,7 +21,6 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - http: ^1.2.1 web: ^0.5.0 webview_flutter_platform_interface: ^2.0.0 From 4ee87cc6816bb33b5013f3e42809cd27ded7f02c Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 8 Jul 2024 20:17:23 -0700 Subject: [PATCH 15/20] Use the web.Response API. --- .../lib/src/web_webview_controller.dart | 16 +++++++------- .../lib/src/webview_flutter_web_legacy.dart | 21 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart index bbb7a24dece..2d8297fb5fd 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/web_webview_controller.dart @@ -3,11 +3,11 @@ // found in the LICENSE file. import 'dart:convert'; +import 'dart:js_interop'; import 'dart:ui_web' as ui_web; -import 'package:flutter/cupertino.dart'; -import 'package:http/http.dart' as http; -import 'package:web/web.dart' as html; +import 'package:flutter/widgets.dart'; +import 'package:web/web.dart' as web; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'content_type.dart'; @@ -39,7 +39,7 @@ class WebWebViewControllerCreationParams /// The underlying element used as the WebView. @visibleForTesting - final html.HTMLIFrameElement iFrame = html.HTMLIFrameElement() + final web.HTMLIFrameElement iFrame = web.HTMLIFrameElement() ..id = 'webView${_nextIFrameId++}' ..style.width = '100%' ..style.height = '100%' @@ -87,21 +87,21 @@ class WebWebViewController extends PlatformWebViewController { /// Performs an AJAX request defined by [params]. Future _updateIFrameFromXhr(LoadRequestParams params) async { - final http.Response httpReq = + final web.Response response = await _webWebViewParams.httpRequestFactory.request( params.uri.toString(), method: params.method.serialize(), requestHeaders: params.headers, sendData: params.body, - ); + ) as web.Response; - final String header = httpReq.headers['content-type'] ?? 'text/html'; + final String header = response.headers.get('content-type') ?? 'text/html'; final ContentType contentType = ContentType.parse(header); final Encoding encoding = Encoding.getByName(contentType.charset) ?? utf8; // ignore: unsafe_html _webWebViewParams.iFrame.src = Uri.dataFromString( - httpReq.body, + (await response.text().toDart).toDart, mimeType: contentType.mimeType, encoding: encoding, ).toString(); diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart index dc24e37bca5..4820743a08d 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/webview_flutter_web_legacy.dart @@ -4,14 +4,14 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:js_interop'; import 'dart:ui_web' as ui_web; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; -import 'package:http/http.dart' as http; -import 'package:web/web.dart' as html; +import 'package:web/web.dart' as web; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; @@ -25,7 +25,7 @@ class WebWebViewPlatform implements WebViewPlatform { WebWebViewPlatform() { ui_web.platformViewRegistry.registerViewFactory( 'webview-iframe', - (int viewId) => html.HTMLIFrameElement() + (int viewId) => web.HTMLIFrameElement() ..id = 'webview-$viewId' ..width = '100%' ..height = '100%' @@ -47,8 +47,8 @@ class WebWebViewPlatform implements WebViewPlatform { if (onWebViewPlatformCreated == null) { return; } - final html.HTMLIFrameElement element = html.document - .getElementById('webview-$viewId')! as html.HTMLIFrameElement; + final web.HTMLIFrameElement element = web.document + .getElementById('webview-$viewId')! as web.HTMLIFrameElement; final String? initialUrl = creationParams.initialUrl; if (initialUrl != null) { @@ -74,7 +74,7 @@ class WebWebViewPlatformController implements WebViewPlatformController { /// Constructs a [WebWebViewPlatformController]. WebWebViewPlatformController(this._element); - final html.HTMLIFrameElement _element; + final web.HTMLIFrameElement _element; HttpRequestFactory _httpRequestFactory = const HttpRequestFactory(); /// Setter for setting the HttpRequestFactory, for testing purposes. @@ -203,16 +203,17 @@ class WebWebViewPlatformController implements WebViewPlatformController { if (!request.uri.hasScheme) { throw ArgumentError('WebViewRequest#uri is required to have a scheme.'); } - final http.Response httpReq = await _httpRequestFactory.request( + final web.Response response = await _httpRequestFactory.request( request.uri.toString(), method: request.method.serialize(), requestHeaders: request.headers, - sendData: request.body); + sendData: request.body) as web.Response; - final String contentType = httpReq.headers['content-type'] ?? 'text/html'; + final String contentType = + response.headers.get('content-type') ?? 'text/html'; _element.src = Uri.dataFromString( - httpReq.body, + (await response.text().toDart).toDart, mimeType: contentType, encoding: utf8, ).toString(); From 87c7243ff1189f3695b7ed4e0bfcfdc7642a9967 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 8 Jul 2024 20:18:39 -0700 Subject: [PATCH 16/20] Fake web.Response and IFrames with the new JS-interop style (without mockito). --- .../test/legacy/webview_flutter_web_test.dart | 113 +++++++----------- .../test/web_webview_controller_test.dart | 45 ++++--- 2 files changed, 70 insertions(+), 88 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart index 07ebec7def4..22e2a06e66e 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.dart @@ -7,23 +7,20 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:http/http.dart' as http; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; +import 'package:web/web.dart' as web; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; import 'package:webview_flutter_web/src/http_request_factory.dart'; import 'package:webview_flutter_web/src/webview_flutter_web_legacy.dart'; -import 'mock_fake_iframe_element.dart'; import 'webview_flutter_web_test.mocks.dart'; @GenerateMocks([ - FakeIFrameElement, BuildContext, CreationParams, WebViewPlatformCallbacksHandler, HttpRequestFactory, - http.Response, ]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -47,70 +44,47 @@ void main() { group('WebWebViewPlatformController', () { test('loadUrl sets url on iframe src attribute', () { // Setup - final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); - final MockHTMLIFrameElement mockElement = - createJSInteropWrapper(fakeElem) - as MockHTMLIFrameElement; - + final web.HTMLIFrameElement fakeIFrame = web.HTMLIFrameElement(); final WebWebViewPlatformController controller = - WebWebViewPlatformController( - mockElement, - ); + WebWebViewPlatformController(fakeIFrame); // Run - controller.loadUrl('test url', null); + controller.loadUrl('http://example.com/', null); // Verify - verify(mockElement.src = 'test url'); + expect(fakeIFrame.src, 'http://example.com/'); }); group('loadHtmlString', () { test('loadHtmlString loads html into iframe', () { // Setup - final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); - final MockHTMLIFrameElement mockElement = - createJSInteropWrapper(fakeElem) - as MockHTMLIFrameElement; - + final web.HTMLIFrameElement fakeIFrame = web.HTMLIFrameElement(); final WebWebViewPlatformController controller = - WebWebViewPlatformController( - mockElement, - ); + WebWebViewPlatformController(fakeIFrame); // Run controller.loadHtmlString('test html'); // Verify - verify(mockElement.src = + expect(fakeIFrame.src, 'data:text/html;charset=utf-8,${Uri.encodeFull('test html')}'); }); test('loadHtmlString escapes "#" correctly', () { // Setup - final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); - final MockHTMLIFrameElement mockElement = - createJSInteropWrapper(fakeElem) - as MockHTMLIFrameElement; - + final web.HTMLIFrameElement fakeIFrame = web.HTMLIFrameElement(); final WebWebViewPlatformController controller = - WebWebViewPlatformController( - mockElement, - ); + WebWebViewPlatformController(fakeIFrame); // Run controller.loadHtmlString('#'); // Verify - verify(mockElement.src = argThat(contains('%23'))); + expect(fakeIFrame.src, contains('%23')); }); }); group('loadRequest', () { test('loadRequest throws ArgumentError on missing scheme', () { // Setup - final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); - final MockHTMLIFrameElement mockElement = - createJSInteropWrapper(fakeElem) - as MockHTMLIFrameElement; - + final web.HTMLIFrameElement fakeIFrame = web.HTMLIFrameElement(); final WebWebViewPlatformController controller = - WebWebViewPlatformController( - mockElement, - ); + WebWebViewPlatformController(fakeIFrame); + // Run & Verify expect( () async => controller.loadRequest( @@ -125,20 +99,18 @@ void main() { test('loadRequest makes request and loads response into iframe', () async { // Setup - final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); - final MockHTMLIFrameElement mockElement = - createJSInteropWrapper(fakeElem) - as MockHTMLIFrameElement; - + final web.HTMLIFrameElement fakeIFrame = web.HTMLIFrameElement(); final WebWebViewPlatformController controller = - WebWebViewPlatformController( - mockElement, - ); - final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.headers) - .thenReturn({'content-type': 'text/plain'}); + WebWebViewPlatformController(fakeIFrame); + + final web.Response fakeResponse = web.Response( + 'test data'.toJS, + { + 'headers': { + 'content-type': 'text/plain', + }, + }.jsify()! as web.ResponseInit); - when(mockHttpRequest.body).thenReturn('test data'); final MockHttpRequestFactory mockHttpRequestFactory = MockHttpRequestFactory(); when(mockHttpRequestFactory.request( @@ -146,8 +118,10 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(fakeResponse)); + controller.httpRequestFactory = mockHttpRequestFactory; + // Run await controller.loadRequest( WebViewRequest( @@ -163,26 +137,25 @@ void main() { requestHeaders: {'Foo': 'Bar'}, sendData: Uint8List.fromList('test body'.codeUnits), )); - verify(mockElement.src = + + expect(fakeIFrame.src, 'data:;charset=utf-8,${Uri.encodeFull('test data')}'); }); test('loadRequest escapes "#" correctly', () async { // Setup - final MockFakeIFrameElement fakeElem = MockFakeIFrameElement(); - final MockHTMLIFrameElement mockElement = - createJSInteropWrapper(fakeElem) - as MockHTMLIFrameElement; - + final web.HTMLIFrameElement fakeIFrame = web.HTMLIFrameElement(); final WebWebViewPlatformController controller = - WebWebViewPlatformController( - mockElement, - ); - final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.headers) - .thenReturn({'content-type': 'text/html'}); + WebWebViewPlatformController(fakeIFrame); + + final web.Response fakeResponse = web.Response( + '#'.toJS, + { + 'headers': { + 'content-type': 'text/html', + }, + }.jsify()! as web.ResponseInit); - when(mockHttpRequest.body).thenReturn('#'); final MockHttpRequestFactory mockHttpRequestFactory = MockHttpRequestFactory(); when(mockHttpRequestFactory.request( @@ -190,8 +163,10 @@ void main() { method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(fakeResponse)); + controller.httpRequestFactory = mockHttpRequestFactory; + // Run await controller.loadRequest( WebViewRequest( @@ -200,8 +175,8 @@ void main() { body: Uint8List.fromList('test body'.codeUnits), headers: {'Foo': 'Bar'}), ); - // Verify - verify(mockElement.src = argThat(contains('%23'))); + + expect(fakeIFrame.src, contains('%23')); }); }); }); diff --git a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart index 7c2180519a8..c7a7245279e 100644 --- a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.dart @@ -3,20 +3,20 @@ // found in the LICENSE file. import 'dart:convert'; +import 'dart:js_interop'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:http/http.dart' as http; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; +import 'package:web/web.dart' as web; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'package:webview_flutter_web/webview_flutter_web.dart'; import 'web_webview_controller_test.mocks.dart'; @GenerateMocks([], customMocks: >[ - MockSpec(onMissingStub: OnMissingStub.returnDefault), MockSpec(onMissingStub: OnMissingStub.returnDefault), ]) void main() { @@ -105,18 +105,20 @@ void main() { httpRequestFactory: mockHttpRequestFactory, )); - final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.headers) - .thenReturn({'content-type': 'text/plain'}); - - when(mockHttpRequest.body).thenReturn('test data'); + final web.Response fakeResponse = web.Response( + 'test data'.toJS, + { + 'headers': { + 'content-type': 'text/plain', + }, + }.jsify()! as web.ResponseInit); when(mockHttpRequestFactory.request( any, method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(fakeResponse)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), @@ -147,19 +149,21 @@ void main() { )); final Encoding iso = Encoding.getByName('latin1')!; - final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.body) - .thenReturn(String.fromCharCodes(iso.encode('España'))); - when(mockHttpRequest.headers).thenReturn( - {'content-type': 'Text/HTmL; charset=latin1'}); + final web.Response fakeResponse = web.Response( + String.fromCharCodes(iso.encode('España')).toJS, + { + 'headers': { + 'content-type': 'Text/HTmL; charset=latin1', + }, + }.jsify()! as web.ResponseInit); when(mockHttpRequestFactory.request( any, method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(fakeResponse)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), @@ -180,17 +184,20 @@ void main() { httpRequestFactory: mockHttpRequestFactory, )); - final MockResponse mockHttpRequest = MockResponse(); - when(mockHttpRequest.headers) - .thenReturn({'content-type': 'text/html'}); + final web.Response fakeResponse = web.Response( + '#'.toJS, + { + 'headers': { + 'content-type': 'text/html', + }, + }.jsify()! as web.ResponseInit); - when(mockHttpRequest.body).thenReturn('#'); when(mockHttpRequestFactory.request( any, method: anyNamed('method'), requestHeaders: anyNamed('requestHeaders'), sendData: anyNamed('sendData'), - )).thenAnswer((_) => Future.value(mockHttpRequest)); + )).thenAnswer((_) => Future.value(fakeResponse)); await controller.loadRequest(LoadRequestParams( uri: Uri.parse('https://flutter.dev'), From e01a712c08e28f8def9bb11e5689d8c13e845d81 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 8 Jul 2024 20:19:12 -0700 Subject: [PATCH 17/20] Regenerate/clean mocks. --- .../test/legacy/mock_fake_iframe_element.dart | 17 --- .../webview_flutter_web_test.mocks.dart | 126 ++++-------------- .../web_webview_controller_test.mocks.dart | 82 ++---------- 3 files changed, 41 insertions(+), 184 deletions(-) delete mode 100644 packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart deleted file mode 100644 index 4541f31f6cd..00000000000 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/mock_fake_iframe_element.dart +++ /dev/null @@ -1,17 +0,0 @@ -// 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:js_interop'; -import 'package:web/web.dart' as html; - -@JSExport() -class FakeIFrameElement { - @JSExport('src') - String? src; -} - -extension type MockHTMLIFrameElement(JSObject _) - implements html.HTMLIFrameElement, JSObject { - external set src(String? value); - external String? get src; -} diff --git a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart index 9cdc8b2511c..896f9e397f0 100644 --- a/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_web/test/legacy/webview_flutter_web_test.mocks.dart @@ -3,22 +3,18 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i9; -import 'dart:typed_data' as _i11; +import 'dart:async' as _i7; +import 'dart:typed_data' as _i9; import 'package:flutter/foundation.dart' as _i3; -import 'package:flutter/src/widgets/notification_listener.dart' as _i6; +import 'package:flutter/src/widgets/notification_listener.dart' as _i4; import 'package:flutter/widgets.dart' as _i2; -import 'package:http/http.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i12; import 'package:webview_flutter_platform_interface/src/legacy/platform_interface/webview_platform_callbacks_handler.dart' - as _i8; + as _i6; import 'package:webview_flutter_platform_interface/src/legacy/types/types.dart' - as _i7; -import 'package:webview_flutter_web/src/http_request_factory.dart' as _i10; - -import 'mock_fake_iframe_element.dart' as _i5; + as _i5; +import 'package:webview_flutter_web/src/http_request_factory.dart' as _i8; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -80,8 +76,8 @@ class _FakeDiagnosticsNode_2 extends _i1.SmartFake super.toString(); } -class _FakeResponse_3 extends _i1.SmartFake implements _i4.Response { - _FakeResponse_3( +class _FakeObject_3 extends _i1.SmartFake implements Object { + _FakeObject_3( Object parent, Invocation parentInvocation, ) : super( @@ -90,24 +86,6 @@ class _FakeResponse_3 extends _i1.SmartFake implements _i4.Response { ); } -/// A class which mocks [FakeIFrameElement]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockFakeIFrameElement extends _i1.Mock implements _i5.FakeIFrameElement { - MockFakeIFrameElement() { - _i1.throwOnMissingStub(this); - } - - @override - set src(String? _src) => super.noSuchMethod( - Invocation.setter( - #src, - _src, - ), - returnValueForMissingStub: null, - ); -} - /// A class which mocks [BuildContext]. /// /// See the documentation for Mockito's code generation for more information. @@ -178,7 +156,7 @@ class MockBuildContext extends _i1.Mock implements _i2.BuildContext { ); @override - void dispatchNotification(_i6.Notification? notification) => + void dispatchNotification(_i4.Notification? notification) => super.noSuchMethod( Invocation.method( #dispatchNotification, @@ -261,7 +239,7 @@ class MockBuildContext extends _i1.Mock implements _i2.BuildContext { /// A class which mocks [CreationParams]. /// /// See the documentation for Mockito's code generation for more information. -class MockCreationParams extends _i1.Mock implements _i7.CreationParams { +class MockCreationParams extends _i1.Mock implements _i5.CreationParams { MockCreationParams() { _i1.throwOnMissingStub(this); } @@ -273,31 +251,31 @@ class MockCreationParams extends _i1.Mock implements _i7.CreationParams { ) as Set); @override - _i7.AutoMediaPlaybackPolicy get autoMediaPlaybackPolicy => + _i5.AutoMediaPlaybackPolicy get autoMediaPlaybackPolicy => (super.noSuchMethod( Invocation.getter(#autoMediaPlaybackPolicy), returnValue: - _i7.AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, - ) as _i7.AutoMediaPlaybackPolicy); + _i5.AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, + ) as _i5.AutoMediaPlaybackPolicy); @override - List<_i7.WebViewCookie> get cookies => (super.noSuchMethod( + List<_i5.WebViewCookie> get cookies => (super.noSuchMethod( Invocation.getter(#cookies), - returnValue: <_i7.WebViewCookie>[], - ) as List<_i7.WebViewCookie>); + returnValue: <_i5.WebViewCookie>[], + ) as List<_i5.WebViewCookie>); } /// A class which mocks [WebViewPlatformCallbacksHandler]. /// /// See the documentation for Mockito's code generation for more information. class MockWebViewPlatformCallbacksHandler extends _i1.Mock - implements _i8.WebViewPlatformCallbacksHandler { + implements _i6.WebViewPlatformCallbacksHandler { MockWebViewPlatformCallbacksHandler() { _i1.throwOnMissingStub(this); } @override - _i9.FutureOr onNavigationRequest({ + _i7.FutureOr onNavigationRequest({ required String? url, required bool? isForMainFrame, }) => @@ -310,8 +288,8 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock #isForMainFrame: isForMainFrame, }, ), - returnValue: _i9.Future.value(false), - ) as _i9.FutureOr); + returnValue: _i7.Future.value(false), + ) as _i7.FutureOr); @override void onPageStarted(String? url) => super.noSuchMethod( @@ -341,7 +319,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock ); @override - void onWebResourceError(_i7.WebResourceError? error) => super.noSuchMethod( + void onWebResourceError(_i5.WebResourceError? error) => super.noSuchMethod( Invocation.method( #onWebResourceError, [error], @@ -354,19 +332,19 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockHttpRequestFactory extends _i1.Mock - implements _i10.HttpRequestFactory { + implements _i8.HttpRequestFactory { MockHttpRequestFactory() { _i1.throwOnMissingStub(this); } @override - _i9.Future<_i4.Response> request( + _i7.Future request( String? url, { - String? method, - bool? withCredentials, + String? method = r'GET', + bool? withCredentials = false, String? mimeType, Map? requestHeaders, - _i11.Uint8List? sendData, + _i9.Uint8List? sendData, }) => (super.noSuchMethod( Invocation.method( @@ -380,7 +358,7 @@ class MockHttpRequestFactory extends _i1.Mock #sendData: sendData, }, ), - returnValue: _i9.Future<_i4.Response>.value(_FakeResponse_3( + returnValue: _i7.Future.value(_FakeObject_3( this, Invocation.method( #request, @@ -394,53 +372,5 @@ class MockHttpRequestFactory extends _i1.Mock }, ), )), - ) as _i9.Future<_i4.Response>); -} - -/// A class which mocks [Response]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockResponse extends _i1.Mock implements _i4.Response { - MockResponse() { - _i1.throwOnMissingStub(this); - } - - @override - _i11.Uint8List get bodyBytes => (super.noSuchMethod( - Invocation.getter(#bodyBytes), - returnValue: _i11.Uint8List(0), - ) as _i11.Uint8List); - - @override - String get body => (super.noSuchMethod( - Invocation.getter(#body), - returnValue: _i12.dummyValue( - this, - Invocation.getter(#body), - ), - ) as String); - - @override - int get statusCode => (super.noSuchMethod( - Invocation.getter(#statusCode), - returnValue: 0, - ) as int); - - @override - Map get headers => (super.noSuchMethod( - Invocation.getter(#headers), - returnValue: {}, - ) as Map); - - @override - bool get isRedirect => (super.noSuchMethod( - Invocation.getter(#isRedirect), - returnValue: false, - ) as bool); - - @override - bool get persistentConnection => (super.noSuchMethod( - Invocation.getter(#persistentConnection), - returnValue: false, - ) as bool); + ) as _i7.Future); } diff --git a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart index ca0f0c188af..87fe1defb11 100644 --- a/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_web/test/web_webview_controller_test.mocks.dart @@ -3,13 +3,11 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i6; -import 'dart:typed_data' as _i3; +import 'dart:async' as _i3; +import 'dart:typed_data' as _i4; -import 'package:http/src/response.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i4; -import 'package:webview_flutter_web/src/http_request_factory.dart' as _i5; +import 'package:webview_flutter_web/src/http_request_factory.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -24,8 +22,8 @@ import 'package:webview_flutter_web/src/http_request_factory.dart' as _i5; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { - _FakeResponse_0( +class _FakeObject_0 extends _i1.SmartFake implements Object { + _FakeObject_0( Object parent, Invocation parentInvocation, ) : super( @@ -34,72 +32,19 @@ class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { ); } -/// A class which mocks [Response]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockResponse extends _i1.Mock implements _i2.Response { - @override - _i3.Uint8List get bodyBytes => (super.noSuchMethod( - Invocation.getter(#bodyBytes), - returnValue: _i3.Uint8List(0), - returnValueForMissingStub: _i3.Uint8List(0), - ) as _i3.Uint8List); - - @override - String get body => (super.noSuchMethod( - Invocation.getter(#body), - returnValue: _i4.dummyValue( - this, - Invocation.getter(#body), - ), - returnValueForMissingStub: _i4.dummyValue( - this, - Invocation.getter(#body), - ), - ) as String); - - @override - int get statusCode => (super.noSuchMethod( - Invocation.getter(#statusCode), - returnValue: 0, - returnValueForMissingStub: 0, - ) as int); - - @override - Map get headers => (super.noSuchMethod( - Invocation.getter(#headers), - returnValue: {}, - returnValueForMissingStub: {}, - ) as Map); - - @override - bool get isRedirect => (super.noSuchMethod( - Invocation.getter(#isRedirect), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - - @override - bool get persistentConnection => (super.noSuchMethod( - Invocation.getter(#persistentConnection), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); -} - /// A class which mocks [HttpRequestFactory]. /// /// See the documentation for Mockito's code generation for more information. class MockHttpRequestFactory extends _i1.Mock - implements _i5.HttpRequestFactory { + implements _i2.HttpRequestFactory { @override - _i6.Future<_i2.Response> request( + _i3.Future request( String? url, { - String? method, - bool? withCredentials, + String? method = r'GET', + bool? withCredentials = false, String? mimeType, Map? requestHeaders, - _i3.Uint8List? sendData, + _i4.Uint8List? sendData, }) => (super.noSuchMethod( Invocation.method( @@ -113,7 +58,7 @@ class MockHttpRequestFactory extends _i1.Mock #sendData: sendData, }, ), - returnValue: _i6.Future<_i2.Response>.value(_FakeResponse_0( + returnValue: _i3.Future.value(_FakeObject_0( this, Invocation.method( #request, @@ -127,8 +72,7 @@ class MockHttpRequestFactory extends _i1.Mock }, ), )), - returnValueForMissingStub: - _i6.Future<_i2.Response>.value(_FakeResponse_0( + returnValueForMissingStub: _i3.Future.value(_FakeObject_0( this, Invocation.method( #request, @@ -142,5 +86,5 @@ class MockHttpRequestFactory extends _i1.Mock }, ), )), - ) as _i6.Future<_i2.Response>); + ) as _i3.Future); } From befc2d8096774344340a9ecef3851a1c582d8e20 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 8 Jul 2024 20:22:28 -0700 Subject: [PATCH 18/20] Remove webview_flutter_web from Wasm exclusion list. --- script/configs/exclude_all_packages_app_wasm.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/script/configs/exclude_all_packages_app_wasm.yaml b/script/configs/exclude_all_packages_app_wasm.yaml index d10cdbf6ff2..2f96224d678 100644 --- a/script/configs/exclude_all_packages_app_wasm.yaml +++ b/script/configs/exclude_all_packages_app_wasm.yaml @@ -8,7 +8,6 @@ # Packages that aren't migrated yet. # https://github.com/flutter/flutter/issues/117022 - camera -- webview_flutter # Dependencies are not migrated yet # https://github.com/flutter/flutter/issues/148624 From ba4a2e5f112e18df06eeb3a9450b2d66da41e447 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Mon, 8 Jul 2024 20:29:24 -0700 Subject: [PATCH 19/20] Roll a full minor version. Update CHANGELOG. --- .../webview_flutter/webview_flutter_web/CHANGELOG.md | 9 ++++----- .../webview_flutter/webview_flutter_web/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/CHANGELOG.md b/packages/webview_flutter/webview_flutter_web/CHANGELOG.md index 0c7a525a377..6bdb9145ff9 100644 --- a/packages/webview_flutter/webview_flutter_web/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_web/CHANGELOG.md @@ -1,10 +1,9 @@ -## 0.2.2+5 +## 0.2.3 * Migrates to `package:web` -* Updates `HttpRequestFactory.request` to use `package:http` `BrowserClient` -* Updates `ìndex.html` in the example to use `flutter_bootstrap.js` -* Updates minimum dart sdk to `^3.3.0` -* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2. +* Updates `HttpRequestFactory.request` to use the Fetch API. +* Updates `index.html` in the example to use `flutter_bootstrap.js` +* Updates minimum supported SDK version to Flutter 3.16/Dart 3.3. ## 0.2.2+4 diff --git a/packages/webview_flutter/webview_flutter_web/pubspec.yaml b/packages/webview_flutter/webview_flutter_web/pubspec.yaml index 8a9f969718e..c10c125030e 100644 --- a/packages/webview_flutter/webview_flutter_web/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_web/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_web description: A Flutter plugin that provides a WebView widget on web. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_web issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 0.2.2+5 +version: 0.2.3 environment: sdk: ^3.3.0 From da0b90308c8d10969c51b93f8ac9ab410a2c937b Mon Sep 17 00:00:00 2001 From: David Iglesias Date: Tue, 9 Jul 2024 11:25:31 -0700 Subject: [PATCH 20/20] Apply suggestions from code review Co-authored-by: Navaron Bracke --- .../webview_flutter_web/lib/src/http_request_factory.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart index 1d9eefc4183..1540e547c02 100644 --- a/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart +++ b/packages/webview_flutter/webview_flutter_web/lib/src/http_request_factory.dart @@ -24,7 +24,7 @@ class HttpRequestFactory { /// /// The Future is completed when the [web.Response] is available. /// - /// If specified, `sendData` will be sent as the `body` of the fetch. + /// If specified, [sendData] will be sent as the `body` of the fetch. /// /// The [withCredentials] parameter specified that credentials such as a cookie /// (already) set in the header or @@ -55,7 +55,7 @@ class HttpRequestFactory { /// // Do something with the response. /// }); /// - /// Requests for file:// URIs are only supported by Chrome extensions + /// Requests for `file://` URIs are only supported by Chrome extensions /// with appropriate permissions in their manifest. Requests to file:// URIs /// will also never fail- the Future will always complete successfully, even /// when the file cannot be found.