flutter/packages/flutter/test/widgets/semantics_merge_test.dart
Michael Goderbauer 8a6e973739
Remove semantics boundary from gesture detector AND MORE (#13983)
`RenderSemanticsGestureHandler` is no longer a semantics boundary, which allows us to correctly mark disabled buttons as disabled without having their semantics size and semantics node id change unexpectedly.

Fixes https://github.com/flutter/flutter/issues/12589.
Fixes https://github.com/flutter/flutter/issues/11991.
See also https://github.com/flutter/flutter/issues/11993.

This change also required some refactoring to how we deal with `twoPaneSemantics` scrolling as it previously relied on `RenderSemanticsGestureHandler` being a semantics boundary. This should also make the underlying logic easier to understand.

In addition, the following minor changes are included in this PR:
* Removal of orphaned and unused `SemanticsConfiguration.isMergingDescendantsIntoOneNode`.
* Logic optimizations for `markNeedsSemanticsUpdate` .
* Fix for edge case where `MergeSemantics` failed to merge semantics.
* Use of emojis to better indicate leaf merging in the printed semantics tree.
* Better assert message for adding invisible child semantics nodes.
* Make some semantics tests robuster by not relying on creation order of SemanticsNode ids across test boundaries.

Fixes https://github.com/flutter/flutter/issues/13943.
2018-01-09 13:31:59 -08:00

164 lines
4.1 KiB
Dart

// 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 SemanticsFlag;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'semantics_tester.dart';
void main() {
setUp(() {
debugResetSemanticsIdCounter();
});
testWidgets('MergeSemantics', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
// not merged
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Row(
children: <Widget>[
new Semantics(
container: true,
child: const Text('test1'),
),
new Semantics(
container: true,
child: const Text('test2'),
),
],
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(id: 1, label: 'test1'),
new TestSemantics.rootChild(id: 2, label: 'test2'),
],
),
ignoreRect: true,
ignoreTransform: true,
));
// merged
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new MergeSemantics(
child: new Row(
children: <Widget>[
new Semantics(
container: true,
child: const Text('test1'),
),
new Semantics(
container: true,
child: const Text('test2'),
),
],
),
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 3,
label: 'test1\ntest2',
),
]
),
ignoreRect: true,
ignoreTransform: true,
));
// not merged
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new Row(
children: <Widget>[
new Semantics(
container: true,
child: const Text('test1'),
),
new Semantics(
container: true,
child: const Text('test2'),
),
],
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(id: 6, label: 'test1'),
new TestSemantics.rootChild(id: 7, label: 'test2'),
],
),
ignoreRect: true,
ignoreTransform: true,
));
semantics.dispose();
});
testWidgets('MergeSemantics works if other nodes are implicitly merged into its node', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new MergeSemantics(
child: new Semantics(
selected: true, // this is implicitly merged into the MergeSemantics node
child: new Row(
children: <Widget>[
new Semantics(
container: true,
child: const Text('test1'),
),
new Semantics(
container: true,
child: const Text('test2'),
),
],
),
),
),
),
);
expect(semantics, hasSemantics(
new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
id: 1,
flags: <SemanticsFlag>[
SemanticsFlag.isSelected,
],
label: 'test1\ntest2',
),
]
),
ignoreRect: true,
ignoreTransform: true,
));
semantics.dispose();
});
}