22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5-
6- import 'package:web/helpers.dart' ;
7- import 'package:web/web.dart' as html;
85import 'dart:typed_data' ;
96
107import 'package:flutter/material.dart' ;
118import 'package:flutter_test/flutter_test.dart' ;
9+ import 'package:http/http.dart' as http;
1210import 'package:mockito/annotations.dart' ;
1311import 'package:mockito/mockito.dart' ;
12+ import 'package:web/web.dart' as html;
1413import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart' ;
1514import 'package:webview_flutter_web/src/http_request_factory.dart' ;
1615import 'package:webview_flutter_web/src/webview_flutter_web_legacy.dart' ;
@@ -23,7 +22,7 @@ import 'webview_flutter_web_test.mocks.dart';
2322 CreationParams ,
2423 WebViewPlatformCallbacksHandler ,
2524 HttpRequestFactory ,
26- html. XMLHttpRequest ,
25+ http. StreamedResponse ,
2726])
2827void main () {
2928 TestWidgetsFlutterBinding .ensureInitialized ();
@@ -47,7 +46,7 @@ void main() {
4746 group ('WebWebViewPlatformController' , () {
4847 test ('loadUrl sets url on iframe src attribute' , () {
4948 // Setup
50- final MockIFrameElement mockElement = MockIFrameElement ();
49+ final html. HTMLIFrameElement mockElement = html. HTMLIFrameElement ();
5150 final WebWebViewPlatformController controller =
5251 WebWebViewPlatformController (
5352 mockElement,
@@ -61,7 +60,7 @@ void main() {
6160 group ('loadHtmlString' , () {
6261 test ('loadHtmlString loads html into iframe' , () {
6362 // Setup
64- final MockIFrameElement mockElement = MockIFrameElement ();
63+ final html. HTMLIFrameElement mockElement = html. HTMLIFrameElement ();
6564 final WebWebViewPlatformController controller =
6665 WebWebViewPlatformController (
6766 mockElement,
@@ -75,22 +74,22 @@ void main() {
7574
7675 test ('loadHtmlString escapes "#" correctly' , () {
7776 // Setup
78- final MockIFrameElement mockElement = MockIFrameElement ();
77+ final html. HTMLIFrameElement mockElement = html. HTMLIFrameElement ();
7978 final WebWebViewPlatformController controller =
8079 WebWebViewPlatformController (
8180 mockElement,
8281 );
8382 // Run
8483 controller.loadHtmlString ('#' );
8584 // Verify
86- verify (mockElement.src = argThat (contains ('%23' )));
85+ verify (mockElement.src = argThat (contains ('%23' )) ?? '' );
8786 });
8887 });
8988
9089 group ('loadRequest' , () {
9190 test ('loadRequest throws ArgumentError on missing scheme' , () {
9291 // Setup
93- final MockIFrameElement mockElement = MockIFrameElement ();
92+ final html. HTMLIFrameElement mockElement = html. HTMLIFrameElement ();
9493 final WebWebViewPlatformController controller =
9594 WebWebViewPlatformController (
9695 mockElement,
@@ -109,23 +108,26 @@ void main() {
109108 test ('loadRequest makes request and loads response into iframe' ,
110109 () async {
111110 // Setup
112- final MockIFrameElement mockElement = MockIFrameElement ();
111+ final html. HTMLIFrameElement mockElement = html. HTMLIFrameElement ();
113112 final WebWebViewPlatformController controller =
114113 WebWebViewPlatformController (
115114 mockElement,
116115 );
117- final MockHttpRequest mockHttpRequest = MockHttpRequest ();
118- when (mockHttpRequest.getResponseHeader ('content-type' ))
119- .thenReturn ('text/plain' );
120- when (mockHttpRequest.responseText).thenReturn ('test data' );
116+ final MockStreamedResponse mockHttpRequest = MockStreamedResponse ();
117+ when (mockHttpRequest.headers['content-type' ]).thenReturn ('text/plain' );
118+
119+ final http.Response res =
120+ await http.Response .fromStream (mockHttpRequest);
121+ when (res.body).thenReturn ('test data' );
121122 final MockHttpRequestFactory mockHttpRequestFactory =
122123 MockHttpRequestFactory ();
123124 when (mockHttpRequestFactory.request (
124125 any,
125126 method: anyNamed ('method' ),
126127 requestHeaders: anyNamed ('requestHeaders' ),
127128 sendData: anyNamed ('sendData' ),
128- )).thenAnswer ((_) => Future <XMLHttpRequest >.value (mockHttpRequest));
129+ )).thenAnswer (
130+ (_) => Future <http.StreamedResponse >.value (mockHttpRequest));
129131 controller.httpRequestFactory = mockHttpRequestFactory;
130132 // Run
131133 await controller.loadRequest (
@@ -148,23 +150,26 @@ void main() {
148150
149151 test ('loadRequest escapes "#" correctly' , () async {
150152 // Setup
151- final MockIFrameElement mockElement = MockIFrameElement ();
153+ final html. HTMLIFrameElement mockElement = html. HTMLIFrameElement ();
152154 final WebWebViewPlatformController controller =
153155 WebWebViewPlatformController (
154156 mockElement,
155157 );
156- final MockHttpRequest mockHttpRequest = MockHttpRequest ();
157- when (mockHttpRequest.getResponseHeader ('content-type' ))
158- .thenReturn ('text/html' );
159- when (mockHttpRequest.responseText).thenReturn ('#' );
158+ final MockStreamedResponse mockHttpRequest = MockStreamedResponse ();
159+ when (mockHttpRequest.headers['content-type' ]).thenReturn ('text/html' );
160+
161+ final http.Response res =
162+ await http.Response .fromStream (mockHttpRequest);
163+ when (res.body).thenReturn ('#' );
160164 final MockHttpRequestFactory mockHttpRequestFactory =
161165 MockHttpRequestFactory ();
162166 when (mockHttpRequestFactory.request (
163167 any,
164168 method: anyNamed ('method' ),
165169 requestHeaders: anyNamed ('requestHeaders' ),
166170 sendData: anyNamed ('sendData' ),
167- )).thenAnswer ((_) => Future <XMLHttpRequest >.value (mockHttpRequest));
171+ )).thenAnswer (
172+ (_) => Future <http.StreamedResponse >.value (mockHttpRequest));
168173 controller.httpRequestFactory = mockHttpRequestFactory;
169174 // Run
170175 await controller.loadRequest (
@@ -175,7 +180,7 @@ void main() {
175180 headers: < String , String > {'Foo' : 'Bar' }),
176181 );
177182 // Verify
178- verify (mockElement.src = argThat (contains ('%23' )));
183+ verify (mockElement.src = argThat (contains ('%23' )) ?? '' );
179184 });
180185 });
181186 });
0 commit comments