66import 'dart:html' as html;
77import 'dart:js_util' as js_util;
88import 'dart:typed_data' ;
9- import 'dart:convert' hide Codec;
109
1110import 'package:quiver/testing/async.dart' ;
1211import 'package:test/bootstrap/browser.dart' ;
@@ -18,14 +17,6 @@ void main() {
1817 internalBootstrapBrowserTest (() => testMain);
1918}
2019
21- ByteData _toByteData (List <int > bytes) {
22- final ByteData byteData = ByteData (bytes.length);
23- for (int i = 0 ; i < bytes.length; i++ ) {
24- byteData.setUint8 (i, bytes[i]);
25- }
26- return byteData;
27- }
28-
2920void testMain () {
3021 group ('Keyboard' , () {
3122 /// Used to save and restore [ui.window.onPlatformMessage] after each test.
@@ -236,21 +227,13 @@ void testMain() {
236227 });
237228
238229 test ('prevents default when key is handled by the framework' , () {
239- ByteData _toByteData (List <int > bytes) {
240- final ByteData byteData = ByteData (bytes.length);
241- for (int i = 0 ; i < bytes.length; i++ ) {
242- byteData.setUint8 (i, bytes[i]);
243- }
244- return byteData;
245- }
246-
247230 Keyboard .initialize ();
248231
249232 int count = 0 ;
250233 ui.window.onPlatformMessage = (String channel, ByteData data,
251234 ui.PlatformMessageResponseCallback callback) {
252235 count += 1 ;
253- ByteData response = _toByteData (utf8. encode (json. encode ( < String , dynamic > {'handled' : true })) );
236+ ByteData response = const JSONMessageCodec (). encodeMessage ( < String , dynamic > {'handled' : true });
254237 callback (response);
255238 };
256239
@@ -273,7 +256,7 @@ void testMain() {
273256 ui.window.onPlatformMessage = (String channel, ByteData data,
274257 ui.PlatformMessageResponseCallback callback) {
275258 count += 1 ;
276- ByteData response = _toByteData (utf8. encode (json. encode ( < String , dynamic > {'handled' : false })) );
259+ ByteData response = const JSONMessageCodec (). encodeMessage ( < String , dynamic > {'handled' : false });
277260 callback (response);
278261 };
279262
@@ -320,7 +303,7 @@ void testMain() {
320303 ui.window.onPlatformMessage = (String channel, ByteData data,
321304 ui.PlatformMessageResponseCallback callback) {
322305 count += 1 ;
323- ByteData response = _toByteData (utf8. encode (json. encode ( < String , dynamic > {'handled' : true })) );
306+ ByteData response = const JSONMessageCodec (). encodeMessage ( < String , dynamic > {'handled' : true });
324307 callback (response);
325308 };
326309
0 commit comments