semantics_service_test.dart 1.31 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart' show SystemChannels;
7
import 'package:flutter_test/flutter_test.dart';
8 9

void main() {
10 11
  TestWidgetsFlutterBinding.ensureInitialized();

12
  test('Semantic announcement', () async {
13
    final List<Map<dynamic, dynamic>> log = <Map<dynamic, dynamic>>[];
14

15
    Future<dynamic> handleMessage(dynamic mockMessage) async {
16
      final Map<dynamic, dynamic> message = mockMessage as Map<dynamic, dynamic>;
17
      log.add(message);
18 19
    }

20
    TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, handleMessage);
21 22

    await SemanticsService.announce('announcement 1', TextDirection.ltr);
23
    await SemanticsService.announce('announcement 2', TextDirection.rtl, assertiveness: Assertiveness.assertive);
24
    expect(log, equals(<Map<String, dynamic>>[
25
      <String, dynamic>{'type': 'announce', 'data': <String, dynamic>{'message': 'announcement 1', 'textDirection': 1}},
26
      <String, dynamic>{'type': 'announce', 'data': <String, dynamic>{'message': 'announcement 2', 'textDirection': 0, 'assertiveness': 1}},
27 28 29
    ]));
  });
}