semantics_service_test.dart 1.09 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui' show TextDirection;

import 'package:flutter/semantics.dart';
import 'package:flutter/services.dart' show SystemChannels;
9 10

import '../flutter_test_alternative.dart';
11 12 13

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

16
    SystemChannels.accessibility.setMockMessageHandler((Object mockMessage) async {
17
      final Map<dynamic, dynamic> message = mockMessage;
18 19 20 21 22 23 24 25 26 27 28 29
      log.add(message);
    });

    await SemanticsService.announce('announcement 1', TextDirection.ltr);
    await SemanticsService.announce('announcement 2', TextDirection.rtl);

    expect(log, equals(<Map<String, dynamic>>[
      <String, dynamic> {'type': 'announce', 'data': <String, dynamic> {'message': 'announcement 1', 'textDirection': 1}},
      <String, dynamic> {'type': 'announce', 'data': <String, dynamic> {'message': 'announcement 2', 'textDirection': 0}},
    ]));
  });
}