@@ -54,17 +54,33 @@ void main() {
54
54
verify (mockElement.src = 'test url' );
55
55
});
56
56
57
- test ('loadHtmlString loads html into iframe' , () {
58
- // Setup
59
- final MockIFrameElement mockElement = MockIFrameElement ();
60
- final WebWebViewPlatformController controller =
61
- WebWebViewPlatformController (
62
- mockElement,
63
- );
64
- // Run
65
- controller.loadHtmlString ('test html' );
66
- // Verify
67
- verify (mockElement.src = 'data:text/html,${Uri .encodeFull ('test html' )}' );
57
+ group ('loadHtmlString' , () {
58
+ test ('loadHtmlString loads html into iframe' , () {
59
+ // Setup
60
+ final MockIFrameElement mockElement = MockIFrameElement ();
61
+ final WebWebViewPlatformController controller =
62
+ WebWebViewPlatformController (
63
+ mockElement,
64
+ );
65
+ // Run
66
+ controller.loadHtmlString ('test html' );
67
+ // Verify
68
+ verify (mockElement.src =
69
+ 'data:text/html;charset=utf-8,${Uri .encodeFull ('test html' )}' );
70
+ });
71
+
72
+ test ('loadHtmlString escapes "#" correctly' , () {
73
+ // Setup
74
+ final MockIFrameElement mockElement = MockIFrameElement ();
75
+ final WebWebViewPlatformController controller =
76
+ WebWebViewPlatformController (
77
+ mockElement,
78
+ );
79
+ // Run
80
+ controller.loadHtmlString ('#' );
81
+ // Verify
82
+ verify (mockElement.src = argThat (contains ('%23' )));
83
+ });
68
84
});
69
85
70
86
group ('loadRequest' , () {
@@ -122,8 +138,40 @@ void main() {
122
138
requestHeaders: < String , String > {'Foo' : 'Bar' },
123
139
sendData: Uint8List .fromList ('test body' .codeUnits),
124
140
));
125
- verify (
126
- mockElement.src = 'data:text/plain,${Uri .encodeFull ('test data' )}' );
141
+ verify (mockElement.src =
142
+ 'data:;charset=utf-8,${Uri .encodeFull ('test data' )}' );
143
+ });
144
+
145
+ test ('loadRequest escapes "#" correctly' , () async {
146
+ // Setup
147
+ final MockIFrameElement mockElement = MockIFrameElement ();
148
+ final WebWebViewPlatformController controller =
149
+ WebWebViewPlatformController (
150
+ mockElement,
151
+ );
152
+ final MockHttpRequest mockHttpRequest = MockHttpRequest ();
153
+ when (mockHttpRequest.getResponseHeader ('content-type' ))
154
+ .thenReturn ('text/html' );
155
+ when (mockHttpRequest.responseText).thenReturn ('#' );
156
+ final MockHttpRequestFactory mockHttpRequestFactory =
157
+ MockHttpRequestFactory ();
158
+ when (mockHttpRequestFactory.request (
159
+ any,
160
+ method: anyNamed ('method' ),
161
+ requestHeaders: anyNamed ('requestHeaders' ),
162
+ sendData: anyNamed ('sendData' ),
163
+ )).thenAnswer ((_) => Future <HttpRequest >.value (mockHttpRequest));
164
+ controller.httpRequestFactory = mockHttpRequestFactory;
165
+ // Run
166
+ await controller.loadRequest (
167
+ WebViewRequest (
168
+ uri: Uri .parse ('https://flutter.dev' ),
169
+ method: WebViewRequestMethod .post,
170
+ body: Uint8List .fromList ('test body' .codeUnits),
171
+ headers: < String , String > {'Foo' : 'Bar' }),
172
+ );
173
+ // Verify
174
+ verify (mockElement.src = argThat (contains ('%23' )));
127
175
});
128
176
});
129
177
});
0 commit comments