semantics_test.dart 2.62 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2015 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 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

9
import 'semantics_tester.dart';
10 11 12

void main() {
  testWidgets('Semantics shutdown and restart', (WidgetTester tester) async {
13 14 15 16 17 18
    SemanticsTester semantics = new SemanticsTester(tester);

    TestSemantics expectedSemantics = new TestSemantics(
      id: 0,
      label: 'test1',
    );
19 20 21 22 23 24 25 26 27 28

    await tester.pumpWidget(
      new Container(
        child: new Semantics(
          label: 'test1',
          child: new Container()
        )
      )
    );

29
    expect(semantics, hasSemantics(expectedSemantics));
30

31 32
    semantics.dispose();
    semantics = null;
33 34

    expect(tester.binding.hasScheduledFrame, isFalse);
35
    semantics = new SemanticsTester(tester);
36 37 38
    expect(tester.binding.hasScheduledFrame, isTrue);
    await tester.pump();

39 40
    expect(semantics, hasSemantics(expectedSemantics));
    semantics.dispose();
41
  });
42 43

  testWidgets('Detach and reattach assert', (WidgetTester tester) async {
44
    SemanticsTester semantics = new SemanticsTester(tester);
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    GlobalKey key = new GlobalKey();

    await tester.pumpWidget(
      new Container(
        child: new Semantics(
          label: 'test1',
          child: new Semantics(
            key: key,
            container: true,
            label: 'test2a',
            child: new Container()
          )
        )
      )
    );

61 62 63 64 65 66 67 68 69 70 71 72
    expect(semantics, hasSemantics(
      new TestSemantics(
        id: 0,
        label: 'test1',
        children: <TestSemantics>[
          new TestSemantics(
            id: 1,
            label: 'test2a',
          )
        ]
      )
    ));
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

    await tester.pumpWidget(
      new Container(
        child: new Semantics(
          label: 'test1',
          child: new Semantics(
            container: true,
            label: 'middle',
            child: new Semantics(
              key: key,
              container: true,
              label: 'test2b',
              child: new Container()
            )
          )
        )
      )
    );

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    expect(semantics, hasSemantics(
      new TestSemantics(
        id: 0,
        label: 'test1',
        children: <TestSemantics>[
          new TestSemantics(
            id: 2,
            label: 'middle',
            children: <TestSemantics>[
              new TestSemantics(
                id: 1,
                label: 'test2b',
              )
            ]
          )
        ]
      )
    ));
110

111
    semantics.dispose();
112
  });
113
}