flutter_flutter/packages/flutter/test/widget/semantics_debugger_test.dart
Adam Barth 63eedb7677 Semantics debugger shouldn't crash when reparenting nodes (#4782)
Our previous approach to detecting when we needed to remove semantics nodes
didn't account for reparenting.
2016-06-28 14:44:02 -07:00

110 lines
2.9 KiB
Dart

// 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';
void main() {
testWidgets('SemanticsDebugger smoke test', (WidgetTester tester) async {
// This is a smoketest to verify that adding a debugger doesn't crash.
await tester.pumpWidget(
new Stack(
children: <Widget>[
new Semantics(),
new Semantics(
container: true
),
new Semantics(
label: 'label'
),
]
)
);
await tester.pumpWidget(
new SemanticsDebugger(
child: new Stack(
children: <Widget>[
new Semantics(),
new Semantics(
container: true
),
new Semantics(
label: 'label'
),
]
)
)
);
expect(true, isTrue); // expect that we reach here without crashing
});
testWidgets('SemanticsDebugger reparents subtree', (WidgetTester tester) async {
GlobalKey key = new GlobalKey();
await tester.pumpWidget(
new SemanticsDebugger(
child: new Stack(
children: <Widget>[
new Semantics(label: 'label1'),
new Positioned(
key: key, left: 0.0, top: 0.0, width: 100.0, height: 100.0,
child: new Semantics(label: 'label2')
),
]
)
)
);
await tester.pumpWidget(
new SemanticsDebugger(
child: new Stack(
children: <Widget>[
new Semantics(label: 'label1'),
new Semantics(
container: true,
child: new Stack(
children: <Widget>[
new Positioned(
key: key, left: 0.0, top: 0.0, width: 100.0, height: 100.0,
child: new Semantics(label: 'label2')
),
new Semantics(label: 'label3'),
]
)
)
]
)
)
);
await tester.pumpWidget(
new SemanticsDebugger(
child: new Stack(
children: <Widget>[
new Semantics(label: 'label1'),
new Semantics(
container: true,
child: new Stack(
children: <Widget>[
new Positioned(
key: key, left: 0.0, top: 0.0, width: 100.0, height: 100.0,
child: new Semantics(label: 'label2')
),
new Semantics(label: 'label3'),
new Semantics(label: 'label4'),
]
)
)
]
)
)
);
expect(tester.takeException(), isNull);
});
}