-
Notifications
You must be signed in to change notification settings - Fork 27.3k
/
platform_messages_test.dart
31 lines (24 loc) · 1.08 KB
/
platform_messages_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2014 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.
@TestOn('!chrome')
library;
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test('Mock binary message handler control test', () async {
final List<ByteData?> log = <ByteData>[];
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler('test1', (ByteData? message) async {
log.add(message);
return null;
});
final ByteData message = ByteData(2)..setUint16(0, 0xABCD);
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.send('test1', message);
expect(log, equals(<ByteData>[message]));
log.clear();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMessageHandler('test1', null);
await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.send('test1', message);
expect(log, isEmpty);
});
}